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 duplicate TABLE_TYPE listing for view from system.jdbc.tables #24525

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -187,6 +187,41 @@ public void testResetAutoCommit()
}
}

@Test
public void testTableType()
throws SQLException
{
try (Connection connection = createConnection()) {
assertThat(connection.getCatalog()).isEqualTo("hive");
assertThat(connection.getSchema()).isEqualTo("default");

try (Statement statement = connection.createStatement()) {
statement.execute("CREATE TABLE test_table_type (x bigint)");
statement.execute("CREATE VIEW table_type_view AS SELECT * FROM test_table_type");
ResultSet rs = statement.executeQuery("SELECT TABLE_NAME, TABLE_TYPE FROM system.jdbc.tables WHERE TABLE_SCHEM = 'default' AND TABLE_NAME = 'table_type_view'");
int rowCount = 0;
while (rs.next()) {
assertEquals(rs.getString("TABLE_NAME"), "table_type_view");
assertEquals(rs.getString("TABLE_TYPE"), "VIEW");
rowCount++;
}
assertEquals(rowCount, 1);

rowCount = 0;
rs = statement.executeQuery("SELECT TABLE_NAME, TABLE_TYPE FROM system.jdbc.tables WHERE TABLE_SCHEM = 'default' AND TABLE_NAME = 'test_table_type'");
while (rs.next()) {
assertEquals(rs.getString("TABLE_NAME"), "test_table_type");
assertEquals(rs.getString("TABLE_TYPE"), "TABLE");
rowCount++;
}
assertEquals(rowCount, 1);

statement.execute("DROP TABLE test_table_type");
statement.execute("DROP VIEW table_type_view");
}
}
}

@Test
public void testRollback()
throws SQLException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
import com.facebook.presto.spi.SchemaTableName;
import com.facebook.presto.spi.connector.ConnectorTransactionHandle;
import com.facebook.presto.spi.security.AccessControl;
import com.google.common.collect.ImmutableSet;

import javax.inject.Inject;

import java.util.Optional;
import java.util.Set;

import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
import static com.facebook.presto.connector.system.SystemConnectorSessionUtil.toSession;
Expand Down Expand Up @@ -88,15 +90,19 @@ public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, Connect
for (String catalog : filter(listCatalogs(session, metadata, accessControl).keySet(), catalogFilter)) {
QualifiedTablePrefix prefix = tablePrefix(catalog, schemaFilter, tableFilter);

if (FilterUtil.emptyOrEquals(typeFilter, "TABLE")) {
for (SchemaTableName name : listTables(session, metadata, accessControl, prefix)) {
table.addRow(tableRow(catalog, name, "TABLE"));
Set<SchemaTableName> views = ImmutableSet.of();
if (FilterUtil.emptyOrEquals(typeFilter, "VIEW")) {
views = ImmutableSet.copyOf(listViews(session, metadata, accessControl, prefix));
for (SchemaTableName name : views) {
table.addRow(tableRow(catalog, name, "VIEW"));
}
}

if (FilterUtil.emptyOrEquals(typeFilter, "VIEW")) {
for (SchemaTableName name : listViews(session, metadata, accessControl, prefix)) {
table.addRow(tableRow(catalog, name, "VIEW"));
if (FilterUtil.emptyOrEquals(typeFilter, "TABLE")) {
for (SchemaTableName name : listTables(session, metadata, accessControl, prefix)) {
if (!views.contains(name)) {
table.addRow(tableRow(catalog, name, "TABLE"));
}
}
}
}
Expand Down
Loading