Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SHOW TABLES for hidden tpch and tpcds schemas #1007

Merged
merged 2 commits into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> listSchemaNames(ConnectorSession session)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
*/
package io.prestosql.plugin.tpcds;

import io.prestosql.Session;
import io.prestosql.testing.MaterializedResult;
import io.prestosql.tests.AbstractTestQueryFramework;
import org.testng.annotations.Test;

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;
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> listSchemaNames(ConnectorSession session)
{
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -129,6 +130,17 @@ public void testTableStatsWithConstraints()
});
}

@Test
public void testHiddenSchemas()
findepi marked this conversation as resolved.
Show resolved Hide resolved
{
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);
Expand Down