Skip to content

log_query of AthenaOperator dumps un readable query #34189

Closed

Description

@eladkal

Body

Log:
Screenshot 2023-09-07 at 22 18 41

Compare to render tab:
Screenshot 2023-09-07 at 22 19 50

Reproduce steps:

set file.sql as:

CREATE EXTERNAL TABLE IF NOT EXISTS `outputs3`(
  `region` string,
  ....
)

set operator as:

AthenaOperator(
    task_id="my_task",
    query="file.sql",
    database="my_db",
    log_query=True,
    output_location="s3://...",
)

The needed fix:
Pretty print the query. It should appear exactly like it is in the .sql file.

Committer

  • I acknowledge that I am a maintainer/committer of the Apache Airflow project.

Activity

  1. mingdaoy commented on Sep 9, 2023

    @mingdaoy
    Contributor

    @eladkal Can I take ownership of this issue? I wanna learn and be curious

  2. eladkal commented on Sep 9, 2023

    @eladkal
    ContributorAuthor

    Assigned to you @mingdaoy

  3. mingdaoy commented on Sep 12, 2023

    @mingdaoy
    Contributor

    My initial investigation would be format the params with sqlparse and I need to figure out how to use Athena within Airflow to verify the result. Am I on the right track?

    self.log.info("Running Query with params: %s", params)
    https://github.com/apache/airflow/blob/main/airflow/providers/amazon/aws/hooks/athena.py#L118C60-L118C60

    sqlparse.format(query, reindent=True, keyword_case='upper')

  4. eladkal commented on Sep 12, 2023

    @eladkal
    ContributorAuthor

    use Athena within Airflow to verify the result.

    You can setup aws connection with Athena table to test it
    I think AWS offers free trail account if you don't have one? cc @shubham22

  5. eladkal commented on Sep 12, 2023

    @eladkal
    ContributorAuthor

    By the way the log_query is useful also for other cases. So we can also add it in BaseSQLOperator then you can test it with almost any databasse using SQLExecuteQueryOperator. Since this is just parsing strings I think it's safe to say that if it works for SQLExecuteQueryOperator it will work also for Athena.
    Then open PR for Athena and PR for common.sql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions