Skip to content

Add TableFunctionHandle for TVF #15394

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

Merged
merged 6 commits into from
Apr 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
package org.apache.iotdb.udf.table;

import org.apache.iotdb.udf.api.exception.UDFException;
import org.apache.iotdb.udf.api.relational.EmptyTableFunctionHandle;
import org.apache.iotdb.udf.api.relational.TableFunction;
import org.apache.iotdb.udf.api.relational.table.TableFunctionAnalysis;
import org.apache.iotdb.udf.api.relational.table.TableFunctionHandle;
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;
Expand Down Expand Up @@ -85,11 +87,18 @@ public TableFunctionAnalysis analyze(Map<String, Argument> arguments) throws UDF
return TableFunctionAnalysis.builder()
.properColumnSchema(schemaBuilder.build())
.requiredColumns(TBL_PARAM, requiredColumns)
.handle(new EmptyTableFunctionHandle())
.build();
}

@Override
public TableFunctionProcessorProvider getProcessorProvider(Map<String, Argument> arguments) {
public TableFunctionHandle createTableFunctionHandle() {
return new EmptyTableFunctionHandle();
}

@Override
public TableFunctionProcessorProvider getProcessorProvider(
TableFunctionHandle tableFunctionHandle) {
return new TableFunctionProcessorProvider() {
@Override
public TableFunctionDataProcessor getDataProcessor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
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.MapTableFunctionHandle;
import org.apache.iotdb.udf.api.relational.table.TableFunctionAnalysis;
import org.apache.iotdb.udf.api.relational.table.TableFunctionHandle;
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;
Expand Down Expand Up @@ -81,22 +83,31 @@ public TableFunctionAnalysis analyze(Map<String, Argument> arguments) throws UDF
throw new UDFArgumentNotValidException(
"count argument for function repeat() must be positive");
}
MapTableFunctionHandle handle =
new MapTableFunctionHandle.Builder().addProperty(N_PARAM, count.getValue()).build();
return TableFunctionAnalysis.builder()
.properColumnSchema(DescribedSchema.builder().addField("repeat_index", Type.INT32).build())
.requiredColumns(
TBL_PARAM,
Collections.singletonList(0)) // per spec, function must require at least one column
.handle(handle)
.build();
}

@Override
public TableFunctionProcessorProvider getProcessorProvider(Map<String, Argument> arguments) {
ScalarArgument count = (ScalarArgument) arguments.get("N");
public TableFunctionHandle createTableFunctionHandle() {
return new MapTableFunctionHandle();
}

@Override
public TableFunctionProcessorProvider getProcessorProvider(
TableFunctionHandle tableFunctionHandle) {
return new TableFunctionProcessorProvider() {
@Override
public TableFunctionDataProcessor getDataProcessor() {
return new TableFunctionDataProcessor() {
private final int n = (int) count.getValue();
private final int n =
(int) ((MapTableFunctionHandle) tableFunctionHandle).getProperty(N_PARAM);
private long recordIndex = 0;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

import org.apache.iotdb.udf.api.exception.UDFException;
import org.apache.iotdb.udf.api.relational.TableFunction;
import org.apache.iotdb.udf.api.relational.table.MapTableFunctionHandle;
import org.apache.iotdb.udf.api.relational.table.TableFunctionAnalysis;
import org.apache.iotdb.udf.api.relational.table.TableFunctionHandle;
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;
Expand Down Expand Up @@ -73,17 +75,34 @@ public List<ParameterSpecification> getArgumentsSpecifications() {
@Override
public TableFunctionAnalysis analyze(Map<String, Argument> arguments) throws UDFException {
DescribedSchema schema = DescribedSchema.builder().addField("output", Type.STRING).build();
return TableFunctionAnalysis.builder().properColumnSchema(schema).build();
MapTableFunctionHandle handle =
new MapTableFunctionHandle.Builder()
.addProperty(
INPUT_PARAMETER_NAME,
((ScalarArgument) arguments.get(INPUT_PARAMETER_NAME)).getValue())
.addProperty(
SPLIT_PARAMETER_NAME,
((ScalarArgument) arguments.get(SPLIT_PARAMETER_NAME)).getValue())
.build();
return TableFunctionAnalysis.builder().properColumnSchema(schema).handle(handle).build();
}

@Override
public TableFunctionProcessorProvider getProcessorProvider(Map<String, Argument> arguments) {
public TableFunctionHandle createTableFunctionHandle() {
return new MapTableFunctionHandle();
}

@Override
public TableFunctionProcessorProvider getProcessorProvider(
TableFunctionHandle tableFunctionHandle) {
return new TableFunctionProcessorProvider() {
@Override
public TableFunctionLeafProcessor getSplitProcessor() {
return new SplitProcessor(
(String) ((ScalarArgument) arguments.get(INPUT_PARAMETER_NAME)).getValue(),
(String) ((ScalarArgument) arguments.get(SPLIT_PARAMETER_NAME)).getValue());
(String)
((MapTableFunctionHandle) tableFunctionHandle).getProperty(INPUT_PARAMETER_NAME),
(String)
((MapTableFunctionHandle) tableFunctionHandle).getProperty(SPLIT_PARAMETER_NAME));
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import org.apache.iotdb.udf.api.exception.UDFArgumentNotValidException;
import org.apache.iotdb.udf.api.exception.UDFException;
import org.apache.iotdb.udf.api.relational.TableFunction;
import org.apache.iotdb.udf.api.relational.table.MapTableFunctionHandle;
import org.apache.iotdb.udf.api.relational.table.TableFunctionAnalysis;
import org.apache.iotdb.udf.api.relational.table.TableFunctionHandle;
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;
Expand Down Expand Up @@ -67,41 +69,52 @@ public TableFunctionAnalysis analyze(Map<String, Argument> arguments) throws UDF
return TableFunctionAnalysis.builder()
.properColumnSchema(
DescribedSchema.builder().addField("proper_column", Type.INT32).build())
.handle(new MapTableFunctionHandle())
.build();
} else if (nValue == 1) {
// set empty required columns
return TableFunctionAnalysis.builder()
.properColumnSchema(
DescribedSchema.builder().addField("proper_column", Type.INT32).build())
.requiredColumns(TBL_PARAM, Collections.emptyList())
.handle(new MapTableFunctionHandle())
.build();
} else if (nValue == 2) {
// set negative required columns
return TableFunctionAnalysis.builder()
.properColumnSchema(
DescribedSchema.builder().addField("proper_column", Type.INT32).build())
.requiredColumns(TBL_PARAM, Collections.singletonList(-1))
.handle(new MapTableFunctionHandle())
.build();
} else if (nValue == 3) {
// set required columns out of bound (0~10)
return TableFunctionAnalysis.builder()
.properColumnSchema(
DescribedSchema.builder().addField("proper_column", Type.INT32).build())
.requiredColumns(TBL_PARAM, IntStream.range(0, 11).boxed().collect(Collectors.toList()))
.handle(new MapTableFunctionHandle())
.build();
} else if (nValue == 4) {
// specify required columns to unknown table
return TableFunctionAnalysis.builder()
.properColumnSchema(
DescribedSchema.builder().addField("proper_column", Type.INT32).build())
.requiredColumns("TIMECHO", Collections.singletonList(1))
.handle(new MapTableFunctionHandle())
.build();
}
throw new UDFArgumentNotValidException("unexpected argument value");
}

@Override
public TableFunctionProcessorProvider getProcessorProvider(Map<String, Argument> arguments) {
public TableFunctionHandle createTableFunctionHandle() {
return new MapTableFunctionHandle();
}

@Override
public TableFunctionProcessorProvider getProcessorProvider(
TableFunctionHandle tableFunctionHandle) {
return new TableFunctionProcessorProvider() {
@Override
public TableFunctionDataProcessor getDataProcessor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

import org.apache.iotdb.udf.api.exception.UDFException;
import org.apache.iotdb.udf.api.relational.TableFunction;
import org.apache.iotdb.udf.api.relational.table.MapTableFunctionHandle;
import org.apache.iotdb.udf.api.relational.table.TableFunctionAnalysis;
import org.apache.iotdb.udf.api.relational.table.TableFunctionHandle;
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;
Expand Down Expand Up @@ -66,11 +68,18 @@ public TableFunctionAnalysis analyze(Map<String, Argument> arguments) throws UDF
return TableFunctionAnalysis.builder()
.properColumnSchema(schemaBuilder.build())
.requiredColumns(TBL_PARAM, requiredColumns)
.handle(new MapTableFunctionHandle())
.build();
}

@Override
public TableFunctionProcessorProvider getProcessorProvider(Map<String, Argument> arguments) {
public TableFunctionHandle createTableFunctionHandle() {
return new MapTableFunctionHandle();
}

@Override
public TableFunctionProcessorProvider getProcessorProvider(
TableFunctionHandle tableFunctionHandle) {
return new TableFunctionProcessorProvider() {
@Override
public TableFunctionDataProcessor getDataProcessor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
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.MapTableFunctionHandle;
import org.apache.iotdb.udf.api.relational.table.TableFunctionAnalysis;
import org.apache.iotdb.udf.api.relational.table.TableFunctionHandle;
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;
Expand Down Expand Up @@ -66,22 +68,31 @@ public TableFunctionAnalysis analyze(Map<String, Argument> arguments) throws UDF
throw new UDFArgumentNotValidException(
"count argument for function repeat() must be positive");
}
MapTableFunctionHandle handle =
new MapTableFunctionHandle.Builder().addProperty(N_PARAM, count.getValue()).build();
return TableFunctionAnalysis.builder()
.properColumnSchema(DescribedSchema.builder().addField("repeat_index", Type.INT32).build())
.requiredColumns(
TBL_PARAM,
Collections.singletonList(0)) // per spec, function must require at least one column
.handle(handle)
.build();
}

@Override
public TableFunctionProcessorProvider getProcessorProvider(Map<String, Argument> arguments) {
ScalarArgument count = (ScalarArgument) arguments.get("N");
public TableFunctionHandle createTableFunctionHandle() {
return new MapTableFunctionHandle();
}

@Override
public TableFunctionProcessorProvider getProcessorProvider(
TableFunctionHandle tableFunctionHandle) {
return new TableFunctionProcessorProvider() {
@Override
public TableFunctionDataProcessor getDataProcessor() {
return new TableFunctionDataProcessor() {
private final int n = (int) count.getValue();
private final int n =
(int) ((MapTableFunctionHandle) tableFunctionHandle).getProperty(N_PARAM);
private long recordIndex = 0;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
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.MapTableFunctionHandle;
import org.apache.iotdb.udf.api.relational.table.TableFunctionAnalysis;
import org.apache.iotdb.udf.api.relational.table.TableFunctionHandle;
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;
Expand Down Expand Up @@ -65,21 +67,30 @@ public TableFunctionAnalysis analyze(Map<String, Argument> arguments) throws UDF
throw new UDFArgumentNotValidException(
"count argument for function repeat() must be positive");
}
MapTableFunctionHandle handle =
new MapTableFunctionHandle.Builder().addProperty(N_PARAM, count.getValue()).build();
return TableFunctionAnalysis.builder()
.requiredColumns(
TBL_PARAM,
Collections.singletonList(0)) // per spec, function must require at least one column
.handle(handle)
.build();
}

@Override
public TableFunctionProcessorProvider getProcessorProvider(Map<String, Argument> arguments) {
ScalarArgument count = (ScalarArgument) arguments.get("N");
public TableFunctionHandle createTableFunctionHandle() {
return new MapTableFunctionHandle();
}

@Override
public TableFunctionProcessorProvider getProcessorProvider(
TableFunctionHandle tableFunctionHandle) {
return new TableFunctionProcessorProvider() {
@Override
public TableFunctionDataProcessor getDataProcessor() {
return new TableFunctionDataProcessor() {
private final int n = (int) count.getValue();
private final int n =
(int) ((MapTableFunctionHandle) tableFunctionHandle).getProperty(N_PARAM);
private long recordIndex = 0;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
package org.apache.iotdb.db.query.udf.example.relational;

import org.apache.iotdb.udf.api.exception.UDFException;
import org.apache.iotdb.udf.api.relational.EmptyTableFunctionHandle;
import org.apache.iotdb.udf.api.relational.TableFunction;
import org.apache.iotdb.udf.api.relational.table.TableFunctionAnalysis;
import org.apache.iotdb.udf.api.relational.table.TableFunctionHandle;
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;
Expand Down Expand Up @@ -66,11 +68,18 @@ public TableFunctionAnalysis analyze(Map<String, Argument> arguments) throws UDF
return TableFunctionAnalysis.builder()
.properColumnSchema(schemaBuilder.build())
.requiredColumns(TBL_PARAM, requiredColumns)
.handle(new EmptyTableFunctionHandle())
.build();
}

@Override
public TableFunctionProcessorProvider getProcessorProvider(Map<String, Argument> arguments) {
public TableFunctionHandle createTableFunctionHandle() {
return new EmptyTableFunctionHandle();
}

@Override
public TableFunctionProcessorProvider getProcessorProvider(
TableFunctionHandle tableFunctionHandle) {
return new TableFunctionProcessorProvider() {
@Override
public TableFunctionDataProcessor getDataProcessor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

import org.apache.iotdb.udf.api.exception.UDFException;
import org.apache.iotdb.udf.api.relational.TableFunction;
import org.apache.iotdb.udf.api.relational.table.MapTableFunctionHandle;
import org.apache.iotdb.udf.api.relational.table.TableFunctionAnalysis;
import org.apache.iotdb.udf.api.relational.table.TableFunctionHandle;
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;
Expand Down Expand Up @@ -57,17 +59,34 @@ public List<ParameterSpecification> getArgumentsSpecifications() {
@Override
public TableFunctionAnalysis analyze(Map<String, Argument> arguments) throws UDFException {
DescribedSchema schema = DescribedSchema.builder().addField("output", Type.STRING).build();
return TableFunctionAnalysis.builder().properColumnSchema(schema).build();
MapTableFunctionHandle handle =
new MapTableFunctionHandle.Builder()
.addProperty(
INPUT_PARAMETER_NAME,
((ScalarArgument) arguments.get(INPUT_PARAMETER_NAME)).getValue())
.addProperty(
SPLIT_PARAMETER_NAME,
((ScalarArgument) arguments.get(SPLIT_PARAMETER_NAME)).getValue())
.build();
return TableFunctionAnalysis.builder().properColumnSchema(schema).handle(handle).build();
}

@Override
public TableFunctionProcessorProvider getProcessorProvider(Map<String, Argument> arguments) {
public TableFunctionHandle createTableFunctionHandle() {
return new MapTableFunctionHandle();
}

@Override
public TableFunctionProcessorProvider getProcessorProvider(
TableFunctionHandle tableFunctionHandle) {
return new TableFunctionProcessorProvider() {
@Override
public TableFunctionLeafProcessor getSplitProcessor() {
return new SplitProcessor(
(String) ((ScalarArgument) arguments.get(INPUT_PARAMETER_NAME)).getValue(),
(String) ((ScalarArgument) arguments.get(SPLIT_PARAMETER_NAME)).getValue());
(String)
((MapTableFunctionHandle) tableFunctionHandle).getProperty(INPUT_PARAMETER_NAME),
(String)
((MapTableFunctionHandle) tableFunctionHandle).getProperty(SPLIT_PARAMETER_NAME));
}
};
}
Expand Down
Loading
Loading