You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "Caideyipi (via GitHub)" <gi...@apache.org> on 2025/01/02 13:56:45 UTC

[PR] Added partial schema for tree device view [iotdb]

Caideyipi opened a new pull request, #14617:
URL: https://github.com/apache/iotdb/pull/14617

   ## Description
   As the title said.
   
   <!--
   In each section, please describe design decisions made, including:
    - Choice of algorithms
    - Behavioral aspects. What configuration values are acceptable? How are corner cases and error 
       conditions handled, such as when there are insufficient resources?
    - Class organization and design (how the logic is split between classes, inheritance, composition, 
       design patterns)
    - Method organization and design (how the logic is split between methods, parameters and return types)
    - Naming (class, method, API, configuration, HTTP endpoint, names of emitted metrics)
   -->
   
   
   <!-- It's good to describe an alternative design (or mention an alternative name) for every design 
   (or naming) decision point and compare the alternatives with the designs that you've implemented 
   (or the names you've chosen) to highlight the advantages of the chosen designs and names. -->
   
   <!-- If there was a discussion of the design of the feature implemented in this PR elsewhere 
   (e. g. a "Proposal" issue, any other issue, or a thread in the development mailing list), 
   link to that discussion from this PR description and explain what have changed in your final design 
   compared to your original proposal or the consensus version in the end of the discussion. 
   If something hasn't changed since the original discussion, you can omit a detailed discussion of 
   those aspects of the design here, perhaps apart from brief mentioning for the sake of readability 
   of this PR description. -->
   
   <!-- Some of the aspects mentioned above may be omitted for simple and small changes. -->
   
   <hr>
   
   This PR has:
   - [ ] been self-reviewed.
       - [ ] concurrent read
       - [ ] concurrent write
       - [ ] concurrent read and write 
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] added Javadocs for most classes and all non-trivial methods. 
   - [ ] added or updated version, __license__, or notice information
   - [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious 
     for an unfamiliar reader.
   - [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold 
     for code coverage.
   - [ ] added integration tests.
   - [ ] been tested in a test IoTDB cluster.
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not all of these items 
   apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items 
   from the checklist above are strictly necessary, but it would be very helpful if you at least 
   self-review the PR. -->
   
   <hr>
   
   ##### Key changed/added classes (or packages if there are too many classes) in this PR
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords [iotdb]

Posted by "Caideyipi (via GitHub)" <gi...@apache.org>.
Caideyipi commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2050403759


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/read/resp/info/impl/ShowDevicesResult.java:
##########
@@ -81,13 +83,25 @@ public PartialPath getPartialPath() {
   }
 
   public static ShowDevicesResult convertDeviceEntry2ShowDeviceResult(
-      final DeviceEntry entry, final List<String> attributeColumns) {
+      final DeviceEntry entry, final List<String> attributeColumns, final int databaseSegmentNum) {
+    final String deviceIdStr = entry.getDeviceID().toString();
     final ShowDevicesResult result =
         new ShowDevicesResult(
-            entry.getDeviceID().toString(), null, -1, (String[]) entry.getDeviceID().getSegments());
+            deviceIdStr,
+            null,
+            -1,
+            databaseSegmentNum > 0
+                ? Arrays.copyOfRange(
+                    TreeViewSchema.forceSeparateStringToPartialPath(deviceIdStr).getNodes(),
+                    databaseSegmentNum - 1,
+                    TreeViewSchema.forceSeparateStringToPartialPath(deviceIdStr).getNodeLength())
+                : (String[]) entry.getDeviceID().getSegments());
     final Map<String, Binary> attributeProviderMap = new HashMap<>();
-    for (int i = 0; i < attributeColumns.size(); ++i) {
-      attributeProviderMap.put(attributeColumns.get(i), entry.getAttributeColumnValues()[i]);
+
+    if (entry instanceof AlignedDeviceEntry) {

Review Comment:
   May be useless.. Will delete it



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords [iotdb]

Posted by "shuwenwei (via GitHub)" <gi...@apache.org>.
shuwenwei commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2048623711


##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/schema/ClusterSchemaManager.java:
##########
@@ -813,6 +816,93 @@ public TGetPathsSetTemplatesResp getPathsSetTemplate(String templateName, PathPa
     }
   }
 
+  public static TSStatus enrichDatabaseSchemaWithDefaultProperties(
+      final TDatabaseSchema databaseSchema) {
+    TSStatus errorResp = null;
+    final boolean isSystemDatabase =
+        databaseSchema.getName().equals(SchemaConstant.SYSTEM_DATABASE);
+
+    if (databaseSchema.getTTL() < 0) {
+      errorResp =
+          new TSStatus(TSStatusCode.DATABASE_CONFIG_ERROR.getStatusCode())
+              .setMessage("Failed to create database. The TTL should be positive.");

Review Comment:
   should be non-negative



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords [iotdb]

Posted by "shuwenwei (via GitHub)" <gi...@apache.org>.
shuwenwei commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2050376795


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/read/resp/info/impl/ShowDevicesResult.java:
##########
@@ -81,13 +83,25 @@ public PartialPath getPartialPath() {
   }
 
   public static ShowDevicesResult convertDeviceEntry2ShowDeviceResult(
-      final DeviceEntry entry, final List<String> attributeColumns) {
+      final DeviceEntry entry, final List<String> attributeColumns, final int databaseSegmentNum) {
+    final String deviceIdStr = entry.getDeviceID().toString();
     final ShowDevicesResult result =
         new ShowDevicesResult(
-            entry.getDeviceID().toString(), null, -1, (String[]) entry.getDeviceID().getSegments());
+            deviceIdStr,
+            null,
+            -1,
+            databaseSegmentNum > 0
+                ? Arrays.copyOfRange(
+                    TreeViewSchema.forceSeparateStringToPartialPath(deviceIdStr).getNodes(),
+                    databaseSegmentNum - 1,
+                    TreeViewSchema.forceSeparateStringToPartialPath(deviceIdStr).getNodeLength())
+                : (String[]) entry.getDeviceID().getSegments());
     final Map<String, Binary> attributeProviderMap = new HashMap<>();
-    for (int i = 0; i < attributeColumns.size(); ++i) {
-      attributeProviderMap.put(attributeColumns.get(i), entry.getAttributeColumnValues()[i]);
+
+    if (entry instanceof AlignedDeviceEntry) {

Review Comment:
   What is the meaning of this judgment?



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords [iotdb]

Posted by "shuwenwei (via GitHub)" <gi...@apache.org>.
shuwenwei commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2050289658


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/TableDeviceSchemaFetcher.java:
##########
@@ -467,6 +511,68 @@ private void fetchMissingDeviceSchemaForQuery(
     }
   }
 
+  private void constructTableResults(
+      final TsBlock tsBlock,
+      final List<ColumnHeader> columnHeaderList,
+      final TsTable tableInstance,
+      final ShowDevice statement,
+      final MPPQueryContext mppQueryContext,
+      final List<String> attributeColumns,
+      final List<DeviceEntry> deviceEntryList) {
+    final Column[] columns = tsBlock.getValueColumns();
+    for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+      final String[] nodes = new String[tableInstance.getIdNums() + 1];
+      final Map<String, Binary> attributeMap = new HashMap<>();
+      constructNodsArrayAndAttributeMap(
+          attributeMap,
+          nodes,
+          tableInstance.getTableName(),
+          columnHeaderList,
+          columns,
+          tableInstance,
+          i);
+      final IDeviceID deviceID = IDeviceID.Factory.DEFAULT_FACTORY.create(nodes);
+      final AlignedDeviceEntry deviceEntry =
+          new AlignedDeviceEntry(
+              deviceID, attributeColumns.stream().map(attributeMap::get).toArray(Binary[]::new));
+      mppQueryContext.reserveMemoryForFrontEnd(deviceEntry.ramBytesUsed());
+      deviceEntryList.add(deviceEntry);
+      // Only cache those exact device query
+      // Fetch paths is null iff there are fuzzy queries related to id columns
+      if (Objects.nonNull(statement.getPartitionKeyList())) {
+        cache.putAttributes(statement.getDatabase(), deviceID, attributeMap);
+      }
+    }
+  }
+
+  private void constructTreeResults(
+      final TsBlock tsBlock,
+      final List<ColumnHeader> columnHeaderList,
+      final TsTable tableInstance,
+      final MPPQueryContext mppQueryContext,
+      final List<DeviceEntry> deviceEntryList) {
+    final Column[] columns = tsBlock.getValueColumns();
+    for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+      final String[] nodes = new String[tableInstance.getIdNums() + 1];

Review Comment:
   For a tree model device, is it redundant to add table view name to the IDeviceID?



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords [iotdb]

Posted by "shuwenwei (via GitHub)" <gi...@apache.org>.
shuwenwei commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2048590961


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/relational/ShowCreateTableTask.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * 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.execution.config.metadata.relational;
+
+import org.apache.iotdb.commons.schema.column.ColumnHeader;
+import org.apache.iotdb.commons.schema.column.ColumnHeaderConstant;
+import org.apache.iotdb.commons.schema.table.TreeViewSchema;
+import org.apache.iotdb.commons.schema.table.TsTable;
+import org.apache.iotdb.commons.schema.table.column.TsTableColumnSchema;
+import org.apache.iotdb.db.queryengine.common.header.DatasetHeader;
+import org.apache.iotdb.db.queryengine.common.header.DatasetHeaderFactory;
+import org.apache.iotdb.db.queryengine.plan.execution.config.ConfigTaskResult;
+import org.apache.iotdb.db.queryengine.plan.execution.config.executor.IConfigTaskExecutor;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+import org.apache.tsfile.common.conf.TSFileConfig;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.read.common.block.TsBlockBuilder;
+import org.apache.tsfile.utils.Binary;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+public class ShowCreateTableTask extends AbstractTableTask {
+  public ShowCreateTableTask(final String database, final String tableName) {
+    super(database, tableName);
+  }
+
+  @Override
+  public ListenableFuture<ConfigTaskResult> execute(final IConfigTaskExecutor configTaskExecutor)
+      throws InterruptedException {
+    return configTaskExecutor.describeTable(database, tableName, false, false);
+  }
+
+  public static void buildTsBlock(
+      final TsTable table, final SettableFuture<ConfigTaskResult> future) {
+    if (TreeViewSchema.isTreeViewTable(table)) {
+      ShowCreateViewTask.buildTsBlock(table, future);
+      return;
+    }
+    final List<TSDataType> outputDataTypes =
+        ColumnHeaderConstant.showCreateTableColumnHeaders.stream()
+            .map(ColumnHeader::getColumnType)
+            .collect(Collectors.toList());
+
+    final TsBlockBuilder builder = new TsBlockBuilder(outputDataTypes);
+    builder.getTimeColumnBuilder().writeLong(0L);
+    builder
+        .getColumnBuilder(0)
+        .writeBinary(new Binary(table.getTableName(), TSFileConfig.STRING_CHARSET));
+    builder
+        .getColumnBuilder(1)
+        .writeBinary(new Binary(getShowCreateTableSQL(table), TSFileConfig.STRING_CHARSET));
+    builder.declarePosition();
+
+    final DatasetHeader datasetHeader = DatasetHeaderFactory.getShowCreateTableColumnHeader();
+    future.set(new ConfigTaskResult(TSStatusCode.SUCCESS_STATUS, builder.build(), datasetHeader));
+  }
+
+  private static String getShowCreateTableSQL(final TsTable table) {
+    final StringBuilder builder =
+        new StringBuilder("CREATE TABLE \"").append(table.getTableName()).append("\" (");
+
+    for (final TsTableColumnSchema schema : table.getColumnList()) {
+      switch (schema.getColumnCategory()) {
+        case TAG:
+          builder
+              .append(schema.getColumnName())
+              .append(" ")
+              .append(schema.getDataType())
+              .append(" ")
+              .append("TAG");
+          break;
+        case TIME:
+          continue;
+        case FIELD:
+          builder
+              .append(schema.getColumnName())

Review Comment:
   Is it necessary to ensure that the final output SQL can be successfully executed?  If a column name is s"0, does it need special processing?



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords & Optimized the config tasks' error code + log [iotdb]

Posted by "shuwenwei (via GitHub)" <gi...@apache.org>.
shuwenwei commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2053529898


##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/schema/table/view/CreateTableViewProcedure.java:
##########
@@ -0,0 +1,192 @@
+/*
+ * 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.confignode.procedure.impl.schema.table.view;
+
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.exception.IoTDBException;
+import org.apache.iotdb.commons.exception.MetadataException;
+import org.apache.iotdb.commons.schema.table.TableNodeStatus;
+import org.apache.iotdb.commons.schema.table.TreeViewSchema;
+import org.apache.iotdb.commons.schema.table.TsTable;
+import org.apache.iotdb.confignode.consensus.request.write.table.view.PreCreateTableViewPlan;
+import org.apache.iotdb.confignode.exception.DatabaseNotExistsException;
+import org.apache.iotdb.confignode.persistence.schema.TreeDeviceViewFieldDetector;
+import org.apache.iotdb.confignode.procedure.env.ConfigNodeProcedureEnv;
+import org.apache.iotdb.confignode.procedure.exception.ProcedureException;
+import org.apache.iotdb.confignode.procedure.impl.schema.SchemaUtils;
+import org.apache.iotdb.confignode.procedure.impl.schema.table.CreateTableProcedure;
+import org.apache.iotdb.confignode.procedure.state.schema.CreateTableState;
+import org.apache.iotdb.confignode.procedure.store.ProcedureType;
+import org.apache.iotdb.confignode.rpc.thrift.TDatabaseSchema;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import org.apache.tsfile.utils.Pair;
+import org.apache.tsfile.utils.ReadWriteIOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Objects;
+import java.util.Optional;
+
+import static org.apache.iotdb.rpc.TSStatusCode.TABLE_ALREADY_EXISTS;
+
+public class CreateTableViewProcedure extends CreateTableProcedure {
+  private static final Logger LOGGER = LoggerFactory.getLogger(CreateTableViewProcedure.class);
+  private boolean replace;
+  private TsTable oldView;
+  private TableNodeStatus oldStatus;
+
+  public CreateTableViewProcedure(final boolean isGeneratedByPipe) {
+    super(isGeneratedByPipe);
+  }
+
+  public CreateTableViewProcedure(
+      final String database,
+      final TsTable table,
+      final boolean replace,
+      final boolean isGeneratedByPipe) {
+    super(database, table, isGeneratedByPipe);
+    this.replace = replace;
+  }
+
+  @Override
+  protected void checkTableExistence(final ConfigNodeProcedureEnv env) {
+    if (!replace) {

Review Comment:
   <img width="1174" alt="截屏2025-04-22 15 42 32" src="https://github.com/user-attachments/assets/0e205cce-6aef-4cf4-a0d9-bf516cd6c2e7" />
   



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords & Optimized the config tasks' error code + log [iotdb]

Posted by "shuwenwei (via GitHub)" <gi...@apache.org>.
shuwenwei commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2055468215


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/RelationPlanner.java:
##########
@@ -222,8 +222,8 @@ protected RelationPlan visitTable(final Table table, final Void context) {
               outputSymbols,
               tableColumnSchema,
               idAndAttributeIndexMap,
-              treeDeviceViewSchema.getTreeDBName(),
-              treeDeviceViewSchema.getMeasurementColumnNameMap()),
+              treeDeviceViewSchema.getTreePathPatternName(),

Review Comment:
   Using treePathPatternName as treeDBName will result in failure to obtain DataPartition later in `PushPredicateIntoTableScan.fetchDataPartitionByDevices`. Maybe we should make `PushPredicateIntoTableScan.fetchDataPartitionByDevices` support pattern



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords & Optimized the config tasks' error code + log [iotdb]

Posted by "shuwenwei (via GitHub)" <gi...@apache.org>.
shuwenwei commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2063063788


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/schema/source/TableDeviceQuerySource.java:
##########
@@ -283,4 +347,39 @@ public long getMaxMemory(final ISchemaRegion schemaRegion) {
                     : 0))
         : TSFileDescriptor.getInstance().getConfig().getMaxTsBlockSizeInBytes();
   }
+
+  private static class RleBinaryColumnBuilder extends BinaryColumnBuilder {
+
+    private final BinaryColumnBuilder innerBuilder;
+
+    public RleBinaryColumnBuilder(final BinaryColumnBuilder innerBuilder) {
+      super(null, 0);
+      this.innerBuilder = innerBuilder;
+    }
+
+    @Override
+    public int getPositionCount() {
+      return innerBuilder.getPositionCount();
+    }
+
+    @Override
+    public ColumnBuilder writeBinary(final Binary value) {
+      return innerBuilder.writeBinary(value);
+    }
+
+    @Override
+    public ColumnBuilder appendNull() {
+      return innerBuilder.appendNull();
+    }
+
+    @Override
+    public Column build() {
+      return new RunLengthEncodedColumn(innerBuilder.build(), getPositionCount());

Review Comment:
   The column generated by innerBuilder may cause an IllegalArgumentException.
   <img width="949" alt="截屏2025-04-28 15 38 23" src="https://github.com/user-attachments/assets/e44e5f46-5b0e-4814-899d-6296c0e8104b" />
   ![Uploading 截屏2025-04-28 15.40.00.png…]()
   



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords & Optimized the config tasks' error code + log [iotdb]

Posted by "shuwenwei (via GitHub)" <gi...@apache.org>.
shuwenwei commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2053527549


##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/schema/table/view/CreateTableViewProcedure.java:
##########
@@ -0,0 +1,192 @@
+/*
+ * 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.confignode.procedure.impl.schema.table.view;
+
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.exception.IoTDBException;
+import org.apache.iotdb.commons.exception.MetadataException;
+import org.apache.iotdb.commons.schema.table.TableNodeStatus;
+import org.apache.iotdb.commons.schema.table.TreeViewSchema;
+import org.apache.iotdb.commons.schema.table.TsTable;
+import org.apache.iotdb.confignode.consensus.request.write.table.view.PreCreateTableViewPlan;
+import org.apache.iotdb.confignode.exception.DatabaseNotExistsException;
+import org.apache.iotdb.confignode.persistence.schema.TreeDeviceViewFieldDetector;
+import org.apache.iotdb.confignode.procedure.env.ConfigNodeProcedureEnv;
+import org.apache.iotdb.confignode.procedure.exception.ProcedureException;
+import org.apache.iotdb.confignode.procedure.impl.schema.SchemaUtils;
+import org.apache.iotdb.confignode.procedure.impl.schema.table.CreateTableProcedure;
+import org.apache.iotdb.confignode.procedure.state.schema.CreateTableState;
+import org.apache.iotdb.confignode.procedure.store.ProcedureType;
+import org.apache.iotdb.confignode.rpc.thrift.TDatabaseSchema;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import org.apache.tsfile.utils.Pair;
+import org.apache.tsfile.utils.ReadWriteIOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Objects;
+import java.util.Optional;
+
+import static org.apache.iotdb.rpc.TSStatusCode.TABLE_ALREADY_EXISTS;
+
+public class CreateTableViewProcedure extends CreateTableProcedure {
+  private static final Logger LOGGER = LoggerFactory.getLogger(CreateTableViewProcedure.class);
+  private boolean replace;
+  private TsTable oldView;
+  private TableNodeStatus oldStatus;
+
+  public CreateTableViewProcedure(final boolean isGeneratedByPipe) {
+    super(isGeneratedByPipe);
+  }
+
+  public CreateTableViewProcedure(
+      final String database,
+      final TsTable table,
+      final boolean replace,
+      final boolean isGeneratedByPipe) {
+    super(database, table, isGeneratedByPipe);
+    this.replace = replace;
+  }
+
+  @Override
+  protected void checkTableExistence(final ConfigNodeProcedureEnv env) {
+    if (!replace) {

Review Comment:
   If we enter this branch, we may not detect columns with missing data type.



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords & Optimized the config tasks' error code + log [iotdb]

Posted by "shuwenwei (via GitHub)" <gi...@apache.org>.
shuwenwei commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2053595262


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java:
##########
@@ -101,21 +101,31 @@ public boolean tableExists(final QualifiedObjectName name) {
   @Override
   public Optional<TableSchema> getTableSchema(
       final SessionInfo session, final QualifiedObjectName name) {
-    final TsTable table = tableCache.getTable(name.getDatabaseName(), name.getObjectName());
-    return Objects.isNull(table)
-        ? Optional.empty()
-        : Optional.of(
-            new TableSchema(
-                table.getTableName(),
-                table.getColumnList().stream()
-                    .map(
-                        o ->
-                            new ColumnSchema(
-                                o.getColumnName(),
-                                TypeFactory.getType(o.getDataType()),
-                                false,
-                                o.getColumnCategory()))
-                    .collect(Collectors.toList())));
+    final String databaseName = name.getDatabaseName();
+    final String tableName = name.getObjectName();
+
+    TsTable table = tableCache.getTable(databaseName, tableName);
+    if (table == null) {
+      return Optional.empty();
+    }
+    final List<ColumnSchema> columnSchemaList =
+        table.getColumnList().stream()
+            .map(
+                o -> {
+                  final ColumnSchema schema =
+                      new ColumnSchema(
+                          o.getColumnName(),
+                          TypeFactory.getType(o.getDataType()),
+                          false,
+                          o.getColumnCategory());
+                  schema.setProps(o.getProps());
+                  return schema;
+                })
+            .collect(Collectors.toList());
+    return Optional.of(
+        databaseName.equals(TreeViewSchema.TREE_PATH_PATTERN)

Review Comment:
   Maybe props should be used to make the judgement here? `databaseName.equals(TreeViewSchema.TREE_PATH_PATTERN)` is false



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords [iotdb]

Posted by "Caideyipi (via GitHub)" <gi...@apache.org>.
Caideyipi commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2048589781


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/RestApiServiceImpl.java:
##########


Review Comment:
   Seemingly true...



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords [iotdb]

Posted by "shuwenwei (via GitHub)" <gi...@apache.org>.
shuwenwei commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2050416859


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/TableDeviceSchemaFetcher.java:
##########
@@ -467,6 +511,68 @@ private void fetchMissingDeviceSchemaForQuery(
     }
   }
 
+  private void constructTableResults(
+      final TsBlock tsBlock,
+      final List<ColumnHeader> columnHeaderList,
+      final TsTable tableInstance,
+      final ShowDevice statement,
+      final MPPQueryContext mppQueryContext,
+      final List<String> attributeColumns,
+      final List<DeviceEntry> deviceEntryList) {
+    final Column[] columns = tsBlock.getValueColumns();
+    for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+      final String[] nodes = new String[tableInstance.getIdNums() + 1];
+      final Map<String, Binary> attributeMap = new HashMap<>();
+      constructNodsArrayAndAttributeMap(
+          attributeMap,
+          nodes,
+          tableInstance.getTableName(),
+          columnHeaderList,
+          columns,
+          tableInstance,
+          i);
+      final IDeviceID deviceID = IDeviceID.Factory.DEFAULT_FACTORY.create(nodes);
+      final AlignedDeviceEntry deviceEntry =
+          new AlignedDeviceEntry(
+              deviceID, attributeColumns.stream().map(attributeMap::get).toArray(Binary[]::new));
+      mppQueryContext.reserveMemoryForFrontEnd(deviceEntry.ramBytesUsed());
+      deviceEntryList.add(deviceEntry);
+      // Only cache those exact device query
+      // Fetch paths is null iff there are fuzzy queries related to id columns
+      if (Objects.nonNull(statement.getPartitionKeyList())) {
+        cache.putAttributes(statement.getDatabase(), deviceID, attributeMap);
+      }
+    }
+  }
+
+  private void constructTreeResults(
+      final TsBlock tsBlock,
+      final List<ColumnHeader> columnHeaderList,
+      final TsTable tableInstance,
+      final MPPQueryContext mppQueryContext,
+      final List<DeviceEntry> deviceEntryList) {
+    final Column[] columns = tsBlock.getValueColumns();
+    for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+      final String[] nodes = new String[tableInstance.getIdNums() + 1];

Review Comment:
   Here and in the following lines of code, it seems that the table view name is spelled into the IDeviceID.



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords [iotdb]

Posted by "shuwenwei (via GitHub)" <gi...@apache.org>.
shuwenwei commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2050289658


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/TableDeviceSchemaFetcher.java:
##########
@@ -467,6 +511,68 @@ private void fetchMissingDeviceSchemaForQuery(
     }
   }
 
+  private void constructTableResults(
+      final TsBlock tsBlock,
+      final List<ColumnHeader> columnHeaderList,
+      final TsTable tableInstance,
+      final ShowDevice statement,
+      final MPPQueryContext mppQueryContext,
+      final List<String> attributeColumns,
+      final List<DeviceEntry> deviceEntryList) {
+    final Column[] columns = tsBlock.getValueColumns();
+    for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+      final String[] nodes = new String[tableInstance.getIdNums() + 1];
+      final Map<String, Binary> attributeMap = new HashMap<>();
+      constructNodsArrayAndAttributeMap(
+          attributeMap,
+          nodes,
+          tableInstance.getTableName(),
+          columnHeaderList,
+          columns,
+          tableInstance,
+          i);
+      final IDeviceID deviceID = IDeviceID.Factory.DEFAULT_FACTORY.create(nodes);
+      final AlignedDeviceEntry deviceEntry =
+          new AlignedDeviceEntry(
+              deviceID, attributeColumns.stream().map(attributeMap::get).toArray(Binary[]::new));
+      mppQueryContext.reserveMemoryForFrontEnd(deviceEntry.ramBytesUsed());
+      deviceEntryList.add(deviceEntry);
+      // Only cache those exact device query
+      // Fetch paths is null iff there are fuzzy queries related to id columns
+      if (Objects.nonNull(statement.getPartitionKeyList())) {
+        cache.putAttributes(statement.getDatabase(), deviceID, attributeMap);
+      }
+    }
+  }
+
+  private void constructTreeResults(
+      final TsBlock tsBlock,
+      final List<ColumnHeader> columnHeaderList,
+      final TsTable tableInstance,
+      final MPPQueryContext mppQueryContext,
+      final List<DeviceEntry> deviceEntryList) {
+    final Column[] columns = tsBlock.getValueColumns();
+    for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+      final String[] nodes = new String[tableInstance.getIdNums() + 1];

Review Comment:
   In the tree model, is it necessary to add table to the IDeviceID?



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords [iotdb]

Posted by "shuwenwei (via GitHub)" <gi...@apache.org>.
shuwenwei commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2050289658


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/TableDeviceSchemaFetcher.java:
##########
@@ -467,6 +511,68 @@ private void fetchMissingDeviceSchemaForQuery(
     }
   }
 
+  private void constructTableResults(
+      final TsBlock tsBlock,
+      final List<ColumnHeader> columnHeaderList,
+      final TsTable tableInstance,
+      final ShowDevice statement,
+      final MPPQueryContext mppQueryContext,
+      final List<String> attributeColumns,
+      final List<DeviceEntry> deviceEntryList) {
+    final Column[] columns = tsBlock.getValueColumns();
+    for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+      final String[] nodes = new String[tableInstance.getIdNums() + 1];
+      final Map<String, Binary> attributeMap = new HashMap<>();
+      constructNodsArrayAndAttributeMap(
+          attributeMap,
+          nodes,
+          tableInstance.getTableName(),
+          columnHeaderList,
+          columns,
+          tableInstance,
+          i);
+      final IDeviceID deviceID = IDeviceID.Factory.DEFAULT_FACTORY.create(nodes);
+      final AlignedDeviceEntry deviceEntry =
+          new AlignedDeviceEntry(
+              deviceID, attributeColumns.stream().map(attributeMap::get).toArray(Binary[]::new));
+      mppQueryContext.reserveMemoryForFrontEnd(deviceEntry.ramBytesUsed());
+      deviceEntryList.add(deviceEntry);
+      // Only cache those exact device query
+      // Fetch paths is null iff there are fuzzy queries related to id columns
+      if (Objects.nonNull(statement.getPartitionKeyList())) {
+        cache.putAttributes(statement.getDatabase(), deviceID, attributeMap);
+      }
+    }
+  }
+
+  private void constructTreeResults(
+      final TsBlock tsBlock,
+      final List<ColumnHeader> columnHeaderList,
+      final TsTable tableInstance,
+      final MPPQueryContext mppQueryContext,
+      final List<DeviceEntry> deviceEntryList) {
+    final Column[] columns = tsBlock.getValueColumns();
+    for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+      final String[] nodes = new String[tableInstance.getIdNums() + 1];

Review Comment:
   In the tree model, is it necessary to add table view name to the IDeviceID?



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords [iotdb]

Posted by "Caideyipi (via GitHub)" <gi...@apache.org>.
Caideyipi commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2048587941


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/RestApiServiceImpl.java:
##########
@@ -102,21 +105,36 @@ public Response executeNonQueryStatement(SQL sql, SecurityContext securityContex
             .build();
       }
 
-      Response response = authorizationHandler.checkAuthority(securityContext, statement);
-      if (response != null) {
-        return response;
-      }
+      final ExecutionResult result;
       queryId = SESSION_MANAGER.requestQueryId();
-      ExecutionResult result =
-          COORDINATOR.executeForTreeModel(
-              statement,
-              queryId,
-              SESSION_MANAGER.getSessionInfo(SESSION_MANAGER.getCurrSession()),
-              sql.getSql(),
-              partitionFetcher,
-              schemaFetcher,
-              config.getQueryTimeoutThreshold(),
-              false);
+      if (statement instanceof CreateTableViewStatement) {
+        result =
+            COORDINATOR.executeForTableModel(
+                ((CreateTableViewStatement) statement).getCreateTableView(),
+                new SqlParser(),
+                SESSION_MANAGER.getCurrSessionAndUpdateIdleTime(),
+                queryId,
+                SESSION_MANAGER.getSessionInfo(SESSION_MANAGER.getCurrSession()),
+                sql.getSql(),
+                LocalExecutionPlanner.getInstance().metadata,
+                config.getQueryTimeoutThreshold(),
+                false);
+      } else {
+        Response response = authorizationHandler.checkAuthority(securityContext, statement);

Review Comment:
   No, only tree statements need to be checked here, table statements are checked in the inner layer.



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords & Optimized the config tasks' error code + log [iotdb]

Posted by "shuwenwei (via GitHub)" <gi...@apache.org>.
shuwenwei commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2063063788


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/schema/source/TableDeviceQuerySource.java:
##########
@@ -283,4 +347,39 @@ public long getMaxMemory(final ISchemaRegion schemaRegion) {
                     : 0))
         : TSFileDescriptor.getInstance().getConfig().getMaxTsBlockSizeInBytes();
   }
+
+  private static class RleBinaryColumnBuilder extends BinaryColumnBuilder {
+
+    private final BinaryColumnBuilder innerBuilder;
+
+    public RleBinaryColumnBuilder(final BinaryColumnBuilder innerBuilder) {
+      super(null, 0);
+      this.innerBuilder = innerBuilder;
+    }
+
+    @Override
+    public int getPositionCount() {
+      return innerBuilder.getPositionCount();
+    }
+
+    @Override
+    public ColumnBuilder writeBinary(final Binary value) {
+      return innerBuilder.writeBinary(value);
+    }
+
+    @Override
+    public ColumnBuilder appendNull() {
+      return innerBuilder.appendNull();
+    }
+
+    @Override
+    public Column build() {
+      return new RunLengthEncodedColumn(innerBuilder.build(), getPositionCount());

Review Comment:
   The column generated by innerBuilder may cause an IllegalArgumentException.
   <img width="949" alt="截屏2025-04-28 15 38 23" src="https://github.com/user-attachments/assets/e44e5f46-5b0e-4814-899d-6296c0e8104b" />
   <img width="1414" alt="截屏2025-04-28 15 40 17" src="https://github.com/user-attachments/assets/be3a1186-f1eb-46b6-be3f-644ca5cd98b4" />
   
   



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords & Optimized the config tasks' error code + log [iotdb]

Posted by "Caideyipi (via GitHub)" <gi...@apache.org>.
Caideyipi commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2053809035


##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/schema/table/view/CreateTableViewProcedure.java:
##########
@@ -0,0 +1,192 @@
+/*
+ * 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.confignode.procedure.impl.schema.table.view;
+
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.exception.IoTDBException;
+import org.apache.iotdb.commons.exception.MetadataException;
+import org.apache.iotdb.commons.schema.table.TableNodeStatus;
+import org.apache.iotdb.commons.schema.table.TreeViewSchema;
+import org.apache.iotdb.commons.schema.table.TsTable;
+import org.apache.iotdb.confignode.consensus.request.write.table.view.PreCreateTableViewPlan;
+import org.apache.iotdb.confignode.exception.DatabaseNotExistsException;
+import org.apache.iotdb.confignode.persistence.schema.TreeDeviceViewFieldDetector;
+import org.apache.iotdb.confignode.procedure.env.ConfigNodeProcedureEnv;
+import org.apache.iotdb.confignode.procedure.exception.ProcedureException;
+import org.apache.iotdb.confignode.procedure.impl.schema.SchemaUtils;
+import org.apache.iotdb.confignode.procedure.impl.schema.table.CreateTableProcedure;
+import org.apache.iotdb.confignode.procedure.state.schema.CreateTableState;
+import org.apache.iotdb.confignode.procedure.store.ProcedureType;
+import org.apache.iotdb.confignode.rpc.thrift.TDatabaseSchema;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import org.apache.tsfile.utils.Pair;
+import org.apache.tsfile.utils.ReadWriteIOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Objects;
+import java.util.Optional;
+
+import static org.apache.iotdb.rpc.TSStatusCode.TABLE_ALREADY_EXISTS;
+
+public class CreateTableViewProcedure extends CreateTableProcedure {
+  private static final Logger LOGGER = LoggerFactory.getLogger(CreateTableViewProcedure.class);
+  private boolean replace;
+  private TsTable oldView;
+  private TableNodeStatus oldStatus;
+
+  public CreateTableViewProcedure(final boolean isGeneratedByPipe) {
+    super(isGeneratedByPipe);
+  }
+
+  public CreateTableViewProcedure(
+      final String database,
+      final TsTable table,
+      final boolean replace,
+      final boolean isGeneratedByPipe) {
+    super(database, table, isGeneratedByPipe);
+    this.replace = replace;
+  }
+
+  @Override
+  protected void checkTableExistence(final ConfigNodeProcedureEnv env) {
+    if (!replace) {

Review Comment:
   Fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords & Optimized the config tasks' error code + log [iotdb]

Posted by "Caideyipi (via GitHub)" <gi...@apache.org>.
Caideyipi commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2058043678


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/RelationPlanner.java:
##########
@@ -222,8 +222,8 @@ protected RelationPlan visitTable(final Table table, final Void context) {
               outputSymbols,
               tableColumnSchema,
               idAndAttributeIndexMap,
-              treeDeviceViewSchema.getTreeDBName(),
-              treeDeviceViewSchema.getMeasurementColumnNameMap()),
+              treeDeviceViewSchema.getTreePathPatternName(),

Review Comment:
   This may require a comprehensive change in query process...



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords [iotdb]

Posted by "Caideyipi (via GitHub)" <gi...@apache.org>.
Caideyipi commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2050398171


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/TableDeviceSchemaFetcher.java:
##########
@@ -467,6 +511,68 @@ private void fetchMissingDeviceSchemaForQuery(
     }
   }
 
+  private void constructTableResults(
+      final TsBlock tsBlock,
+      final List<ColumnHeader> columnHeaderList,
+      final TsTable tableInstance,
+      final ShowDevice statement,
+      final MPPQueryContext mppQueryContext,
+      final List<String> attributeColumns,
+      final List<DeviceEntry> deviceEntryList) {
+    final Column[] columns = tsBlock.getValueColumns();
+    for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+      final String[] nodes = new String[tableInstance.getIdNums() + 1];
+      final Map<String, Binary> attributeMap = new HashMap<>();
+      constructNodsArrayAndAttributeMap(
+          attributeMap,
+          nodes,
+          tableInstance.getTableName(),
+          columnHeaderList,
+          columns,
+          tableInstance,
+          i);
+      final IDeviceID deviceID = IDeviceID.Factory.DEFAULT_FACTORY.create(nodes);
+      final AlignedDeviceEntry deviceEntry =
+          new AlignedDeviceEntry(
+              deviceID, attributeColumns.stream().map(attributeMap::get).toArray(Binary[]::new));
+      mppQueryContext.reserveMemoryForFrontEnd(deviceEntry.ramBytesUsed());
+      deviceEntryList.add(deviceEntry);
+      // Only cache those exact device query
+      // Fetch paths is null iff there are fuzzy queries related to id columns
+      if (Objects.nonNull(statement.getPartitionKeyList())) {
+        cache.putAttributes(statement.getDatabase(), deviceID, attributeMap);
+      }
+    }
+  }
+
+  private void constructTreeResults(
+      final TsBlock tsBlock,
+      final List<ColumnHeader> columnHeaderList,
+      final TsTable tableInstance,
+      final MPPQueryContext mppQueryContext,
+      final List<DeviceEntry> deviceEntryList) {
+    final Column[] columns = tsBlock.getValueColumns();
+    for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+      final String[] nodes = new String[tableInstance.getIdNums() + 1];

Review Comment:
   The deviceIDs are the same as the original tree ones, for instance, if the pattern is root.a.**, and the tags are b, c, d, then the deviceID will be FACTORY.create("root.a.b.c.d").



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords [iotdb]

Posted by "shuwenwei (via GitHub)" <gi...@apache.org>.
shuwenwei commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2050289658


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/TableDeviceSchemaFetcher.java:
##########
@@ -467,6 +511,68 @@ private void fetchMissingDeviceSchemaForQuery(
     }
   }
 
+  private void constructTableResults(
+      final TsBlock tsBlock,
+      final List<ColumnHeader> columnHeaderList,
+      final TsTable tableInstance,
+      final ShowDevice statement,
+      final MPPQueryContext mppQueryContext,
+      final List<String> attributeColumns,
+      final List<DeviceEntry> deviceEntryList) {
+    final Column[] columns = tsBlock.getValueColumns();
+    for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+      final String[] nodes = new String[tableInstance.getIdNums() + 1];
+      final Map<String, Binary> attributeMap = new HashMap<>();
+      constructNodsArrayAndAttributeMap(
+          attributeMap,
+          nodes,
+          tableInstance.getTableName(),
+          columnHeaderList,
+          columns,
+          tableInstance,
+          i);
+      final IDeviceID deviceID = IDeviceID.Factory.DEFAULT_FACTORY.create(nodes);
+      final AlignedDeviceEntry deviceEntry =
+          new AlignedDeviceEntry(
+              deviceID, attributeColumns.stream().map(attributeMap::get).toArray(Binary[]::new));
+      mppQueryContext.reserveMemoryForFrontEnd(deviceEntry.ramBytesUsed());
+      deviceEntryList.add(deviceEntry);
+      // Only cache those exact device query
+      // Fetch paths is null iff there are fuzzy queries related to id columns
+      if (Objects.nonNull(statement.getPartitionKeyList())) {
+        cache.putAttributes(statement.getDatabase(), deviceID, attributeMap);
+      }
+    }
+  }
+
+  private void constructTreeResults(
+      final TsBlock tsBlock,
+      final List<ColumnHeader> columnHeaderList,
+      final TsTable tableInstance,
+      final MPPQueryContext mppQueryContext,
+      final List<DeviceEntry> deviceEntryList) {
+    final Column[] columns = tsBlock.getValueColumns();
+    for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+      final String[] nodes = new String[tableInstance.getIdNums() + 1];

Review Comment:
   For a tree model device, is it necessary to add table view name to the IDeviceID?



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords [iotdb]

Posted by "Caideyipi (via GitHub)" <gi...@apache.org>.
Caideyipi commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2048691752


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/relational/ShowCreateTableTask.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * 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.execution.config.metadata.relational;
+
+import org.apache.iotdb.commons.schema.column.ColumnHeader;
+import org.apache.iotdb.commons.schema.column.ColumnHeaderConstant;
+import org.apache.iotdb.commons.schema.table.TreeViewSchema;
+import org.apache.iotdb.commons.schema.table.TsTable;
+import org.apache.iotdb.commons.schema.table.column.TsTableColumnSchema;
+import org.apache.iotdb.db.queryengine.common.header.DatasetHeader;
+import org.apache.iotdb.db.queryengine.common.header.DatasetHeaderFactory;
+import org.apache.iotdb.db.queryengine.plan.execution.config.ConfigTaskResult;
+import org.apache.iotdb.db.queryengine.plan.execution.config.executor.IConfigTaskExecutor;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+import org.apache.tsfile.common.conf.TSFileConfig;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.read.common.block.TsBlockBuilder;
+import org.apache.tsfile.utils.Binary;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+public class ShowCreateTableTask extends AbstractTableTask {
+  public ShowCreateTableTask(final String database, final String tableName) {
+    super(database, tableName);
+  }
+
+  @Override
+  public ListenableFuture<ConfigTaskResult> execute(final IConfigTaskExecutor configTaskExecutor)
+      throws InterruptedException {
+    return configTaskExecutor.describeTable(database, tableName, false, false);
+  }
+
+  public static void buildTsBlock(
+      final TsTable table, final SettableFuture<ConfigTaskResult> future) {
+    if (TreeViewSchema.isTreeViewTable(table)) {
+      ShowCreateViewTask.buildTsBlock(table, future);
+      return;
+    }
+    final List<TSDataType> outputDataTypes =
+        ColumnHeaderConstant.showCreateTableColumnHeaders.stream()
+            .map(ColumnHeader::getColumnType)
+            .collect(Collectors.toList());
+
+    final TsBlockBuilder builder = new TsBlockBuilder(outputDataTypes);
+    builder.getTimeColumnBuilder().writeLong(0L);
+    builder
+        .getColumnBuilder(0)
+        .writeBinary(new Binary(table.getTableName(), TSFileConfig.STRING_CHARSET));
+    builder
+        .getColumnBuilder(1)
+        .writeBinary(new Binary(getShowCreateTableSQL(table), TSFileConfig.STRING_CHARSET));
+    builder.declarePosition();
+
+    final DatasetHeader datasetHeader = DatasetHeaderFactory.getShowCreateTableColumnHeader();
+    future.set(new ConfigTaskResult(TSStatusCode.SUCCESS_STATUS, builder.build(), datasetHeader));
+  }
+
+  private static String getShowCreateTableSQL(final TsTable table) {
+    final StringBuilder builder =
+        new StringBuilder("CREATE TABLE \"").append(table.getTableName()).append("\" (");
+
+    for (final TsTableColumnSchema schema : table.getColumnList()) {
+      switch (schema.getColumnCategory()) {
+        case TAG:
+          builder
+              .append(schema.getColumnName())
+              .append(" ")
+              .append(schema.getDataType())
+              .append(" ")
+              .append("TAG");
+          break;
+        case TIME:
+          continue;
+        case FIELD:
+          builder
+              .append(schema.getColumnName())

Review Comment:
   Applied



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords & Optimized the config tasks' error code + log [iotdb]

Posted by "shuwenwei (via GitHub)" <gi...@apache.org>.
shuwenwei merged PR #14617:
URL: https://github.com/apache/iotdb/pull/14617


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords & Optimized the config tasks' error code + log [iotdb]

Posted by "shuwenwei (via GitHub)" <gi...@apache.org>.
shuwenwei commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2063063788


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/schema/source/TableDeviceQuerySource.java:
##########
@@ -283,4 +347,39 @@ public long getMaxMemory(final ISchemaRegion schemaRegion) {
                     : 0))
         : TSFileDescriptor.getInstance().getConfig().getMaxTsBlockSizeInBytes();
   }
+
+  private static class RleBinaryColumnBuilder extends BinaryColumnBuilder {
+
+    private final BinaryColumnBuilder innerBuilder;
+
+    public RleBinaryColumnBuilder(final BinaryColumnBuilder innerBuilder) {
+      super(null, 0);
+      this.innerBuilder = innerBuilder;
+    }
+
+    @Override
+    public int getPositionCount() {
+      return innerBuilder.getPositionCount();
+    }
+
+    @Override
+    public ColumnBuilder writeBinary(final Binary value) {
+      return innerBuilder.writeBinary(value);
+    }
+
+    @Override
+    public ColumnBuilder appendNull() {
+      return innerBuilder.appendNull();
+    }
+
+    @Override
+    public Column build() {
+      return new RunLengthEncodedColumn(innerBuilder.build(), getPositionCount());

Review Comment:
   Using `getPositionCount()` may cause an IllegalArgumentException.
   <img width="949" alt="截屏2025-04-28 15 38 23" src="https://github.com/user-attachments/assets/e44e5f46-5b0e-4814-899d-6296c0e8104b" />
   



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords & Optimized the config tasks' error code + log [iotdb]

Posted by "shuwenwei (via GitHub)" <gi...@apache.org>.
shuwenwei commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2055468215


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/RelationPlanner.java:
##########
@@ -222,8 +222,8 @@ protected RelationPlan visitTable(final Table table, final Void context) {
               outputSymbols,
               tableColumnSchema,
               idAndAttributeIndexMap,
-              treeDeviceViewSchema.getTreeDBName(),
-              treeDeviceViewSchema.getMeasurementColumnNameMap()),
+              treeDeviceViewSchema.getTreePathPatternName(),

Review Comment:
   Using treePathPatternName as treeDBName will result in failure to obtain DataPartition later in `PushPredicateIntoTableScan.fetchDataPartitionByDevices`



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords [iotdb]

Posted by "shuwenwei (via GitHub)" <gi...@apache.org>.
shuwenwei commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2049898505


##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TreeViewSchema.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.commons.schema.table;
+
+import org.apache.iotdb.commons.exception.IllegalPathException;
+import org.apache.iotdb.commons.exception.IoTDBRuntimeException;
+import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.commons.path.PathPatternUtil;
+import org.apache.iotdb.commons.schema.table.column.TsTableColumnSchema;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+public class TreeViewSchema {
+  public static final String ORIGINAL_NAME = "__original_name";
+  public static final String TREE_PATH_PATTERN = "__tree_path_pattern";
+  public static final String RESTRICT = "__restrict";
+
+  public static boolean isTreeViewTable(final TsTable table) {
+    return table.getPropValue(TREE_PATH_PATTERN).isPresent();
+  }
+
+  public static PartialPath getPrefixPattern(final TsTable table) {
+    return table
+        .getPropValue(TreeViewSchema.TREE_PATH_PATTERN)
+        .map(TreeViewSchema::forceSeparateStringToPartialPath)
+        .orElseThrow(
+            () ->
+                new IoTDBRuntimeException(
+                    String.format(
+                        "Failed to get the original database, because the %s is null for table %s",
+                        TreeViewSchema.TREE_PATH_PATTERN, table.getTableName()),
+                    TSStatusCode.SEMANTIC_ERROR.getStatusCode()));
+  }
+
+  public static PartialPath forceSeparateStringToPartialPath(final String string) {
+    final PartialPath partialPath;
+    try {
+      partialPath = new PartialPath(string);
+    } catch (final IllegalPathException e) {
+      throw new IoTDBRuntimeException(
+          String.format(
+              "Failed to parse the tree view string %s when convert to IDeviceID", string),
+          TSStatusCode.SEMANTIC_ERROR.getStatusCode());
+    }
+    return partialPath;
+  }
+
+  public static String getOriginalName(final TsTableColumnSchema schema) {
+    return schema.getProps().get(ORIGINAL_NAME);
+  }
+
+  public static void setOriginalName(final TsTableColumnSchema schema, final String name) {
+    schema.getProps().put(ORIGINAL_NAME, name);
+  }
+
+  public static boolean isRestrict(final TsTable table) {
+    return table.getPropValue(RESTRICT).isPresent();
+  }
+
+  public static void setRestrict(final TsTable table) {
+    table.addProp(RESTRICT, "");
+  }
+
+  public static String setPathPattern(final TsTable table, final PartialPath pathPattern) {
+    final String[] nodes = pathPattern.getNodes();
+    if (!PathPatternUtil.isMultiLevelMatchWildcard(nodes[nodes.length - 1])) {
+      return "The last node must be '**'";

Review Comment:
   You can throw an exception in this method



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords [iotdb]

Posted by "shuwenwei (via GitHub)" <gi...@apache.org>.
shuwenwei commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2048535467


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/RestApiServiceImpl.java:
##########


Review Comment:
   There seem to be different versions of RestApiServiceImpl. Does it also need to be modified?



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords [iotdb]

Posted by "shuwenwei (via GitHub)" <gi...@apache.org>.
shuwenwei commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2048506346


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/RestApiServiceImpl.java:
##########
@@ -102,21 +105,36 @@ public Response executeNonQueryStatement(SQL sql, SecurityContext securityContex
             .build();
       }
 
-      Response response = authorizationHandler.checkAuthority(securityContext, statement);
-      if (response != null) {
-        return response;
-      }
+      final ExecutionResult result;
       queryId = SESSION_MANAGER.requestQueryId();
-      ExecutionResult result =
-          COORDINATOR.executeForTreeModel(
-              statement,
-              queryId,
-              SESSION_MANAGER.getSessionInfo(SESSION_MANAGER.getCurrSession()),
-              sql.getSql(),
-              partitionFetcher,
-              schemaFetcher,
-              config.getQueryTimeoutThreshold(),
-              false);
+      if (statement instanceof CreateTableViewStatement) {
+        result =
+            COORDINATOR.executeForTableModel(
+                ((CreateTableViewStatement) statement).getCreateTableView(),
+                new SqlParser(),
+                SESSION_MANAGER.getCurrSessionAndUpdateIdleTime(),
+                queryId,
+                SESSION_MANAGER.getSessionInfo(SESSION_MANAGER.getCurrSession()),
+                sql.getSql(),
+                LocalExecutionPlanner.getInstance().metadata,
+                config.getQueryTimeoutThreshold(),
+                false);
+      } else {
+        Response response = authorizationHandler.checkAuthority(securityContext, statement);

Review Comment:
   Does CreateTableViewStatement need to do this check?



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords [iotdb]

Posted by "Caideyipi (via GitHub)" <gi...@apache.org>.
Caideyipi commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2049943228


##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TreeViewSchema.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.commons.schema.table;
+
+import org.apache.iotdb.commons.exception.IllegalPathException;
+import org.apache.iotdb.commons.exception.IoTDBRuntimeException;
+import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.commons.path.PathPatternUtil;
+import org.apache.iotdb.commons.schema.table.column.TsTableColumnSchema;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+public class TreeViewSchema {
+  public static final String ORIGINAL_NAME = "__original_name";
+  public static final String TREE_PATH_PATTERN = "__tree_path_pattern";
+  public static final String RESTRICT = "__restrict";
+
+  public static boolean isTreeViewTable(final TsTable table) {
+    return table.getPropValue(TREE_PATH_PATTERN).isPresent();
+  }
+
+  public static PartialPath getPrefixPattern(final TsTable table) {
+    return table
+        .getPropValue(TreeViewSchema.TREE_PATH_PATTERN)
+        .map(TreeViewSchema::forceSeparateStringToPartialPath)
+        .orElseThrow(
+            () ->
+                new IoTDBRuntimeException(
+                    String.format(
+                        "Failed to get the original database, because the %s is null for table %s",
+                        TreeViewSchema.TREE_PATH_PATTERN, table.getTableName()),
+                    TSStatusCode.SEMANTIC_ERROR.getStatusCode()));
+  }
+
+  public static PartialPath forceSeparateStringToPartialPath(final String string) {
+    final PartialPath partialPath;
+    try {
+      partialPath = new PartialPath(string);
+    } catch (final IllegalPathException e) {
+      throw new IoTDBRuntimeException(
+          String.format(
+              "Failed to parse the tree view string %s when convert to IDeviceID", string),
+          TSStatusCode.SEMANTIC_ERROR.getStatusCode());
+    }
+    return partialPath;
+  }
+
+  public static String getOriginalName(final TsTableColumnSchema schema) {
+    return schema.getProps().get(ORIGINAL_NAME);
+  }
+
+  public static void setOriginalName(final TsTableColumnSchema schema, final String name) {
+    schema.getProps().put(ORIGINAL_NAME, name);
+  }
+
+  public static boolean isRestrict(final TsTable table) {
+    return table.getPropValue(RESTRICT).isPresent();
+  }
+
+  public static void setRestrict(final TsTable table) {
+    table.addProp(RESTRICT, "");
+  }
+
+  public static String setPathPattern(final TsTable table, final PartialPath pathPattern) {
+    final String[] nodes = pathPattern.getNodes();
+    if (!PathPatternUtil.isMultiLevelMatchWildcard(nodes[nodes.length - 1])) {
+      return "The last node must be '**'";

Review Comment:
   This class is in "common" and cannot throw the "SemanticException" because the latter one is in "server" module...



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords [iotdb]

Posted by "shuwenwei (via GitHub)" <gi...@apache.org>.
shuwenwei commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2049977528


##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/schema/ClusterSchemaManager.java:
##########
@@ -1423,6 +1527,33 @@ public synchronized Pair<TSStatus, TsTable> updateTableProperties(
     return new Pair<>(RpcUtils.SUCCESS_STATUS, updatedTable);
   }
 
+  public static Optional<Pair<TSStatus, TsTable>> checkTable4View(

Review Comment:
   The right object of the Pair always seems to be null



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added schema & Supported "show create view" + "show create table" for tree device view + base tables & Implemented information_schema for views/models/functions/configurations/keywords [iotdb]

Posted by "Caideyipi (via GitHub)" <gi...@apache.org>.
Caideyipi commented on code in PR #14617:
URL: https://github.com/apache/iotdb/pull/14617#discussion_r2049983576


##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/schema/ClusterSchemaManager.java:
##########
@@ -1423,6 +1527,33 @@ public synchronized Pair<TSStatus, TsTable> updateTableProperties(
     return new Pair<>(RpcUtils.SUCCESS_STATUS, updatedTable);
   }
 
+  public static Optional<Pair<TSStatus, TsTable>> checkTable4View(

Review Comment:
   This is for the convenience of direct return



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org