JackieTien97 commented on code in PR #14314:
URL: https://github.com/apache/iotdb/pull/14314#discussion_r1870926195
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/Coordinator.java:
##########
@@ -160,6 +169,7 @@ private Coordinator() {
LocalExecutionPlanner.getInstance().metadata, new
InternalTypeManager()))
.getPlanOptimizers();
this.accessControl = new AllowAllAccessControl();
+ this.dataNodeLocationSupplier = new
DataNodeLocationSupplierFactory().getSupplier();
Review Comment:
`DataNodeLocationSupplierFactory` should be a Util class which means its
constructor should be private. getSupplier should be a static method
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/optimizations/DataNodeLocationSupplierFactory.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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.db.queryengine.plan.relational.planner.optimizations;
+
+import org.apache.iotdb.common.rpc.thrift.TDataNodeLocation;
+import org.apache.iotdb.commons.client.exception.ClientManagerException;
+import org.apache.iotdb.commons.exception.IoTDBRuntimeException;
+import org.apache.iotdb.confignode.rpc.thrift.TGetDataNodeLocationsResp;
+import org.apache.iotdb.db.protocol.client.ConfigNodeClient;
+import org.apache.iotdb.db.protocol.client.ConfigNodeClientManager;
+import org.apache.iotdb.db.protocol.client.ConfigNodeInfo;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import org.apache.thrift.TException;
+
+import java.util.List;
+
+import static org.apache.iotdb.rpc.TSStatusCode.QUERY_PROCESS_ERROR;
+
+public class DataNodeLocationSupplierFactory {
+ private final DataNodeLocationSupplier supplier;
+
+ public DataNodeLocationSupplierFactory() {
+ this.supplier = new InformationSchemaTableDataNodeLocationSupplier();
+ }
+
+ public DataNodeLocationSupplier getSupplier() {
+ return supplier;
+ }
+
+ public interface DataNodeLocationSupplier {
+ List<TDataNodeLocation> getDataNodeLocations(String table);
+ }
+
+ private static class InformationSchemaTableDataNodeLocationSupplier
+ implements DataNodeLocationSupplier {
+
+ private List<TDataNodeLocation> getRunningDataNodeLocations() {
+ try (ConfigNodeClient client =
+
ConfigNodeClientManager.getInstance().borrowClient(ConfigNodeInfo.CONFIG_REGION_ID))
{
+ TGetDataNodeLocationsResp showDataNodesResp =
client.getRunningDataNodeLocations();
+ if (showDataNodesResp.getStatus().getCode()
+ != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+ throw new IoTDBRuntimeException(
+ "An error occurred when executing getRunningDataNodeLocations():"
+ + showDataNodesResp.getStatus().getMessage(),
+ QUERY_PROCESS_ERROR.getStatusCode());
+ }
+ return showDataNodesResp.getDataNodeLocationList();
+ } catch (ClientManagerException | TException e) {
+ throw new IoTDBRuntimeException(
+ "An error occurred when executing getRunningDataNodeLocations():"
+ e.getMessage(),
+ QUERY_PROCESS_ERROR.getStatusCode());
+ }
+ }
+
+ @Override
+ public List<TDataNodeLocation> getDataNodeLocations(String table) {
+ switch (table) {
+ case "queries":
Review Comment:
using CONSTANT instead.
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/optimizations/DataNodeLocationSupplierFactory.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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.db.queryengine.plan.relational.planner.optimizations;
+
+import org.apache.iotdb.common.rpc.thrift.TDataNodeLocation;
+import org.apache.iotdb.commons.client.exception.ClientManagerException;
+import org.apache.iotdb.commons.exception.IoTDBRuntimeException;
+import org.apache.iotdb.confignode.rpc.thrift.TGetDataNodeLocationsResp;
+import org.apache.iotdb.db.protocol.client.ConfigNodeClient;
+import org.apache.iotdb.db.protocol.client.ConfigNodeClientManager;
+import org.apache.iotdb.db.protocol.client.ConfigNodeInfo;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import org.apache.thrift.TException;
+
+import java.util.List;
+
+import static org.apache.iotdb.rpc.TSStatusCode.QUERY_PROCESS_ERROR;
+
+public class DataNodeLocationSupplierFactory {
+ private final DataNodeLocationSupplier supplier;
+
+ public DataNodeLocationSupplierFactory() {
+ this.supplier = new InformationSchemaTableDataNodeLocationSupplier();
+ }
+
+ public DataNodeLocationSupplier getSupplier() {
+ return supplier;
+ }
+
+ public interface DataNodeLocationSupplier {
+ List<TDataNodeLocation> getDataNodeLocations(String table);
+ }
+
+ private static class InformationSchemaTableDataNodeLocationSupplier
+ implements DataNodeLocationSupplier {
+
+ private List<TDataNodeLocation> getRunningDataNodeLocations() {
+ try (ConfigNodeClient client =
+
ConfigNodeClientManager.getInstance().borrowClient(ConfigNodeInfo.CONFIG_REGION_ID))
{
+ TGetDataNodeLocationsResp showDataNodesResp =
client.getRunningDataNodeLocations();
+ if (showDataNodesResp.getStatus().getCode()
+ != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+ throw new IoTDBRuntimeException(
+ "An error occurred when executing getRunningDataNodeLocations():"
+ + showDataNodesResp.getStatus().getMessage(),
+ QUERY_PROCESS_ERROR.getStatusCode());
+ }
+ return showDataNodesResp.getDataNodeLocationList();
+ } catch (ClientManagerException | TException e) {
+ throw new IoTDBRuntimeException(
+ "An error occurred when executing getRunningDataNodeLocations():"
+ e.getMessage(),
+ QUERY_PROCESS_ERROR.getStatusCode());
+ }
+ }
+
+ @Override
+ public List<TDataNodeLocation> getDataNodeLocations(String table) {
+ switch (table) {
+ case "queries":
+ return getRunningDataNodeLocations();
+ default:
+ throw new UnsupportedOperationException();
Review Comment:
add error msg.
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/InformationSchemaTableScanOperator.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.db.queryengine.execution.operator.source.relational;
+
+import org.apache.iotdb.db.queryengine.execution.MemoryEstimationHelper;
+import org.apache.iotdb.db.queryengine.execution.operator.OperatorContext;
+import
org.apache.iotdb.db.queryengine.execution.operator.source.SourceOperator;
+import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeId;
+
+import org.apache.tsfile.common.conf.TSFileDescriptor;
+import org.apache.tsfile.read.common.block.TsBlock;
+import org.apache.tsfile.utils.RamUsageEstimator;
+
+import java.util.Iterator;
+
+public class InformationSchemaTableScanOperator implements SourceOperator {
+
+ private final OperatorContext operatorContext;
+
+ private final PlanNodeId sourceId;
+
+ private final Iterator<TsBlock> contentSupplier;
+
+ private static final int DEFAULT_MAX_TSBLOCK_SIZE_IN_BYTES =
+ TSFileDescriptor.getInstance().getConfig().getMaxTsBlockSizeInBytes();
+
+ private static final long INSTANCE_SIZE =
+
RamUsageEstimator.shallowSizeOfInstance(InformationSchemaTableScanOperator.class);
+
+ public InformationSchemaTableScanOperator(
+ OperatorContext operatorContext, PlanNodeId sourceId, Iterator<TsBlock>
contentSupplier) {
+ this.operatorContext = operatorContext;
+ this.sourceId = sourceId;
+ this.contentSupplier = contentSupplier;
+ }
+
+ @Override
+ public OperatorContext getOperatorContext() {
+ return operatorContext;
+ }
+
+ @Override
+ public TsBlock next() throws Exception {
+ return contentSupplier.next();
+ }
+
+ @Override
+ public boolean hasNext() throws Exception {
+ return contentSupplier.hasNext();
+ }
+
+ @Override
+ public boolean isFinished() throws Exception {
+ return hasNext();
Review Comment:
```suggestion
return !hasNext();
```
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/InformationSchemaTable.java:
##########
@@ -0,0 +1,79 @@
+package org.apache.iotdb.db.queryengine.plan.relational.metadata;
+
+/*
+ * 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.
+ */
+
+import org.apache.iotdb.db.queryengine.common.header.ColumnHeaderConstant;
+
+import com.google.common.collect.ImmutableList;
+
+import java.util.Locale;
+import java.util.Optional;
+
+import static
org.apache.iotdb.commons.schema.table.column.TsTableColumnCategory.MEASUREMENT;
+import static
org.apache.iotdb.commons.schema.table.column.TsTableColumnCategory.TIME;
+import static org.apache.tsfile.read.common.type.FloatType.FLOAT;
+import static org.apache.tsfile.read.common.type.IntType.INT32;
+import static org.apache.tsfile.read.common.type.StringType.STRING;
+import static org.apache.tsfile.read.common.type.TimestampType.TIMESTAMP;
+
+public enum InformationSchemaTable {
Review Comment:
define it in
`iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table`,
because ConfigNode will also use it.
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/InformationSchemaContentSupplierFactory.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.db.queryengine.execution.operator.source.relational;
+
+import org.apache.iotdb.db.queryengine.plan.Coordinator;
+import org.apache.iotdb.db.queryengine.plan.execution.IQueryExecution;
+import
org.apache.iotdb.db.queryengine.plan.relational.metadata.QualifiedObjectName;
+
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.read.common.block.TsBlock;
+import org.apache.tsfile.read.common.block.TsBlockBuilder;
+import org.apache.tsfile.read.common.block.column.RunLengthEncodedColumn;
+import org.apache.tsfile.utils.BytesUtils;
+
+import java.util.Iterator;
+import java.util.List;
+
+import static
org.apache.iotdb.db.queryengine.plan.relational.metadata.InformationSchemaTable.QUERIES;
+
+public class InformationSchemaContentSupplierFactory {
+ public static Iterator<TsBlock> getSupplier(
+ QualifiedObjectName tableName, List<TSDataType> dataTypes) {
+ if (tableName.getObjectName().equals(QUERIES.getSchemaTableName())) {
+ return new Iterator<TsBlock>() {
+ private final TsBlockBuilder pageBuilder = new
TsBlockBuilder(dataTypes);
Review Comment:
```suggestion
private final TsBlockBuilder resultBuilder = new
TsBlockBuilder(dataTypes);
```
don't mistake Page in Trino
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/InformationSchemaContentSupplierFactory.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.db.queryengine.execution.operator.source.relational;
+
+import org.apache.iotdb.db.queryengine.plan.Coordinator;
+import org.apache.iotdb.db.queryengine.plan.execution.IQueryExecution;
+import
org.apache.iotdb.db.queryengine.plan.relational.metadata.QualifiedObjectName;
+
+import org.apache.tsfile.block.column.ColumnBuilder;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.read.common.block.TsBlock;
+import org.apache.tsfile.read.common.block.TsBlockBuilder;
+import org.apache.tsfile.read.common.block.column.RunLengthEncodedColumn;
+import org.apache.tsfile.utils.BytesUtils;
+
+import java.util.Iterator;
+import java.util.List;
+
+import static
org.apache.iotdb.db.queryengine.plan.relational.metadata.InformationSchemaTable.QUERIES;
+
+public class InformationSchemaContentSupplierFactory {
+ public static Iterator<TsBlock> getSupplier(
+ QualifiedObjectName tableName, List<TSDataType> dataTypes) {
+ if (tableName.getObjectName().equals(QUERIES.getSchemaTableName())) {
+ return new Iterator<TsBlock>() {
+ private final TsBlockBuilder pageBuilder = new
TsBlockBuilder(dataTypes);
+ private final ColumnBuilder[] columnBuilders =
pageBuilder.getValueColumnBuilders();
+
+ private final List<IQueryExecution> queryExecutions =
+ Coordinator.getInstance().getAllQueryExecutions();
+
+ private final long currTime = System.currentTimeMillis();
+
+ private final int totalSize = queryExecutions.size();
+ private int nextConsumedIndex;
+
+ @Override
+ public boolean hasNext() {
+ return nextConsumedIndex < totalSize;
+ }
+
+ @Override
+ public TsBlock next() {
+ while (nextConsumedIndex < totalSize && !pageBuilder.isFull()) {
+
+ IQueryExecution queryExecution =
queryExecutions.get(nextConsumedIndex);
+ String[] splits = queryExecution.getQueryId().split("_");
+ int dataNodeId = Integer.parseInt(splits[splits.length - 1]);
+
+
columnBuilders[0].writeLong(queryExecution.getStartExecutionTime());
+
columnBuilders[1].writeBinary(BytesUtils.valueOf(queryExecution.getQueryId()));
+ columnBuilders[2].writeInt(dataNodeId);
+ columnBuilders[3].writeFloat(
+ (float) (currTime - queryExecution.getStartExecutionTime()) /
1000);
+ columnBuilders[4].writeBinary(
+
BytesUtils.valueOf(queryExecution.getExecuteSQL().orElse("UNKNOWN")));
+
columnBuilders[5].writeBinary(BytesUtils.valueOf(queryExecution.getSQLDialect()));
+ pageBuilder.declarePosition();
+
+ nextConsumedIndex++;
+ }
+ TsBlock result =
+ pageBuilder.build(
+ new RunLengthEncodedColumn(
+ TableScanOperator.TIME_COLUMN_TEMPLATE,
pageBuilder.getPositionCount()));
+ pageBuilder.reset();
+ return result;
+ }
+ };
+
+ } else {
+ throw new UnsupportedOperationException();
Review Comment:
add some error msg, like "unknown table XXXX"
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java:
##########
@@ -90,7 +88,14 @@ public boolean tableExists(QualifiedObjectName name) {
@Override
public Optional<TableSchema> getTableSchema(SessionInfo session,
QualifiedObjectName name) {
- TsTable table = tableCache.getTable(name.getDatabaseName(),
name.getObjectName());
+ String databaseName = name.getDatabaseName();
+ String tableName = name.getObjectName();
+ // get TableSchema of internal table
+ if (databaseName.equals(INFORMATION_SCHEMA)) {
+ return InformationSchemaTable.getTableSchemaFromStringValue(tableName);
+ }
+
+ TsTable table = tableCache.getTable(databaseName, tableName);
Review Comment:
Actually you don't need to do this, @Caideyipi will take over it and will
handle it in `tableCache`.
@Caideyipi can remove this code block in your implementation
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/iterative/rule/PruneTableScanColumns.java:
##########
@@ -68,27 +70,43 @@ public static Optional<PlanNode> pruneColumns(TableScanNode
node, Set<Symbol> re
.forEach(symbol -> newAssignments.put(symbol,
node.getAssignments().get(symbol)));
}
- // add time entry if TimePredicate exists
- node.getTimePredicate()
- .ifPresent(
- timePredicate ->
- SymbolsExtractor.extractUnique(timePredicate)
- .forEach(
- symbol -> newAssignments.put(symbol,
node.getAssignments().get(symbol))));
+ if (node instanceof DeviceTableScanNode) {
+ DeviceTableScanNode deviceTableScanNode = (DeviceTableScanNode) node;
+ // add time entry if TimePredicate exists
+ deviceTableScanNode
+ .getTimePredicate()
+ .ifPresent(
+ timePredicate ->
+ SymbolsExtractor.extractUnique(timePredicate)
+ .forEach(
+ symbol -> newAssignments.put(symbol,
node.getAssignments().get(symbol))));
- return Optional.of(
- new TableScanNode(
- node.getPlanNodeId(),
- node.getQualifiedObjectName(),
- newOutputs,
- newAssignments,
- node.getDeviceEntries(),
- node.getIdAndAttributeIndexMap(),
- node.getScanOrder(),
- node.getTimePredicate().orElse(null),
- node.getPushDownPredicate(),
- node.getPushDownLimit(),
- node.getPushDownOffset(),
- node.isPushLimitToEachDevice()));
+ return Optional.of(
+ new DeviceTableScanNode(
+ deviceTableScanNode.getPlanNodeId(),
+ deviceTableScanNode.getQualifiedObjectName(),
+ newOutputs,
+ newAssignments,
+ deviceTableScanNode.getDeviceEntries(),
+ deviceTableScanNode.getIdAndAttributeIndexMap(),
+ deviceTableScanNode.getScanOrder(),
+ deviceTableScanNode.getTimePredicate().orElse(null),
+ deviceTableScanNode.getPushDownPredicate(),
+ deviceTableScanNode.getPushDownLimit(),
+ deviceTableScanNode.getPushDownOffset(),
+ deviceTableScanNode.isPushLimitToEachDevice()));
+ } else if (node instanceof InformationSchemaTableScanNode) {
+ return Optional.of(
+ new InformationSchemaTableScanNode(
+ node.getPlanNodeId(),
+ node.getQualifiedObjectName(),
+ newOutputs,
+ newAssignments,
+ node.getPushDownPredicate(),
+ node.getPushDownLimit(),
+ node.getPushDownOffset()));
+ } else {
+ throw new UnsupportedOperationException();
Review Comment:
add error msg, like "Unknown TableScanNode XXXX"(getSimpleName).
##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/MergeTreeSortOperatorTest.java:
##########
@@ -1838,6 +1838,11 @@ public String getStatementType() {
return null;
}
+ @Override
+ public String getSQLDialect() {
+ return null;
Review Comment:
better return IClientSession.SqlDialect.TREE
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]