dtenedor commented on code in PR #44450:
URL: https://github.com/apache/spark/pull/44450#discussion_r1434323554
##########
sql/core/src/test/scala/org/apache/spark/sql/ParametersSuite.scala:
##########
@@ -27,6 +27,27 @@ import org.apache.spark.sql.test.SharedSparkSession
class ParametersSuite extends QueryTest with SharedSparkSession {
+ test("SPARK-46481: Test variable folding") {
+ sql("DECLARE a INT = 1").collect()
+ sql("SET VAR a = 1").collect()
+ val expected = sql("SELECT 42 WHERE 1 = 1").queryExecution.executedPlan
+ val variableDirectly = sql("SELECT 42 WHERE 1 =
a").queryExecution.executedPlan
+ val parameterizedSpark =
+ spark.sql("SELECT 42 WHERE 1 = ?", Array(1)).queryExecution.executedPlan
+ val parameterizedSql =
+ spark.sql("EXECUTE IMMEDIATE 'SELECT 42 WHERE 1 = ?' USING
a").queryExecution.executedPlan
+
+ assert(
+ expected.semanticHash() == variableDirectly.semanticHash(),
+ "Select with variable directly query failed")
+ assert(
+ expected.semanticHash() == parameterizedSpark.semanticHash(),
Review Comment:
instead of comparing the `executedPlan` and looking at the semantic hashes,
can we use `comparePlans` like this example [1] on the logical plans?
[1]
https://src.dev.databricks.com/databricks/runtime@master/-/blob/sql/core/src/test/scala/com/databricks/sql/execution/command/DDLParserSuite.scala?L311-331&subtree=true
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]