Alima777 commented on a change in pull request #902:
URL: https://github.com/apache/incubator-iotdb/pull/902#discussion_r495535581



##########
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:
       >  Generally, if i understand it correctly we map the whole storage 
group to a single table where we have one column for the device and then unroll 
all possible sensors of each device as a column, is that right?
   
   Yes, that's right.
   
   > This could be avoided in situations where the query is something like
   SELECT * FROM 'root.vehicles' where device = 'mycar' as we only have this 
single device there.
   
   As you mentioned, it does could be avoided in this situation. But before 
querying, we have to build a relational table here whose column data type has 
to be just one. The table will be validated by Calcite, in this situation which 
type of sensors should we adopt? 
   So I think the same sensor with different types should be avoided. If some 
queries are really needed, we can build a view in model file.
   




----------------------------------------------------------------
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]


Reply via email to