|
15 | 15 | Runs Athena queries end-to-end through SageMaker Pipelines and checks that: |
16 | 16 |
|
17 | 17 | * 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, |
19 | 20 | * an invalid query drives the execution to ``Failed`` with a ``FailureReason``, |
20 | 21 | * a full ``AthenaQueryConfig``, together with ``CacheConfig`` and |
21 | 22 | ``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 |
133 | 134 | _cleanup(pipeline, execution, sagemaker_session_for_pipeline, bucket, key_prefix) |
134 | 135 |
|
135 | 136 |
|
| 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 | + |
136 | 175 | def test_athena_step_invalid_query_fails(sagemaker_session_for_pipeline, role): |
137 | 176 | """An invalid SQL statement drives the step, and the execution, to ``Failed``.""" |
138 | 177 | pipeline_name = unique_name_from_base("athena-step-integ") |
|
0 commit comments