Skip to content

Commit 7d81013

Browse files
remove caching for qmark
1 parent 85e7a48 commit 7d81013

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

awswrangler/athena/_cache.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,11 @@ def _parse_select_query_from_possible_ctas(possible_ctas: str) -> str | None:
110110
return None
111111

112112

113-
def _compare_query_string(
114-
sql: str, other: str, sql_params: list[str] | None = None, other_params: list[str] | None = None
115-
) -> bool:
113+
def _compare_query_string(sql: str, other: str) -> bool:
116114
comparison_query = _prepare_query_string_for_comparison(query_string=other)
117115
_logger.debug("sql: %s", sql)
118116
_logger.debug("comparison_query: %s", comparison_query)
119-
return sql == comparison_query and sql_params == other_params
117+
return sql == comparison_query
120118

121119

122120
def _prepare_query_string_for_comparison(query_string: str) -> str:
@@ -167,7 +165,6 @@ def _check_for_cached_results(
167165
sql: str,
168166
boto3_session: boto3.Session | None,
169167
workgroup: str | None,
170-
params: list[str] | None = None,
171168
athena_cache_settings: typing.AthenaCacheSettings | None = None,
172169
) -> _CacheInfo:
173170
"""
@@ -207,25 +204,15 @@ def _check_for_cached_results(
207204
if statement_type == "DDL" and query_info["Query"].startswith("CREATE TABLE"):
208205
parsed_query: str | None = _parse_select_query_from_possible_ctas(possible_ctas=query_info["Query"])
209206
if parsed_query is not None:
210-
if _compare_query_string(
211-
sql=comparable_sql,
212-
other=parsed_query,
213-
sql_params=params,
214-
other_params=query_info.get("ExecutionParameters"),
215-
):
207+
if _compare_query_string(sql=comparable_sql, other=parsed_query):
216208
return _CacheInfo(
217209
has_valid_cache=True,
218210
file_format="parquet",
219211
query_execution_id=query_execution_id,
220212
query_execution_payload=query_info,
221213
)
222214
elif statement_type == "DML" and not query_info["Query"].startswith("INSERT"):
223-
if _compare_query_string(
224-
sql=comparable_sql,
225-
other=query_info["Query"],
226-
sql_params=params,
227-
other_params=query_info.get("ExecutionParameters"),
228-
):
215+
if _compare_query_string(sql=comparable_sql, other=query_info["Query"]):
229216
return _CacheInfo(
230217
has_valid_cache=True,
231218
file_format="csv",

awswrangler/athena/_read.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,10 +1045,12 @@ def read_sql_query(
10451045
# Substitute query parameters if applicable
10461046
sql, execution_params = _apply_formatter(sql, params, paramstyle)
10471047

1048-
if not client_request_token:
1048+
if not client_request_token and paramstyle != "qmark":
1049+
# For paramstyle=="qmark", we will need to use Athena's caching option.
1050+
# The issue is that when describing an Athena execution, the API does not return
1051+
# the parameters that were used.
10491052
cache_info: _CacheInfo = _check_for_cached_results(
10501053
sql=sql,
1051-
params=params if paramstyle == "qmark" else None,
10521054
boto3_session=boto3_session,
10531055
workgroup=workgroup,
10541056
athena_cache_settings=athena_cache_settings,

tests/unit/test_athena.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ def test_athena_paramstyle_qmark_parameters(
469469
pytest.param(False, True, id="unload"),
470470
],
471471
)
472-
def test_athena_paramstyle_qmark_with_caching(
472+
def test_athena_paramstyle_qmark_skip_caching(
473473
path: str,
474474
path2: str,
475475
glue_database: str,

0 commit comments

Comments
 (0)