File tree Expand file tree Collapse file tree 2 files changed +24
-5
lines changed
core/src/main/scala/org/apache/spark/sql
hive/src/test/scala/org/apache/spark/sql/hive/execution Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -246,7 +246,7 @@ class SQLContext(@transient val sparkContext: SparkContext)
246
246
* @group userf
247
247
*/
248
248
def registerRDDAsTable (rdd : SchemaRDD , tableName : String ): Unit = {
249
- catalog.registerTable(None , tableName, rdd.logicalPlan )
249
+ catalog.registerTable(None , tableName, rdd.queryExecution.analyzed )
250
250
}
251
251
252
252
/**
@@ -411,7 +411,7 @@ class SQLContext(@transient val sparkContext: SparkContext)
411
411
protected def stringOrError [A ](f : => A ): String =
412
412
try f.toString catch { case e : Throwable => e.toString }
413
413
414
- def simpleString : String =
414
+ def simpleString : String =
415
415
s """ == Physical Plan ==
416
416
| ${stringOrError(executedPlan)}
417
417
"""
Original file line number Diff line number Diff line change 17
17
18
18
package org .apache .spark .sql .hive .execution
19
19
20
- import java .io .File
21
-
22
20
import scala .util .Try
23
21
24
- import org .apache .spark .SparkException
25
22
import org .apache .spark .sql .hive ._
26
23
import org .apache .spark .sql .hive .test .TestHive
27
24
import org .apache .spark .sql .hive .test .TestHive ._
@@ -514,6 +511,28 @@ class HiveQuerySuite extends HiveComparisonTest {
514
511
sql(" DROP TABLE alter1" )
515
512
}
516
513
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
+
517
536
test(" parse HQL set commands" ) {
518
537
// Adapted from its SQL counterpart.
519
538
val testKey = " spark.sql.key.usedfortestonly"
You can’t perform that action at this time.
0 commit comments