Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If input string is null, should return null #1

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion src/template/check_yaml.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ CREATE OR REPLACE FUNCTION
COMMENT = 'Parses and validates a YAML string.'
AS
$$
TO_VARCHAR(CHECK_YAML_ARRAY(TO_BINARY(YAML_STRING, 'UTF-8')), 'UTF-8')
CASE WHEN YAML_STRING IS NULL THEN NULL ELSE TO_VARCHAR(CHECK_YAML_ARRAY(TO_BINARY(YAML_STRING, 'UTF-8')), 'UTF-8') END
$$
2 changes: 1 addition & 1 deletion src/template/yaml_to_json_array.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ CREATE OR REPLACE FUNCTION
COMMENT = 'Parses a YAML string into a semi-structured value.'
AS
$$
PARSE_JSON(TO_VARCHAR(YAML_TO_JSON_ARRAY(TO_BINARY(YAML_STRING, 'UTF-8')), 'UTF-8'))
CASE WHEN YAML_STRING IS NULL THEN NULL ELSE PARSE_JSON(TO_VARCHAR(YAML_TO_JSON_ARRAY(TO_BINARY(YAML_STRING, 'UTF-8')), 'UTF-8')) END
Copy link
Owner

Choose a reason for hiding this comment

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

I am surprised that we need the extra CASE for NULL input; YAML_TO_JSON_ARRAY has the annotation RETURNS NULL ON NULL INPUT. Specifically, Snowflake documentation writes,

RETURNS NULL ON NULL INPUT (or its synonym STRICT) will not call the UDF if any input is null. Instead, a null value will always be returned for that row.

The same comment applies to CHECK_YAML_ARRAY and YAML_TO_JSON_STRING.

$$
2 changes: 1 addition & 1 deletion src/template/yaml_to_json_string.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ CREATE OR REPLACE FUNCTION
COMMENT = 'Parses a YAML string into a semi-structured value.'
AS
$$
PARSE_JSON(YAML_TO_JSON_STRING(YAML_STRING))
CASE WHEN YAML_STRING IS NULL THEN NULL ELSE PARSE_JSON(YAML_TO_JSON_STRING(YAML_STRING)) END
$$