File tree Expand file tree Collapse file tree 4 files changed +54
-0
lines changed Expand file tree Collapse file tree 4 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -342,6 +342,16 @@ pub trait Dialect: Debug + Any {
342342 self . supports_trailing_commas ( )
343343 }
344344
345+ /// Returns true if the dialect supports double dot notation for object names
346+ ///
347+ /// Example
348+ /// ```sql
349+ /// SELECT * FROM db_name..table_name
350+ /// ```
351+ fn supports_object_name_double_dot_notation ( & self ) -> bool {
352+ false
353+ }
354+
345355 /// Dialect-specific infix parser override
346356 ///
347357 /// This method is called to parse the next infix expression.
Original file line number Diff line number Diff line change @@ -52,6 +52,14 @@ impl Dialect for SnowflakeDialect {
5252 true
5353 }
5454
55+ // Snowflake supports double-dot notation when the schema name is not specified
56+ // In this case the default PUBLIC schema is used
57+ //
58+ // see https://docs.snowflake.com/en/sql-reference/name-resolution#resolution-when-schema-omitted-double-dot-notation
59+ fn supports_object_name_double_dot_notation ( & self ) -> bool {
60+ true
61+ }
62+
5563 fn is_identifier_part ( & self , ch : char ) -> bool {
5664 ch. is_ascii_lowercase ( )
5765 || ch. is_ascii_uppercase ( )
Original file line number Diff line number Diff line change @@ -8349,6 +8349,13 @@ impl<'a> Parser<'a> {
83498349 pub fn parse_object_name(&mut self, in_table_clause: bool) -> Result<ObjectName, ParserError> {
83508350 let mut idents = vec![];
83518351 loop {
8352+ if self.dialect.supports_object_name_double_dot_notation()
8353+ && !idents.is_empty()
8354+ && self.peek_token() == Token::Period
8355+ {
8356+ self.next_token();
8357+ idents.push(Ident::new(""));
8358+ }
83528359 idents.push(self.parse_identifier(in_table_clause)?);
83538360 if !self.consume_token(&Token::Period) {
83548361 break;
Original file line number Diff line number Diff line change @@ -2846,3 +2846,32 @@ fn test_parse_show_columns_sql() {
28462846 snowflake ( ) . verified_stmt ( "SHOW COLUMNS IN TABLE abc" ) ;
28472847 snowflake ( ) . verified_stmt ( "SHOW COLUMNS LIKE '%xyz%' IN TABLE abc" ) ;
28482848}
2849+
2850+ #[ test]
2851+ fn test_sf_double_dot_notation ( ) {
2852+ snowflake ( ) . verified_stmt ( "SELECT * FROM db_name..table_name" ) ;
2853+ snowflake ( ) . verified_stmt ( "SELECT * FROM x, y..z JOIN a..b as as b ON x.id = b.id" ) ;
2854+ }
2855+
2856+ #[ test]
2857+ fn test_sf_double_dot_notation_wrong_position ( ) { }
2858+
2859+ #[ test]
2860+ fn test_parse_double_dot_notation_wrong_position ( ) {
2861+ assert_eq ! (
2862+ snowflake( )
2863+ . parse_sql_statements( "SELECT * FROM X.Y.." )
2864+ . unwrap_err( )
2865+ . to_string( ) ,
2866+ "sql parser error: Expected: identifier, found: ."
2867+ ) ;
2868+
2869+ assert_eq ! (
2870+ // Ensure we don't parse leading token
2871+ snowflake( )
2872+ . parse_sql_statements( "SELECT * FROM .X.Y" )
2873+ . unwrap_err( )
2874+ . to_string( ) ,
2875+ "sql parser error: Expected: identifier, found: ."
2876+ ) ;
2877+ }
You can’t perform that action at this time.
0 commit comments