Repository navigation
BREAKING: Reject ineffective Spark arguments and unify environment fallbacks #1108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6d0f515
7e48f1d
86f4443
169c8a0
6e91496
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -211,6 +211,7 @@ def __init__( | |
| Args: | ||
| s3_staging_dir: S3 location to store query results. Required if not | ||
| using workgroups or if workgroup doesn't have result location. | ||
| None uses the ``AWS_ATHENA_S3_STAGING_DIR`` environment variable. | ||
| Pass an empty string to explicitly disable S3 staging and skip | ||
| the ``AWS_ATHENA_S3_STAGING_DIR`` environment variable fallback. | ||
| This is required when connecting to a workgroup with managed | ||
|
|
@@ -220,6 +221,9 @@ def __init__( | |
| catalog_name: Data catalog name. Defaults to "awsdatacatalog". | ||
| work_group: Athena workgroup name. Can substitute for s3_staging_dir | ||
| if workgroup has result location configured. | ||
| None uses the ``AWS_ATHENA_WORK_GROUP`` environment variable. | ||
| Pass an empty string to skip that environment variable fallback | ||
| and leave the workgroup unset. | ||
| poll_interval: Seconds between query status polls. Defaults to 1.0. | ||
| encryption_option: S3 encryption for results ("SSE_S3", "SSE_KMS", "CSE_KMS"). | ||
| kms_key: KMS key ID when using SSE_KMS or CSE_KMS encryption. | ||
|
|
@@ -260,7 +264,8 @@ def __init__( | |
| Note: | ||
| Either s3_staging_dir or work_group must be specified. Environment | ||
| variables AWS_ATHENA_S3_STAGING_DIR and AWS_ATHENA_WORK_GROUP are | ||
| checked if parameters are not provided. | ||
| checked only when the corresponding argument is omitted or None. | ||
| An explicit empty string disables that fallback and becomes None. | ||
|
|
||
| When using a workgroup with managed query result storage, pass | ||
| ``s3_staging_dir=""`` to prevent the environment variable fallback | ||
|
|
@@ -282,8 +287,8 @@ def __init__( | |
| self.region_name = region_name | ||
| self.schema_name = schema_name | ||
| self.catalog_name = catalog_name | ||
| if work_group: | ||
| self.work_group: str | None = work_group | ||
| if work_group is not None: | ||
| self.work_group: str | None = work_group or None | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Self-review round two (claims, compatibility, and operational behavior): CLEAN. Frozen diff: 971dd12..6af17de. Audited the PR body, commit claim, all changed docstrings, both migration documents, and regression evidence across the full 10-file inventory. Verified prior silent Spark behavior against the base revision, rejection through **kwargs including work_group=None, the guard's ordering before existing state/reset and submission paths, retained None/positional calls and supported options, and the unchanged successful return/cancellation contracts. Traced connect(), aio_connect(), AioConnection.create()/inheritance, Connection.cursor(), Spark session WorkGroup selection, and SQL request construction. Confirmed that explicit empty connection settings disable environment fallback, both disabled settings raise before session construction, and s3_staging_dir='' still supports managed query result storage. Checked migration instructions against callers and searched related docs for obsolete claims. Documentation builds passed; migration sections render, and warning messages also appear in the unchanged master build. Checked that the core-file workflow filters select Spark/PyAthena plus synchronous and asynchronous SQLAlchemy suites after Ready. Local validation is explicitly offline and has not been described as AWS proof. No actionable findings or repairs; current-head AWS CI remains the final delivery gate. |
||
| else: | ||
| self.work_group = os.getenv(self._ENV_WORK_GROUP) | ||
| self.poll_interval = poll_interval | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ | |
| import logging | ||
| from typing import Any, cast | ||
|
|
||
| from pyathena import OperationalError, ProgrammingError | ||
| from pyathena import NotSupportedError, OperationalError, ProgrammingError | ||
| from pyathena.model import AthenaCalculationExecution, AthenaCalculationExecutionStatus | ||
| from pyathena.spark.common import SparkBaseCursor, WithCalculationExecution | ||
| from pyathena.util import override | ||
|
|
@@ -108,10 +108,29 @@ def execute( | |
| session_id: str | None = None, | ||
| description: str | None = None, | ||
| client_request_token: str | None = None, | ||
| work_group: str | None = None, | ||
| **kwargs, | ||
| ) -> SparkCursor: | ||
| """Execute PySpark code and wait for the calculation to complete. | ||
|
|
||
| Args: | ||
| operation: PySpark code to execute. | ||
| parameters: Must be None; Spark calculations do not support parameters. | ||
| session_id: Spark session ID override. | ||
| description: Calculation description. | ||
| client_request_token: Idempotency token. | ||
| **kwargs: Unknown keyword arguments raise TypeError. | ||
|
|
||
| Returns: | ||
| Self reference for method chaining. | ||
|
|
||
| Raises: | ||
| TypeError: If an unknown keyword argument is given. | ||
| NotSupportedError: If ``parameters`` is not None. | ||
| OperationalError: If the calculation does not complete successfully. | ||
| """ | ||
| self._validate_execute_kwargs(kwargs) | ||
| if parameters is not None: | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independent review (relayed)
Reviewer output:
Author disposition: I accept the result. The coverage gaps it notes are not actionable:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independent follow-up (relayed): Codex CLI 0.161.0,
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independent follow-ups (relayed): Codex CLI 0.161.0,
|
||
| raise NotSupportedError("Spark cursors do not support parameters.") | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Self-review round one (implementation behavior) — base This review covers the branch after it was rebased onto master, which now includes #1102. Covered:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rebase follow-up, self-review round one — new base I compared Checks run at the new head:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Repair follow-up, self-review round one: The Spark The independent follow-up found that the Validation:
|
||
| # A failure below must not leave the previous calculation on the cursor. | ||
| self._calculation_id = None | ||
| self._calculation_execution = None | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self-review round two (claims and callers) — base
dafee9a4264ae2bb765cc7c5e1e3ef842bd6cfb8, head6d39f1489b9f0f2fae568858c8468f508845fc07. Result: CLEAN.Checked against the code:
Nonereads the environment variable,""becomesNone, and a nonempty string is used as given.ProgrammingErrorraised when neither setting resolves.connect(),aio_connect(),Connection, andAioConnection.s3_staging_dir=""behaves as before.docs/spark.md:NotSupportedErrorfor any non-Noneparameters,TypeErrorforwork_groupeven when it isNone, and calculations running in the session selected by the cursor or by thesession_idoverride.Every Spark example in the docs sets
work_groupon the connection; none passes it toexecute().work_grouppassed when creating a cursor reachesStartSessionthroughBaseCursor._work_group.Local evidence at this head:
just lintandjust docs lintpassed.uv run --env-file .env pytest --noconftest -p no:rerunfailures -q tests/pyathena/test_connection.py tests/pyathena/aio/test_connection.py tests/pyathena/spark/test_common.py: 319 passed, offline.I did not run Spark AWS integration tests locally; they are left to the AWS CI run after Ready.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebase follow-up, self-review round two — head
86f4443c6f3f742d250cf4a044a09c0056e05e0c. Result: CLEAN. The claims are unchanged. Readingdocs/usage.mdin order, the migration sections for keyword arguments, worker settings, and environment fallbacks each stand on their own, and nothing in #1103 contradicts the fallback or Spark statements.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Repair follow-up, self-review round two: head
6e9149616721c2b4e7a6ba356ab2b4ce5cb10108. Result: CLEAN. The implementation and docs are unchanged. I updated the PR description's TEST section with the new test locations and commands, and its counts match the runs above.