Skip to content

Commit d9fa1d6

Browse files
committed
Stores analyzed logical plan when registering a temp table
1 parent 7ff8c45 commit d9fa1d6

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

sql/core/src/main/scala/org/apache/spark/sql/SQLContext.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class SQLContext(@transient val sparkContext: SparkContext)
246246
* @group userf
247247
*/
248248
def registerRDDAsTable(rdd: SchemaRDD, tableName: String): Unit = {
249-
catalog.registerTable(None, tableName, rdd.logicalPlan)
249+
catalog.registerTable(None, tableName, rdd.queryExecution.analyzed)
250250
}
251251

252252
/**
@@ -411,7 +411,7 @@ class SQLContext(@transient val sparkContext: SparkContext)
411411
protected def stringOrError[A](f: => A): String =
412412
try f.toString catch { case e: Throwable => e.toString }
413413

414-
def simpleString: String =
414+
def simpleString: String =
415415
s"""== Physical Plan ==
416416
|${stringOrError(executedPlan)}
417417
"""

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717

1818
package org.apache.spark.sql.hive.execution
1919

20-
import java.io.File
21-
2220
import scala.util.Try
2321

24-
import org.apache.spark.SparkException
2522
import org.apache.spark.sql.hive._
2623
import org.apache.spark.sql.hive.test.TestHive
2724
import org.apache.spark.sql.hive.test.TestHive._
@@ -514,6 +511,28 @@ class HiveQuerySuite extends HiveComparisonTest {
514511
sql("DROP TABLE alter1")
515512
}
516513

514+
case class LogEntry(filename: String, message: String)
515+
case class LogFile(name: String)
516+
517+
test("SPARK-3414 regression: should store analyzed logical plan when registering a temp table") {
518+
sparkContext.makeRDD(Seq.empty[LogEntry]).registerTempTable("rawLogs")
519+
sparkContext.makeRDD(Seq.empty[LogFile]).registerTempTable("logFiles")
520+
521+
sql(
522+
"""
523+
SELECT name, message
524+
FROM rawLogs
525+
JOIN (
526+
SELECT name
527+
FROM logFiles
528+
) files
529+
ON rawLogs.filename = files.name
530+
""").registerTempTable("boom")
531+
532+
// This should be successfully analyzed
533+
sql("SELECT * FROM boom").queryExecution.analyzed
534+
}
535+
517536
test("parse HQL set commands") {
518537
// Adapted from its SQL counterpart.
519538
val testKey = "spark.sql.key.usedfortestonly"

0 commit comments

Comments
 (0)