Skip to content

[SPARK-61161][CONNECT][PYTHON] Export the deprecated functions of pyspark.sql.connect.functions, such as countDistinct and bitwiseNOT, as PySpark does - #349

Closed
HyukjinKwon wants to merge 1 commit into
apache:masterfrom
HyukjinKwon:SPARK-61161-connect-functions-exports
Closed

HyukjinKwon wants to merge 1 commit into
apache:masterfrom
HyukjinKwon:SPARK-61161-connect-functions-exports

Conversation

@HyukjinKwon

Copy link
Copy Markdown
Member

What changes were proposed in this pull request?

SPARK-61161: Export the deprecated functions of pyspark.sql.connect.functions, such as countDistinct and bitwiseNOT, as PySpark does.

  • pyspark/sql/connect/functions/__init__.py star-imports pyspark.sql.connect.functions.builtin instead of pyspark.sql.functions, as PySpark's package does. The builtin module has no __all__, so its public names are exported.
  • pyspark/sql/connect/functions/builtin.py exposes py_random, the random module imported as in PySpark's builtin module.
  • pyspark.sql.functions itself is unchanged.

The public functions of PySpark's pyspark.sql.connect.functions that were missing are countDistinct, sumDistinct, approxCountDistinct, chr, toDegrees, toRadians, shiftLeft, shiftRight, shiftRightUnsigned, bitwiseNOT, random, uuid and py_random. The Connect tests use them through the CF alias. After the change, the public names of the package match PySpark 4.3.0's, apart from the expression classes and modules that PySpark's builtin module imports, which are internal.

Why are the changes needed?

from pyspark.sql.connect.functions import countDistinct
# ImportError: cannot import name 'countDistinct' from 'pyspark.sql.connect.functions'

PySpark 4.3.0 imports these names from the same package.

Does this PR introduce any user-facing change?

Yes. pyspark.sql.connect.functions exposes the 13 functions above (and py_random), as PySpark does.

How was this patch tested?

  • Offline test_connect_functions_package_exports_the_deprecated_functions_as_pyspark: each of the 12 functions of the package is the one of the builtin module, py_random is the random module, and bitwiseNOT builds a column. The same results with official PySpark 4.3.0.
  • The lib tests of both crates (590 passed), the build of all tests, also with wasm-udf, and the offline Python suites (2202 passed, 8 skipped), and the live tests of functions and columns (45 passed) against a local Spark 4.3.0 server; rustfmt passes.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Opus 5.5

This pull request and its description were written by Isaac.

…park.sql.connect.functions, such as countDistinct and bitwiseNOT, as PySpark does

pyspark.sql.connect.functions star-imported pyspark.sql.functions, whose __all__ does not list
countDistinct, sumDistinct, approxCountDistinct, chr, toDegrees, toRadians, shiftLeft,
shiftRight, shiftRightUnsigned, bitwiseNOT, random, uuid or py_random. PySpark's package
star-imports its builtin module, which has no __all__. The package now star-imports the builtin
module too, and the builtin module exposes py_random, as PySpark's does.

Co-authored-by: Isaac <no-reply@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant