HyukjinKwon opened a new pull request, #389: URL: https://github.com/apache/spark-connect-rust/pull/389
### What changes were proposed in this pull request? [SPARK-61203](https://issues.apache.org/jira/browse/SPARK-61203): Make `pyspark.sql.functions` an attribute of `pyspark.sql` once `pyspark.sql` is imported, as PySpark does. - `python/pyspark/sql/__init__.py` imports the `functions` submodule with the other submodules that it already imports (`conf`, `geo_utils`, `profiler`, ...). After `import pyspark.sql`, `pyspark.sql.functions` is an attribute, and `import pyspark; pyspark.sql.functions` works too. - Official PySpark 4.3.0 has the same attribute, because its session, dataframe and column modules import the functions package at module level. The sorted set of names of `dir(pyspark.sql)` after `import pyspark.sql` is equal to PySpark's: `functions` was the only name missing. - The import cost does not grow. `python -X importtime -c "import pyspark.sql"` took 145-199 ms cumulative over five runs with the change and 188-238 ms without it; the machine was loaded, so the runs are noisy, and the change adds no measurable time. ### Why are the changes needed? `import pyspark.sql` followed by `pyspark.sql.functions.col("a")` raised `AttributeError: module 'pyspark.sql' has no attribute 'functions'` in the drop-in, until some code imported `pyspark.sql.functions` explicitly. Code that uses the attribute, as it does with PySpark, failed. ### Does this PR introduce _any_ user-facing change? Yes. `pyspark.sql.functions` is an attribute of `pyspark.sql` after `import pyspark.sql`, as in PySpark. ### How was this patch tested? - An offline test `test_sql_functions_is_an_attribute_once_pyspark_sql_is_imported` runs in a new process, which checks `"functions" in dir(pyspark.sql)`, `pyspark.sql.functions.__name__`, and that `col("a")` gives `Column<'a'>`. It fails without this change (AttributeError) and passes with it. Official PySpark 4.3.0 gives the same results for the same script. - The sorted `dir(pyspark.sql)` after `import pyspark.sql` was compared with official PySpark 4.3.0: the two lists are equal. - The lib tests of both crates (618 passed), the build of all tests, also with `wasm-udf`, and the offline Python suites (2457 passed, 8 skipped); rustfmt passes, and clippy reports no diagnostics in the changed lines. CI runs the e2e and live suites. ### 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. -- 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]
