JackieTien97 commented on code in PR #14791:
URL: https://github.com/apache/iotdb/pull/14791#discussion_r1984251960
##########
iotdb-api/udf-api/src/main/java/org/apache/iotdb/udf/api/relational/TableFunction.java:
##########
@@ -19,4 +19,69 @@
package org.apache.iotdb.udf.api.relational;
-public interface TableFunction extends SQLFunction {}
+import org.apache.iotdb.udf.api.exception.UDFException;
+import org.apache.iotdb.udf.api.relational.table.TableFunctionAnalysis;
+import
org.apache.iotdb.udf.api.relational.table.TableFunctionProcessorProvider;
+import org.apache.iotdb.udf.api.relational.table.argument.Argument;
+import org.apache.iotdb.udf.api.relational.table.argument.ScalarArgument;
+import org.apache.iotdb.udf.api.relational.table.argument.TableArgument;
+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 java.util.List;
+import java.util.Map;
+
+public interface TableFunction extends SQLFunction {
+
+ /**
+ * This method is used to define the specification of the arguments required
by the table
+ * function. Each argument is described using a {@link
ParameterSpecification} object, which
+ * encapsulates details such as the argument name, whether it is required,
its default value (if
+ * any), etc.
+ *
+ * <p>The {@link ParameterSpecification} class is abstract and has two
concrete implementations:
+ *
+ * <ul>
+ * <li>{@link TableParameterSpecification}: Used for parameters specific
to table functions.
+ * <li>{@link ScalarParameterSpecification}: Used for parameters specific
to scalar functions.
Review Comment:
```suggestion
* <li>{@link ScalarParameterSpecification}: Used for parameters
specific to scalar arguments.
```
##########
iotdb-api/udf-api/src/main/java/org/apache/iotdb/udf/api/relational/TableFunction.java:
##########
@@ -19,4 +19,69 @@
package org.apache.iotdb.udf.api.relational;
-public interface TableFunction extends SQLFunction {}
+import org.apache.iotdb.udf.api.exception.UDFException;
+import org.apache.iotdb.udf.api.relational.table.TableFunctionAnalysis;
+import
org.apache.iotdb.udf.api.relational.table.TableFunctionProcessorProvider;
+import org.apache.iotdb.udf.api.relational.table.argument.Argument;
+import org.apache.iotdb.udf.api.relational.table.argument.ScalarArgument;
+import org.apache.iotdb.udf.api.relational.table.argument.TableArgument;
+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 java.util.List;
+import java.util.Map;
+
+public interface TableFunction extends SQLFunction {
+
+ /**
+ * This method is used to define the specification of the arguments required
by the table
+ * function. Each argument is described using a {@link
ParameterSpecification} object, which
+ * encapsulates details such as the argument name, whether it is required,
its default value (if
+ * any), etc.
+ *
+ * <p>The {@link ParameterSpecification} class is abstract and has two
concrete implementations:
+ *
+ * <ul>
+ * <li>{@link TableParameterSpecification}: Used for parameters specific
to table functions.
+ * <li>{@link ScalarParameterSpecification}: Used for parameters specific
to scalar functions.
+ * </ul>
+ *
+ * @return a list of {@link ParameterSpecification} objects describing the
function's arguments.
+ * The list should include all parameters that the table function
expects, along with their
+ * constraints and default values (if applicable).
+ */
+ List<ParameterSpecification> getArgumentsSpecifications();
+
+ /**
+ * This method is responsible for analyzing the provided arguments and
constructing a {@link
+ * TableFunctionAnalysis} object in runtime. During analysis, the method
should:
+ *
+ * <ul>
+ * <li>Extract values from scalar arguments (instances of {@link
ScalarArgument}) or extract
+ * table descriptions from table arguments (instances of {@link
TableArgument}).
+ * <li>Construct a {@link TableFunctionAnalysis} object that contains:
+ * <ul>
+ * <li>A description of proper columns.
Review Comment:
explain what's proper columns. I think they're sub columns of the final
output table?
The final table will contain all proper columns and all pass through
columns(or partition by columns)?
##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin/relational/TableBuiltinTableFunction.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.udf.builtin.relational;
+
+import org.apache.iotdb.commons.udf.builtin.relational.tvf.HOPTableFunction;
+import org.apache.iotdb.udf.api.relational.TableFunction;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public enum TableBuiltinTableFunction {
+// TODO(UDF): support built in function
Review Comment:
```suggestion
```
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java:
##########
@@ -2197,6 +2201,122 @@ public Node
visitParenthesizedRelation(RelationalSqlParser.ParenthesizedRelation
return visit(ctx.relation());
}
+ @Override
+ public Node visitTableFunctionInvocation(
+ RelationalSqlParser.TableFunctionInvocationContext context) {
+ return visit(context.tableFunctionCall());
+ }
+
+ @Override
+ public Node
visitTableFunctionCall(RelationalSqlParser.TableFunctionCallContext context) {
+ QualifiedName name = getQualifiedName(context.qualifiedName());
+ List<TableFunctionArgument> arguments =
+ visit(context.tableFunctionArgument(), TableFunctionArgument.class);
+ List<List<QualifiedName>> copartitioning = ImmutableList.of();
+ if (context.COPARTITION() != null) {
Review Comment:
Did we support this now? If not, better to throw SematicException here.
##########
iotdb-api/udf-api/src/main/java/org/apache/iotdb/udf/api/relational/table/TableFunctionAnalysis.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.relational.table;
+
+import org.apache.iotdb.udf.api.relational.table.argument.DescribedSchema;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * An object of this class is produced by the `analyze()` method of a
`ConnectorTableFunction`
Review Comment:
```suggestion
* An object of this class is produced by the `analyze()` method of a
`TableFunction`
```
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/optimizations/PushLimitOffsetIntoTableScan.java:
##########
@@ -237,6 +238,16 @@ public PlanNode visitInformationSchemaTableScan(
return node;
}
+ @Override
+ public PlanNode visitTableFunctionProcessor(TableFunctionProcessorNode
node, Context context) {
+ if (node.getChildren().isEmpty()) {
+ context.enablePushDown = false;
+ return node;
+ } else {
+ return visitPlan(node, context);
Review Comment:
can we push limitOffset through TableFunctionProcessorNode?
##########
iotdb-api/udf-api/src/main/java/org/apache/iotdb/udf/api/relational/TableFunction.java:
##########
@@ -19,4 +19,69 @@
package org.apache.iotdb.udf.api.relational;
-public interface TableFunction extends SQLFunction {}
+import org.apache.iotdb.udf.api.exception.UDFException;
+import org.apache.iotdb.udf.api.relational.table.TableFunctionAnalysis;
+import
org.apache.iotdb.udf.api.relational.table.TableFunctionProcessorProvider;
+import org.apache.iotdb.udf.api.relational.table.argument.Argument;
+import org.apache.iotdb.udf.api.relational.table.argument.ScalarArgument;
+import org.apache.iotdb.udf.api.relational.table.argument.TableArgument;
+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 java.util.List;
+import java.util.Map;
+
+public interface TableFunction extends SQLFunction {
+
+ /**
+ * This method is used to define the specification of the arguments required
by the table
+ * function. Each argument is described using a {@link
ParameterSpecification} object, which
+ * encapsulates details such as the argument name, whether it is required,
its default value (if
+ * any), etc.
+ *
+ * <p>The {@link ParameterSpecification} class is abstract and has two
concrete implementations:
+ *
+ * <ul>
+ * <li>{@link TableParameterSpecification}: Used for parameters specific
to table functions.
Review Comment:
also emphasize here, we only support at most one TableParameterSpecification
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/ShowFunctionsTask.java:
##########
@@ -152,6 +153,11 @@ private static void buildTableModelTsBlock(
TableBuiltinAggregationFunction.getBuiltInAggregateFunctionName(),
BINARY_MAP.get(FUNCTION_TYPE_BUILTIN_AGG_FUNC),
BINARY_MAP.get(FUNCTION_STATE_AVAILABLE));
+ appendFunctions(
+ builder,
+ TableBuiltinTableFunction.getBuiltInTableFunctionName(),
+ BINARY_MAP.get(FUNCTION_TYPE_BUILTIN_AGG_FUNC),
Review Comment:
FUNCTION_TYPE_BUILTIN_TABLE_FUNC
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/grouped/GroupedUserDefinedAggregateAccumulator.java:
##########
@@ -88,6 +88,10 @@ public void addInput(int[] groupIds, Column[] arguments,
AggregationMask mask) {
int groupId = groupIds[selectedPositions[index]];
index++;
State state = getOrCreateState(groupId);
+ if (state == null) {
+ state = aggregateFunction.createState();
+ stateArray.set(groupId, state);
+ }
Review Comment:
```suggestion
```
Why doing this? already included in `getOrCreateState`
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java:
##########
@@ -613,6 +614,23 @@ public SettableFuture<ConfigTaskResult> createFunction(
functionType = FunctionType.AGGREGATE;
} else if (o instanceof TableFunction) {
functionType = FunctionType.TABLE;
+ // check there is no duplicate argument specification for name
+ TableFunction tableFunction = (TableFunction) o;
+ Set<String> argNames = new HashSet<>();
+ for (ParameterSpecification specification :
+ tableFunction.getArgumentsSpecifications()) {
+ if (!argNames.add(specification.getName())) {
+ future.setException(
+ new IoTDBException(
+ "Failed to create function '"
+ + udfName
+ + "', because there is duplicate argument name '"
+ + specification.getName()
+ + "'.",
+ TSStatusCode.UDF_LOAD_CLASS_ERROR.getStatusCode()));
Review Comment:
add it in

avoid print exception stack in warn log, because it's just user's wrong
##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin/relational/tvf/HOPTableFunction.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.udf.builtin.relational.tvf;
+
+import org.apache.iotdb.udf.api.exception.UDFException;
+import org.apache.iotdb.udf.api.relational.TableFunction;
+import org.apache.iotdb.udf.api.relational.access.Record;
+import org.apache.iotdb.udf.api.relational.table.TableFunctionAnalysis;
+import
org.apache.iotdb.udf.api.relational.table.TableFunctionProcessorProvider;
+import org.apache.iotdb.udf.api.relational.table.argument.Argument;
+import org.apache.iotdb.udf.api.relational.table.argument.DescribedSchema;
+import org.apache.iotdb.udf.api.relational.table.argument.ScalarArgument;
+import org.apache.iotdb.udf.api.relational.table.argument.TableArgument;
+import
org.apache.iotdb.udf.api.relational.table.processor.TableFunctionDataProcessor;
+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.Type;
+
+import org.apache.tsfile.block.column.ColumnBuilder;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+public class HOPTableFunction implements TableFunction {
+
+ private static final String DATA_PARAMETER_NAME = "DATA";
+ private static final String TIMECOL_PARAMETER_NAME = "TIMECOL";
+ private static final String SLIDE_PARAMETER_NAME = "SLIDE";
+ private static final String SIZE_PARAMETER_NAME = "SIZE";
+ private static final String START_PARAMETER_NAME = "START";
Review Comment:
```suggestion
private static final String ORIGIN_PARAMETER_NAME = "ORIGIN";
```
same as date_bin's third parameter
##########
iotdb-api/udf-api/src/main/java/org/apache/iotdb/udf/api/relational/TableFunction.java:
##########
@@ -19,4 +19,69 @@
package org.apache.iotdb.udf.api.relational;
-public interface TableFunction extends SQLFunction {}
+import org.apache.iotdb.udf.api.exception.UDFException;
+import org.apache.iotdb.udf.api.relational.table.TableFunctionAnalysis;
+import
org.apache.iotdb.udf.api.relational.table.TableFunctionProcessorProvider;
+import org.apache.iotdb.udf.api.relational.table.argument.Argument;
+import org.apache.iotdb.udf.api.relational.table.argument.ScalarArgument;
+import org.apache.iotdb.udf.api.relational.table.argument.TableArgument;
+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 java.util.List;
+import java.util.Map;
+
+public interface TableFunction extends SQLFunction {
+
+ /**
+ * This method is used to define the specification of the arguments required
by the table
+ * function. Each argument is described using a {@link
ParameterSpecification} object, which
+ * encapsulates details such as the argument name, whether it is required,
its default value (if
+ * any), etc.
+ *
+ * <p>The {@link ParameterSpecification} class is abstract and has two
concrete implementations:
+ *
+ * <ul>
+ * <li>{@link TableParameterSpecification}: Used for parameters specific
to table functions.
Review Comment:
```suggestion
* <li>{@link TableParameterSpecification}: Used for parameter specific
to table argument?.
```
##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin/relational/tvf/HOPTableFunction.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.udf.builtin.relational.tvf;
+
+import org.apache.iotdb.udf.api.exception.UDFException;
+import org.apache.iotdb.udf.api.relational.TableFunction;
+import org.apache.iotdb.udf.api.relational.access.Record;
+import org.apache.iotdb.udf.api.relational.table.TableFunctionAnalysis;
+import
org.apache.iotdb.udf.api.relational.table.TableFunctionProcessorProvider;
+import org.apache.iotdb.udf.api.relational.table.argument.Argument;
+import org.apache.iotdb.udf.api.relational.table.argument.DescribedSchema;
+import org.apache.iotdb.udf.api.relational.table.argument.ScalarArgument;
+import org.apache.iotdb.udf.api.relational.table.argument.TableArgument;
+import
org.apache.iotdb.udf.api.relational.table.processor.TableFunctionDataProcessor;
+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.Type;
+
+import org.apache.tsfile.block.column.ColumnBuilder;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+public class HOPTableFunction implements TableFunction {
+
+ private static final String DATA_PARAMETER_NAME = "DATA";
+ private static final String TIMECOL_PARAMETER_NAME = "TIMECOL";
+ private static final String SLIDE_PARAMETER_NAME = "SLIDE";
+ private static final String SIZE_PARAMETER_NAME = "SIZE";
+ private static final String START_PARAMETER_NAME = "START";
+
+ @Override
+ public List<ParameterSpecification> getArgumentsSpecifications() {
+ return Arrays.asList(
+ TableParameterSpecification.builder()
+ .name(DATA_PARAMETER_NAME)
+ .rowSemantics()
+ .passThroughColumns()
+ .build(),
+ ScalarParameterSpecification.builder()
+ .name(TIMECOL_PARAMETER_NAME)
Review Comment:
defaultValue "time" ?
##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin/relational/tvf/HOPTableFunction.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.udf.builtin.relational.tvf;
+
+import org.apache.iotdb.udf.api.exception.UDFException;
+import org.apache.iotdb.udf.api.relational.TableFunction;
+import org.apache.iotdb.udf.api.relational.access.Record;
+import org.apache.iotdb.udf.api.relational.table.TableFunctionAnalysis;
+import
org.apache.iotdb.udf.api.relational.table.TableFunctionProcessorProvider;
+import org.apache.iotdb.udf.api.relational.table.argument.Argument;
+import org.apache.iotdb.udf.api.relational.table.argument.DescribedSchema;
+import org.apache.iotdb.udf.api.relational.table.argument.ScalarArgument;
+import org.apache.iotdb.udf.api.relational.table.argument.TableArgument;
+import
org.apache.iotdb.udf.api.relational.table.processor.TableFunctionDataProcessor;
+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.Type;
+
+import org.apache.tsfile.block.column.ColumnBuilder;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+public class HOPTableFunction implements TableFunction {
+
+ private static final String DATA_PARAMETER_NAME = "DATA";
+ private static final String TIMECOL_PARAMETER_NAME = "TIMECOL";
+ private static final String SLIDE_PARAMETER_NAME = "SLIDE";
+ private static final String SIZE_PARAMETER_NAME = "SIZE";
+ private static final String START_PARAMETER_NAME = "START";
+
+ @Override
+ public List<ParameterSpecification> getArgumentsSpecifications() {
+ return Arrays.asList(
+ TableParameterSpecification.builder()
+ .name(DATA_PARAMETER_NAME)
+ .rowSemantics()
+ .passThroughColumns()
+ .build(),
+ ScalarParameterSpecification.builder()
+ .name(TIMECOL_PARAMETER_NAME)
+ .type(Type.STRING)
+ .build(),
+
ScalarParameterSpecification.builder().name(SLIDE_PARAMETER_NAME).type(Type.INT64).build(),
+
ScalarParameterSpecification.builder().name(SIZE_PARAMETER_NAME).type(Type.INT64).build(),
+ ScalarParameterSpecification.builder()
+ .name(START_PARAMETER_NAME)
+ .type(Type.TIMESTAMP)
+ .defaultValue(0L)
+ .build());
+ }
+
+ private int findTimeColumnIndex(TableArgument tableArgument, String
expectedFieldName) {
+ int requiredIndex = -1;
+ for (int i = 0; i < tableArgument.getFieldTypes().size(); i++) {
+ Optional<String> fieldName = tableArgument.getFieldNames().get(i);
+ if (fieldName.isPresent() &&
expectedFieldName.equalsIgnoreCase(fieldName.get())) {
+ requiredIndex = i;
+ break;
+ }
+ }
+ return requiredIndex;
+ }
+
+ @Override
+ public TableFunctionAnalysis analyze(Map<String, Argument> arguments) {
+ TableArgument tableArgument = (TableArgument)
arguments.get(DATA_PARAMETER_NAME);
+ String expectedFieldName =
+ (String) ((ScalarArgument)
arguments.get(TIMECOL_PARAMETER_NAME)).getValue();
+ int requiredIndex = findTimeColumnIndex(tableArgument, expectedFieldName);
+ if (requiredIndex == -1) {
+ throw new UDFException("The required field is not found in the input
table");
+ }
+ DescribedSchema properColumnSchema =
+ new DescribedSchema.Builder()
+ .addField("window_start", Type.TIMESTAMP)
+ .addField("window_end", Type.TIMESTAMP)
+ .build();
+
+ // outputColumnSchema
+ return TableFunctionAnalysis.builder()
+ .properColumnSchema(properColumnSchema)
+ .requiredColumns(DATA_PARAMETER_NAME,
Collections.singletonList(requiredIndex))
+ .build();
+ }
+
+ @Override
+ public TableFunctionProcessorProvider getProcessorProvider(Map<String,
Argument> arguments) {
+ return new TableFunctionProcessorProvider() {
+ @Override
+ public TableFunctionDataProcessor getDataProcessor() {
+ return new HOPDataProcessor(
+ (Long) ((ScalarArgument)
arguments.get(START_PARAMETER_NAME)).getValue(),
+ (Long) ((ScalarArgument)
arguments.get(SLIDE_PARAMETER_NAME)).getValue(),
+ (Long) ((ScalarArgument)
arguments.get(SIZE_PARAMETER_NAME)).getValue());
+ }
+ };
+ }
+
+ private static class HOPDataProcessor implements TableFunctionDataProcessor {
+
+ private final long slide;
+ private final long size;
Review Comment:
what if slide or size is year or month level?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]