Skip to content

Commit 05a28ce

Browse files
committed
Ignore unknown table formats when querying system.jdbc.columns table
1 parent f2ec6ad commit 05a28ce

File tree

8 files changed

+59
-9
lines changed

8 files changed

+59
-9
lines changed

presto-hive-common/src/main/java/com/facebook/presto/hive/HiveErrorCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public enum HiveErrorCode
7676
HIVE_RANGER_SERVER_ERROR(48, EXTERNAL),
7777
HIVE_FUNCTION_INITIALIZATION_ERROR(49, EXTERNAL),
7878
HIVE_METASTORE_INITIALIZE_SSL_ERROR(50, EXTERNAL),
79+
UNKNOWN_TABLE_TYPE(51, EXTERNAL),
7980
/**/;
8081

8182
private final ErrorCode errorCode;

presto-iceberg/src/main/java/com/facebook/presto/iceberg/UnknownTableTypeException.java renamed to presto-hive-common/src/main/java/com/facebook/presto/hive/UnknownTableTypeException.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@
1111
* See the License for the specific language governing permissions and
1212
* limitations under the License.
1313
*/
14-
package com.facebook.presto.iceberg;
14+
package com.facebook.presto.hive;
1515

1616
import com.facebook.presto.spi.PrestoException;
17-
import com.facebook.presto.spi.SchemaTableName;
1817

19-
import static com.facebook.presto.iceberg.IcebergErrorCode.ICEBERG_UNKNOWN_TABLE_TYPE;
18+
import static com.facebook.presto.hive.HiveErrorCode.UNKNOWN_TABLE_TYPE;
2019

2120
public class UnknownTableTypeException
2221
extends PrestoException
2322
{
24-
public UnknownTableTypeException(SchemaTableName tableName)
23+
public UnknownTableTypeException(String message)
2524
{
26-
super(ICEBERG_UNKNOWN_TABLE_TYPE, "Not an Iceberg table: " + tableName);
25+
super(UNKNOWN_TABLE_TYPE, message);
2726
}
2827
}

presto-hive/src/main/java/com/facebook/presto/hive/HiveMetadata.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import com.facebook.airlift.json.JsonCodec;
1717
import com.facebook.airlift.json.smile.SmileCodec;
18+
import com.facebook.airlift.log.Logger;
1819
import com.facebook.presto.common.CatalogSchemaName;
1920
import com.facebook.presto.common.Page;
2021
import com.facebook.presto.common.Subfield;
@@ -389,6 +390,7 @@
389390
public class HiveMetadata
390391
implements TransactionalMetadata
391392
{
393+
private static final Logger log = Logger.get(HiveMetadata.class);
392394
public static final Set<String> RESERVED_ROLES = ImmutableSet.of("all", "default", "none");
393395
public static final String REFERENCED_MATERIALIZED_VIEWS = "referenced_materialized_views";
394396

@@ -674,7 +676,7 @@ private ConnectorTableMetadata getTableMetadata(Optional<Table> table, SchemaTab
674676
}
675677

676678
if (isIcebergTable(table.get()) || isDeltaLakeTable(table.get())) {
677-
throw new PrestoException(HIVE_UNSUPPORTED_FORMAT, format("Not a Hive table '%s'", tableName));
679+
throw new UnknownTableTypeException("Not a Hive table: " + tableName);
678680
}
679681

680682
List<TableConstraint<String>> tableConstraints = metastore.getTableConstraints(metastoreContext, tableName.getSchemaName(), tableName.getTableName());
@@ -862,6 +864,9 @@ public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSess
862864
catch (TableNotFoundException e) {
863865
// table disappeared during listing operation
864866
}
867+
catch (UnknownTableTypeException e) {
868+
log.warn(String.format("%s: Unknown table type of table %s", e.getMessage(), tableName));
869+
}
865870
}
866871
return columns.build();
867872
}

presto-iceberg/src/main/java/com/facebook/presto/iceberg/HiveTableOperations.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.facebook.airlift.log.Logger;
1818
import com.facebook.presto.hive.HdfsContext;
1919
import com.facebook.presto.hive.HdfsEnvironment;
20+
import com.facebook.presto.hive.UnknownTableTypeException;
2021
import com.facebook.presto.hive.metastore.ExtendedHiveMetastore;
2122
import com.facebook.presto.hive.metastore.HivePrivilegeInfo;
2223
import com.facebook.presto.hive.metastore.MetastoreContext;
@@ -215,7 +216,7 @@ public TableMetadata refresh()
215216
Table table = getTable();
216217

217218
if (!isIcebergTable(table)) {
218-
throw new UnknownTableTypeException(getSchemaTableName());
219+
throw new UnknownTableTypeException("Not an Iceberg table: " + getSchemaTableName());
219220
}
220221

221222
if (isPrestoView(table)) {

presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergAbstractMetadata.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.facebook.presto.hive.HiveOutputMetadata;
2929
import com.facebook.presto.hive.HivePartition;
3030
import com.facebook.presto.hive.NodeVersion;
31+
import com.facebook.presto.hive.UnknownTableTypeException;
3132
import com.facebook.presto.iceberg.changelog.ChangelogOperation;
3233
import com.facebook.presto.iceberg.changelog.ChangelogUtil;
3334
import com.facebook.presto.iceberg.statistics.StatisticsFileCache;

presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergErrorCode.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
public enum IcebergErrorCode
2525
implements ErrorCodeSupplier
2626
{
27-
ICEBERG_UNKNOWN_TABLE_TYPE(0, EXTERNAL),
2827
ICEBERG_INVALID_METADATA(1, EXTERNAL),
2928
ICEBERG_TOO_MANY_OPEN_PARTITIONS(2, USER_ERROR),
3029
ICEBERG_INVALID_PARTITION_VALUE(3, EXTERNAL),

presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergHiveMetadata.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.facebook.presto.hive.HiveTypeTranslator;
2525
import com.facebook.presto.hive.NodeVersion;
2626
import com.facebook.presto.hive.TableAlreadyExistsException;
27+
import com.facebook.presto.hive.UnknownTableTypeException;
2728
import com.facebook.presto.hive.ViewAlreadyExistsException;
2829
import com.facebook.presto.hive.metastore.Column;
2930
import com.facebook.presto.hive.metastore.Database;
@@ -230,7 +231,7 @@ protected boolean tableExists(ConnectorSession session, SchemaTableName schemaTa
230231
return false;
231232
}
232233
if (!isIcebergTable(hiveTable.get())) {
233-
throw new UnknownTableTypeException(schemaTableName);
234+
throw new UnknownTableTypeException("Not an Iceberg table: " + schemaTableName);
234235
}
235236
return true;
236237
}

presto-product-tests/src/main/java/com/facebook/presto/tests/SystemConnectorTests.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@
1313
*/
1414
package com.facebook.presto.tests;
1515

16+
import com.google.common.collect.ImmutableList;
1617
import io.prestodb.tempto.ProductTest;
18+
import io.prestodb.tempto.assertions.QueryAssert;
1719
import org.testng.annotations.Test;
1820

1921
import java.sql.JDBCType;
22+
import java.util.List;
23+
import java.util.stream.Collectors;
2024

2125
import static com.facebook.presto.tests.TestGroups.JDBC;
2226
import static com.facebook.presto.tests.TestGroups.SYSTEM_CONNECTOR;
2327
import static com.facebook.presto.tests.utils.JdbcDriverUtils.usingTeradataJdbcDriver;
28+
import static com.facebook.presto.tests.utils.QueryExecutors.onPresto;
29+
import static io.prestodb.tempto.assertions.QueryAssert.Row.row;
2430
import static io.prestodb.tempto.assertions.QueryAssert.assertThat;
2531
import static io.prestodb.tempto.query.QueryExecutor.defaultQueryExecutor;
2632
import static io.prestodb.tempto.query.QueryExecutor.query;
@@ -107,4 +113,41 @@ public void selectMetadataCatalogs()
107113
.hasColumns(VARCHAR, VARCHAR)
108114
.hasAnyRows();
109115
}
116+
117+
@Test(groups = SYSTEM_CONNECTOR)
118+
public void selectJdbcColumns()
119+
{
120+
try {
121+
String hiveSQL = "select table_name, column_name from system.jdbc.columns where table_cat = 'hive' AND table_schem = 'default'";
122+
String icebergSQL = "select table_name, column_name from system.jdbc.columns where table_cat = 'iceberg' AND table_schem = 'default'";
123+
124+
List<QueryAssert.Row> preexistingHiveColumns = onPresto().executeQuery(hiveSQL).rows().stream()
125+
.map(list -> row(list.toArray()))
126+
.collect(Collectors.toList());
127+
128+
List<QueryAssert.Row> preexistingIcebergColumns = onPresto().executeQuery(icebergSQL).rows().stream()
129+
.map(list -> row(list.toArray()))
130+
.collect(Collectors.toList());
131+
132+
onPresto().executeQuery("CREATE TABLE hive.default.test_hive_system_jdbc_columns (_double DOUBLE)");
133+
onPresto().executeQuery("CREATE TABLE iceberg.default.test_iceberg_system_jdbc_columns (_string VARCHAR, _integer INTEGER)");
134+
135+
assertThat(onPresto().executeQuery(hiveSQL))
136+
.containsOnly(ImmutableList.<QueryAssert.Row>builder()
137+
.addAll(preexistingHiveColumns)
138+
.add(row("test_hive_system_jdbc_columns", "_double"))
139+
.build());
140+
141+
assertThat(onPresto().executeQuery(icebergSQL))
142+
.containsOnly(ImmutableList.<QueryAssert.Row>builder()
143+
.addAll(preexistingIcebergColumns)
144+
.add(row("test_iceberg_system_jdbc_columns", "_string"))
145+
.add(row("test_iceberg_system_jdbc_columns", "_integer"))
146+
.build());
147+
}
148+
finally {
149+
onPresto().executeQuery("DROP TABLE IF EXISTS hive.default.test_hive_system_jdbc_columns");
150+
onPresto().executeQuery("DROP TABLE IF EXISTS iceberg.default.test_iceberg_system_jdbc_columns");
151+
}
152+
}
110153
}

0 commit comments

Comments
 (0)