Alima777 commented on a change in pull request #902: URL: https://github.com/apache/incubator-iotdb/pull/902#discussion_r487775869
########## File path: calcite/src/main/java/org/apache/iotdb/calcite/IoTDBTable.java ########## @@ -0,0 +1,306 @@ +/* + * 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.ImmutableList; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import org.apache.calcite.adapter.java.AbstractQueryableTable; +import org.apache.calcite.linq4j.AbstractEnumerable; +import org.apache.calcite.linq4j.Enumerable; +import org.apache.calcite.linq4j.Enumerator; +import org.apache.calcite.linq4j.QueryProvider; +import org.apache.calcite.linq4j.Queryable; +import org.apache.calcite.linq4j.function.Function1; +import org.apache.calcite.plan.RelOptCluster; +import org.apache.calcite.plan.RelOptTable; +import org.apache.calcite.rel.RelNode; +import org.apache.calcite.rel.type.RelDataType; +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.TranslatableTable; +import org.apache.calcite.schema.impl.AbstractTableQueryable; +import org.apache.calcite.sql.type.SqlTypeFactoryImpl; +import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.calcite.util.Util; +import org.apache.iotdb.db.exception.query.QueryProcessException; + +public class IoTDBTable extends AbstractQueryableTable + implements TranslatableTable { + + RelProtoDataType protoRowType; + private final IoTDBSchema schema; + private final String storageGroup; + + public IoTDBTable(IoTDBSchema schema, String storageGroup) { + super(Object[].class); + this.schema = schema; + this.storageGroup = storageGroup; + } + + public String toString() { + return "IoTDBTable {" + storageGroup + "}"; + } + + @Override + public RelDataType getRowType(RelDataTypeFactory typeFactory) { + try { + if (protoRowType == null) { + protoRowType = schema.getRelDataType(storageGroup); + } + } catch (SQLException | QueryProcessException e) { + // print exception error here + e.printStackTrace(); + } + return protoRowType.apply(typeFactory); + } + + @Override + public <T> Queryable<T> asQueryable(QueryProvider queryProvider, SchemaPlus schema, + String tableName) { + return new IoTDBQueryable<>(queryProvider, schema, this, storageGroup); + } + + @Override + public RelNode toRel(RelOptTable.ToRelContext context, RelOptTable relOptTable) { + final RelOptCluster cluster = context.getCluster(); + return new IoTDBTableScan(cluster, cluster.traitSetOf(IoTDBRel.CONVENTION), + relOptTable, this, null); + } + + public Enumerable<Object> query(final Connection connection) { + return query(connection, ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), + ImmutableList.of(), 0, 0); Review comment: It's a default empty value of query() method. Actually, I don't know what's the function of this method exactly... I just referred to the Cassandra Adapter. I will appreciate that if you can explain it to me :) ---------------------------------------------------------------- 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]
