diff --git a/presto-tests/src/test/java/io/prestosql/tests/TestTpchDistributedQueries.java b/presto-tests/src/test/java/io/prestosql/tests/TestTpchDistributedQueries.java index 0172faf22ec97..99b04d1e3f930 100644 --- a/presto-tests/src/test/java/io/prestosql/tests/TestTpchDistributedQueries.java +++ b/presto-tests/src/test/java/io/prestosql/tests/TestTpchDistributedQueries.java @@ -15,6 +15,7 @@ import com.google.common.base.Strings; import com.google.common.collect.ImmutableSet; +import io.prestosql.Session; import io.prestosql.spi.connector.CatalogSchemaTableName; import io.prestosql.sql.planner.planprinter.IoPlanPrinter; import io.prestosql.testing.MaterializedResult; @@ -28,6 +29,7 @@ import static io.airlift.json.JsonCodec.jsonCodec; import static io.prestosql.spi.predicate.Marker.Bound.EXACTLY; import static io.prestosql.spi.type.VarcharType.createVarcharType; +import static io.prestosql.testing.TestingSession.testSessionBuilder; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; @@ -116,4 +118,22 @@ public void testTableSampleSystem() } assertTrue(sampleSizeFound, "Table sample returned unexpected number of rows"); } + + public void testShowTables() + { + assertQuerySucceeds(createSession("sf1"), "SHOW TABLES"); + assertQuerySucceeds(createSession("sf1.0"), "SHOW TABLES"); + assertQuerySucceeds("SHOW TABLES FROM sf1"); + assertQuerySucceeds("SHOW TABLES FROM \"sf1.0\""); + assertQueryFails("SHOW TABLES FROM sf0", "line 1:1: Schema 'sf0' does not exist"); + } + + private Session createSession(String schemaName) + { + return testSessionBuilder() + .setSource("test") + .setCatalog("tpch") + .setSchema(schemaName) + .build(); + } } diff --git a/presto-tpcds/src/main/java/io/prestosql/plugin/tpcds/TpcdsMetadata.java b/presto-tpcds/src/main/java/io/prestosql/plugin/tpcds/TpcdsMetadata.java index a82bc6fb33832..f7f5319db7150 100644 --- a/presto-tpcds/src/main/java/io/prestosql/plugin/tpcds/TpcdsMetadata.java +++ b/presto-tpcds/src/main/java/io/prestosql/plugin/tpcds/TpcdsMetadata.java @@ -73,6 +73,12 @@ public TpcdsMetadata() this.tableNames = tableNames.build(); } + @Override + public boolean schemaExists(ConnectorSession session, String schemaName) + { + return schemaNameToScaleFactor(schemaName) > 0; + } + @Override public List listSchemaNames(ConnectorSession session) { diff --git a/presto-tpcds/src/test/java/io/prestosql/plugin/tpcds/TestTpcds.java b/presto-tpcds/src/test/java/io/prestosql/plugin/tpcds/TestTpcds.java index dead77da7b3c3..ce95a9f147dd1 100644 --- a/presto-tpcds/src/test/java/io/prestosql/plugin/tpcds/TestTpcds.java +++ b/presto-tpcds/src/test/java/io/prestosql/plugin/tpcds/TestTpcds.java @@ -13,6 +13,7 @@ */ package io.prestosql.plugin.tpcds; +import io.prestosql.Session; import io.prestosql.testing.MaterializedResult; import io.prestosql.tests.AbstractTestQueryFramework; import org.testng.annotations.Test; @@ -20,6 +21,7 @@ import java.math.BigDecimal; import static io.prestosql.testing.MaterializedResult.resultBuilder; +import static io.prestosql.testing.TestingSession.testSessionBuilder; import static io.prestosql.testing.assertions.Assert.assertEquals; import static java.util.stream.Collectors.joining; import static java.util.stream.IntStream.range; @@ -71,4 +73,23 @@ public void testLargeInWithShortDecimal() assertQuerySucceeds("SELECT i_current_price FROM item WHERE i_current_price IN (i_wholesale_cost, " + longValues + ")"); assertQuerySucceeds("SELECT i_current_price FROM item WHERE i_current_price NOT IN (i_wholesale_cost, " + longValues + ")"); } + + @Test + public void testShowTables() + { + assertQuerySucceeds(createSession("sf1"), "SHOW TABLES"); + assertQuerySucceeds(createSession("sf1.0"), "SHOW TABLES"); + assertQuerySucceeds("SHOW TABLES FROM sf1"); + assertQuerySucceeds("SHOW TABLES FROM \"sf1.0\""); + assertQueryFails("SHOW TABLES FROM sf0", "line 1:1: Schema 'sf0' does not exist"); + } + + private Session createSession(String schemaName) + { + return testSessionBuilder() + .setSource("test") + .setCatalog("tpcds") + .setSchema(schemaName) + .build(); + } } diff --git a/presto-tpcds/src/test/java/io/prestosql/plugin/tpcds/TestTpcdsMetadata.java b/presto-tpcds/src/test/java/io/prestosql/plugin/tpcds/TestTpcdsMetadata.java new file mode 100644 index 0000000000000..205367ede8f6f --- /dev/null +++ b/presto-tpcds/src/test/java/io/prestosql/plugin/tpcds/TestTpcdsMetadata.java @@ -0,0 +1,37 @@ +/* + * 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.prestosql.plugin.tpcds; + +import io.prestosql.spi.connector.ConnectorSession; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +public class TestTpcdsMetadata +{ + private final TpcdsMetadata tpcdsMetadata = new TpcdsMetadata(); + private final ConnectorSession session = null; + + @Test + public void testHiddenSchemas() + { + assertTrue(tpcdsMetadata.schemaExists(session, "sf1")); + assertTrue(tpcdsMetadata.schemaExists(session, "sf3000.0")); + assertFalse(tpcdsMetadata.schemaExists(session, "sf0")); + assertFalse(tpcdsMetadata.schemaExists(session, "hf1")); + assertFalse(tpcdsMetadata.schemaExists(session, "sf")); + assertFalse(tpcdsMetadata.schemaExists(session, "sfabc")); + } +} diff --git a/presto-tpch/src/main/java/io/prestosql/plugin/tpch/TpchMetadata.java b/presto-tpch/src/main/java/io/prestosql/plugin/tpch/TpchMetadata.java index 5f2f36fd5a25e..a26caf675f0b7 100644 --- a/presto-tpch/src/main/java/io/prestosql/plugin/tpch/TpchMetadata.java +++ b/presto-tpch/src/main/java/io/prestosql/plugin/tpch/TpchMetadata.java @@ -153,6 +153,12 @@ private static StatisticsEstimator createStatisticsEstimator() return new StatisticsEstimator(tableStatisticsDataRepository); } + @Override + public boolean schemaExists(ConnectorSession session, String schemaName) + { + return schemaNameToScaleFactor(schemaName) > 0; + } + @Override public List listSchemaNames(ConnectorSession session) { @@ -169,7 +175,7 @@ public TpchTableHandle getTableHandle(ConnectorSession session, SchemaTableName // parse the scale factor double scaleFactor = schemaNameToScaleFactor(tableName.getSchemaName()); - if (scaleFactor < 0) { + if (scaleFactor <= 0) { return null; } diff --git a/presto-tpch/src/test/java/io/prestosql/plugin/tpch/TestTpchMetadata.java b/presto-tpch/src/test/java/io/prestosql/plugin/tpch/TestTpchMetadata.java index 3606086f0c655..de15946c8e6a6 100644 --- a/presto-tpch/src/test/java/io/prestosql/plugin/tpch/TestTpchMetadata.java +++ b/presto-tpch/src/test/java/io/prestosql/plugin/tpch/TestTpchMetadata.java @@ -71,6 +71,7 @@ import static java.util.Objects.requireNonNull; import static java.util.stream.Collectors.toList; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; @@ -129,6 +130,17 @@ public void testTableStatsWithConstraints() }); } + @Test + public void testHiddenSchemas() + { + assertTrue(tpchMetadata.schemaExists(session, "sf1")); + assertTrue(tpchMetadata.schemaExists(session, "sf3000.0")); + assertFalse(tpchMetadata.schemaExists(session, "sf0")); + assertFalse(tpchMetadata.schemaExists(session, "hf1")); + assertFalse(tpchMetadata.schemaExists(session, "sf")); + assertFalse(tpchMetadata.schemaExists(session, "sfabc")); + } + private void testTableStats(String schema, TpchTable table, double expectedRowCount) { testTableStats(schema, table, alwaysTrue(), expectedRowCount);