Add initial legacy Presto/Athena compatibility udfs (#316)
* Add initial legacy Presto/Athena compatibility udfs * fixup! Add initial legacy Presto/Athena compatibility udfs
This commit is contained in:
Родитель
c5b33ee739
Коммит
525b9f05af
|
@ -53,6 +53,8 @@ Recommended practices
|
|||
- Each file must define a single function using `CREATE TEMP FUNCTION` syntax
|
||||
- SQL UDFs must be defined in the `udf/` directory and JS UDFs must be defined
|
||||
in the `udf_js` directory
|
||||
- The `udf_legacy/` directory is an exception which should only contain
|
||||
compatibility functions for queries migrated from Athena/Presto.
|
||||
- The function must be named as `<dir_name>_<file_name_without_suffix>`
|
||||
so `udf/mode_last.sql` must define a function `udf_mode_last`
|
||||
- Must be defined as temporary UDFs
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Legacy UDFs
|
||||
===
|
||||
|
||||
This directory contains compatibility functions for query migrations from Athena/Presto, and is named `udf_legacy` to discourage their ongoing use.
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
|
||||
Returns true if the array arr contains the element el
|
||||
|
||||
*/
|
||||
CREATE TEMP FUNCTION
|
||||
udf_legacy_contains(arr ANY TYPE, el ANY TYPE)
|
||||
RETURNS BOOLEAN
|
||||
AS (
|
||||
el IN UNNEST(arr)
|
||||
);
|
||||
|
||||
-- Tests
|
||||
|
||||
assert_true(udf_legacy_contains([1, 2, 3], 1)),
|
||||
asset_false(udf_legacy_contains([1, 2, 3], 5))
|
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
|
||||
Shim for Presto/Athena's DATE_FORMAT to BigQuery's FORMAT_DATE
|
||||
|
||||
Note that the format strings for FORMAT_DATE vs DATE_FORMAT are not
|
||||
identical, but usages found in existing scheduled queries had format
|
||||
strings that were portable between the two
|
||||
|
||||
*/
|
||||
CREATE TEMP FUNCTION
|
||||
udf_legacy_date_format(d DATE, f STRING)
|
||||
RETURNS STRING
|
||||
AS (
|
||||
FORMAT_DATE(f, d)
|
||||
);
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
|
||||
Takes in a DATE type and returns a `YYYY-MM-DD` formatted string. This
|
||||
function does _not_ attempt to replicate the entirety of the
|
||||
functionality of Presto/Athena's `to_iso8601()` (which takes in a DATE,
|
||||
DATETIME or TIMESTAMP type and returns either an iso8601-formatted date
|
||||
string or a date-time string depending on the input type) since all use
|
||||
cases found in legacy scheduled queries were for the DATE case.
|
||||
|
||||
*/
|
||||
CREATE TEMP FUNCTION
|
||||
udf_legacy_to_iso8601(x DATE)
|
||||
RETURNS STRING
|
||||
AS (
|
||||
FORMAT_DATE('%F', x)
|
||||
);
|
Загрузка…
Ссылка в новой задаче