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

RETURNS NULL ON NULL INPUT for CREATE FUNCTION in Snowflake Dialect is not supported #3503

Closed
krzysztof-kwitt opened this issue May 17, 2024 · 3 comments · Fixed by #3504
Closed

Comments

@krzysztof-kwitt
Copy link
Contributor

krzysztof-kwitt commented May 17, 2024

Before you file an issue

  • Make sure you specify the "read" dialect eg. parse_one(sql, read="spark")
  • Make sure you specify the "write" dialect eg. ast.sql(dialect="duckdb")
  • Check if the issue still exists on main

Fully reproducible code snippet
Please include a fully reproducible code snippet or the input sql, dialect, and expected output.

pip install 'sqlglot@git+ssh://git@github.com/tobymao/sqlglot.git'
create_text = """
CREATE OR REPLACE FUNCTION ibis_udfs.public.object_values("obj" OBJECT)
RETURNS ARRAY
LANGUAGE JAVASCRIPT
RETURNS NULL ON NULL INPUT
AS
$$ return Object.values(obj) $$
"""
import sqlglot
sqlglot.parse(create_text, dialect='snowflake')
sqlglot.errors.ParseError: Required keyword: 'this' missing for <class 'sqlglot.expressions.InputModelProperty'>. Line 6, Col: 2.

Official Documentation
Please include links to official SQL documentation related to your issue.
https://docs.snowflake.com/en/sql-reference/sql/create-function#optional-parameters

@krzysztof-kwitt
Copy link
Contributor Author

STRICT keyword (alias for RETURNS NULL ON NULL INPUT) is also not supported correctly;

>>> create_text = """
... CREATE OR REPLACE FUNCTION ibis_udfs.public.object_values("obj" OBJECT)
... RETURNS ARRAY
... LANGUAGE JAVASCRIPT
... STRICT
... AS
... $$ return Object.values(obj) $$
... """
>>> expr = sqlglot.parse_one(create_text, dialect='snowflake')
>>> expr
Create(
  this=UserDefinedFunction(
    this=Dot(
      this=Dot(
        this=Identifier(this=ibis_udfs, quoted=False),
        expression=Identifier(this=public, quoted=False)),
      expression=Identifier(this=object_values, quoted=False)),
    expressions=[
      ColumnDef(
        this=Identifier(this=obj, quoted=True),
        kind=DataType(this=Type.OBJECT, nested=True))],
    wrapped=True),
  kind=FUNCTION,
  replace=True,
  expression=Alias(
    this=Column(
      this=Identifier(this=STRICT, quoted=False)),
    alias=Identifier(this=return Object.values(obj) , quoted=False)),
  properties=Properties(
    expressions=[
      ReturnsProperty(
        this=DataType(this=Type.ARRAY, nested=True)),
      LanguageProperty(
        this=Var(this=JAVASCRIPT))]))
>>> print(expr)
CREATE OR REPLACE FUNCTION ibis_udfs.public.object_values("obj" OBJECT) RETURNS ARRAY LANGUAGE JAVASCRIPT AS STRICT AS  return Object.values(obj)
CREATE OR REPLACE FUNCTION ibis_udfs.public.object_values("obj" OBJECT) RETURNS ARRAY LANGUAGE JAVASCRIPT AS STRICT AS  return Object.values(obj)

raises the error:

Syntax error: unexpected 'STRICT'. (line 1)

@tobymao
Copy link
Owner

tobymao commented May 18, 2024

this isn’t high priority for us, feel free to submit a pr for this.

we welcome well documented, tested, and conforming prs, but won’t have time to implement this one for you

@tobymao tobymao closed this as not planned Won't fix, can't repro, duplicate, stale May 18, 2024
@krzysztof-kwitt
Copy link
Contributor Author

@georgesittas Thank you!
image

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 a pull request may close this issue.

2 participants