Skip to content

Commit ded2747

Browse files
authored
feat: Implement configurable debug_query_state parameter for AthenaCursor (#395)
1 parent fda4895 commit ded2747

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ A dbt profile can be configured to run against AWS Athena using the following co
8282
| schema | Specify the schema (Athena database) to build models into (lowercase **only**) | Required | `dbt` |
8383
| database | Specify the database (Data catalog) to build models into (lowercase **only**) | Required | `awsdatacatalog` |
8484
| poll_interval | Interval in seconds to use for polling the status of query results in Athena | Optional | `5` |
85+
| debug_query_state | Flag if debug message with Athena query state is needed | Optional | `false` |
8586
| aws_access_key_id | Access key ID of the user performing requests. | Optional | `AKIAIOSFODNN7EXAMPLE` |
8687
| aws_secret_access_key | Secret access key of the user performing requests | Optional | `wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY` |
8788
| aws_profile_name | Profile to use from your AWS shared credentials file. | Optional | `my-profile` |

dbt/adapters/athena/connections.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class AthenaCredentials(Credentials):
5454
aws_access_key_id: Optional[str] = None
5555
aws_secret_access_key: Optional[str] = None
5656
poll_interval: float = 1.0
57+
debug_query_state: bool = False
5758
_ALIASES = {"catalog": "database"}
5859
num_retries: Optional[int] = 5
5960
s3_data_dir: Optional[str] = None
@@ -81,7 +82,7 @@ def _connection_keys(self) -> Tuple[str, ...]:
8182
"endpoint_url",
8283
"s3_data_dir",
8384
"s3_data_naming",
84-
"lf_tags",
85+
"debug_query_state",
8586
)
8687

8788

@@ -122,7 +123,8 @@ def __poll(self, query_id: str) -> AthenaQueryExecution:
122123
]:
123124
return query_execution
124125
else:
125-
logger.debug(f"Query state is: {query_execution.state}. Sleeping for {self._poll_interval}...")
126+
if self.connection.cursor_kwargs.get("debug_query_state", False):
127+
logger.debug(f"Query state is: {query_execution.state}. Sleeping for {self._poll_interval}...")
126128
time.sleep(self._poll_interval)
127129

128130
def execute( # type: ignore
@@ -215,6 +217,7 @@ def open(cls, connection: Connection) -> Connection:
215217
schema_name=creds.schema,
216218
work_group=creds.work_group,
217219
cursor_class=AthenaCursor,
220+
cursor_kwargs={"debug_query_state": creds.debug_query_state},
218221
formatter=AthenaParameterFormatter(),
219222
poll_interval=creds.poll_interval,
220223
session=get_boto3_session(connection),

0 commit comments

Comments
 (0)