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

Add support for data type specific methods #1535

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,17 @@ impl<'a> Parser<'a> {
body: Box::new(self.parse_expr()?),
}));
}
Token::DoubleColon if self.dialect.supports_methods() => {
let namespace = w.value;
self.expect_token(&Token::DoubleColon)?;
let name_with_namespace = match self.next_token().token {
Token::Word(func_name) => {
ObjectName(vec![Ident::new(format!("{}::{}", namespace, func_name.value))])
},
_ => return self.expected("identifier", self.peek_token())
};
Ok(self.parse_function(name_with_namespace)?)
Comment on lines +1228 to +1236
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move the body to a self.parse_namespaced_method(w)? or similar function? Also if we can add an example syntax to the function doc with the link to clarify the syntax

}
_ => Ok(Expr::Identifier(w.to_ident())),
},
}, // End of Token::Word
Expand Down
8 changes: 8 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11550,6 +11550,14 @@ fn parse_method_expr() {
}
_ => unreachable!(),
}

dialects.verified_stmt(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a scenario in the style of a::b::c().d()?

"SELECT phone, some_namespace::some_function().method_a(345345) FROM customers",
);

dialects.verified_stmt(
"SELECT geography::STGeomFromText('POLYGON((-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))', 4326).STAsText() FROM customers"
);
}

#[test]
Expand Down
Loading