-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[Table Model] Schema Validation Interface #12707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 @@ List<DeviceEntry> indexScan( | |
| 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( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if auto create is false? So I think should return Optional, if we cannot auto craete this table we just return Optinal.empty()
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if schema validation failed? dataType miss match? throw what kind of exception?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Throw SemanticException |
||
| 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. think about partial insert, how to return info to caller about:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First, We haven't define what is "partial insert" in table model. Device level or series level? Second, to support partial insert, another interface "markFailed(int index)" shall be added to the ITableDeviceSchemaValidation and will be recalled during validation process. For "auto create succeed or this device already exists before", no exception or info should be return in current stage. Id column data type may be should be returned if we support device id values with different data type.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After confirmation with @jt2594838 and @qiaojialin , auto create won't affect device creation, so the creation for device won't failed because of auto_create is false, but there may be other reasons. If your current implementation will throw some specific exception if any device creation failed, it's ok but you need add that exception in java doc and make your interface more clear. |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add java doc for each method and examples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.