From 2e66c6232fae1ac28dabfb12e5a73f8b1ed6f22d Mon Sep 17 00:00:00 2001 From: praveenkrishna Date: Thu, 1 Sep 2022 15:12:47 +0530 Subject: [PATCH] Minor cleanups in JdbcConnectorTest - Use TemporaryRelation instead of TestTable - Allow customization of schemaName specific to connector implementation --- .../plugin/jdbc/BaseJdbcConnectorTest.java | 73 +++++++++---------- .../BaseClickHouseConnectorTest.java | 7 +- .../mariadb/BaseMariaDbConnectorTest.java | 3 +- .../oracle/BaseOracleConnectorTest.java | 5 +- .../phoenix5/TestPhoenixConnectorTest.java | 11 +-- .../TestSingleStoreConnectorTest.java | 3 +- 6 files changed, 51 insertions(+), 51 deletions(-) diff --git a/plugin/trino-base-jdbc/src/test/java/io/trino/plugin/jdbc/BaseJdbcConnectorTest.java b/plugin/trino-base-jdbc/src/test/java/io/trino/plugin/jdbc/BaseJdbcConnectorTest.java index fb50609f33c2..be5879c08e7f 100644 --- a/plugin/trino-base-jdbc/src/test/java/io/trino/plugin/jdbc/BaseJdbcConnectorTest.java +++ b/plugin/trino-base-jdbc/src/test/java/io/trino/plugin/jdbc/BaseJdbcConnectorTest.java @@ -37,6 +37,7 @@ import io.trino.testing.MaterializedResultWithQueryId; import io.trino.testing.TestingConnectorBehavior; import io.trino.testing.sql.SqlExecutor; +import io.trino.testing.sql.TemporaryRelation; import io.trino.testing.sql.TestTable; import io.trino.testing.sql.TestView; import org.intellij.lang.annotations.Language; @@ -144,7 +145,7 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) @Test public void testInsertInPresenceOfNotSupportedColumn() { - try (TestTable testTable = createTableWithUnsupportedColumn()) { + try (TemporaryRelation testTable = createTableWithUnsupportedColumn()) { String unqualifiedTableName = testTable.getName().replaceAll("^\\w+\\.", ""); // Check that column 'two' is not supported. assertQuery("SELECT column_name FROM information_schema.columns WHERE table_name = '" + unqualifiedTableName + "'", "VALUES 'one', 'three'"); @@ -157,7 +158,7 @@ public void testInsertInPresenceOfNotSupportedColumn() * Creates a table with columns {@code one, two, three} where the middle one is of an unsupported (unmapped) type. * The first column should be numeric, and third should be varchar. */ - protected TestTable createTableWithUnsupportedColumn() + protected TemporaryRelation createTableWithUnsupportedColumn() { // TODO throw new UnsupportedOperationException(); throw new SkipException("Not implemented"); @@ -195,7 +196,7 @@ public void testAggregationPushdown() assertThat(query("SELECT count(1) FROM nation")).isFullyPushedDown(); assertThat(query("SELECT count() FROM nation")).isFullyPushedDown(); assertThat(query("SELECT regionkey, count(1) FROM nation GROUP BY regionkey")).isFullyPushedDown(); - try (TestTable emptyTable = createAggregationTestTable(getSession().getSchema().orElseThrow() + ".empty_table", ImmutableList.of())) { + try (TemporaryRelation emptyTable = createAggregationTestTable("empty_table", ImmutableList.of())) { assertThat(query("SELECT count(*) FROM " + emptyTable.getName())).isFullyPushedDown(); assertThat(query("SELECT count(a_bigint) FROM " + emptyTable.getName())).isFullyPushedDown(); assertThat(query("SELECT count(1) FROM " + emptyTable.getName())).isFullyPushedDown(); @@ -208,7 +209,7 @@ public void testAggregationPushdown() assertThat(query("SELECT regionkey, max(nationkey) FROM nation GROUP BY regionkey")).isFullyPushedDown(); assertThat(query("SELECT regionkey, sum(nationkey) FROM nation GROUP BY regionkey")).isFullyPushedDown(); assertThat(query("SELECT regionkey, avg(nationkey) FROM nation GROUP BY regionkey")).isFullyPushedDown(); - try (TestTable emptyTable = createAggregationTestTable(getSession().getSchema().orElseThrow() + ".empty_table", ImmutableList.of())) { + try (TemporaryRelation emptyTable = createAggregationTestTable("empty_table", ImmutableList.of())) { assertThat(query("SELECT t_double, min(a_bigint) FROM " + emptyTable.getName() + " GROUP BY t_double")).isFullyPushedDown(); assertThat(query("SELECT t_double, max(a_bigint) FROM " + emptyTable.getName() + " GROUP BY t_double")).isFullyPushedDown(); assertThat(query("SELECT t_double, sum(a_bigint) FROM " + emptyTable.getName() + " GROUP BY t_double")).isFullyPushedDown(); @@ -423,7 +424,7 @@ public void testDistinctAggregationPushdown() assertThat(query("SELECT DISTINCT regionkey FROM nation")).isFullyPushedDown(); assertThat(query("SELECT min(DISTINCT regionkey) FROM nation")).isFullyPushedDown(); assertThat(query("SELECT DISTINCT regionkey, min(nationkey) FROM nation GROUP BY regionkey")).isFullyPushedDown(); - try (TestTable emptyTable = createAggregationTestTable(getSession().getSchema().orElseThrow() + ".empty_table", ImmutableList.of())) { + try (TemporaryRelation emptyTable = createAggregationTestTable("empty_table", ImmutableList.of())) { assertThat(query("SELECT DISTINCT a_bigint FROM " + emptyTable.getName())).isFullyPushedDown(); assertThat(query("SELECT min(DISTINCT a_bigint) FROM " + emptyTable.getName())).isFullyPushedDown(); assertThat(query("SELECT DISTINCT t_double, min(a_bigint) FROM " + emptyTable.getName() + " GROUP BY t_double")).isFullyPushedDown(); @@ -493,16 +494,15 @@ public void testNumericAggregationPushdown() return; } - String schemaName = getSession().getSchema().orElseThrow(); // empty table - try (TestTable emptyTable = createAggregationTestTable(schemaName + ".test_num_agg_pd", ImmutableList.of())) { + try (TemporaryRelation emptyTable = createAggregationTestTable("test_num_agg_pd", ImmutableList.of())) { assertThat(query("SELECT min(short_decimal), min(long_decimal), min(a_bigint), min(t_double) FROM " + emptyTable.getName())).isFullyPushedDown(); assertThat(query("SELECT max(short_decimal), max(long_decimal), max(a_bigint), max(t_double) FROM " + emptyTable.getName())).isFullyPushedDown(); assertThat(query("SELECT sum(short_decimal), sum(long_decimal), sum(a_bigint), sum(t_double) FROM " + emptyTable.getName())).isFullyPushedDown(); assertThat(query("SELECT avg(short_decimal), avg(long_decimal), avg(a_bigint), avg(t_double) FROM " + emptyTable.getName())).isFullyPushedDown(); } - try (TestTable testTable = createAggregationTestTable(schemaName + ".test_num_agg_pd", + try (TemporaryRelation testTable = createAggregationTestTable("test_num_agg_pd", ImmutableList.of("100.000, 100000000.000000000, 100.000, 100000000", "123.321, 123456789.987654321, 123.321, 123456789"))) { assertThat(query("SELECT min(short_decimal), min(long_decimal), min(a_bigint), min(t_double) FROM " + testTable.getName())).isFullyPushedDown(); assertThat(query("SELECT max(short_decimal), max(long_decimal), max(a_bigint), max(t_double) FROM " + testTable.getName())).isFullyPushedDown(); @@ -584,21 +584,20 @@ public void testCountDistinctWithStringTypes() * Creates a table with columns {@code short_decimal decimal(9, 3), long_decimal decimal(30, 10), t_double double, a_bigint bigint} populated * with the provided rows. */ - protected TestTable createAggregationTestTable(String name, List rows) + protected TemporaryRelation createAggregationTestTable(String name, List rows) { - return new TestTable(onRemoteDatabase(), name, "(short_decimal decimal(9, 3), long_decimal decimal(30, 10), t_double double precision, a_bigint bigint)", rows); + return new TestTable(onRemoteDatabase(), format("%s.%s", getSession().getSchema().orElseThrow(), name), "(short_decimal decimal(9, 3), long_decimal decimal(30, 10), t_double double precision, a_bigint bigint)", rows); } @Test public void testStddevAggregationPushdown() { - String schemaName = getSession().getSchema().orElseThrow(); if (!hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN_STDDEV)) { if (!hasBehavior(SUPPORTS_CREATE_TABLE)) { throw new SkipException("Unable to CREATE TABLE to test aggregation pushdown"); } - try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_stddev_pushdown", ImmutableList.of())) { + try (TemporaryRelation testTable = createTableWithDoubleAndRealColumns("test_stddev_pushdown", ImmutableList.of())) { assertThat(query("SELECT stddev_pop(t_double) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class); assertThat(query("SELECT stddev(t_double) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class); assertThat(query("SELECT stddev_samp(t_double) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class); @@ -606,7 +605,7 @@ public void testStddevAggregationPushdown() } } - try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_stddev_pushdown", ImmutableList.of())) { + try (TemporaryRelation testTable = createTableWithDoubleAndRealColumns("test_stddev_pushdown", ImmutableList.of())) { assertThat(query("SELECT stddev_pop(t_double) FROM " + testTable.getName())).isFullyPushedDown(); assertThat(query("SELECT stddev(t_double) FROM " + testTable.getName())).isFullyPushedDown(); assertThat(query("SELECT stddev_samp(t_double) FROM " + testTable.getName())).isFullyPushedDown(); @@ -631,7 +630,7 @@ public void testStddevAggregationPushdown() assertThat(query("SELECT stddev_samp(t_double) FROM " + testTable.getName())).isFullyPushedDown(); } - try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_stddev_pushdown", + try (TemporaryRelation testTable = createTableWithDoubleAndRealColumns("test_stddev_pushdown", ImmutableList.of("1, 1, 1, 1", "2, 2, 2, 2", "4, 4, 4, 4", "5, 5, 5, 5"))) { // Test non-whole number results assertThat(query("SELECT stddev_pop(t_double) FROM " + testTable.getName())).isFullyPushedDown(); @@ -643,13 +642,12 @@ public void testStddevAggregationPushdown() @Test public void testVarianceAggregationPushdown() { - String schemaName = getSession().getSchema().orElseThrow(); if (!hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN_VARIANCE)) { if (!hasBehavior(SUPPORTS_CREATE_TABLE)) { throw new SkipException("Unable to CREATE TABLE to test aggregation pushdown"); } - try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_var_pushdown", ImmutableList.of())) { + try (TemporaryRelation testTable = createTableWithDoubleAndRealColumns("test_var_pushdown", ImmutableList.of())) { assertThat(query("SELECT var_pop(t_double) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class); assertThat(query("SELECT variance(t_double) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class); assertThat(query("SELECT var_samp(t_double) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class); @@ -657,7 +655,7 @@ public void testVarianceAggregationPushdown() } } - try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_var_pushdown", ImmutableList.of())) { + try (TemporaryRelation testTable = createTableWithDoubleAndRealColumns("test_var_pushdown", ImmutableList.of())) { assertThat(query("SELECT var_pop(t_double) FROM " + testTable.getName())).isFullyPushedDown(); assertThat(query("SELECT variance(t_double) FROM " + testTable.getName())).isFullyPushedDown(); assertThat(query("SELECT var_samp(t_double) FROM " + testTable.getName())).isFullyPushedDown(); @@ -675,7 +673,7 @@ public void testVarianceAggregationPushdown() assertThat(query("SELECT var_samp(t_double) FROM " + testTable.getName())).isFullyPushedDown(); } - try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_var_pushdown", + try (TemporaryRelation testTable = createTableWithDoubleAndRealColumns("test_var_pushdown", ImmutableList.of("1, 1, 1, 1", "2, 2, 2, 2", "4, 4, 4, 4", "5, 5, 5, 5"))) { // Test non-whole number results assertThat(query("SELECT var_pop(t_double) FROM " + testTable.getName())).isFullyPushedDown(); @@ -687,13 +685,12 @@ public void testVarianceAggregationPushdown() @Test public void testCovarianceAggregationPushdown() { - String schemaName = getSession().getSchema().orElseThrow(); if (!hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN_COVARIANCE)) { if (!hasBehavior(SUPPORTS_CREATE_TABLE)) { throw new SkipException("Unable to CREATE TABLE to test aggregation pushdown"); } - try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_covar_pushdown", ImmutableList.of())) { + try (TemporaryRelation testTable = createTableWithDoubleAndRealColumns("test_covar_pushdown", ImmutableList.of())) { assertThat(query("SELECT covar_pop(t_double, u_double), covar_pop(v_real, w_real) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class); assertThat(query("SELECT covar_samp(t_double, u_double), covar_samp(v_real, w_real) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class); return; @@ -701,20 +698,20 @@ public void testCovarianceAggregationPushdown() } // empty table - try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_covar_pushdown", ImmutableList.of())) { + try (TemporaryRelation testTable = createTableWithDoubleAndRealColumns("test_covar_pushdown", ImmutableList.of())) { assertThat(query("SELECT covar_pop(t_double, u_double), covar_pop(v_real, w_real) FROM " + testTable.getName())).isFullyPushedDown(); assertThat(query("SELECT covar_samp(t_double, u_double), covar_samp(v_real, w_real) FROM " + testTable.getName())).isFullyPushedDown(); } // test some values for which the aggregate functions return whole numbers - try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_covar_pushdown", + try (TemporaryRelation testTable = createTableWithDoubleAndRealColumns("test_covar_pushdown", ImmutableList.of("2, 2, 2, 2", "4, 4, 4, 4"))) { assertThat(query("SELECT covar_pop(t_double, u_double), covar_pop(v_real, w_real) FROM " + testTable.getName())).isFullyPushedDown(); assertThat(query("SELECT covar_samp(t_double, u_double), covar_samp(v_real, w_real) FROM " + testTable.getName())).isFullyPushedDown(); } // non-whole number results - try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_covar_pushdown", + try (TemporaryRelation testTable = createTableWithDoubleAndRealColumns("test_covar_pushdown", ImmutableList.of("1, 2, 1, 2", "100000000.123456, 4, 100000000.123456, 4", "123456789.987654, 8, 123456789.987654, 8"))) { assertThat(query("SELECT covar_pop(t_double, u_double), covar_pop(v_real, w_real) FROM " + testTable.getName())).isFullyPushedDown(); assertThat(query("SELECT covar_samp(t_double, u_double), covar_samp(v_real, w_real) FROM " + testTable.getName())).isFullyPushedDown(); @@ -724,31 +721,30 @@ public void testCovarianceAggregationPushdown() @Test public void testCorrAggregationPushdown() { - String schemaName = getSession().getSchema().orElseThrow(); if (!hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN_CORRELATION)) { if (!hasBehavior(SUPPORTS_CREATE_TABLE)) { throw new SkipException("Unable to CREATE TABLE to test aggregation pushdown"); } - try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_corr_pushdown", ImmutableList.of())) { + try (TemporaryRelation testTable = createTableWithDoubleAndRealColumns("test_corr_pushdown", ImmutableList.of())) { assertThat(query("SELECT corr(t_double, u_double), corr(v_real, w_real) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class); return; } } // empty table - try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_corr_pushdown", ImmutableList.of())) { + try (TemporaryRelation testTable = createTableWithDoubleAndRealColumns("test_corr_pushdown", ImmutableList.of())) { assertThat(query("SELECT corr(t_double, u_double), corr(v_real, w_real) FROM " + testTable.getName())).isFullyPushedDown(); } // test some values for which the aggregate functions return whole numbers - try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_corr_pushdown", + try (TemporaryRelation testTable = createTableWithDoubleAndRealColumns("test_corr_pushdown", ImmutableList.of("2, 2, 2, 2", "4, 4, 4, 4"))) { assertThat(query("SELECT corr(t_double, u_double), corr(v_real, w_real) FROM " + testTable.getName())).isFullyPushedDown(); } // non-whole number results - try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_corr_pushdown", + try (TemporaryRelation testTable = createTableWithDoubleAndRealColumns("test_corr_pushdown", ImmutableList.of("1, 2, 1, 2", "100000000.123456, 4, 100000000.123456, 4", "123456789.987654, 8, 123456789.987654, 8"))) { assertThat(query("SELECT corr(t_double, u_double), corr(v_real, w_real) FROM " + testTable.getName())).isFullyPushedDown(); } @@ -757,13 +753,12 @@ public void testCorrAggregationPushdown() @Test public void testRegrAggregationPushdown() { - String schemaName = getSession().getSchema().orElseThrow(); if (!hasBehavior(SUPPORTS_AGGREGATION_PUSHDOWN_REGRESSION)) { if (!hasBehavior(SUPPORTS_CREATE_TABLE)) { throw new SkipException("Unable to CREATE TABLE to test aggregation pushdown"); } - try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_regr_pushdown", ImmutableList.of())) { + try (TemporaryRelation testTable = createTableWithDoubleAndRealColumns("test_regr_pushdown", ImmutableList.of())) { assertThat(query("SELECT regr_intercept(t_double, u_double), regr_intercept(v_real, w_real) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class); assertThat(query("SELECT regr_slope(t_double, u_double), regr_slope(v_real, w_real) FROM " + testTable.getName())).isNotFullyPushedDown(AggregationNode.class); return; @@ -771,20 +766,20 @@ public void testRegrAggregationPushdown() } // empty table - try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_regr_pushdown", ImmutableList.of())) { + try (TemporaryRelation testTable = createTableWithDoubleAndRealColumns("test_regr_pushdown", ImmutableList.of())) { assertThat(query("SELECT regr_intercept(t_double, u_double), regr_intercept(v_real, w_real) FROM " + testTable.getName())).isFullyPushedDown(); assertThat(query("SELECT regr_slope(t_double, u_double), regr_slope(v_real, w_real) FROM " + testTable.getName())).isFullyPushedDown(); } // test some values for which the aggregate functions return whole numbers - try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_regr_pushdown", + try (TemporaryRelation testTable = createTableWithDoubleAndRealColumns("test_regr_pushdown", ImmutableList.of("2, 2, 2, 2", "4, 4, 4, 4"))) { assertThat(query("SELECT regr_intercept(t_double, u_double), regr_intercept(v_real, w_real) FROM " + testTable.getName())).isFullyPushedDown(); assertThat(query("SELECT regr_slope(t_double, u_double), regr_slope(v_real, w_real) FROM " + testTable.getName())).isFullyPushedDown(); } // non-whole number results - try (TestTable testTable = createTableWithDoubleAndRealColumns(schemaName + ".test_regr_pushdown", + try (TemporaryRelation testTable = createTableWithDoubleAndRealColumns("test_regr_pushdown", ImmutableList.of("1, 2, 1, 2", "100000000.123456, 4, 100000000.123456, 4", "123456789.987654, 8, 123456789.987654, 8"))) { assertThat(query("SELECT regr_intercept(t_double, u_double), regr_intercept(v_real, w_real) FROM " + testTable.getName())).isFullyPushedDown(); assertThat(query("SELECT regr_slope(t_double, u_double), regr_slope(v_real, w_real) FROM " + testTable.getName())).isFullyPushedDown(); @@ -794,9 +789,9 @@ public void testRegrAggregationPushdown() /** * Creates a table with columns {@code t_double double, u_double double, v_real real, w_real real} populated with the provided rows. */ - protected TestTable createTableWithDoubleAndRealColumns(String name, List rows) + protected TemporaryRelation createTableWithDoubleAndRealColumns(String name, List rows) { - return new TestTable(onRemoteDatabase(), name, "(t_double double precision, u_double double precision, v_real real, w_real real)", rows); + return new TestTable(onRemoteDatabase(), format("%s.%s", getSession().getSchema().orElseThrow(), name), "(t_double double precision, u_double double precision, v_real real, w_real real)", rows); } @Test @@ -1637,7 +1632,7 @@ public void testNativeQuerySelectFromNation() @Test public void testNativeQuerySelectFromTestTable() { - try (TestTable testTable = simpleTable()) { + try (TemporaryRelation testTable = simpleTable()) { assertQuery( format("SELECT * FROM TABLE(system.query(query => 'SELECT * FROM %s'))", testTable.getName()), "VALUES 1, 2"); @@ -1647,7 +1642,7 @@ public void testNativeQuerySelectFromTestTable() @Test public void testNativeQuerySelectUnsupportedType() { - try (TestTable testTable = createTableWithUnsupportedColumn()) { + try (TemporaryRelation testTable = createTableWithUnsupportedColumn()) { String unqualifiedTableName = testTable.getName().replaceAll("^\\w+\\.", ""); // Check that column 'two' is not supported. assertQuery("SELECT column_name FROM information_schema.columns WHERE table_name = '" + unqualifiedTableName + "'", "VALUES 'one', 'three'"); @@ -1677,7 +1672,7 @@ public void testNativeQueryInsertStatementTableDoesNotExist() @Test public void testNativeQueryInsertStatementTableExists() { - try (TestTable testTable = simpleTable()) { + try (TemporaryRelation testTable = simpleTable()) { assertThatThrownBy(() -> query(format("SELECT * FROM TABLE(system.query(query => 'INSERT INTO %s VALUES (3)'))", testTable.getName()))) .hasMessageContaining(format("Query not supported: ResultSetMetaData not available for query: INSERT INTO %s VALUES (3)", testTable.getName())); assertQuery("SELECT * FROM " + testTable.getName(), "VALUES 1, 2"); @@ -1691,7 +1686,7 @@ public void testNativeQueryIncorrectSyntax() .hasMessageContaining("Failed to get table handle for prepared query"); } - protected TestTable simpleTable() + protected TemporaryRelation simpleTable() { return new TestTable(onRemoteDatabase(), format("%s.simple_table", getSession().getSchema().orElseThrow()), "(col BIGINT)", ImmutableList.of("1", "2")); } diff --git a/plugin/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/BaseClickHouseConnectorTest.java b/plugin/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/BaseClickHouseConnectorTest.java index 952c8c9e0632..cb8d5122feeb 100644 --- a/plugin/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/BaseClickHouseConnectorTest.java +++ b/plugin/trino-clickhouse/src/test/java/io/trino/plugin/clickhouse/BaseClickHouseConnectorTest.java @@ -21,6 +21,7 @@ import io.trino.testing.MaterializedResult; import io.trino.testing.TestingConnectorBehavior; import io.trino.testing.sql.SqlExecutor; +import io.trino.testing.sql.TemporaryRelation; import io.trino.testing.sql.TestTable; import org.testng.SkipException; import org.testng.annotations.Test; @@ -505,7 +506,7 @@ protected Optional filterDataMappingSmokeTestData(DataMapp public void testNumericAggregationPushdown() { String schemaName = getSession().getSchema().orElseThrow(); - try (TestTable testTable = createAggregationTestTable(schemaName + ".test_aggregation_pushdown", + try (TemporaryRelation testTable = createAggregationTestTable(schemaName + ".test_aggregation_pushdown", ImmutableList.of("100.000, 100000000.000000000, 100.000, 100000000", "123.321, 123456789.987654321, 123.321, 123456789"))) { assertThat(query("SELECT min(short_decimal), min(long_decimal), min(a_bigint), min(t_double) FROM " + testTable.getName())).isFullyPushedDown(); assertThat(query("SELECT max(short_decimal), max(long_decimal), max(a_bigint), max(t_double) FROM " + testTable.getName())).isFullyPushedDown(); @@ -516,9 +517,9 @@ public void testNumericAggregationPushdown() } @Override - protected TestTable createAggregationTestTable(String name, List rows) + protected TemporaryRelation createAggregationTestTable(String name, List rows) { - return new TestTable(onRemoteDatabase(), name, "(short_decimal Nullable(Decimal(9, 3)), long_decimal Nullable(Decimal(30, 10)), t_double Nullable(Float64), a_bigint Nullable(Int64)) Engine=Log", rows); + return new TestTable(onRemoteDatabase(), format("%s.%s", getSession().getSchema().orElseThrow(), name), "(short_decimal Nullable(Decimal(9, 3)), long_decimal Nullable(Decimal(30, 10)), t_double Nullable(Float64), a_bigint Nullable(Int64)) Engine=Log", rows); } @Override diff --git a/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/BaseMariaDbConnectorTest.java b/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/BaseMariaDbConnectorTest.java index 9d5f32ce502c..3605201adc03 100644 --- a/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/BaseMariaDbConnectorTest.java +++ b/plugin/trino-mariadb/src/test/java/io/trino/plugin/mariadb/BaseMariaDbConnectorTest.java @@ -17,6 +17,7 @@ import io.trino.sql.planner.plan.FilterNode; import io.trino.testing.MaterializedResult; import io.trino.testing.TestingConnectorBehavior; +import io.trino.testing.sql.TemporaryRelation; import io.trino.testing.sql.TestTable; import org.testng.annotations.Test; @@ -305,7 +306,7 @@ public void testNativeQueryInsertStatementTableExists() // This is unusual, because other connectors don't produce a ResultSet metadata for INSERT at all. // The query fails because there are no columns, but even if columns were not required, the query would fail // to execute in MariaDB because the connector wraps it in additional syntax, which causes syntax error. - try (TestTable testTable = simpleTable()) { + try (TemporaryRelation testTable = simpleTable()) { assertThatThrownBy(() -> query(format("SELECT * FROM TABLE(system.query(query => 'INSERT INTO %s VALUES (3)'))", testTable.getName()))) .hasMessageContaining("descriptor has no fields"); assertQuery("SELECT * FROM " + testTable.getName(), "VALUES 1, 2"); diff --git a/plugin/trino-oracle/src/test/java/io/trino/plugin/oracle/BaseOracleConnectorTest.java b/plugin/trino-oracle/src/test/java/io/trino/plugin/oracle/BaseOracleConnectorTest.java index 0b237cae5c18..675256f304f0 100644 --- a/plugin/trino-oracle/src/test/java/io/trino/plugin/oracle/BaseOracleConnectorTest.java +++ b/plugin/trino-oracle/src/test/java/io/trino/plugin/oracle/BaseOracleConnectorTest.java @@ -21,6 +21,7 @@ import io.trino.sql.planner.plan.ProjectNode; import io.trino.testing.MaterializedResult; import io.trino.testing.TestingConnectorBehavior; +import io.trino.testing.sql.TemporaryRelation; import io.trino.testing.sql.TestTable; import io.trino.testing.sql.TestView; import org.testng.annotations.Test; @@ -309,9 +310,9 @@ public void testAggregationWithUnsupportedResultType() } @Override - protected TestTable createAggregationTestTable(String name, List rows) + protected TemporaryRelation createAggregationTestTable(String name, List rows) { - return new TestTable(onRemoteDatabase(), name, "(short_decimal number(9, 3), long_decimal number(30, 10), a_bigint number(19), t_double binary_double)", rows); + return new TestTable(onRemoteDatabase(), format("%s.%s", getSession().getSchema().orElseThrow(), name), "(short_decimal number(9, 3), long_decimal number(30, 10), a_bigint number(19), t_double binary_double)", rows); } @Override diff --git a/plugin/trino-phoenix5/src/test/java/io/trino/plugin/phoenix5/TestPhoenixConnectorTest.java b/plugin/trino-phoenix5/src/test/java/io/trino/plugin/phoenix5/TestPhoenixConnectorTest.java index d29f58e1ad24..b57899e36d44 100644 --- a/plugin/trino-phoenix5/src/test/java/io/trino/plugin/phoenix5/TestPhoenixConnectorTest.java +++ b/plugin/trino-phoenix5/src/test/java/io/trino/plugin/phoenix5/TestPhoenixConnectorTest.java @@ -23,6 +23,7 @@ import io.trino.testing.QueryRunner; import io.trino.testing.TestingConnectorBehavior; import io.trino.testing.sql.SqlExecutor; +import io.trino.testing.sql.TemporaryRelation; import io.trino.testing.sql.TestTable; import org.testng.SkipException; import org.testng.annotations.AfterClass; @@ -598,7 +599,7 @@ public void testNativeQuerySelectFromNation() public void testNativeQuerySelectFromTestTable() { // not implemented - try (TestTable testTable = simpleTable()) { + try (TemporaryRelation testTable = simpleTable()) { assertQueryFails( format("SELECT * FROM TABLE(system.query(query => 'SELECT * FROM %s'))", testTable.getName()), "line 1:21: Table function system.query not registered"); @@ -628,7 +629,7 @@ public void testNativeQueryInsertStatementTableDoesNotExist() public void testNativeQueryInsertStatementTableExists() { // not implemented - try (TestTable testTable = simpleTable()) { + try (TemporaryRelation testTable = simpleTable()) { assertThatThrownBy(() -> query(format("SELECT * FROM TABLE(system.query(query => 'INSERT INTO %s VALUES (3)'))", testTable.getName()))) .hasMessage("line 1:21: Table function system.query not registered"); assertThat(query("SELECT * FROM " + testTable.getName())) @@ -645,16 +646,16 @@ public void testNativeQueryIncorrectSyntax() } @Override - protected TestTable simpleTable() + protected TemporaryRelation simpleTable() { // override because Phoenix requires primary key specification return new PhoenixTestTable(onRemoteDatabase(), "tpch.simple_table", "(col BIGINT PRIMARY KEY)", ImmutableList.of("1", "2")); } @Override - protected TestTable createTableWithDoubleAndRealColumns(String name, List rows) + protected TemporaryRelation createTableWithDoubleAndRealColumns(String name, List rows) { - return new TestTable(onRemoteDatabase(), name, "(t_double double primary key, u_double double, v_real float, w_real float)", rows); + return new TestTable(onRemoteDatabase(), format("%s.%s", getSession().getSchema().orElseThrow(), name), "(t_double double primary key, u_double double, v_real float, w_real float)", rows); } @Override diff --git a/plugin/trino-singlestore/src/test/java/io/trino/plugin/singlestore/TestSingleStoreConnectorTest.java b/plugin/trino-singlestore/src/test/java/io/trino/plugin/singlestore/TestSingleStoreConnectorTest.java index c25a5464ba04..76cf3f937e5a 100644 --- a/plugin/trino-singlestore/src/test/java/io/trino/plugin/singlestore/TestSingleStoreConnectorTest.java +++ b/plugin/trino-singlestore/src/test/java/io/trino/plugin/singlestore/TestSingleStoreConnectorTest.java @@ -22,6 +22,7 @@ import io.trino.testing.QueryRunner; import io.trino.testing.TestingConnectorBehavior; import io.trino.testing.sql.SqlExecutor; +import io.trino.testing.sql.TemporaryRelation; import io.trino.testing.sql.TestTable; import org.testng.SkipException; import org.testng.annotations.AfterClass; @@ -324,7 +325,7 @@ public void testNativeQueryInsertStatementTableExists() // This is unusual, because other connectors don't produce a ResultSet metadata for INSERT at all. // The query fails because there are no columns, but even if columns were not required, the query would fail // to execute in SingleStore because the connector wraps it in additional syntax, which causes syntax error. - try (TestTable testTable = simpleTable()) { + try (TemporaryRelation testTable = simpleTable()) { assertThatThrownBy(() -> query(format("SELECT * FROM TABLE(system.query(query => 'INSERT INTO %s VALUES (3)'))", testTable.getName()))) .hasMessageContaining("descriptor has no fields"); assertQuery("SELECT * FROM " + testTable.getName(), "VALUES 1, 2");