Alima777 commented on a change in pull request #902: URL: https://github.com/apache/incubator-iotdb/pull/902#discussion_r495533642
########## File path: calcite/src/main/java/org/apache/iotdb/calcite/IoTDBSchema.java ########## @@ -0,0 +1,167 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iotdb.calcite; + +import com.google.common.collect.ImmutableMap; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.calcite.rel.type.RelDataTypeFactory; +import org.apache.calcite.rel.type.RelDataTypeImpl; +import org.apache.calcite.rel.type.RelDataTypeSystem; +import org.apache.calcite.rel.type.RelProtoDataType; +import org.apache.calcite.schema.SchemaPlus; +import org.apache.calcite.schema.Table; +import org.apache.calcite.schema.impl.AbstractSchema; +import org.apache.calcite.sql.type.SqlTypeFactoryImpl; +import org.apache.iotdb.db.exception.query.QueryProcessException; +import org.apache.iotdb.jdbc.Config; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class IoTDBSchema extends AbstractSchema { + + private static final Logger logger = LoggerFactory.getLogger(IoTDBSchema.class); + final Connection connection; + private Map<String, Table> tableMap; + private final SchemaPlus parentSchema; + final String name; + public static Map<String, List<String>> sgToDeviceMap = new HashMap<>(); + + /** + * Creates a IoTDB schema. + * + * @param host IoTDB host, e.g. "localhost" + * @param port IoTDB port, e.g. 6667 + * @param username IoTDB username + * @param password IoTDB password + */ + public IoTDBSchema(String host, int port, String username, String password, + SchemaPlus parentSchema, String name) { + super(); + try { + Class.forName(Config.JDBC_DRIVER_NAME); + this.connection = DriverManager + .getConnection(Config.IOTDB_URL_PREFIX + host + ":" + port + "/", username, password); + } catch (Exception e) { + throw new RuntimeException(e); + } + + this.parentSchema = parentSchema; + this.name = name; + } + + /** + * Generate the columns' names and data types in the given table. + * @param storageGroup the table name + * @return the columns' names and data types + */ + RelProtoDataType getRelDataType(String storageGroup) throws SQLException, QueryProcessException { Review comment: Hi, it's explained as follows in Calcite: > // Temporary type factory, just for the duration of this method. Allowable // because we're creating a proto-type, not a type; before being used, the // proto-type will be copied into a real type factory. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
