Skip to content

Add support for Snowflake identifier function #1929

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

yoavcloud
Copy link
Contributor

Expand the support for the IDENTIFIER function in Snowflake, which is used to generate identifiers dynamically. See here: https://docs.snowflake.com/en/sql-reference/identifier-literal

The ObjectNamePart enum was extended with a new part type to support the use of the identifier function as an object name. Some work went into organizing Parser:parse_object_name a bit.

A few examples:

-- identifier for table name
create or replace temp table identifier('test')(c1 int, identifier int); 
-- identifier for column name
select identifier('identifier') from test;
-- identifier for table name
select c1 from identifier('test');
-- identifier for table alias
select identifier('alias1').* from test as alias1;

Comment on lines 10398 to 10399
} else if let Some(func_part) =
self.maybe_parse(|parser| parser.parse_object_name_function_part())?
Copy link
Contributor

Choose a reason for hiding this comment

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

wondering can we instead extende the else clause to do something like this?

else {
    let ident = self.parse_identifier()?;
    let part = if self.dialect.is_identifier_generating_function_name(&ident) {
          self.expect_token(&Token::LParen)?;
          let args = ...
          self.expect_token(&Token::RParen)?;
         ObjectNamePartFunction { name:ident, args }
    } else {
          ObjectNamePart::Identifier(ident));
    }
}

thinking that way we skip this extra branch, and the extra error scenario in the function part parsing

@@ -4232,3 +4232,122 @@ fn test_snowflake_create_view_with_composite_policy_name() {
r#"CREATE VIEW X (COL WITH MASKING POLICY foo.bar.baz) AS SELECT * FROM Y"#;
snowflake().verified_stmt(create_view_with_tag);
}

#[test]
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add a test scenario for how this interacts with the double dot feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In what way? I believe you cannot chain IDENTIFIER. For example, this is illegal: SELECT * FROM IDENTIFIER('db1')..IDENTIFIER('tbl1').

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