diff --git a/udfs/community/cw_csvld.sqlx b/udfs/community/cw_csvld.sqlx index 8683a3524..b30b184ca 100644 --- a/udfs/community/cw_csvld.sqlx +++ b/udfs/community/cw_csvld.sqlx @@ -17,7 +17,11 @@ config { hasOutput: true } CREATE OR REPLACE FUNCTION ${self()}(text string, comma string, quote string,len INT64) RETURNS array -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; diff --git a/udfs/community/cw_error_number.sqlx b/udfs/community/cw_error_number.sqlx index 7a09b47f9..7536ef408 100644 --- a/udfs/community/cw_error_number.sqlx +++ b/udfs/community/cw_error_number.sqlx @@ -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; diff --git a/udfs/community/cw_error_severity.sqlx b/udfs/community/cw_error_severity.sqlx index 7a09b47f9..7536ef408 100644 --- a/udfs/community/cw_error_severity.sqlx +++ b/udfs/community/cw_error_severity.sqlx @@ -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; diff --git a/udfs/community/cw_error_state.sqlx b/udfs/community/cw_error_state.sqlx index 7a09b47f9..7536ef408 100644 --- a/udfs/community/cw_error_state.sqlx +++ b/udfs/community/cw_error_state.sqlx @@ -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; diff --git a/udfs/community/cw_regex_mode.sqlx b/udfs/community/cw_regex_mode.sqlx index f7fd40f9f..e79064c6a 100644 --- a/udfs/community/cw_regex_mode.sqlx +++ b/udfs/community/cw_regex_mode.sqlx @@ -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; diff --git a/udfs/community/cw_regexp_instr_2.sqlx b/udfs/community/cw_regexp_instr_2.sqlx index 84cbbeb80..b86f64cdd 100644 --- a/udfs/community/cw_regexp_instr_2.sqlx +++ b/udfs/community/cw_regexp_instr_2.sqlx @@ -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).""" +) 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 diff --git a/udfs/community/cw_regexp_instr_3.sqlx b/udfs/community/cw_regexp_instr_3.sqlx index 6efaa783a..cb7965f9a 100644 --- a/udfs/community/cw_regexp_instr_3.sqlx +++ b/udfs/community/cw_regexp_instr_3.sqlx @@ -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 ( + 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 diff --git a/udfs/community/cw_regexp_instr_4.sqlx b/udfs/community/cw_regexp_instr_4.sqlx index 278fdc940..42f57caba 100644 --- a/udfs/community/cw_regexp_instr_4.sqlx +++ b/udfs/community/cw_regexp_instr_4.sqlx @@ -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; diff --git a/udfs/community/cw_regexp_instr_5.sqlx b/udfs/community/cw_regexp_instr_5.sqlx index f5f906da0..c0dfd85c6 100644 --- a/udfs/community/cw_regexp_instr_5.sqlx +++ b/udfs/community/cw_regexp_instr_5.sqlx @@ -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")}('')) ); diff --git a/udfs/community/cw_regexp_instr_6.sqlx b/udfs/community/cw_regexp_instr_6.sqlx index ece258baf..abd177425 100644 --- a/udfs/community/cw_regexp_instr_6.sqlx +++ b/udfs/community/cw_regexp_instr_6.sqlx @@ -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)) ); diff --git a/udfs/community/cw_regexp_instr_generic.sqlx b/udfs/community/cw_regexp_instr_generic.sqlx index a803026a1..2a5c4d3ca 100644 --- a/udfs/community/cw_regexp_instr_generic.sqlx +++ b/udfs/community/cw_regexp_instr_generic.sqlx @@ -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; diff --git a/udfs/community/cw_regexp_replace_4.sqlx b/udfs/community/cw_regexp_replace_4.sqlx index ee989ad86..73b6b4135 100644 --- a/udfs/community/cw_regexp_replace_4.sqlx +++ b/udfs/community/cw_regexp_replace_4.sqlx @@ -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")}('')) ); diff --git a/udfs/community/cw_regexp_replace_5.sqlx b/udfs/community/cw_regexp_replace_5.sqlx index c05945d71..3c224c708 100644 --- a/udfs/community/cw_regexp_replace_5.sqlx +++ b/udfs/community/cw_regexp_replace_5.sqlx @@ -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")}('')) ); diff --git a/udfs/community/cw_regexp_replace_6.sqlx b/udfs/community/cw_regexp_replace_6.sqlx index 9e769b0b7..6f7660f39 100644 --- a/udfs/community/cw_regexp_replace_6.sqlx +++ b/udfs/community/cw_regexp_replace_6.sqlx @@ -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")}('')) ); diff --git a/udfs/community/cw_regexp_replace_generic.sqlx b/udfs/community/cw_regexp_replace_generic.sqlx index 73cb4c907..9331480df 100644 --- a/udfs/community/cw_regexp_replace_generic.sqlx +++ b/udfs/community/cw_regexp_replace_generic.sqlx @@ -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); diff --git a/udfs/community/cw_regexp_split.sqlx b/udfs/community/cw_regexp_split.sqlx index 129c41961..b07058be4 100644 --- a/udfs/community/cw_regexp_split.sqlx +++ b/udfs/community/cw_regexp_split.sqlx @@ -17,7 +17,11 @@ config { hasOutput: true } CREATE OR REPLACE FUNCTION ${self()}(text string, delim string, flags string) RETURNS array> -LANGUAGE js AS """ +LANGUAGE js +OPTIONS ( + description="""Implements regexp split on delim""" +) +AS """ var idx = 0; var nxt = function() { idx ++; diff --git a/udfs/community/cw_regexp_substr_5.sqlx b/udfs/community/cw_regexp_substr_5.sqlx index 6a352ead9..ed50be5be 100644 --- a/udfs/community/cw_regexp_substr_5.sqlx +++ b/udfs/community/cw_regexp_substr_5.sqlx @@ -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) ); diff --git a/udfs/community/cw_regexp_substr_6.sqlx b/udfs/community/cw_regexp_substr_6.sqlx index 8337c8cb0..651d578db 100644 --- a/udfs/community/cw_regexp_substr_6.sqlx +++ b/udfs/community/cw_regexp_substr_6.sqlx @@ -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) ); diff --git a/udfs/community/cw_regexp_substr_generic.sqlx b/udfs/community/cw_regexp_substr_generic.sqlx index d13a27fa9..9a2f2d796 100644 --- a/udfs/community/cw_regexp_substr_generic.sqlx +++ b/udfs/community/cw_regexp_substr_generic.sqlx @@ -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); diff --git a/udfs/community/jaccard.sqlx b/udfs/community/jaccard.sqlx index 241277dba..f8a1da205 100644 --- a/udfs/community/jaccard.sqlx +++ b/udfs/community/jaccard.sqlx @@ -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) { diff --git a/udfs/community/json_typeof.sqlx b/udfs/community/json_typeof.sqlx index 0c61d99ad..f851eb41f 100644 --- a/udfs/community/json_typeof.sqlx +++ b/udfs/community/json_typeof.sqlx @@ -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 diff --git a/udfs/community/linear_interpolate.sqlx b/udfs/community/linear_interpolate.sqlx index 431437602..af073cf3e 100644 --- a/udfs/community/linear_interpolate.sqlx +++ b/udfs/community/linear_interpolate.sqlx @@ -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, next STRUCT) -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 diff --git a/udfs/community/linear_regression.sqlx b/udfs/community/linear_regression.sqlx index f63a62a28..471ab5e81 100644 --- a/udfs/community/linear_regression.sqlx +++ b/udfs/community/linear_regression.sqlx @@ -16,6 +16,9 @@ config { hasOutput: true } */ CREATE OR REPLACE FUNCTION ${self()}(data ARRAY>) +OPTIONS ( + description="Linear Regression." +) AS (( WITH results AS ( WITH sums AS ( diff --git a/udfs/community/meters_to_miles.sqlx b/udfs/community/meters_to_miles.sqlx index 218fda1ff..4f8a4f19b 100644 --- a/udfs/community/meters_to_miles.sqlx +++ b/udfs/community/meters_to_miles.sqlx @@ -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 ); diff --git a/udfs/community/miles_to_meters.sqlx b/udfs/community/miles_to_meters.sqlx index 4b8870ba1..580d309b9 100644 --- a/udfs/community/miles_to_meters.sqlx +++ b/udfs/community/miles_to_meters.sqlx @@ -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 );