Skip to content

Commit 0efd6c2

Browse files
author
nayan3107
committed
test(mlops): Add AthenaStep integ test for raw request dict
--- X-AI-Prompt: Add an integ test for the raw dict path X-AI-Tool: kiro-cli
1 parent 47e9d5a commit 0efd6c2

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
Runs Athena queries end-to-end through SageMaker Pipelines and checks that:
1616
1717
* a valid query drives the execution to ``Succeeded`` and the result CSV is
18-
written to the configured S3 output location,
18+
written to the configured S3 output location, both when the query is built
19+
with ``AthenaQueryConfig`` and when it is passed as a raw request dict,
1920
* an invalid query drives the execution to ``Failed`` with a ``FailureReason``,
2021
* a full ``AthenaQueryConfig``, together with ``CacheConfig`` and
2122
``RetryPolicies``, is accepted by ``CreatePipeline`` and round-trips
@@ -133,6 +134,44 @@ def test_athena_step_query_succeeds_and_writes_result(sagemaker_session_for_pipe
133134
_cleanup(pipeline, execution, sagemaker_session_for_pipeline, bucket, key_prefix)
134135

135136

137+
def test_athena_step_raw_request_dict_succeeds(sagemaker_session_for_pipeline, role):
138+
"""A raw ``StartQueryExecution`` dict passed as ``query_config`` runs to ``Succeeded``."""
139+
pipeline_name = unique_name_from_base("athena-step-integ")
140+
bucket, key_prefix, output_location = _result_location(
141+
sagemaker_session_for_pipeline, pipeline_name
142+
)
143+
output_location_parameter = ParameterString(name=_OUTPUT_LOCATION_PARAMETER)
144+
145+
step = AthenaStep(
146+
name="AthenaRawQuery",
147+
query_config={
148+
"QueryString": "SELECT 1 AS test_result",
149+
"QueryExecutionContext": {"Database": "default"},
150+
"WorkGroup": "primary",
151+
"ResultConfiguration": {"OutputLocation": output_location_parameter},
152+
},
153+
)
154+
pipeline = Pipeline(
155+
name=pipeline_name,
156+
parameters=[output_location_parameter],
157+
steps=[step],
158+
sagemaker_session=sagemaker_session_for_pipeline,
159+
)
160+
161+
execution = None
162+
try:
163+
execution, status, athena_step = _create_and_execute(pipeline, role, output_location)
164+
assert status == "Succeeded", "Execution status was {}".format(status)
165+
assert athena_step["StepStatus"] == "Succeeded", athena_step.get("FailureReason")
166+
167+
query_execution_id = athena_step["Metadata"]["Athena"]["QueryExecutionId"]
168+
result_key = "{}/{}.csv".format(key_prefix, query_execution_id)
169+
result_files = sagemaker_session_for_pipeline.list_s3_files(bucket, key_prefix)
170+
assert result_key in result_files, "Athena result file not found: {}".format(result_files)
171+
finally:
172+
_cleanup(pipeline, execution, sagemaker_session_for_pipeline, bucket, key_prefix)
173+
174+
136175
def test_athena_step_invalid_query_fails(sagemaker_session_for_pipeline, role):
137176
"""An invalid SQL statement drives the step, and the execution, to ``Failed``."""
138177
pipeline_name = unique_name_from_base("athena-step-integ")

0 commit comments

Comments
 (0)