spark-test commented on code in PR #59980:
URL: https://github.com/apache/spark/pull/59980#discussion_r4576319374
##########
python/pyspark/sql/tests/test_udf_transpile_unit.py:
##########
@@ -179,6 +180,73 @@ def plus_four(x):
"when both transpilePyUDFs and ANSI mode are enabled",
)
+ def test_get_transpilers_reports_unknown_names(self):
+ for names, expected, unknown in [
+ ("catalyst", [CatalystTranspiler], []),
+ ("catalyst,catalist", [CatalystTranspiler], ["catalist"]),
+ ("catalist", [], ["catalist"]),
+ ("catalyst,", [CatalystTranspiler], []),
+ ("catalyst,,catalyst", [CatalystTranspiler, CatalystTranspiler],
[]),
+ ("catalyst, ", [CatalystTranspiler], []),
+ (" catalyst", [], [" catalyst"]),
+ ]:
+ with self.subTest(names=names):
+ with
self.sql_conf({"spark.sql.experimental.optimizer.pyTranspilers": names}):
+ transpilers, unknown_names = _get_transpilers(self.spark)
+ self.assertEqual([type(t) for t in transpilers], expected)
+ self.assertEqual(unknown_names, unknown)
+
+ def test_udf_transpile_warns_on_unknown_names(self):
+ import warnings
+
+ from pyspark.sql.transpile import AbstractTranspiler
+
+ def plus_one(x):
+ return x + 1
+
+ expected = (
+ "Ignoring unknown transpilers ['catalist'] in "
+ "spark.sql.experimental.optimizer.pyTranspilers; registered
transpilers are "
+ f"{sorted(AbstractTranspiler.varieties)}"
+ )
+ with self.sql_conf(
+ dict(
+ _TRANSPILE_ON,
+ **{"spark.sql.experimental.optimizer.pyTranspilers":
"catalyst,catalist"},
Review Comment:
**Nit (P3):** This mixed value is the only one with an unregistered entry
for which this test defines a UDF, and `catalyst` still lowers `plus_one` with
it, so the generic fallback warning never fires here. The case the PR
description names, a typo that turns transpilation off (for example
`pyTranspilers="catalist"`), is checked only through the list
`_get_transpilers` returns, in `test_get_transpilers_reports_unknown_names`.
For that value the constructor first warns `Unable to transpile UDF ...` and
only then issues the unknown-name warning, and nothing asserts the second one.
As the tests stand, a later change that issued the warning only when
`self.transpiled` is non-empty, or that made `_transpile_func` return no
unregistered names when it selects no transpiler, would make that case silent
again and still pass every assertion. The PR's first commit asserted the
warning for `"catalist"`; that check was lost when the warning moved into the
constructor. The code is correct today. Adding a `"catalist"` case to this
test, checked at UDF definition, would close the gap.
**Verification:**
- **Regression:** With transpilation and ANSI enabled and every
pyTranspilers entry unregistered, defining a lowerable UDF under default
warning filters yields no lowered options and records the generic fallback
warning followed by exactly one unknown-name warning naming those entries and
the registered transpilers. The check fails if the warning is emitted only when
some transpiler lowers the UDF, or if transpilation stops passing the
unregistered names out when no transpiler is selected.
- **Behavior:** With every pyTranspilers entry unregistered, a warnings
filter that escalates only the unknown-name message makes UDF definition raise
that UserWarning with the expected text.
--
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]