From 58cac63efdd700c0724d06f544a74da1c2b0240c Mon Sep 17 00:00:00 2001 From: xuboqing <11812910@mail.sustech.edu.cn> Date: Wed, 19 May 2021 22:02:18 +0800 Subject: [PATCH] Migrate Thrift connector tests to use BaseConnectorTest #7117 creating a pull request for issue #7117 to fix #7117 --- .../plugin/thrift/MyThriftConnector.java | 100 ++++++++++++++++++ ...Test.java => TestThriftConnectorTest.java} | 25 ++++- .../TestThriftDistributedQueries.java | 31 ------ 3 files changed, 121 insertions(+), 35 deletions(-) create mode 100644 plugin/trino-thrift/src/main/java/io/trino/plugin/thrift/MyThriftConnector.java rename plugin/trino-thrift/src/test/java/io/trino/plugin/thrift/integration/{TestThriftIntegrationSmokeTest.java => TestThriftConnectorTest.java} (65%) delete mode 100644 plugin/trino-thrift/src/test/java/io/trino/plugin/thrift/integration/TestThriftDistributedQueries.java diff --git a/plugin/trino-thrift/src/main/java/io/trino/plugin/thrift/MyThriftConnector.java b/plugin/trino-thrift/src/main/java/io/trino/plugin/thrift/MyThriftConnector.java new file mode 100644 index 000000000000..d74e578b0b0e --- /dev/null +++ b/plugin/trino-thrift/src/main/java/io/trino/plugin/thrift/MyThriftConnector.java @@ -0,0 +1,100 @@ +/* + * Licensed 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 io.trino.plugin.thrift; + +import io.airlift.bootstrap.LifeCycleManager; +import io.trino.spi.connector.Connector; +import io.trino.spi.connector.ConnectorIndexProvider; +import io.trino.spi.connector.ConnectorMetadata; +import io.trino.spi.connector.ConnectorPageSourceProvider; +import io.trino.spi.connector.ConnectorSplitManager; +import io.trino.spi.connector.ConnectorTransactionHandle; +import io.trino.spi.session.PropertyMetadata; +import io.trino.spi.transaction.IsolationLevel; + +import javax.inject.Inject; + +import java.util.List; + +import static java.util.Objects.requireNonNull; + +public class MyThriftConnector + implements Connector +{ + private final LifeCycleManager lifeCycleManager; + private final ThriftMetadata metadata; + private final ThriftSplitManager splitManager; + private final ThriftPageSourceProvider pageSourceProvider; + private final ThriftSessionProperties sessionProperties; + private final ThriftIndexProvider indexProvider; + + @Inject + public MyThriftConnector( + LifeCycleManager lifeCycleManager, + ThriftMetadata metadata, + ThriftSplitManager splitManager, + ThriftPageSourceProvider pageSourceProvider, + ThriftSessionProperties sessionProperties, + ThriftIndexProvider indexProvider) + { + this.lifeCycleManager = requireNonNull(lifeCycleManager, "lifeCycleManager is null"); + this.metadata = requireNonNull(metadata, "metadata is null"); + this.splitManager = requireNonNull(splitManager, "splitManager is null"); + this.pageSourceProvider = requireNonNull(pageSourceProvider, "pageSourceProvider is null"); + this.sessionProperties = requireNonNull(sessionProperties, "sessionProperties is null"); + this.indexProvider = requireNonNull(indexProvider, "indexProvider is null"); + } + + @Override + public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) + { + return ThriftTransactionHandle.INSTANCE; + } + + @Override + public ConnectorMetadata getMetadata(ConnectorTransactionHandle transactionHandle) + { + return metadata; + } + + @Override + public ConnectorSplitManager getSplitManager() + { + return splitManager; + } + + @Override + public ConnectorPageSourceProvider getPageSourceProvider() + { + return pageSourceProvider; + } + + @Override + public List> getSessionProperties() + { + return sessionProperties.getSessionProperties(); + } + + @Override + public ConnectorIndexProvider getIndexProvider() + { + return indexProvider; + } + + @Override + public final void shutdown() + { + lifeCycleManager.stop(); + } +} diff --git a/plugin/trino-thrift/src/test/java/io/trino/plugin/thrift/integration/TestThriftIntegrationSmokeTest.java b/plugin/trino-thrift/src/test/java/io/trino/plugin/thrift/integration/TestThriftConnectorTest.java similarity index 65% rename from plugin/trino-thrift/src/test/java/io/trino/plugin/thrift/integration/TestThriftIntegrationSmokeTest.java rename to plugin/trino-thrift/src/test/java/io/trino/plugin/thrift/integration/TestThriftConnectorTest.java index a6b81fb0850f..f30d85ccbb7f 100644 --- a/plugin/trino-thrift/src/test/java/io/trino/plugin/thrift/integration/TestThriftIntegrationSmokeTest.java +++ b/plugin/trino-thrift/src/test/java/io/trino/plugin/thrift/integration/TestThriftConnectorTest.java @@ -14,7 +14,7 @@ package io.trino.plugin.thrift.integration; import com.google.common.collect.ImmutableMap; -import io.trino.testing.AbstractTestIntegrationSmokeTest; +import io.trino.testing.BaseConnectorTest; import io.trino.testing.MaterializedResult; import io.trino.testing.QueryRunner; import org.testng.annotations.Test; @@ -23,15 +23,15 @@ import static io.trino.spi.type.VarcharType.VARCHAR; import static io.trino.testing.QueryAssertions.assertContains; -public class TestThriftIntegrationSmokeTest +public class TestThriftConnectorTest // TODO extend BaseConnectorTest - extends AbstractTestIntegrationSmokeTest + extends BaseConnectorTest { @Override protected QueryRunner createQueryRunner() throws Exception { - return createThriftQueryRunner(2, false, ImmutableMap.of()); + return createThriftQueryRunner(3, false, ImmutableMap.of()); } @Override @@ -44,4 +44,21 @@ public void testShowSchemas() .row("sf1"); assertContains(actualSchemas, resultBuilder.build()); } + + @Test + public void testCreateArrayTable() + { + assertUpdate("CREATE TABLE array_test AS SELECT ARRAY [1, 2, 3] AS c", 1); + assertQuery("SELECT cardinality(c) FROM array_test", "SELECT 3"); + assertUpdate("DROP TABLE array_test"); + } + + @Test + public void testMapTable() + { + assertUpdate("CREATE TABLE map_test AS SELECT MAP(ARRAY [1, 2, 3], ARRAY ['hi', 'bye', NULL]) AS c", 1); + assertQuery("SELECT c[1] FROM map_test", "SELECT 'hi'"); + assertQuery("SELECT c[3] FROM map_test", "SELECT NULL"); + assertUpdate("DROP TABLE map_test"); + } } diff --git a/plugin/trino-thrift/src/test/java/io/trino/plugin/thrift/integration/TestThriftDistributedQueries.java b/plugin/trino-thrift/src/test/java/io/trino/plugin/thrift/integration/TestThriftDistributedQueries.java deleted file mode 100644 index 71775af9d7c8..000000000000 --- a/plugin/trino-thrift/src/test/java/io/trino/plugin/thrift/integration/TestThriftDistributedQueries.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed 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 io.trino.plugin.thrift.integration; - -import com.google.common.collect.ImmutableMap; -import io.trino.testing.AbstractTestQueries; -import io.trino.testing.QueryRunner; - -import static io.trino.plugin.thrift.integration.ThriftQueryRunner.createThriftQueryRunner; - -public class TestThriftDistributedQueries - extends AbstractTestQueries -{ - @Override - protected QueryRunner createQueryRunner() - throws Exception - { - return createThriftQueryRunner(3, false, ImmutableMap.of()); - } -}