From d1d465e8a9b4459e35903e6f3fb4fac56973508a Mon Sep 17 00:00:00 2001 From: David Phillips Date: Wed, 22 Mar 2023 13:53:19 -0400 Subject: [PATCH] Fix formatting and simplify condition in HiveMetadata --- .../io/trino/plugin/hive/HiveMetadata.java | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadata.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadata.java index b39428bcd7d2..395736172fd7 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadata.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadata.java @@ -804,35 +804,38 @@ public Map> listTableColumns(ConnectorSess throw new UnsupportedOperationException("The deprecated listTableColumns is not supported because streamTableColumns is implemented instead"); } - @SuppressWarnings("TryWithIdenticalCatches") @Override public Iterator streamTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { requireNonNull(prefix, "prefix is null"); - return listTables(session, prefix).stream().flatMap(tableName -> { - try { - if (redirectTable(session, tableName).isPresent()) { - return Stream.of(TableColumnsMetadata.forRedirectedTable(tableName)); - } - return Stream.of(TableColumnsMetadata.forTable(tableName, getTableMetadata(session, tableName).getColumns())); - } - catch (HiveViewNotSupportedException e) { - // view is not supported - return Stream.empty(); - } - catch (TableNotFoundException e) { - // table disappeared during listing operation - return Stream.empty(); + return listTables(session, prefix).stream() + .flatMap(tableName -> streamTableColumns(session, tableName)) + .iterator(); + } + + private Stream streamTableColumns(ConnectorSession session, SchemaTableName tableName) + { + try { + if (redirectTable(session, tableName).isPresent()) { + return Stream.of(TableColumnsMetadata.forRedirectedTable(tableName)); } - catch (TrinoException e) { - // Skip this table if there's a failure due to Hive, a bad Serde, or bad metadata - if (!e.getErrorCode().getType().equals(ErrorType.EXTERNAL)) { - throw e; - } + return Stream.of(TableColumnsMetadata.forTable(tableName, getTableMetadata(session, tableName).getColumns())); + } + catch (HiveViewNotSupportedException e) { + // view is not supported + return Stream.empty(); + } + catch (TableNotFoundException e) { + // table disappeared during listing operation + return Stream.empty(); + } + catch (TrinoException e) { + // Skip this table if there's a failure due to Hive, a bad Serde, or bad metadata + if (e.getErrorCode().getType() == ErrorType.EXTERNAL) { return Stream.empty(); } - }) - .iterator(); + throw e; + } } @Override