Skip to content

Commit

Permalink
Rename testing classes
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiafi committed Apr 21, 2023
1 parent c4c4859 commit 000dd65
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class TestingTableFunctions
private static final String SCHEMA_NAME = "system";
private static final String TABLE_NAME = "table";
private static final String COLUMN_NAME = "column";
private static final ConnectorTableFunctionHandle HANDLE = new TestingTableFunctionHandle();
private static final ConnectorTableFunctionHandle HANDLE = new TestingTableFunctionPushdownHandle();
private static final TableFunctionAnalysis ANALYSIS = TableFunctionAnalysis.builder()
.handle(HANDLE)
.returnedType(new Descriptor(ImmutableList.of(new Descriptor.Field(COLUMN_NAME, Optional.of(BOOLEAN)))))
Expand Down Expand Up @@ -181,11 +181,13 @@ public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransact
public static class TableArgumentFunction
extends AbstractConnectorTableFunction
{
public static final String FUNCTION_NAME = "table_argument_function";

public TableArgumentFunction()
{
super(
SCHEMA_NAME,
"table_argument_function",
FUNCTION_NAME,
ImmutableList.of(
TableArgumentSpecification.builder()
.name("INPUT")
Expand All @@ -198,7 +200,7 @@ public TableArgumentFunction()
public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map<String, Argument> arguments)
{
return TableFunctionAnalysis.builder()
.handle(HANDLE)
.handle(new TestingTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.returnedType(new Descriptor(ImmutableList.of(new Descriptor.Field(COLUMN_NAME, Optional.of(BOOLEAN)))))
.requiredColumns("INPUT", ImmutableList.of(0))
.build();
Expand All @@ -208,11 +210,13 @@ public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransact
public static class TableArgumentRowSemanticsFunction
extends AbstractConnectorTableFunction
{
public static final String FUNCTION_NAME = "table_argument_row_semantics_function";

public TableArgumentRowSemanticsFunction()
{
super(
SCHEMA_NAME,
"table_argument_row_semantics_function",
FUNCTION_NAME,
ImmutableList.of(
TableArgumentSpecification.builder()
.name("INPUT")
Expand All @@ -225,7 +229,7 @@ public TableArgumentRowSemanticsFunction()
public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map<String, Argument> arguments)
{
return TableFunctionAnalysis.builder()
.handle(HANDLE)
.handle(new TestingTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.returnedType(new Descriptor(ImmutableList.of(new Descriptor.Field(COLUMN_NAME, Optional.of(BOOLEAN)))))
.requiredColumns("INPUT", ImmutableList.of(0))
.build();
Expand Down Expand Up @@ -258,11 +262,13 @@ public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransact
public static class TwoTableArgumentsFunction
extends AbstractConnectorTableFunction
{
public static final String FUNCTION_NAME = "two_table_arguments_function";

public TwoTableArgumentsFunction()
{
super(
SCHEMA_NAME,
"two_table_arguments_function",
FUNCTION_NAME,
ImmutableList.of(
TableArgumentSpecification.builder()
.name("INPUT1")
Expand All @@ -279,7 +285,7 @@ public TwoTableArgumentsFunction()
public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map<String, Argument> arguments)
{
return TableFunctionAnalysis.builder()
.handle(HANDLE)
.handle(new TestingTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.returnedType(new Descriptor(ImmutableList.of(new Descriptor.Field(COLUMN_NAME, Optional.of(BOOLEAN)))))
.requiredColumns("INPUT1", ImmutableList.of(0))
.requiredColumns("INPUT2", ImmutableList.of(0))
Expand Down Expand Up @@ -386,11 +392,13 @@ public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransact
public static class DifferentArgumentTypesFunction
extends AbstractConnectorTableFunction
{
public static final String FUNCTION_NAME = "different_arguments_function";

public DifferentArgumentTypesFunction()
{
super(
SCHEMA_NAME,
"different_arguments_function",
FUNCTION_NAME,
ImmutableList.of(
TableArgumentSpecification.builder()
.name("INPUT_1")
Expand Down Expand Up @@ -420,7 +428,7 @@ public DifferentArgumentTypesFunction()
public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map<String, Argument> arguments)
{
return TableFunctionAnalysis.builder()
.handle(HANDLE)
.handle(new TestingTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.returnedType(new Descriptor(ImmutableList.of(new Descriptor.Field(COLUMN_NAME, Optional.of(BOOLEAN)))))
.requiredColumns("INPUT_1", ImmutableList.of(0))
.requiredColumns("INPUT_2", ImmutableList.of(0))
Expand All @@ -432,11 +440,13 @@ public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransact
public static class RequiredColumnsFunction
extends AbstractConnectorTableFunction
{
public static final String FUNCTION_NAME = "required_columns_function";

public RequiredColumnsFunction()
{
super(
SCHEMA_NAME,
"required_columns_function",
FUNCTION_NAME,
ImmutableList.of(
TableArgumentSpecification.builder()
.name("INPUT")
Expand All @@ -449,19 +459,19 @@ public RequiredColumnsFunction()
public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map<String, Argument> arguments)
{
return TableFunctionAnalysis.builder()
.handle(HANDLE)
.handle(new TestingTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.returnedType(new Descriptor(ImmutableList.of(new Descriptor.Field("column", Optional.of(BOOLEAN)))))
.requiredColumns("INPUT", ImmutableList.of(0, 1))
.build();
}
}

public static class TestingTableFunctionHandle
public static class TestingTableFunctionPushdownHandle
implements ConnectorTableFunctionHandle
{
private final MockConnectorTableHandle tableHandle;

public TestingTableFunctionHandle()
public TestingTableFunctionPushdownHandle()
{
this.tableHandle = new MockConnectorTableHandle(
new SchemaTableName(SCHEMA_NAME, TABLE_NAME),
Expand Down Expand Up @@ -503,7 +513,7 @@ public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransact
.map(field -> new Descriptor.Field(field.getName().orElse("anonymous_column"), Optional.of(field.getType())))
.collect(toImmutableList()));
return TableFunctionAnalysis.builder()
.handle(new EmptyTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.handle(new TestingTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.returnedType(returnedType)
.requiredColumns("INPUT", IntStream.range(0, inputColumns.size()).boxed().collect(toImmutableList()))
.build();
Expand Down Expand Up @@ -549,7 +559,7 @@ public IdentityPassThroughFunction()
public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map<String, Argument> arguments)
{
return TableFunctionAnalysis.builder()
.handle(new EmptyTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.handle(new TestingTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.requiredColumns("INPUT", ImmutableList.of(0)) // per spec, function must require at least one column
.build();
}
Expand Down Expand Up @@ -730,7 +740,7 @@ public EmptyOutputFunction()
public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map<String, Argument> arguments)
{
return TableFunctionAnalysis.builder()
.handle(new EmptyTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.handle(new TestingTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.requiredColumns("INPUT", IntStream.range(0, ((TableArgument) arguments.get("INPUT")).getRowType().getFields().size()).boxed().collect(toImmutableList()))
.build();
}
Expand Down Expand Up @@ -784,7 +794,7 @@ public EmptyOutputWithPassThroughFunction()
public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map<String, Argument> arguments)
{
return TableFunctionAnalysis.builder()
.handle(new EmptyTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.handle(new TestingTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.requiredColumns("INPUT", IntStream.range(0, ((TableArgument) arguments.get("INPUT")).getRowType().getFields().size()).boxed().collect(toImmutableList()))
.build();
}
Expand Down Expand Up @@ -853,7 +863,7 @@ public TestInputsFunction()
public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map<String, Argument> arguments)
{
return TableFunctionAnalysis.builder()
.handle(new EmptyTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.handle(new TestingTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.requiredColumns("INPUT_1", IntStream.range(0, ((TableArgument) arguments.get("INPUT_1")).getRowType().getFields().size()).boxed().collect(toImmutableList()))
.requiredColumns("INPUT_2", IntStream.range(0, ((TableArgument) arguments.get("INPUT_2")).getRowType().getFields().size()).boxed().collect(toImmutableList()))
.requiredColumns("INPUT_3", IntStream.range(0, ((TableArgument) arguments.get("INPUT_3")).getRowType().getFields().size()).boxed().collect(toImmutableList()))
Expand Down Expand Up @@ -912,7 +922,7 @@ public PassThroughInputFunction()
public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map<String, Argument> arguments)
{
return TableFunctionAnalysis.builder()
.handle(new EmptyTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.handle(new TestingTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.requiredColumns("INPUT_1", ImmutableList.of(0))
.requiredColumns("INPUT_2", ImmutableList.of(0))
.build();
Expand Down Expand Up @@ -1008,7 +1018,7 @@ public TestInputFunction()
public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map<String, Argument> arguments)
{
return TableFunctionAnalysis.builder()
.handle(new EmptyTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.handle(new TestingTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.requiredColumns("INPUT", IntStream.range(0, ((TableArgument) arguments.get("INPUT")).getRowType().getFields().size()).boxed().collect(toImmutableList()))
.build();
}
Expand Down Expand Up @@ -1068,7 +1078,7 @@ public TestSingleInputRowSemanticsFunction()
public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map<String, Argument> arguments)
{
return TableFunctionAnalysis.builder()
.handle(new EmptyTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.handle(new TestingTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.requiredColumns("INPUT", IntStream.range(0, ((TableArgument) arguments.get("INPUT")).getRowType().getFields().size()).boxed().collect(toImmutableList()))
.build();
}
Expand Down Expand Up @@ -1279,7 +1289,7 @@ public EmptySourceFunction()
public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map<String, Argument> arguments)
{
return TableFunctionAnalysis.builder()
.handle(new EmptyTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.handle(new TestingTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME)))
.build();
}

Expand Down Expand Up @@ -1312,10 +1322,10 @@ public TableFunctionProcessorState process()
}
}

public record EmptyTableFunctionHandle(SchemaFunctionName name)
public record TestingTableFunctionHandle(SchemaFunctionName name)
implements ConnectorTableFunctionHandle
{
public EmptyTableFunctionHandle
public TestingTableFunctionHandle
{
requireNonNull(name, "name is null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.trino.connector.TestingTableFunctions.DescriptorArgumentFunction;
import io.trino.connector.TestingTableFunctions.DifferentArgumentTypesFunction;
import io.trino.connector.TestingTableFunctions.PassThroughFunction;
import io.trino.connector.TestingTableFunctions.TestingTableFunctionHandle;
import io.trino.connector.TestingTableFunctions.TestingTableFunctionPushdownHandle;
import io.trino.connector.TestingTableFunctions.TwoScalarArgumentsFunction;
import io.trino.connector.TestingTableFunctions.TwoTableArgumentsFunction;
import io.trino.spi.connector.TableFunctionApplicationResult;
Expand Down Expand Up @@ -74,7 +74,7 @@ public final void setup()
new TwoTableArgumentsFunction(),
new PassThroughFunction()))
.withApplyTableFunction((session, handle) -> {
if (handle instanceof TestingTableFunctionHandle functionHandle) {
if (handle instanceof TestingTableFunctionPushdownHandle functionHandle) {
return Optional.of(new TableFunctionApplicationResult<>(functionHandle.getTableHandle(), functionHandle.getTableHandle().getColumns().orElseThrow()));
}
throw new IllegalStateException("Unsupported table function handle: " + handle.getClass().getSimpleName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import io.trino.connector.TestingTableFunctions.EmptyOutputWithPassThroughFunction.EmptyOutputWithPassThroughProcessorProvider;
import io.trino.connector.TestingTableFunctions.EmptySourceFunction;
import io.trino.connector.TestingTableFunctions.EmptySourceFunction.EmptySourceFunctionProcessorProvider;
import io.trino.connector.TestingTableFunctions.EmptyTableFunctionHandle;
import io.trino.connector.TestingTableFunctions.IdentityFunction;
import io.trino.connector.TestingTableFunctions.IdentityFunction.IdentityFunctionProcessorProvider;
import io.trino.connector.TestingTableFunctions.IdentityPassThroughFunction;
Expand All @@ -44,6 +43,7 @@
import io.trino.connector.TestingTableFunctions.TestInputsFunction.TestInputsFunctionProcessorProvider;
import io.trino.connector.TestingTableFunctions.TestSingleInputRowSemanticsFunction;
import io.trino.connector.TestingTableFunctions.TestSingleInputRowSemanticsFunction.TestSingleInputFunctionProcessorProvider;
import io.trino.connector.TestingTableFunctions.TestingTableFunctionHandle;
import io.trino.plugin.tpch.TpchPlugin;
import io.trino.spi.connector.FixedSplitSource;
import io.trino.spi.connector.TableFunctionApplicationResult;
Expand Down Expand Up @@ -112,7 +112,7 @@ public void setUp()
@Override
public TableFunctionProcessorProvider getTableFunctionProcessorProvider(ConnectorTableFunctionHandle functionHandle)
{
if (functionHandle instanceof EmptyTableFunctionHandle handle) {
if (functionHandle instanceof TestingTableFunctionHandle handle) {
return switch (handle.name().getFunctionName()) {
case "identity_function" -> new IdentityFunctionProcessorProvider();
case "identity_pass_through_function" -> new IdentityPassThroughFunctionProcessorProvider();
Expand Down Expand Up @@ -140,7 +140,7 @@ public TableFunctionProcessorProvider getTableFunctionProcessorProvider(Connecto
if (functionHandle instanceof ConstantFunctionHandle handle) {
return getConstantFunctionSplitSource(handle);
}
if (functionHandle instanceof EmptyTableFunctionHandle handle && handle.name().equals(new SchemaFunctionName("system", "empty_source"))) {
if (functionHandle instanceof TestingTableFunctionHandle handle && handle.name().equals(new SchemaFunctionName("system", "empty_source"))) {
return new FixedSplitSource(ImmutableList.of(MOCK_CONNECTOR_SPLIT));
}

Expand Down

0 comments on commit 000dd65

Please sign in to comment.