Skip to content

Commit 47e9d5a

Browse files
author
nayan3107
committed
refactor(mlops): Collapse AthenaStep query_config and arguments
Take a single query_config that is either an AthenaQueryConfig or a raw StartQueryExecution dict, so customers have one field to set. The docstring prefers AthenaQueryConfig and keeps the dict for fields it does not cover. --- X-AI-Prompt: Collapse query_config and arguments into one union param X-AI-Tool: kiro-cli
1 parent c0c42b5 commit 47e9d5a

2 files changed

Lines changed: 20 additions & 42 deletions

File tree

‎sagemaker-mlops/src/sagemaker/mlops/workflow/athena_step.py‎

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
),
3333
)
3434
35-
For ``StartQueryExecution`` fields that ``AthenaQueryConfig`` does not cover,
36-
pass the full request as a dict through ``arguments`` instead; it is emitted
37-
unchanged.
35+
Prefer ``AthenaQueryConfig``. For ``StartQueryExecution`` fields it does not
36+
cover, pass the full request as a dict to ``query_config`` instead; the dict
37+
is emitted unchanged.
3838
3939
The SageMaker Pipelines service validates the request at ``CreatePipeline``
4040
time, not this module:
@@ -178,23 +178,13 @@ def _drop_none(values: Dict[str, Any]) -> Dict[str, Any]:
178178
return {key: value for key, value in values.items() if value is not None}
179179

180180

181-
ERR_STR_WITH_BOTH_QUERY_CONFIG_AND_ARGUMENTS = (
182-
"AthenaStep {step_name} cannot have both query_config and arguments."
183-
)
184-
185-
ERR_STR_WITHOUT_QUERY_CONFIG_AND_ARGUMENTS = (
186-
"AthenaStep {step_name} must have either query_config or arguments."
187-
)
188-
189-
190181
class AthenaStep(ConfigurableRetryStep):
191182
"""Runs an Amazon Athena query as part of a SageMaker Pipeline."""
192183

193184
def __init__(
194185
self,
195186
name: str,
196-
query_config: Optional[AthenaQueryConfig] = None,
197-
arguments: Optional[Dict[str, Any]] = None,
187+
query_config: Union[AthenaQueryConfig, Dict[str, Any]],
198188
display_name: Optional[str] = None,
199189
description: Optional[str] = None,
200190
depends_on: Optional[List[Union[str, Step, StepCollection]]] = None,
@@ -203,14 +193,13 @@ def __init__(
203193
): # pylint: disable=too-many-positional-arguments
204194
"""Construct an ``AthenaStep``.
205195
206-
Exactly one of ``query_config`` and ``arguments`` must be given.
207-
208196
Args:
209197
name: The name of the step.
210-
query_config: The Athena query to run.
211-
arguments: The full Athena ``StartQueryExecution`` request as a dict
212-
(PascalCase keys), emitted unchanged. Use it for request fields
213-
that ``AthenaQueryConfig`` does not cover.
198+
query_config: The Athena query to run. Prefer an
199+
``AthenaQueryConfig``. Pass the full ``StartQueryExecution``
200+
request as a dict (PascalCase keys) only when you need a field
201+
``AthenaQueryConfig`` does not cover; the dict is emitted
202+
unchanged.
214203
display_name: Optional display name.
215204
description: Optional description.
216205
depends_on: Optional explicit step dependencies. Wrap an entry in
@@ -228,14 +217,12 @@ def __init__(
228217
retry_policies=retry_policies,
229218
)
230219

231-
if query_config is None and arguments is None:
232-
raise ValueError(ERR_STR_WITHOUT_QUERY_CONFIG_AND_ARGUMENTS.format(step_name=name))
233-
if query_config is not None and arguments is not None:
234-
raise ValueError(ERR_STR_WITH_BOTH_QUERY_CONFIG_AND_ARGUMENTS.format(step_name=name))
235-
236220
# Copy so caller-side mutations after construction do not leak into the
237221
# compiled pipeline definition.
238-
request = query_config.to_request() if query_config is not None else arguments
222+
if isinstance(query_config, AthenaQueryConfig):
223+
request = query_config.to_request()
224+
else:
225+
request = query_config
239226
self.args: Dict[str, Any] = copy.deepcopy(request)
240227
self.cache_config = cache_config
241228
self._properties = Properties(

‎sagemaker-mlops/tests/unit/workflow/test_athena_step.py‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,36 +115,27 @@ def test_step_with_query_config_emits_built_request():
115115
# ---------------------------------------------------------------------------
116116

117117

118-
def test_raw_arguments_passed_through_unchanged():
119-
arguments = {
118+
def test_raw_request_dict_passed_through_unchanged():
119+
request = {
120120
"QueryString": "SELECT 1",
121121
"EngineConfiguration": {"MaxConcurrentDpus": 4},
122122
}
123-
step = AthenaStep(name="RunQuery", arguments=arguments)
124-
assert step.arguments == arguments
123+
step = AthenaStep(name="RunQuery", query_config=request)
124+
assert step.arguments == request
125125

126126

127-
def test_requires_query_config_or_arguments():
128-
with pytest.raises(ValueError, match="must have either query_config or arguments"):
127+
def test_query_config_is_required():
128+
with pytest.raises(TypeError):
129129
AthenaStep(name="RunQuery")
130130

131131

132-
def test_rejects_both_query_config_and_arguments():
133-
with pytest.raises(ValueError, match="cannot have both query_config and arguments"):
134-
AthenaStep(
135-
name="RunQuery",
136-
query_config=AthenaQueryConfig(query_string="SELECT 1"),
137-
arguments={"QueryString": "SELECT 1"},
138-
)
139-
140-
141132
def test_caller_mutations_do_not_leak_into_step_state():
142133
arguments = {
143134
"QueryString": "SELECT 1",
144135
"ResultConfiguration": {"EncryptionConfiguration": {"EncryptionOption": "SSE_S3"}},
145136
"ExecutionParameters": ["1"],
146137
}
147-
step = AthenaStep(name="RunQuery", arguments=arguments)
138+
step = AthenaStep(name="RunQuery", query_config=arguments)
148139

149140
arguments["QueryString"] = "MUTATED"
150141
arguments["ResultConfiguration"]["EncryptionConfiguration"]["EncryptionOption"] = "MUTATED"

0 commit comments

Comments
 (0)