@@ -189,3 +189,77 @@ fn test_values_clause() {
189
189
// TODO: support this example from https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select-values.html#examples
190
190
// databricks().verified_query("VALUES 1, 2, 3");
191
191
}
192
+
193
+ #[ test]
194
+ fn parse_use ( ) {
195
+ let valid_object_names = [ "mydb" , "WAREHOUSE" , "DEFAULT" ] ;
196
+ let quote_styles = [ '"' , '`' ] ;
197
+
198
+ for object_name in & valid_object_names {
199
+ // Test single identifier without quotes
200
+ assert_eq ! (
201
+ databricks( ) . verified_stmt( & format!( "USE {}" , object_name) ) ,
202
+ Statement :: Use ( Use :: Object ( ObjectName ( vec![ Ident :: new(
203
+ object_name. to_string( )
204
+ ) ] ) ) )
205
+ ) ;
206
+ for & quote in & quote_styles {
207
+ // Test single identifier with different type of quotes
208
+ assert_eq ! (
209
+ databricks( ) . verified_stmt( & format!( "USE {0}{1}{0}" , quote, object_name) ) ,
210
+ Statement :: Use ( Use :: Object ( ObjectName ( vec![ Ident :: with_quote(
211
+ quote,
212
+ object_name. to_string( ) ,
213
+ ) ] ) ) )
214
+ ) ;
215
+ }
216
+ }
217
+
218
+ for & quote in & quote_styles {
219
+ // Test single identifier with keyword and different type of quotes
220
+ assert_eq ! (
221
+ databricks( ) . verified_stmt( & format!( "USE CATALOG {0}my_catalog{0}" , quote) ) ,
222
+ Statement :: Use ( Use :: Catalog ( ObjectName ( vec![ Ident :: with_quote(
223
+ quote,
224
+ "my_catalog" . to_string( ) ,
225
+ ) ] ) ) )
226
+ ) ;
227
+ assert_eq ! (
228
+ databricks( ) . verified_stmt( & format!( "USE DATABASE {0}my_database{0}" , quote) ) ,
229
+ Statement :: Use ( Use :: Database ( ObjectName ( vec![ Ident :: with_quote(
230
+ quote,
231
+ "my_database" . to_string( ) ,
232
+ ) ] ) ) )
233
+ ) ;
234
+ assert_eq ! (
235
+ databricks( ) . verified_stmt( & format!( "USE SCHEMA {0}my_schema{0}" , quote) ) ,
236
+ Statement :: Use ( Use :: Schema ( ObjectName ( vec![ Ident :: with_quote(
237
+ quote,
238
+ "my_schema" . to_string( ) ,
239
+ ) ] ) ) )
240
+ ) ;
241
+ }
242
+
243
+ // Test single identifier with keyword and no quotes
244
+ assert_eq ! (
245
+ databricks( ) . verified_stmt( "USE CATALOG my_catalog" ) ,
246
+ Statement :: Use ( Use :: Catalog ( ObjectName ( vec![ Ident :: new( "my_catalog" ) ] ) ) )
247
+ ) ;
248
+ assert_eq ! (
249
+ databricks( ) . verified_stmt( "USE DATABASE my_schema" ) ,
250
+ Statement :: Use ( Use :: Database ( ObjectName ( vec![ Ident :: new( "my_schema" ) ] ) ) )
251
+ ) ;
252
+ assert_eq ! (
253
+ databricks( ) . verified_stmt( "USE SCHEMA my_schema" ) ,
254
+ Statement :: Use ( Use :: Schema ( ObjectName ( vec![ Ident :: new( "my_schema" ) ] ) ) )
255
+ ) ;
256
+
257
+ // Test invalid syntax - missing identifier
258
+ let invalid_cases = [ "USE SCHEMA" , "USE DATABASE" , "USE CATALOG" ] ;
259
+ for sql in & invalid_cases {
260
+ assert_eq ! (
261
+ databricks( ) . parse_sql_statements( sql) . unwrap_err( ) ,
262
+ ParserError :: ParserError ( "Expected: identifier, found: EOF" . to_string( ) ) ,
263
+ ) ;
264
+ }
265
+ }
0 commit comments