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

Conversation

vmatt
Copy link
Collaborator

@vmatt vmatt commented Dec 4, 2024

SELECT YAML_TO_JSON(null); currently fails with error:

JavaScript execution error: Uncaught TypeError: Cannot read properties of undefined (reading 'length') in YAML_TO_JSON_ARRAY at '"use strict";...

@@ -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.

@vmatt
Copy link
Collaborator Author

vmatt commented Dec 4, 2024

Sorry, you are right, ON NULL INPUT RETURNS NULL was not in the DDL definition in our current deployment.

@vmatt vmatt closed this Dec 4, 2024
@hunyadi hunyadi deleted the handle-errors branch December 6, 2024 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants