diff --git a/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala b/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala index 3f70387a3b..58ad5449b4 100644 --- a/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala +++ b/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala @@ -759,15 +759,17 @@ private[hive] class HiveClientImpl( dbName: String, pattern: String, tableType: CatalogTableType): Seq[String] = withHiveState { + val hiveTableType = toHiveTableType(tableType) try { // Try with Hive API getTablesByType first, it's supported from Hive 2.3+. - shim.getTablesByType(client, dbName, pattern, toHiveTableType(tableType)) + shim.getTablesByType(client, dbName, pattern, hiveTableType) } catch { case _: UnsupportedOperationException => // Fallback to filter logic if getTablesByType not supported. val tableNames = client.getTablesByPattern(dbName, pattern).asScala - val tables = getTablesByName(dbName, tableNames.toSeq).filter(_.tableType == tableType) - tables.map(_.identifier.table) + getRawTablesByName(dbName, tableNames) + .filter(_.getTableType == hiveTableType) + .map(_.getTableName) } }