Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render sql code with parameters in BaseSQLDecoratedOperator #897

Merged
merged 7 commits into from
Feb 6, 2023

Conversation

feluelle
Copy link
Member

@feluelle feluelle commented Sep 23, 2022

Description

What is the current behavior?

Currently, when using operators inheriting from BaseSQLDecoratedOperator we are unable to view the rendered SQL in the UI.

closes: #1003
depends on: #1004

What is the new behavior?

  • add sql and parameters to BaseSQLDecoratedOperator template_fields
  • add .sql to BaseSQLDecoratedOperator template_ext
  • add check for template_fields and template_ext

Does this introduce a breaking change?

No.

Checklist

  • Created tests which fail without the change (if possible)
  • Extended the README / documentation, if necessary

@feluelle feluelle changed the title Use TransformOperator in transform_file and render sql code with parameters Add transform_sql operator and render sql code with parameters Sep 26, 2022
Copy link
Collaborator

@tatiana tatiana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@feluelle I think it could be confusing to end-users to have three methods for creating a table from a SQL statement:

  • transform
  • transform_file
  • transform_sql

I can see the need for having a decorator (transform) x a task, and I understand you didn't want to introduce any breaking changes, but it is confusing overall. What do you think of:

1, Adding a deprecation warning in transform_file
2. Name the new task transform_task (or something else) - so it is clear the difference in comparison to transform - and it could be used both to load from a file and a string?
3. Should we have some tests?

@feluelle
Copy link
Member Author

1, Adding a deprecation warning in transform_file
2. Name the new task transform_task (or something else) - so it is clear the difference in comparison to transform - and it could be used both to load from a file and a string?
3. Should we have some tests?

Yes, actually this makes more sense.

@feluelle feluelle changed the title Add transform_sql operator and render sql code with parameters Fix transform_file and render sql code with parameters Sep 30, 2022
@codecov
Copy link

codecov bot commented Sep 30, 2022

Codecov Report

Base: 92.57% // Head: 93.50% // Increases project coverage by +0.93% 🎉

Coverage data is based on head (03a1719) compared to base (49c08b9).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #897      +/-   ##
==========================================
+ Coverage   92.57%   93.50%   +0.93%     
==========================================
  Files          91       91              
  Lines        4810     4837      +27     
  Branches      476      480       +4     
==========================================
+ Hits         4453     4523      +70     
+ Misses        260      225      -35     
+ Partials       97       89       -8     
Impacted Files Coverage Δ
...thon-sdk/src/astro/sql/operators/base_decorator.py 95.65% <100.00%> (+0.87%) ⬆️
python-sdk/src/astro/sql/operators/load_file.py 95.14% <0.00%> (-1.95%) ⬇️
python-sdk/src/astro/databases/base.py 92.51% <0.00%> (+4.84%) ⬆️
python-sdk/src/astro/files/locations/amazon/s3.py 92.72% <0.00%> (+5.45%) ⬆️
python-sdk/src/astro/utils/table.py 100.00% <0.00%> (+5.71%) ⬆️
python-sdk/src/astro/databases/snowflake.py 92.24% <0.00%> (+8.33%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@feluelle feluelle force-pushed the feature/template-fields-sql branch 2 times, most recently from fc85f21 to cc19916 Compare October 12, 2022 08:16
@tatiana tatiana added this to the sql-cli/0.4.0 milestone Jan 24, 2023
@tatiana tatiana force-pushed the feature/template-fields-sql branch 8 times, most recently from 047f0c4 to 9f615d9 Compare February 3, 2023 13:18
feluelle and others added 5 commits February 6, 2023 14:08
- add sql and parameters to BaseSQLDecoratedOperator template_fields
- add .sql to BaseSQLDecoratedOperator template_ext
- add check for template_fields and template_ext
@tatiana
Copy link
Collaborator

tatiana commented Feb 6, 2023

I've worked on this PR independently and with @feluelle, and the tests are now passing.

I also validated that both aql. transform and aql.transform_file are rendering the SQL query in the UI:

Example of aql.transform_file:
Screenshot from 2023-02-06 14-01-15

Example of aql.transform:
Screenshot from 2023-02-06 14-06-17

Since it was long approved, I'm merging this PR as soon as the CI checks pass - before it completes its five months anniversary. We can continuously improve and iterate over it with time.

Co-authored-by: Felix Uellendall <feluelle@users.noreply.github.com>
@feluelle feluelle marked this pull request as ready for review February 6, 2023 14:15
@tatiana tatiana dismissed dimberman’s stale review February 6, 2023 15:17

This PR has been long standing and was approved a while ago, we can iterate and improve the implementation over time.

@tatiana tatiana merged commit 9a18c33 into main Feb 6, 2023
@tatiana tatiana deleted the feature/template-fields-sql branch February 6, 2023 15:22
@sunank200 sunank200 modified the milestones: sql-cli/0.4.0, 1.5.0 Feb 6, 2023
utkarsharma2 pushed a commit that referenced this pull request Feb 8, 2023
)

Allow users to view the SQL statements, regardless of whether they are part of the DAG definition or declared on a separate file, within the Airflow UI task "Rendered Template" field. 

This change affects `aql.transform`, `aql.transform_file` and `aql.dataframe`, since it is implemented on the `BaseSQLDecoratedOperator`.

The following changes were made:
- add sql and parameters to BaseSQLDecoratedOperator template_fields
- add .sql to BaseSQLDecoratedOperator template_ext
- add check for template_fields and template_ext

closes: #1003 
depends on: #1004 

Co-authored-by: Tatiana Al-Chueyr <tatiana.alchueyr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SQL is not being rendered in BaseSQLDecoratedOperator
5 participants