Skip to content

[SPARK-57065][PYTHON][TESTS] Add with_sql_conf decorator in SQLTestUtils#56106

Open
zhengruifeng wants to merge 6 commits into
apache:masterfrom
zhengruifeng:with-class-conf-decorator
Open

[SPARK-57065][PYTHON][TESTS] Add with_sql_conf decorator in SQLTestUtils#56106
zhengruifeng wants to merge 6 commits into
apache:masterfrom
zhengruifeng:with-class-conf-decorator

Conversation

@zhengruifeng
Copy link
Copy Markdown
Contributor

@zhengruifeng zhengruifeng commented May 26, 2026

What changes were proposed in this pull request?

Adds with_sql_conf({K: V, ...}) as a class decorator in
pyspark.testing.sqlutils that wraps setUpClass / tearDownClass
to apply and revert Spark confs around the inherited fixtures.
Migrates three parity files as proof of usage:

  • test_parity_column.py (2 classes)
  • test_parity_udf_combinations.py (1 class — also makes the
    previously asymmetric set-without-unset pair symmetric)
  • test_parity_arrow_python_udf.py (5 classes)

Usage:

from pyspark.testing.sqlutils import with_sql_conf

@with_sql_conf({"spark.sql.execution.pythonUDF.arrow.enabled": "true"})
class MyParityTests(SomeMixin, ReusedConnectTestCase):
    pass

Why are the changes needed?

Many parity tests override setUpClass / tearDownClass solely to
set one or two Spark confs and unset them on teardown. Each such
override is ~10 lines of identical-shape boilerplate, and the
hand-written set / unset pairs are easy to drift apart (one such
asymmetric pair is fixed by this PR). Consolidating to a single
declarative decorator removes the duplication and provides a common
seam for migrating the remaining callsites in a follow-up.

Does this PR introduce any user-facing change?

No — test infrastructure only.

How was this patch tested?

  • WithSqlConfTests in python/pyspark/sql/tests/test_utils.py
    exercises the decorator end-to-end against ReusedSQLTestCase,
    asserting both decorator-set keys land via
    self.spark.conf.get(...).
  • WithSqlConfParityTests in
    python/pyspark/sql/tests/connect/test_parity_utils.py is the
    Connect counterpart, exercising the decorator against
    ReusedConnectTestCase.
  • All three migrated parity files were run locally against a real
    session; in particular ColumnParityTests.test_df_col_resolution_mode
    and its WithNonStrictDFColResolution subclass read the
    decorator-set conf back through self.spark.conf.get(...) and pass,
    confirming the decorator composes through layered subclassing.

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

Generated-by: Claude Code (model: claude-opus-4-7)

…lass duplication in parity tests

Many parity tests override setUpClass/tearDownClass solely to set a Spark
conf and unset it on teardown. This adds a `with_class_conf({K: V, ...})`
class decorator in `pyspark.testing.sqlutils` that wraps the inherited
setUpClass/tearDownClass to apply and revert the confs.

Migrates three callsites as proof:
- test_parity_column.py (2 classes)
- test_parity_udf_combinations.py (1 class; also makes the previously
  asymmetric set-without-unset pair symmetric)
- test_parity_arrow_python_udf.py (5 classes)

Adds `WithClassConfTests` in test_utils.py to verify the decorator
applies the configured confs to the active SparkSession.
…ame to with_sql_conf

Promotes the decorator to a static method of SQLTestUtils so it lives
alongside the existing sql_conf context manager. Updates all callers
and the test class accordingly.

No behavior change.
… callsites

Replaces `@SQLTestUtils.with_sql_conf(...)` with a local rebind
`with_sql_conf = SQLTestUtils.with_sql_conf` per file, then
`@with_sql_conf(...)` for the decorator. Keeps the decorator definition
inside SQLTestUtils while making callsites read more like a regular
imported helper.
…sqlutils

Adds `with_sql_conf = SQLTestUtils.with_sql_conf` at module scope in
pyspark.testing.sqlutils, so callsites can simply do
`from pyspark.testing.sqlutils import with_sql_conf` instead of rebinding
the static method locally. The decorator definition still lives on
SQLTestUtils.
…Tests

Mirrors WithSqlConfTests as WithSqlConfParityTests in test_parity_utils.py,
extending ReusedConnectTestCase, so the decorator's behavior is regression-
tested against both classic and Connect sessions.
…le scope

Defines with_sql_conf as a plain module-level function in sqlutils.py
instead of a static method on SQLTestUtils with a module-level alias.
Callsites already import it via `from pyspark.testing.sqlutils import
with_sql_conf` so no other changes are needed.
@zhengruifeng zhengruifeng changed the title [MINOR][PYTHON][TESTS] Add with_sql_conf decorator in SQLTestUtils [SPARK-57065][PYTHON][TESTS] Add with_sql_conf decorator in SQLTestUtils May 26, 2026
@zhengruifeng zhengruifeng marked this pull request as ready for review May 26, 2026 06:35
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