Skip to content

Commit

Permalink
Convert exception when failed to get columns in Phoenix
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Mar 7, 2022
1 parent 5c87f42 commit 98b794a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import java.io.IOException;
import java.sql.Array;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.JDBCType;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand Down Expand Up @@ -375,6 +376,20 @@ protected String getTableSchemaName(ResultSet resultSet)
return firstNonNull(resultSet.getString("TABLE_SCHEM"), DEFAULT_SCHEMA);
}

@Override
protected ResultSet getColumns(JdbcTableHandle handle, DatabaseMetaData metadata)
throws SQLException
{
try {
return super.getColumns(handle, metadata);
}
catch (org.apache.phoenix.schema.TableNotFoundException e) {
// Most JDBC driver return an empty result when DatabaseMetaData.getColumns can't find objects, but Phoenix driver throws an exception
// Rethrow as Trino TableNotFoundException to suppress the exception during listing information_schema
throw new io.trino.spi.connector.TableNotFoundException(new SchemaTableName(handle.getSchemaName(), handle.getTableName()));
}
}

@Override
public Optional<ColumnMapping> toColumnMapping(ConnectorSession session, Connection connection, JdbcTypeHandle typeHandle)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import io.trino.testing.TestingConnectorBehavior;
import io.trino.testing.sql.SqlExecutor;
import io.trino.testing.sql.TestTable;
import io.trino.testng.services.Flaky;
import org.testng.SkipException;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -221,30 +220,6 @@ public void testShowCreateTable()
")");
}

// TODO (https://github.com/trinodb/trino/issues/10904): Test is flaky because tests execute in parallel
@Flaky(issue = "https://github.com/trinodb/trino/issues/10904", match = "\\QERROR 1012 (42M03): Table undefined. tableName=")
@Test
@Override
public void testSelectInformationSchemaColumns()
{
super.testSelectInformationSchemaColumns();
}

@Override
public void testReadMetadataWithRelationsConcurrentModifications()
{
try {
super.testReadMetadataWithRelationsConcurrentModifications();
}
catch (Exception expected) {
// The test failure is not guaranteed
// TODO (https://github.com/trinodb/trino/issues/10904): shouldn't fail
assertThat(expected)
.hasMessageContaining("ERROR 1012 (42M03): Table undefined. tableName=");
throw new SkipException("to be fixed");
}
}

@Override
public void testCharVarcharComparison()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
import java.io.IOException;
import java.sql.Array;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.JDBCType;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand Down Expand Up @@ -367,6 +368,20 @@ protected String getTableSchemaName(ResultSet resultSet)
return firstNonNull(resultSet.getString("TABLE_SCHEM"), DEFAULT_SCHEMA);
}

@Override
protected ResultSet getColumns(JdbcTableHandle handle, DatabaseMetaData metadata)
throws SQLException
{
try {
return super.getColumns(handle, metadata);
}
catch (org.apache.phoenix.schema.TableNotFoundException e) {
// Most JDBC driver return an empty result when DatabaseMetaData.getColumns can't find objects, but Phoenix driver throws an exception
// Rethrow as Trino TableNotFoundException to suppress the exception during listing information_schema
throw new io.trino.spi.connector.TableNotFoundException(new SchemaTableName(handle.getSchemaName(), handle.getTableName()));
}
}

@Override
public Optional<ColumnMapping> toColumnMapping(ConnectorSession session, Connection connection, JdbcTypeHandle typeHandle)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import io.trino.testing.TestingConnectorBehavior;
import io.trino.testing.sql.SqlExecutor;
import io.trino.testing.sql.TestTable;
import io.trino.testng.services.Flaky;
import org.testng.SkipException;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -239,30 +238,6 @@ public void testShowCreateTable()
")");
}

// TODO (https://github.com/trinodb/trino/issues/10904): Test is flaky because tests execute in parallel
@Flaky(issue = "https://github.com/trinodb/trino/issues/10904", match = "\\QERROR 1012 (42M03): Table undefined. tableName=")
@Test
@Override
public void testSelectInformationSchemaColumns()
{
super.testSelectInformationSchemaColumns();
}

@Override
public void testReadMetadataWithRelationsConcurrentModifications()
{
try {
super.testReadMetadataWithRelationsConcurrentModifications();
}
catch (Exception expected) {
// The test failure is not guaranteed
// TODO (https://github.com/trinodb/trino/issues/10904): shouldn't fail
assertThat(expected)
.hasMessageContaining("ERROR 1012 (42M03): Table undefined. tableName=");
throw new SkipException("to be fixed");
}
}

@Override
public void testCharVarcharComparison()
{
Expand Down

0 comments on commit 98b794a

Please sign in to comment.