Skip to content

Commit b9a72ca

Browse files
committed
[SPARK-LLAP-106] Fix table alias bug (#107)
## What changes were proposed in this pull request? Currently, Spark-LLAP 2.1 fails to handle table alias. This fixes the bug and simplify the logic. ## How was this patch tested? Tested manually. This closes #106 (cherry picked from commit 82bf99d) Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent d210a2d commit b9a72ca

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

Diff for: src/main/scala/org/apache/spark/sql/hive/llap/LlapMetastoreCatalog.scala

+13-21
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,23 @@ class LlapMetastoreCatalog(sparkSession: SparkSession)
3636
tableIdentifier: TableIdentifier,
3737
alias: Option[String] = None): LogicalPlan = {
3838
val qualifiedTableName = getQualifiedTableName(tableIdentifier)
39+
40+
// Use metastore catalog to lookup tables
3941
val catalog = sparkSession.sharedState.externalCatalog.asInstanceOf[LlapExternalCatalog]
4042
val table = catalog.getTable(qualifiedTableName.database, qualifiedTableName.name)
4143

42-
// Use metastore catalog to lookup tables, then convert to our relations
43-
val client = sparkSession.sharedState.externalCatalog.asInstanceOf[LlapExternalCatalog].client
44-
val qualifiedTable = MetastoreRelation(
45-
qualifiedTableName.database, qualifiedTableName.name)(table, sparkSession)
46-
val relation = alias.map(a => SubqueryAlias(a, qualifiedTable, None)).getOrElse(qualifiedTable)
47-
4844
// Now convert to LlapRelation
49-
val logicalRelation = relation match {
50-
case MetastoreRelation(dbName, tabName) =>
51-
val sessionState = sparkSession.sessionState.asInstanceOf[LlapSessionState]
52-
LogicalRelation(
53-
DataSource(
54-
sparkSession = sparkSession,
55-
className = "org.apache.spark.sql.hive.llap",
56-
options = Map(
57-
"table" -> (dbName + "." + tabName),
58-
"url" -> sessionState.getConnectionUrl())
59-
).resolveRelation())
60-
case _ => throw new Exception("Expected MetastoreRelation")
61-
}
62-
63-
val tableWithQualifiers = SubqueryAlias(tableIdentifier.table, logicalRelation, None)
45+
val sessionState = sparkSession.sessionState.asInstanceOf[LlapSessionState]
46+
val logicalRelation = LogicalRelation(
47+
DataSource(
48+
sparkSession = sparkSession,
49+
className = "org.apache.spark.sql.hive.llap",
50+
options = Map(
51+
"table" -> (qualifiedTableName.database + "." + qualifiedTableName.name),
52+
"url" -> sessionState.getConnectionUrl())
53+
).resolveRelation())
54+
55+
val tableWithQualifiers = SubqueryAlias(qualifiedTableName.name, logicalRelation, None)
6456
alias.map(a => SubqueryAlias(a, tableWithQualifiers, None)).getOrElse(tableWithQualifiers)
6557
}
6658
}

0 commit comments

Comments
 (0)