Skip to content

Commit a39f70d

Browse files
[SPARK-48843] Prevent infinite loop with BindParameters
### What changes were proposed in this pull request? In order to resolve the named parameters on the subtree, BindParameters recurses into the subtrees and tries to match the pattern with the named parameters. If there's no named parameter in the current level, the rule tries to return the unchanged plan. However, instead of returning the current plan object, the rule always returns the captured root plan node, leading into the infinite recursion. ### Why are the changes needed? Infinite recursion with the named parameters and the global limit. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Added unit tests. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #47271 from nemanja-boric-databricks/fix-bind. Lead-authored-by: Nemanja Boric <nemanja.boric@databricks.com> Co-authored-by: Wenchen Fan <cloud0fan@gmail.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
1 parent 35fbedb commit a39f70d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

python/pyspark/sql/tests/connect/test_connect_basic.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,13 @@ def test_sql_with_named_args(self):
630630
df2 = self.spark.sql(sqlText, args={"minId": 7, "m": SF.create_map(SF.lit("a"), SF.lit(1))})
631631
self.assert_eq(df.toPandas(), df2.toPandas())
632632

633+
def test_namedargs_with_global_limit(self):
634+
sqlText = """SELECT * FROM VALUES (TIMESTAMP('2022-12-25 10:30:00'), 1) as tab(date, val)
635+
where val = :val"""
636+
df = self.connect.sql(sqlText, args={"val": 1})
637+
df2 = self.spark.sql(sqlText, args={"val": 1})
638+
self.assert_eq(df.toPandas(), df2.toPandas())
639+
633640
def test_sql_with_pos_args(self):
634641
sqlText = "SELECT *, element_at(?, 1) FROM range(10) WHERE id > ?"
635642
df = self.connect.sql(sqlText, args=[CF.array(CF.lit(1)), 7])

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/parameters.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ object BindParameters extends ParameterizedQueryProcessor with QueryErrorsBase {
212212
args(posToIndex(pos))
213213
}
214214

215-
case _ => plan
215+
case other => other
216216
}
217217
}
218218
}

0 commit comments

Comments
 (0)