Skip to content

Commit

Permalink
Feature/add substitution condition (#43)
Browse files Browse the repository at this point in the history
* add condition for sql formatting to fix error when no substitution togetehr with sql containing curly brackets was given.

* edit changelog and contributors
  • Loading branch information
Depaccu committed Sep 19, 2023
1 parent 1d01825 commit 381254d
Show file tree
Hide file tree
Showing 5 changed files with 367 additions and 324 deletions.
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

0 comments on commit 381254d

Please sign in to comment.