@@ -479,6 +479,16 @@ fn test_snowflake_create_invalid_temporal_table() {
479479 ) ;
480480}
481481
482+ #[ test]
483+ fn test_snowflake_create_invalid_temporal_file_format ( ) {
484+ assert_eq ! (
485+ snowflake( ) . parse_sql_statements( "CREATE TEMPORARY VOLATILE FILE FORMAT my_fmt" ) ,
486+ Err ( ParserError :: ParserError (
487+ "Expected: an object type after CREATE, found: FILE" . to_string( )
488+ ) )
489+ ) ;
490+ }
491+
482492#[ test]
483493fn test_snowflake_create_table_if_not_exists ( ) {
484494 match snowflake ( ) . verified_stmt ( "CREATE TABLE IF NOT EXISTS my_table (a INT)" ) {
@@ -2160,6 +2170,129 @@ fn test_create_stage_with_copy_options() {
21602170 assert_eq ! ( snowflake( ) . verified_stmt( sql) . to_string( ) , sql) ;
21612171}
21622172
2173+ #[ test]
2174+ fn test_create_file_format ( ) {
2175+ let sql = "CREATE FILE FORMAT my_fmt" ;
2176+ match snowflake ( ) . verified_stmt ( sql) {
2177+ Statement :: CreateFileFormat {
2178+ or_replace,
2179+ temporary,
2180+ volatile,
2181+ if_not_exists,
2182+ name,
2183+ options,
2184+ comment,
2185+ } => {
2186+ assert ! ( !or_replace) ;
2187+ assert ! ( !temporary) ;
2188+ assert ! ( !volatile) ;
2189+ assert ! ( !if_not_exists) ;
2190+ assert_eq ! ( "my_fmt" , name. to_string( ) ) ;
2191+ assert ! ( options. options. is_empty( ) ) ;
2192+ assert ! ( comment. is_none( ) ) ;
2193+ }
2194+ _ => unreachable ! ( ) ,
2195+ } ;
2196+ assert_eq ! ( snowflake( ) . verified_stmt( sql) . to_string( ) , sql) ;
2197+
2198+ let extended_sql = concat ! (
2199+ "CREATE OR REPLACE TEMPORARY FILE FORMAT IF NOT EXISTS my_fmt " ,
2200+ "COMMENT='some-comment'"
2201+ ) ;
2202+ match snowflake ( ) . verified_stmt ( extended_sql) {
2203+ Statement :: CreateFileFormat {
2204+ or_replace,
2205+ temporary,
2206+ if_not_exists,
2207+ name,
2208+ comment,
2209+ ..
2210+ } => {
2211+ assert ! ( or_replace) ;
2212+ assert ! ( temporary) ;
2213+ assert ! ( if_not_exists) ;
2214+ assert_eq ! ( "my_fmt" , name. to_string( ) ) ;
2215+ assert_eq ! ( "some-comment" , comment. unwrap( ) ) ;
2216+ }
2217+ _ => unreachable ! ( ) ,
2218+ } ;
2219+ assert_eq ! (
2220+ snowflake( ) . verified_stmt( extended_sql) . to_string( ) ,
2221+ extended_sql
2222+ ) ;
2223+ }
2224+
2225+ #[ test]
2226+ fn test_create_file_format_with_options ( ) {
2227+ let sql = concat ! (
2228+ "CREATE FILE FORMAT my_fmt " ,
2229+ "TYPE=CSV FIELD_DELIMITER='|' SKIP_HEADER=1 COMPRESSION=GZIP"
2230+ ) ;
2231+ match snowflake ( ) . verified_stmt ( sql) {
2232+ Statement :: CreateFileFormat { options, .. } => {
2233+ assert ! ( options. options. contains( & KeyValueOption {
2234+ option_name: "TYPE" . to_string( ) ,
2235+ option_value: KeyValueOptionKind :: Single (
2236+ Value :: Placeholder ( "CSV" . to_string( ) ) . with_empty_span( )
2237+ ) ,
2238+ } ) ) ;
2239+ assert ! ( options. options. contains( & KeyValueOption {
2240+ option_name: "FIELD_DELIMITER" . to_string( ) ,
2241+ option_value: KeyValueOptionKind :: Single (
2242+ Value :: SingleQuotedString ( "|" . to_string( ) ) . with_empty_span( )
2243+ ) ,
2244+ } ) ) ;
2245+ assert ! ( options. options. contains( & KeyValueOption {
2246+ option_name: "SKIP_HEADER" . to_string( ) ,
2247+ option_value: KeyValueOptionKind :: Single (
2248+ Value :: Number ( "1" . parse( ) . unwrap( ) , false ) . with_empty_span( )
2249+ ) ,
2250+ } ) ) ;
2251+ assert ! ( options. options. contains( & KeyValueOption {
2252+ option_name: "COMPRESSION" . to_string( ) ,
2253+ option_value: KeyValueOptionKind :: Single (
2254+ Value :: Placeholder ( "GZIP" . to_string( ) ) . with_empty_span( )
2255+ ) ,
2256+ } ) ) ;
2257+ }
2258+ _ => unreachable ! ( ) ,
2259+ } ;
2260+ assert_eq ! ( snowflake( ) . verified_stmt( sql) . to_string( ) , sql) ;
2261+ }
2262+
2263+ #[ test]
2264+ fn test_create_file_format_volatile ( ) {
2265+ let sql = "CREATE VOLATILE FILE FORMAT my_fmt TYPE=JSON STRIP_OUTER_ARRAY=true" ;
2266+ match snowflake ( ) . verified_stmt ( sql) {
2267+ Statement :: CreateFileFormat {
2268+ temporary,
2269+ volatile,
2270+ options,
2271+ ..
2272+ } => {
2273+ assert ! ( !temporary) ;
2274+ assert ! ( volatile) ;
2275+ assert ! ( options. options. contains( & KeyValueOption {
2276+ option_name: "STRIP_OUTER_ARRAY" . to_string( ) ,
2277+ option_value: KeyValueOptionKind :: Single ( Value :: Boolean ( true ) . with_empty_span( ) ) ,
2278+ } ) ) ;
2279+ }
2280+ _ => unreachable ! ( ) ,
2281+ } ;
2282+ assert_eq ! ( snowflake( ) . verified_stmt( sql) . to_string( ) , sql) ;
2283+ }
2284+
2285+ #[ test]
2286+ fn test_create_file_format_with_identifier_function ( ) {
2287+ // The Snowflake driver emits `CREATE TEMP FILE FORMAT identifier(?) ...` when
2288+ // uploading pandas DataFrames. `TEMP` is an alias of `TEMPORARY` and the name
2289+ // is a call to the `IDENTIFIER` function with a bind parameter.
2290+ snowflake ( ) . one_statement_parses_to (
2291+ "CREATE TEMP FILE FORMAT identifier(?) TYPE=PARQUET COMPRESSION=auto" ,
2292+ "CREATE TEMPORARY FILE FORMAT identifier(?) TYPE=PARQUET COMPRESSION=auto" ,
2293+ ) ;
2294+ }
2295+
21632296#[ test]
21642297fn test_copy_into ( ) {
21652298 let sql = concat ! (
0 commit comments