This is an automated email from the ASF dual-hosted git repository.

jackietien pushed a commit to branch ty/TableModelGrammar
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/ty/TableModelGrammar by this 
push:
     new 50d8708f2ec [Table Model] Schema Validation Interface (#12707)
50d8708f2ec is described below

commit 50d8708f2ec19e151baccf2e9bda7eb154bdf917
Author: Marcos_Zyk <[email protected]>
AuthorDate: Wed Jun 12 08:55:47 2024 +0800

    [Table Model] Schema Validation Interface (#12707)
---
 .../metadata/ITableDeviceSchemaValidation.java     | 66 ++++++++++++++++++++++
 .../plan/relational/metadata/Metadata.java         | 30 ++++++++++
 .../relational/metadata/TableMetadataImpl.java     | 13 +++++
 .../plan/relational/analyzer/TestMatadata.java     | 14 +++++
 4 files changed, 123 insertions(+)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/ITableDeviceSchemaValidation.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/ITableDeviceSchemaValidation.java
new file mode 100644
index 00000000000..60ca965e632
--- /dev/null
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/ITableDeviceSchemaValidation.java
@@ -0,0 +1,66 @@
+/*
+ * 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.metadata;
+
+import java.util.List;
+
+/**
+ * This class acts as a request for device schema validation and defines the 
necessary information
+ * interfaces.
+ *
+ * <p>e.g. {database"db", "t1", [["hebei", "p_1", "t_1"], ["shandong", null, 
"t_1"]], ["attr_1",
+ * "attr_2"], [["attr_value1", "attr_value2"], ["v_1", null]]}
+ *
+ * <ol>
+ *   <li>database = "db"
+ *   <li>tableName = "t1"
+ *   <li>deviceIdList = [["hebei", "p_1", "t_1"], ["shandong", null, "t_1"]]
+ *   <li>attributeColumnNameList = ["attr_1", "attr_2"]
+ *   <li>attributeValueList = [["attr_value1", "attr_value2"], ["v_1", null]]
+ * </ol>
+ */
+public interface ITableDeviceSchemaValidation {
+
+  /**
+   * @return database name
+   */
+  String getDatabase();
+
+  /**
+   * @return table name without database name as prefix
+   */
+  String getTableName();
+
+  /**
+   * @return ids, without db or table name, of all involved devices
+   */
+  List<Object[]> getDeviceIdList();
+
+  /**
+   * @return attribute column names
+   */
+  List<String> getAttributeColumnNameList();
+
+  /**
+   * @return attribute values, the order of which shall be consistent with 
that of the provided
+   *     device ids and attribute column names.
+   */
+  List<Object[]> getAttributeValueList();
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/Metadata.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/Metadata.java
index f37aabbce8b..dc66581b74c 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/Metadata.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/Metadata.java
@@ -19,6 +19,7 @@
 
 package org.apache.iotdb.db.queryengine.plan.relational.metadata;
 
+import org.apache.iotdb.db.queryengine.common.MPPQueryContext;
 import org.apache.iotdb.db.queryengine.common.SessionInfo;
 import org.apache.iotdb.db.queryengine.plan.relational.function.OperatorType;
 import org.apache.iotdb.db.queryengine.plan.relational.security.AccessControl;
@@ -67,4 +68,33 @@ public interface Metadata {
       QualifiedObjectName tableName,
       List<Expression> expressionList,
       List<String> attributeColumns);
+
+  /**
+   * This method is used for table column validation and should be invoked 
before device validation.
+   *
+   * <p>This method return all the existing column schemas in the target table.
+   *
+   * <p>When table or column is missing, this method will execute auto 
creation.
+   *
+   * <p>When using SQL, the columnSchemaList could be null and there won't be 
any validation.
+   *
+   * <p>When the input dataType or category of one column is null, the column 
cannot be auto
+   * created.
+   *
+   * <p>If validation failed, a SemanticException will be thrown.
+   */
+  TableSchema validateTableHeaderSchema(
+      String database, TableSchema tableSchema, MPPQueryContext context);
+
+  /**
+   * This method is used for table device validation and should be invoked 
after column validation.
+   *
+   * <p>When device id is missing, this method will execute auto creation.
+   *
+   * <p>When device attribute is missing or different from that stored in 
IoTDB, the attribute will
+   * be auto upsert.
+   *
+   * <p>If validation failed, a SemanticException will be thrown.
+   */
+  void validateDeviceSchema(ITableDeviceSchemaValidation schemaValidation, 
MPPQueryContext context);
 }
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java
index 1c897c9646e..67f030ede35 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java
@@ -22,6 +22,7 @@ package 
org.apache.iotdb.db.queryengine.plan.relational.metadata;
 import org.apache.iotdb.commons.udf.builtin.BuiltinAggregationFunction;
 import org.apache.iotdb.commons.udf.builtin.BuiltinScalarFunction;
 import org.apache.iotdb.db.exception.sql.SemanticException;
+import org.apache.iotdb.db.queryengine.common.MPPQueryContext;
 import org.apache.iotdb.db.queryengine.common.SessionInfo;
 import org.apache.iotdb.db.queryengine.plan.relational.function.OperatorType;
 import org.apache.iotdb.db.queryengine.plan.relational.security.AccessControl;
@@ -275,6 +276,18 @@ public class TableMetadataImpl implements Metadata {
     return result;
   }
 
+  @Override
+  public TableSchema validateTableHeaderSchema(
+      String database, TableSchema tableSchema, MPPQueryContext context) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public void validateDeviceSchema(
+      ITableDeviceSchemaValidation schemaValidation, MPPQueryContext context) {
+    throw new UnsupportedOperationException();
+  }
+
   public static boolean isTwoNumericType(List<? extends Type> argumentTypes) {
     return argumentTypes.size() == 2
         && isNumericType(argumentTypes.get(0))
diff --git 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/TestMatadata.java
 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/TestMatadata.java
index c8eec5486c0..585898e2b08 100644
--- 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/TestMatadata.java
+++ 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/TestMatadata.java
@@ -16,11 +16,13 @@ package 
org.apache.iotdb.db.queryengine.plan.relational.analyzer;
 
 import org.apache.iotdb.commons.schema.table.column.TsTableColumnCategory;
 import org.apache.iotdb.commons.udf.builtin.BuiltinAggregationFunction;
+import org.apache.iotdb.db.queryengine.common.MPPQueryContext;
 import org.apache.iotdb.db.queryengine.common.SessionInfo;
 import org.apache.iotdb.db.queryengine.plan.relational.function.OperatorType;
 import org.apache.iotdb.db.queryengine.plan.relational.metadata.ColumnMetadata;
 import org.apache.iotdb.db.queryengine.plan.relational.metadata.ColumnSchema;
 import org.apache.iotdb.db.queryengine.plan.relational.metadata.DeviceEntry;
+import 
org.apache.iotdb.db.queryengine.plan.relational.metadata.ITableDeviceSchemaValidation;
 import org.apache.iotdb.db.queryengine.plan.relational.metadata.Metadata;
 import 
org.apache.iotdb.db.queryengine.plan.relational.metadata.OperatorNotFoundException;
 import 
org.apache.iotdb.db.queryengine.plan.relational.metadata.QualifiedObjectName;
@@ -184,6 +186,18 @@ public class TestMatadata implements Metadata {
             Arrays.asList("a1", "a2")));
   }
 
+  @Override
+  public TableSchema validateTableHeaderSchema(
+      String database, TableSchema tableSchema, MPPQueryContext context) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public void validateDeviceSchema(
+      ITableDeviceSchemaValidation schemaValidation, MPPQueryContext context) {
+    throw new UnsupportedOperationException();
+  }
+
   public static boolean isTwoNumericType(List<? extends Type> argumentTypes) {
     return argumentTypes.size() == 2
         && isNumericType(argumentTypes.get(0))

Reply via email to