This is an automated email from the ASF dual-hosted git repository. chenyz pushed a commit to branch udtf in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 87fc892d0725e7e70b101ce47a86520e8fd01611 Author: Chen YZ <[email protected]> AuthorDate: Mon Jan 20 19:05:23 2025 +0800 save --- .../relational/table/argument/DescribedSchema.java | 20 ++++-------- .../relational/table/argument/TableArgument.java | 11 ------- .../apache/iotdb/udf/api/type/ColumnCategory.java | 37 ---------------------- .../function/table/ExcludeColumnFunction.java | 3 +- .../execution/function/table/HOPTableFunction.java | 11 ++++--- .../execution/function/table/SplitFunction.java | 4 +-- .../relational/analyzer/StatementAnalyzer.java | 11 ++----- .../plan/relational/sql/parser/AstBuilder.java | 21 +++++++++++- .../schema/table/column/TsTableColumnCategory.java | 31 ------------------ .../db/relational/grammar/sql/RelationalSql.g4 | 7 +++- 10 files changed, 42 insertions(+), 114 deletions(-) diff --git a/iotdb-api/udf-api/src/main/java/org/apache/iotdb/udf/api/relational/table/argument/DescribedSchema.java b/iotdb-api/udf-api/src/main/java/org/apache/iotdb/udf/api/relational/table/argument/DescribedSchema.java index 95411b7513a..aecea22067f 100644 --- a/iotdb-api/udf-api/src/main/java/org/apache/iotdb/udf/api/relational/table/argument/DescribedSchema.java +++ b/iotdb-api/udf-api/src/main/java/org/apache/iotdb/udf/api/relational/table/argument/DescribedSchema.java @@ -19,7 +19,6 @@ package org.apache.iotdb.udf.api.relational.table.argument; -import org.apache.iotdb.udf.api.type.ColumnCategory; import org.apache.iotdb.udf.api.type.Type; import java.util.ArrayList; @@ -50,13 +49,13 @@ public class DescribedSchema { public static class Builder { private final List<Field> fields = new ArrayList<>(); - public Builder addField(String name, Type type, ColumnCategory category) { - fields.add(new Field(name, type, category)); + public Builder addField(String name, Type type) { + fields.add(new Field(name, type)); return this; } - public Builder addField(Optional<String> name, Type type, ColumnCategory category) { - fields.add(new Field(name, type, category)); + public Builder addField(Optional<String> name, Type type) { + fields.add(new Field(name, type)); return this; } @@ -68,18 +67,15 @@ public class DescribedSchema { public static class Field { private final Optional<String> name; private final Type type; - private final ColumnCategory category; - public Field(String name, Type type, ColumnCategory category) { + public Field(String name, Type type) { this.name = Optional.ofNullable(name); this.type = type; - this.category = category; } - public Field(Optional<String> name, Type type, ColumnCategory category) { + public Field(Optional<String> name, Type type) { this.name = name; this.type = type; - this.category = category; } public Optional<String> getName() { @@ -89,9 +85,5 @@ public class DescribedSchema { public Type getType() { return type; } - - public ColumnCategory getCategory() { - return category; - } } } diff --git a/iotdb-api/udf-api/src/main/java/org/apache/iotdb/udf/api/relational/table/argument/TableArgument.java b/iotdb-api/udf-api/src/main/java/org/apache/iotdb/udf/api/relational/table/argument/TableArgument.java index d989f526694..4160caa52e6 100644 --- a/iotdb-api/udf-api/src/main/java/org/apache/iotdb/udf/api/relational/table/argument/TableArgument.java +++ b/iotdb-api/udf-api/src/main/java/org/apache/iotdb/udf/api/relational/table/argument/TableArgument.java @@ -19,7 +19,6 @@ package org.apache.iotdb.udf.api.relational.table.argument; -import org.apache.iotdb.udf.api.type.ColumnCategory; import org.apache.iotdb.udf.api.type.Type; import java.util.List; @@ -30,25 +29,19 @@ import static java.util.Objects.requireNonNull; public class TableArgument implements Argument { private final List<Optional<String>> fieldNames; private final List<Type> fieldTypes; - private final List<ColumnCategory> fieldCategories; private final List<String> partitionBy; private final List<String> orderBy; public TableArgument( List<Optional<String>> fieldNames, List<Type> fieldTypes, - List<ColumnCategory> fieldCategories, List<String> partitionBy, List<String> orderBy) { this.fieldNames = requireNonNull(fieldNames, "fieldNames is null"); this.fieldTypes = requireNonNull(fieldTypes, "fieldTypes is null"); - this.fieldCategories = requireNonNull(fieldCategories, "fieldCategories is null"); if (fieldNames.size() != fieldTypes.size()) { throw new IllegalArgumentException("fieldNames and fieldTypes must have the same size"); } - if (fieldNames.size() != fieldCategories.size()) { - throw new IllegalArgumentException("fieldNames and fieldCategories must have the same size"); - } this.partitionBy = requireNonNull(partitionBy, "partitionBy is null"); this.orderBy = requireNonNull(orderBy, "orderBy is null"); } @@ -61,10 +54,6 @@ public class TableArgument implements Argument { return fieldTypes; } - public List<ColumnCategory> getFieldCategories() { - return fieldCategories; - } - public List<String> getPartitionBy() { return partitionBy; } diff --git a/iotdb-api/udf-api/src/main/java/org/apache/iotdb/udf/api/type/ColumnCategory.java b/iotdb-api/udf-api/src/main/java/org/apache/iotdb/udf/api/type/ColumnCategory.java deleted file mode 100644 index 8ac065bf942..00000000000 --- a/iotdb-api/udf-api/src/main/java/org/apache/iotdb/udf/api/type/ColumnCategory.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.udf.api.type; - -public enum ColumnCategory { - TAG((byte) 0), - ATTRIBUTE((byte) 1), - TIME((byte) 2), - FIELD((byte) 3); - - private final byte category; - - ColumnCategory(byte category) { - this.category = category; - } - - byte getValue() { - return category; - } -} diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/function/table/ExcludeColumnFunction.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/function/table/ExcludeColumnFunction.java index 5ba833ed7a2..2b3998365a5 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/function/table/ExcludeColumnFunction.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/function/table/ExcludeColumnFunction.java @@ -68,8 +68,7 @@ public class ExcludeColumnFunction implements TableFunction { requiredColumns.add(i); schemaBuilder.addField( fieldName, - tableArgument.getFieldTypes().get(i), - tableArgument.getFieldCategories().get(i)); + tableArgument.getFieldTypes().get(i)); } } return TableFunctionAnalysis.builder() diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/function/table/HOPTableFunction.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/function/table/HOPTableFunction.java index ce4021a0771..6bf8df15f04 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/function/table/HOPTableFunction.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/function/table/HOPTableFunction.java @@ -32,7 +32,6 @@ import org.apache.iotdb.udf.api.relational.table.processor.TableFunctionDataProc import org.apache.iotdb.udf.api.relational.table.specification.ParameterSpecification; import org.apache.iotdb.udf.api.relational.table.specification.ScalarParameterSpecification; import org.apache.iotdb.udf.api.relational.table.specification.TableParameterSpecification; -import org.apache.iotdb.udf.api.type.ColumnCategory; import org.apache.iotdb.udf.api.type.Type; import org.apache.tsfile.block.column.ColumnBuilder; @@ -85,6 +84,7 @@ public class HOPTableFunction implements TableFunction { return requiredIndex; } + // TODO: ImmutableMap @Override public TableFunctionAnalysis analyze(Map<String, Argument> arguments) { TableArgument tableArgument = (TableArgument) arguments.get(DATA_PARAMETER_NAME); @@ -96,10 +96,11 @@ public class HOPTableFunction implements TableFunction { } DescribedSchema properColumnSchema = new DescribedSchema.Builder() - .addField("window_start", Type.TIMESTAMP, ColumnCategory.FIELD) - .addField("window_end", Type.TIMESTAMP, ColumnCategory.FIELD) + .addField("window_start", Type.TIMESTAMP) + .addField("window_end", Type.TIMESTAMP) .build(); + // outputColumnSchema return TableFunctionAnalysis.builder() .properColumnSchema(properColumnSchema) .requiredColumns( @@ -122,8 +123,8 @@ public class HOPTableFunction implements TableFunction { public TableFunctionDataProcessor getDataProcessor() { return new HOPDataProcessor( (Long) ((ScalarArgument) arguments.get(START_PARAMETER_NAME)).getValue(), - (Long) ((ScalarArgument) arguments.get(SLIDE_PARAMETER_NAME)).getValue() * 1000, - (Long) ((ScalarArgument) arguments.get(SLIDE_PARAMETER_NAME)).getValue() * 1000, + (Long) ((ScalarArgument) arguments.get(SLIDE_PARAMETER_NAME)).getValue(), + (Long) ((ScalarArgument) arguments.get(SIZE_PARAMETER_NAME)).getValue(), requiredIndex); } }; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/function/table/SplitFunction.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/function/table/SplitFunction.java index 263cfa79d7f..76880270f37 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/function/table/SplitFunction.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/function/table/SplitFunction.java @@ -29,7 +29,6 @@ import org.apache.iotdb.udf.api.relational.table.argument.ScalarArgument; import org.apache.iotdb.udf.api.relational.table.processor.TableFunctionLeafProcessor; import org.apache.iotdb.udf.api.relational.table.specification.ParameterSpecification; import org.apache.iotdb.udf.api.relational.table.specification.ScalarParameterSpecification; -import org.apache.iotdb.udf.api.type.ColumnCategory; import org.apache.iotdb.udf.api.type.Type; import org.apache.tsfile.block.column.ColumnBuilder; @@ -57,8 +56,7 @@ public class SplitFunction implements TableFunction { @Override public TableFunctionAnalysis analyze(Map<String, Argument> arguments) throws UDFException { - DescribedSchema schema = - DescribedSchema.builder().addField("output", Type.STRING, ColumnCategory.FIELD).build(); + DescribedSchema schema = DescribedSchema.builder().addField("output", Type.STRING).build(); return TableFunctionAnalysis.builder().properColumnSchema(schema).build(); } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java index 9528f7e2e2f..bbdb55815ac 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java @@ -174,7 +174,6 @@ import org.apache.iotdb.udf.api.relational.table.specification.DescriptorParamet import org.apache.iotdb.udf.api.relational.table.specification.ParameterSpecification; import org.apache.iotdb.udf.api.relational.table.specification.ScalarParameterSpecification; import org.apache.iotdb.udf.api.relational.table.specification.TableParameterSpecification; -import org.apache.iotdb.udf.api.type.ColumnCategory; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ImmutableList; @@ -3196,7 +3195,7 @@ public class StatementAnalyzer { Field.newUnqualified( f.getName(), UDFDataTypeTransformer.transformUDFDataTypeToReadType(f.getType()), - TsTableColumnCategory.fromUdfColumnType(f.getCategory()))) + TsTableColumnCategory.FIELD)) .forEach(fields::add)); // next, columns derived from table arguments, in order of argument declarations @@ -3394,7 +3393,6 @@ public class StatementAnalyzer { Optional<Scope> scope) { List<Optional<String>> fieldNames; List<org.apache.iotdb.udf.api.type.Type> fieldTypes; - List<ColumnCategory> fieldCategories; List<String> partitionBy = Collections.emptyList(); List<String> orderBy = Collections.emptyList(); @@ -3418,11 +3416,6 @@ public class StatementAnalyzer { .map(Field::getType) .map(UDFDataTypeTransformer::transformReadTypeToUDFDataType) .collect(toImmutableList()); - fieldCategories = - fields.stream() - .map(Field::getColumnCategory) - .map(TsTableColumnCategory::toUdfColumnCategory) - .collect(toImmutableList()); // analyze PARTITION BY if (tableArgument.getPartitionBy().isPresent()) { @@ -3522,7 +3515,7 @@ public class StatementAnalyzer { analysisBuilder.withPassThroughColumns(argumentSpecification.isPassThroughColumns()); return new ArgumentAnalysis( - new TableArgument(fieldNames, fieldTypes, fieldCategories, partitionBy, orderBy), + new TableArgument(fieldNames, fieldTypes, partitionBy, orderBy), Optional.of(analysisBuilder.build())); } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java index b4f40236b6c..482c6bf5e93 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java @@ -243,6 +243,7 @@ import static org.apache.iotdb.db.queryengine.plan.relational.sql.ast.GroupingSe import static org.apache.iotdb.db.queryengine.plan.relational.sql.ast.QualifiedName.mapIdentifier; import static org.apache.iotdb.db.queryengine.plan.relational.sql.ast.TableFunctionDescriptorArgument.descriptorArgument; import static org.apache.iotdb.db.queryengine.plan.relational.sql.ast.TableFunctionDescriptorArgument.nullDescriptorArgument; +import static org.apache.iotdb.db.utils.TimestampPrecisionUtils.currPrecision; import static org.apache.iotdb.db.utils.constant.SqlConstant.FIRST_AGGREGATION; import static org.apache.iotdb.db.utils.constant.SqlConstant.FIRST_BY_AGGREGATION; import static org.apache.iotdb.db.utils.constant.SqlConstant.LAST_AGGREGATION; @@ -1834,7 +1835,7 @@ public class AstBuilder extends RelationalSqlBaseVisitor<Node> { } else if (context.descriptorArgument() != null) { value = visit(context.descriptorArgument()); } else { - value = visit(context.expression()); + value = visit(context.scalarArgument()); } return new TableFunctionArgument(getLocation(context), name, value); @@ -1931,6 +1932,24 @@ public class AstBuilder extends RelationalSqlBaseVisitor<Node> { visitIfPresent(context.type(), DataType.class)); } + @Override + public Node visitScalarArgument(RelationalSqlParser.ScalarArgumentContext ctx) { + if (ctx.expression() != null) { + return visit(ctx.expression()); + } else { + TimeDuration timeDuration = DateTimeUtils.constructTimeDuration(ctx.timeDuration().getText()); + + if (timeDuration.monthDuration != 0 && timeDuration.nonMonthDuration != 0) { + throw new SemanticException( + "Simultaneous setting of monthly and non-monthly intervals is not supported."); + } + + return new LongLiteral( + getLocation(ctx.timeDuration()), + String.valueOf(timeDuration.getTotalDuration(currPrecision))); + } + } + // ********************* predicates ******************* @Override diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/column/TsTableColumnCategory.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/column/TsTableColumnCategory.java index 4ff0c6663b9..9f6dcd6019c 100644 --- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/column/TsTableColumnCategory.java +++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/column/TsTableColumnCategory.java @@ -102,37 +102,6 @@ public enum TsTableColumnCategory { } } - public org.apache.iotdb.udf.api.type.ColumnCategory toUdfColumnCategory() { - switch (this) { - case TAG: - return org.apache.iotdb.udf.api.type.ColumnCategory.TAG; - case ATTRIBUTE: - return org.apache.iotdb.udf.api.type.ColumnCategory.ATTRIBUTE; - case FIELD: - return org.apache.iotdb.udf.api.type.ColumnCategory.FIELD; - case TIME: - return org.apache.iotdb.udf.api.type.ColumnCategory.TIME; - default: - throw new IllegalArgumentException("Unsupported column type in UDF: " + this); - } - } - - public static TsTableColumnCategory fromUdfColumnType( - org.apache.iotdb.udf.api.type.ColumnCategory columnType) { - switch (columnType) { - case FIELD: - return FIELD; - case TAG: - return TAG; - case ATTRIBUTE: - return ATTRIBUTE; - case TIME: - return TIME; - default: - throw new IllegalArgumentException("Unknown column type: " + columnType); - } - } - public byte getCategory() { return category; } diff --git a/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4 b/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4 index e53900465a5..4f0ae953dac 100644 --- a/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4 +++ b/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4 @@ -735,7 +735,7 @@ tableFunctionCall ; tableFunctionArgument - : (identifier '=>')? (tableArgument | descriptorArgument | expression) // descriptor before expression to avoid parsing descriptor as a function call + : (identifier '=>')? (tableArgument | descriptorArgument | scalarArgument) // descriptor before expression to avoid parsing descriptor as a function call ; tableArgument @@ -759,6 +759,11 @@ descriptorField : identifier type? ; +scalarArgument + : expression + | timeDuration + ; + copartitionTables : '(' qualifiedName ',' qualifiedName (',' qualifiedName)* ')' ;
