-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(bigquery): escape the schema (project ID) for BQ builtin UDFs
- Loading branch information
Showing
5 changed files
with
47 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
ibis/backends/bigquery/tests/unit/udf/snapshots/test_builtin/test_bqutil_fn_from_hex/out.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELECT | ||
`bqutil`.`fn`.from_hex('face') AS `from_hex_'face'` |
2 changes: 2 additions & 0 deletions
2
ibis/backends/bigquery/tests/unit/udf/snapshots/test_builtin/test_farm_fingerprint/out.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELECT | ||
farm_fingerprint(b'Hello, World!') AS `farm_fingerprint_b'Hello_ World_'` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
import ibis | ||
|
||
to_sql = ibis.bigquery.compile | ||
|
||
|
||
@ibis.udf.scalar.builtin | ||
def farm_fingerprint(value: bytes) -> int: | ||
... | ||
|
||
|
||
@ibis.udf.scalar.builtin(schema="bqutil.fn") | ||
def from_hex(value: str) -> int: | ||
"""Community function to convert from hex string to integer. | ||
See: | ||
https://github.com/GoogleCloudPlatform/bigquery-utils/tree/master/udfs/community#from_hexvalue-string | ||
""" | ||
|
||
|
||
def test_bqutil_fn_from_hex(snapshot): | ||
# Project ID should be enclosed in backticks. | ||
expr = from_hex("face") | ||
snapshot.assert_match(to_sql(expr), "out.sql") | ||
|
||
|
||
def test_farm_fingerprint(snapshot): | ||
# No backticks needed if there is no schema defined. | ||
expr = farm_fingerprint(b"Hello, World!") | ||
snapshot.assert_match(to_sql(expr), "out.sql") |