Skip to content
Open
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: 5 additions & 1 deletion udfs/community/cw_csvld.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ config { hasOutput: true }

CREATE OR REPLACE FUNCTION ${self()}(text string, comma string, quote string,len INT64)
RETURNS array<string>
LANGUAGE js AS """
LANGUAGE js
OPTIONS (
description="Determine if value exists in json (a string containing a JSON array)."
)
AS """

var ret = []
var index = 0;
Expand Down
6 changes: 5 additions & 1 deletion udfs/community/cw_error_number.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ config { hasOutput: true }
/* TODO: Convert BQ generated error string to a number appropriate for other DBs */
CREATE OR REPLACE FUNCTION ${self()}( errmsg string)
RETURNS int64
LANGUAGE js AS """
LANGUAGE js
OPTIONS (
description="Convert BQ generated error string to a number appropriate for other DBs"
)
AS """
if ( ! errmsg )
return 0;
return 1;
Expand Down
6 changes: 5 additions & 1 deletion udfs/community/cw_error_severity.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ config { hasOutput: true }
/* TODO: Convert BQ generated error string to a number appropriate for other DBs */
CREATE OR REPLACE FUNCTION ${self()}( errmsg string)
RETURNS int64
LANGUAGE js AS """
LANGUAGE js
OPTIONS (
description="Convert BQ generated error string to a number appropriate for other DBs"
)
AS """
if ( ! errmsg )
return 0;
return 1;
Expand Down
6 changes: 5 additions & 1 deletion udfs/community/cw_error_state.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ config { hasOutput: true }
/* TODO: Convert BQ generated error string to a number appropriate for other DBs */
CREATE OR REPLACE FUNCTION ${self()}( errmsg string)
RETURNS int64
LANGUAGE js AS """
LANGUAGE js
OPTIONS (
description="Convert BQ generated error string to a number appropriate for other DBs"
)
AS """
if ( ! errmsg )
return 0;
return 1;
Expand Down
5 changes: 4 additions & 1 deletion udfs/community/cw_regex_mode.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ config { hasOutput: true }

/* Internal function */
CREATE OR REPLACE FUNCTION ${self()}(mode STRING) RETURNS STRING
LANGUAGE js AS """
LANGUAGE js
OPTIONS (
description="""Internal function"""
) AS """
var m = '';
if (mode == 'i' || mode == 'm')
m += mode;
Expand Down
5 changes: 4 additions & 1 deletion udfs/community/cw_regexp_instr_2.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ config { hasOutput: true }
* limitations under the License.
*/

CREATE OR REPLACE FUNCTION ${self()}(haystack STRING, needle STRING) RETURNS INT64 AS (
CREATE OR REPLACE FUNCTION ${self()}(haystack STRING, needle STRING) RETURNS INT64
OPTIONS (
description="""Implements regexp_instr/2 (haystack, needle)."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is that possible to provide a little bit meaningful description so anyone can identify basic use case ?

This function aims to find the starting position of the first occurrence of a "needle" string within a "haystack" string.

) AS (
CASE WHEN REGEXP_CONTAINS(haystack, needle) THEN
LENGTH(REGEXP_REPLACE(haystack, CONCAT('(.*?)', needle, '(.*)'), '\\1')) + 1
WHEN needle IS NULL OR haystack IS NULL THEN
Expand Down
5 changes: 4 additions & 1 deletion udfs/community/cw_regexp_instr_3.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ config { hasOutput: true }
* limitations under the License.
*/

CREATE OR REPLACE FUNCTION ${self()}(haystack STRING, needle STRING, start INT64) RETURNS INT64 AS (
CREATE OR REPLACE FUNCTION ${self()}(haystack STRING, needle STRING, start INT64) RETURNS INT64
OPTIONS (
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function is an extension of **cw_regexp_instr_2.sqlx** adding a start parameter to specify the starting position for searching the needle within the haystack

description="""Implements regexp_instr/3 (haystack, needle, start)."""
) AS (
CASE WHEN REGEXP_CONTAINS(substr(haystack, GREATEST(start, 1)), needle) THEN
LENGTH(REGEXP_REPLACE(substr(haystack, GREATEST(start, 1)), CONCAT('(.*?)', needle, '(.*)'), '\\1')) + GREATEST(start, 1)
WHEN needle IS NULL OR haystack IS NULL or start IS NULL THEN
Expand Down
5 changes: 4 additions & 1 deletion udfs/community/cw_regexp_instr_4.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ config { hasOutput: true }
*/

CREATE OR REPLACE FUNCTION ${self()}(haystack STRING, regexp STRING, p INT64, o INT64) RETURNS INT64
LANGUAGE js AS """
LANGUAGE js
OPTIONS (
description="""Implements regexp_instr/4 (haystack, regexp, p, o)."""
) AS """
if (haystack == null || regexp == null || o == null) return null;
p = p -1;
o = o -1;
Expand Down
5 changes: 4 additions & 1 deletion udfs/community/cw_regexp_instr_5.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ config { hasOutput: true }
* limitations under the License.
*/

CREATE OR REPLACE FUNCTION ${self()}(haystack STRING, regexp STRING, p INT64, o INT64, returnopt INT64) RETURNS INT64 AS
CREATE OR REPLACE FUNCTION ${self()}(haystack STRING, regexp STRING, p INT64, o INT64, returnopt INT64) RETURNS INT64
OPTIONS (
description="""Implements regexp_instr/5 (haystack, regexp, p, o, returnopt)."""
) AS
(
${ref("cw_regexp_instr_generic")}(haystack, regexp, p, o, returnopt, ${ref("cw_regex_mode")}(''))
);
5 changes: 4 additions & 1 deletion udfs/community/cw_regexp_instr_6.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ config { hasOutput: true }
* limitations under the License.
*/

CREATE OR REPLACE FUNCTION ${self()}(haystack STRING, regexp STRING, p INT64, o INT64, returnopt INT64, mode STRING) RETURNS INT64 AS
CREATE OR REPLACE FUNCTION ${self()}(haystack STRING, regexp STRING, p INT64, o INT64, returnopt INT64, mode STRING) RETURNS INT64
OPTIONS (
description="""Implements regexp_instr/6 (haystack, regexp, p, o, returnopt, mode)."""
) AS
(
${ref("cw_regexp_instr_generic")}(haystack, regexp, p, o, returnopt, ${ref("cw_regex_mode")}(mode))
);
5 changes: 4 additions & 1 deletion udfs/community/cw_regexp_instr_generic.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ config { hasOutput: true }
// case 'x': not supported
*/
CREATE OR REPLACE FUNCTION ${self()}(haystack STRING, regexp STRING, p INT64, o INT64, returnopt INT64, mode STRING) RETURNS INT64
LANGUAGE js AS """
LANGUAGE js
OPTIONS (
description="""Implements regexp_instr_generic (haystack, needle, position, occurence, returnopt)."""
) AS """
if (haystack == null || regexp == null || p == null || o == null || returnopt == null || mode == null) return null;
p = p -1;
o = o -1;
Expand Down
5 changes: 4 additions & 1 deletion udfs/community/cw_regexp_replace_4.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ config { hasOutput: true }
* limitations under the License.
*/

CREATE OR REPLACE FUNCTION ${self()}(haystack STRING, regexp STRING, replacement STRING, offset INT64) RETURNS STRING AS
CREATE OR REPLACE FUNCTION ${self()}(haystack STRING, regexp STRING, replacement STRING, offset INT64) RETURNS STRING
OPTIONS (
description="""Implements regexp_replace/4 (haystack, regexp, replacement, offset)."""
) AS
(
${ref("cw_regexp_replace_generic")}(haystack, regexp, replacement, offset, 0, ${ref("cw_regex_mode")}(''))
);
5 changes: 4 additions & 1 deletion udfs/community/cw_regexp_replace_5.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ config { hasOutput: true }
* limitations under the License.
*/

CREATE OR REPLACE FUNCTION ${self()}(haystack STRING, regexp STRING, replacement STRING, offset INT64, occurrence INT64) RETURNS STRING AS
CREATE OR REPLACE FUNCTION ${self()}(haystack STRING, regexp STRING, replacement STRING, offset INT64, occurrence INT64) RETURNS STRING
OPTIONS (
description="""Implements regexp_replace/5 (haystack, regexp, replacement, offset, occurrence)."""
) AS
(
${ref("cw_regexp_replace_generic")}(haystack, regexp, replacement, offset, occurrence, ${ref("cw_regex_mode")}(''))
);
5 changes: 4 additions & 1 deletion udfs/community/cw_regexp_replace_6.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ config { hasOutput: true }
* limitations under the License.
*/

CREATE OR REPLACE FUNCTION ${self()}(haystack STRING, regexp STRING, replacement STRING, p INT64, o INT64, mode STRING) RETURNS STRING AS
CREATE OR REPLACE FUNCTION ${self()}(haystack STRING, regexp STRING, replacement STRING, p INT64, o INT64, mode STRING) RETURNS STRING
OPTIONS (
description="""Implements regexp_replace/6 (haystack, regexp, replacement, p, o, mode)."""
) AS
(
${ref("cw_regexp_replace_generic")}(haystack, regexp, replacement, p, o, ${ref("cw_regex_mode")}(''))
);
6 changes: 5 additions & 1 deletion udfs/community/cw_regexp_replace_generic.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ config { hasOutput: true }

/* Generic regexp_replace, which is the 6-args version with regexp_mode already decoded */
CREATE OR REPLACE FUNCTION ${self()}(haystack STRING, regexp STRING, replacement STRING, offset INT64, occurrence INT64, mode STRING) RETURNS STRING
LANGUAGE js AS """
LANGUAGE js
OPTIONS (
description="""Generic regexp_replace, which is the 6-args version with regexp_mode already decoded"""
)
AS """
if (haystack == null || regexp == null || replacement == null || offset == null || occurrence == null || mode == null) return null;
replacement = replacement.replace('\\\\', '$');
let regExp = new RegExp(regexp, mode);
Expand Down
6 changes: 5 additions & 1 deletion udfs/community/cw_regexp_split.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ config { hasOutput: true }

CREATE OR REPLACE FUNCTION ${self()}(text string, delim string, flags string)
RETURNS array<struct<tokennumber int64, token string>>
LANGUAGE js AS """
LANGUAGE js
OPTIONS (
description="""Implements regexp split on delim"""
)
AS """
var idx = 0;
var nxt = function() {
idx ++;
Expand Down
5 changes: 4 additions & 1 deletion udfs/community/cw_regexp_substr_5.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ config { hasOutput: true }
*/

/* Implements regexp_substr/5 (haystack, needle, position, occurence, mode) */
CREATE OR REPLACE FUNCTION ${self()}(h STRING, n STRING, p INT64, o INT64, mode STRING) RETURNS STRING AS
CREATE OR REPLACE FUNCTION ${self()}(h STRING, n STRING, p INT64, o INT64, mode STRING) RETURNS STRING
OPTIONS (
description="""Implements regexp_substr/5 (haystack, needle, position, occurence, mode)"""
) AS
(
${ref("cw_regexp_substr_generic")}(h, n, p, o, ${ref("cw_regex_mode")}(mode), 0)
);
5 changes: 4 additions & 1 deletion udfs/community/cw_regexp_substr_6.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ config { hasOutput: true }
*/

/* Implements regexp_substr/6 (haystack, needle, position, occurence, mode, captured_subexp) */
CREATE OR REPLACE FUNCTION ${self()}(h STRING, n STRING, p INT64, o INT64, mode STRING, g INT64) RETURNS STRING AS
CREATE OR REPLACE FUNCTION ${self()}(h STRING, n STRING, p INT64, o INT64, mode STRING, g INT64) RETURNS STRING
OPTIONS (
description="""Implements regexp_substr/6 (haystack, needle, position, occurence, mode, captured_subexp)"""
) AS
(
${ref("cw_regexp_substr_generic")}(h, n, p, o, ${ref("cw_regex_mode")}(mode), g)
);
5 changes: 4 additions & 1 deletion udfs/community/cw_regexp_substr_generic.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ config { hasOutput: true }
*/

CREATE OR REPLACE FUNCTION ${self()}(str STRING, regexp STRING, p INT64, o INT64, mode STRING, g INT64) RETURNS STRING
LANGUAGE js AS """
LANGUAGE js
OPTIONS (
description="""Implements regexp_substr_generic (str, regexp, p, o, mode, g)."""
) AS """
if (str == null || regexp == null || p == null || o == null || mode == null) return null;
var r = new RegExp(regexp, mode);
var m = str.substring(p - 1).matchAll(r);
Expand Down
6 changes: 5 additions & 1 deletion udfs/community/jaccard.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ config { hasOutput: true }

CREATE OR REPLACE FUNCTION ${self()}(a STRING, b STRING)
RETURNS FLOAT64
LANGUAGE js AS r"""
LANGUAGE js
OPTIONS (
description="Compute Jaccard distance."
)
AS r"""
let intersectSize = 0;

if(a && b) {
Expand Down
3 changes: 3 additions & 0 deletions udfs/community/json_typeof.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ config { hasOutput: true }
-- Input: JSON string
-- Output: The JSON value type of the argument or NULL if the argument is an unknown value
CREATE OR REPLACE FUNCTION ${self()}(json STRING)
OPTIONS (
description="Converts JSON string to the JSON value type of the argument or NULL if the argument is an unknown value."
)
AS ( (
SELECT AS VALUE
CASE
Expand Down
5 changes: 4 additions & 1 deletion udfs/community/linear_interpolate.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ config { hasOutput: true }
-- next: the x,y coordinate of the following value
-- Output: the interpolated y value
CREATE OR REPLACE FUNCTION ${self()}(pos INT64, prev STRUCT<x INT64,y FLOAT64>, next STRUCT<x INT64,y FLOAT64>)
RETURNS FLOAT64 AS (
RETURNS FLOAT64
OPTIONS (
description="Linear_interpolate."
) AS (
CASE
WHEN pos IS NULL OR prev IS NULL OR next IS NULL THEN NULL
ELSE
Expand Down
3 changes: 3 additions & 0 deletions udfs/community/linear_regression.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ config { hasOutput: true }
*/

CREATE OR REPLACE FUNCTION ${self()}(data ARRAY<STRUCT<X FLOAT64, Y FLOAT64>>)
OPTIONS (
description="Linear Regression."
)
AS ((
WITH results AS (
WITH sums AS (
Expand Down
5 changes: 4 additions & 1 deletion udfs/community/meters_to_miles.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ config { hasOutput: true }
* limitations under the License.
*/

CREATE OR REPLACE FUNCTION ${self()}(input_meters FLOAT64) AS (
CREATE OR REPLACE FUNCTION ${self()}(input_meters FLOAT64)
OPTIONS (
description="Convert meters to miles."
) AS (
input_meters / 1609.344
);
5 changes: 4 additions & 1 deletion udfs/community/miles_to_meters.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ config { hasOutput: true }
* limitations under the License.
*/

CREATE OR REPLACE FUNCTION ${self()}(input_miles FLOAT64) AS (
CREATE OR REPLACE FUNCTION ${self()}(input_miles FLOAT64)
OPTIONS (
description="Convert miles to meters."
) AS (
input_miles * 1609.344
);