From 000dd650fea5a516dbb1d6fb15333aed6918aab6 Mon Sep 17 00:00:00 2001 From: kasiafi <30203062+kasiafi@users.noreply.github.com> Date: Fri, 21 Apr 2023 10:21:02 +0200 Subject: [PATCH] Rename testing classes --- .../connector/TestingTableFunctions.java | 58 +++++++++++-------- .../planner/TestTableFunctionInvocation.java | 4 +- .../tests/TestTableFunctionInvocation.java | 6 +- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/core/trino-main/src/test/java/io/trino/connector/TestingTableFunctions.java b/core/trino-main/src/test/java/io/trino/connector/TestingTableFunctions.java index 3df5c413921a..4917ddfc79e1 100644 --- a/core/trino-main/src/test/java/io/trino/connector/TestingTableFunctions.java +++ b/core/trino-main/src/test/java/io/trino/connector/TestingTableFunctions.java @@ -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))))) @@ -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") @@ -198,7 +200,7 @@ public TableArgumentFunction() public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map 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(); @@ -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") @@ -225,7 +229,7 @@ public TableArgumentRowSemanticsFunction() public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map 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(); @@ -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") @@ -279,7 +285,7 @@ public TwoTableArgumentsFunction() public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map 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)) @@ -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") @@ -420,7 +428,7 @@ public DifferentArgumentTypesFunction() public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map 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)) @@ -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") @@ -449,19 +459,19 @@ public RequiredColumnsFunction() public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map 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), @@ -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(); @@ -549,7 +559,7 @@ public IdentityPassThroughFunction() public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map 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(); } @@ -730,7 +740,7 @@ public EmptyOutputFunction() public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map 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(); } @@ -784,7 +794,7 @@ public EmptyOutputWithPassThroughFunction() public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map 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(); } @@ -853,7 +863,7 @@ public TestInputsFunction() public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map 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())) @@ -912,7 +922,7 @@ public PassThroughInputFunction() public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map 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(); @@ -1008,7 +1018,7 @@ public TestInputFunction() public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map 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(); } @@ -1068,7 +1078,7 @@ public TestSingleInputRowSemanticsFunction() public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map 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(); } @@ -1279,7 +1289,7 @@ public EmptySourceFunction() public TableFunctionAnalysis analyze(ConnectorSession session, ConnectorTransactionHandle transaction, Map arguments) { return TableFunctionAnalysis.builder() - .handle(new EmptyTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME))) + .handle(new TestingTableFunctionHandle(new SchemaFunctionName(SCHEMA_NAME, FUNCTION_NAME))) .build(); } @@ -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"); } diff --git a/core/trino-main/src/test/java/io/trino/sql/planner/TestTableFunctionInvocation.java b/core/trino-main/src/test/java/io/trino/sql/planner/TestTableFunctionInvocation.java index 2eb3621fc538..317d18826336 100644 --- a/core/trino-main/src/test/java/io/trino/sql/planner/TestTableFunctionInvocation.java +++ b/core/trino-main/src/test/java/io/trino/sql/planner/TestTableFunctionInvocation.java @@ -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; @@ -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()); diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestTableFunctionInvocation.java b/testing/trino-tests/src/test/java/io/trino/tests/TestTableFunctionInvocation.java index 24c3cf54c89f..84153d48471c 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestTableFunctionInvocation.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestTableFunctionInvocation.java @@ -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; @@ -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; @@ -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(); @@ -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)); }