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

Feature/add substitution condition #43

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Development
***********

0.3.2 (2023-09-19)
******************

- Add condition for string substitution so that empty substitutions together with sqls,
that contain curly brackets won't fail

0.3.1 (2023-08-15)
******************

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ This is a list of the people who directly contributed to bquest in one way or an
* `Nils Weisbach <https://github.com/ncwhh>`_
* `Julian Werner <https://github.com/scieneers-jw>`_
* `Jia-Jen Yang <https://github.com/jiajentw>`_
* `Jeffrey Ungelenk <https://github.com/Depaccu>`_

Special thanks goes to `Mike Czech <https://github.com/mikeczech>`_ who initiated the development of bquest!
6 changes: 4 additions & 2 deletions bquest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ def run(
sql: SQL query that is being executed in BigQuery
source_table_definitions: source table definitions, list of BQTableDefinition
substitutions: substitutions for the given query
Can't use substitutions together with sql that contains curly brackets, for example sql with regexs.
This leads to error when trying to substitute the regex which shouldn't be substituted.
string_replacements: entire string replacements for the query, substitutions are placed before
result_table_definition: result table definition

Expand All @@ -219,8 +221,8 @@ def run(
if result_table_definition
else self._create_empty_result_table("result")
)

sql_with_substitutions = sql.format(**substitutions)
if substitutions:
sql_with_substitutions = sql.format(**substitutions)
for key, value in string_replacements.items():
sql_with_substitutions = sql_with_substitutions.replace(key, value)

Expand Down
Loading