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

Support for projection item prefix operator (CONNECT_BY_ROOT) #1780

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

Conversation

tomershaniii
Copy link
Contributor

Support for the snowflake CONNECT_BY_ROOT operator
https://docs.snowflake.com/en/sql-reference/constructs/connect-by

@tomershaniii tomershaniii changed the title Support for projection prefix operator (CONNECT_BY_ROOT) Support for projection item prefix operator (CONNECT_BY_ROOT) Mar 28, 2025
@@ -1237,6 +1237,23 @@ impl<'a> Parser<'a> {
}
}

//Select item operators
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
//Select item operators
/// Select item operators

for the doc comment can we describe what the function does?

Comment on lines +13752 to 13756
let prefix = self
.maybe_parse(|parser| parser.parse_select_item_prefix_by_reserved_word())?
.flatten();

match self.parse_wildcard_expr()? {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking introducing the prefix field into the select item is a bit more invasive and would be nice to avoid if it makes sense. I noticed this use case is similar in representation to IntroducedString, maybe we can repurpose that one to be generic.

I'm thinking something like this?

changing that enum variant into

Expr::Prefixed { prefix: Ident, expr: Expr }

Then impl wise here we could wrap the self.parse_wildcard_expr() call with the logic to optionally parse the prefix

fn parse_select_item_expr() {
  let prefix = self.parse_one_of_keywords(self.dialect.get_reserved_keywords_for_select_item());

  let expr = self.parse_wildcard_expr()?

  if let Some(prefix) = prefix {
    Expr::Prefixed {
      prefix: Ident::new(prefix),
      expr,
    }
  } else {
    expr
  }
}


/// See: <https://docs.snowflake.com/en/sql-reference/constructs/connect-by>
fn get_reserved_keywords_for_select_item_operator(&self) -> &[Keyword] {
const RESERVED_KEYWORDS_FOR_SELECT_ITEM_OPERATOR: [Keyword; 1] = [Keyword::CONNECT_BY_ROOT];
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 move this to the top of the file maybe? thinking it would be more visible there and if the list happens to get long it doesnt add to the function's length

tomershaniii and others added 3 commits April 2, 2025 14:13
Co-authored-by: Ifeanyi Ubah <[email protected]>
Co-authored-by: Ifeanyi Ubah <[email protected]>
Co-authored-by: Ifeanyi Ubah <[email protected]>
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