@@ -11523,6 +11523,160 @@ fn parse_notify_channel() {
1152311523 }
1152411524}
1152511525
11526+ #[ test]
11527+ fn parse_load_data ( ) {
11528+ let dialects = all_dialects_where ( |d| d. supports_load_data ( ) ) ;
11529+
11530+ match dialects
11531+ . verified_stmt ( "LOAD DATA INPATH '/local/path/to/data.txt' INTO TABLE test.my_table" )
11532+ {
11533+ Statement :: LoadData {
11534+ local,
11535+ inpath,
11536+ overwrite,
11537+ table_name,
11538+ partitioned,
11539+ table_format,
11540+ } => {
11541+ assert_eq ! ( false , local) ;
11542+ assert_eq ! ( "/local/path/to/data.txt" , inpath) ;
11543+ assert_eq ! ( false , overwrite) ;
11544+ assert_eq ! (
11545+ ObjectName ( vec![ Ident :: new( "test" ) , Ident :: new( "my_table" ) ] ) ,
11546+ table_name
11547+ ) ;
11548+ assert_eq ! ( None , partitioned) ;
11549+ assert_eq ! ( None , table_format) ;
11550+ }
11551+ _ => unreachable ! ( ) ,
11552+ } ;
11553+
11554+ // with OVERWRITE keyword
11555+ match dialects
11556+ . verified_stmt ( "LOAD DATA INPATH '/local/path/to/data.txt' OVERWRITE INTO TABLE my_table" )
11557+ {
11558+ Statement :: LoadData {
11559+ local,
11560+ inpath,
11561+ overwrite,
11562+ table_name,
11563+ partitioned,
11564+ table_format,
11565+ } => {
11566+ assert_eq ! ( false , local) ;
11567+ assert_eq ! ( "/local/path/to/data.txt" , inpath) ;
11568+ assert_eq ! ( true , overwrite) ;
11569+ assert_eq ! ( ObjectName ( vec![ Ident :: new( "my_table" ) ] ) , table_name) ;
11570+ assert_eq ! ( None , partitioned) ;
11571+ assert_eq ! ( None , table_format) ;
11572+ }
11573+ _ => unreachable ! ( ) ,
11574+ } ;
11575+
11576+ // with LOCAL keyword
11577+ match dialects
11578+ . verified_stmt ( "LOAD DATA LOCAL INPATH '/local/path/to/data.txt' INTO TABLE test.my_table" )
11579+ {
11580+ Statement :: LoadData {
11581+ local,
11582+ inpath,
11583+ overwrite,
11584+ table_name,
11585+ partitioned,
11586+ table_format,
11587+ } => {
11588+ assert_eq ! ( true , local) ;
11589+ assert_eq ! ( "/local/path/to/data.txt" , inpath) ;
11590+ assert_eq ! ( false , overwrite) ;
11591+ assert_eq ! (
11592+ ObjectName ( vec![ Ident :: new( "test" ) , Ident :: new( "my_table" ) ] ) ,
11593+ table_name
11594+ ) ;
11595+ assert_eq ! ( None , partitioned) ;
11596+ assert_eq ! ( None , table_format) ;
11597+ }
11598+ _ => unreachable ! ( ) ,
11599+ } ;
11600+
11601+ // with PARTITION clause
11602+ match dialects. verified_stmt ( "LOAD DATA LOCAL INPATH '/local/path/to/data.txt' INTO TABLE my_table PARTITION (year = 2024, month = 11)" ) {
11603+ Statement :: LoadData { local, inpath, overwrite, table_name, partitioned, table_format} => {
11604+ assert_eq ! ( true , local) ;
11605+ assert_eq ! ( "/local/path/to/data.txt" , inpath) ;
11606+ assert_eq ! ( false , overwrite) ;
11607+ assert_eq ! ( ObjectName ( vec![ Ident :: new( "my_table" ) ] ) , table_name) ;
11608+ assert_eq ! ( Some ( vec![
11609+ Expr :: BinaryOp {
11610+ left: Box :: new( Expr :: Identifier ( Ident :: new( "year" ) ) ) ,
11611+ op: BinaryOperator :: Eq ,
11612+ right: Box :: new( Expr :: Value ( Value :: Number ( "2024" . parse( ) . unwrap( ) , false ) ) ) ,
11613+ } ,
11614+ Expr :: BinaryOp {
11615+ left: Box :: new( Expr :: Identifier ( Ident :: new( "month" ) ) ) ,
11616+ op: BinaryOperator :: Eq ,
11617+ right: Box :: new( Expr :: Value ( Value :: Number ( "11" . parse( ) . unwrap( ) , false ) ) ) ,
11618+ } ] ) , partitioned) ;
11619+ assert_eq ! ( None , table_format) ;
11620+ }
11621+ _ => unreachable ! ( ) ,
11622+ } ;
11623+
11624+ // with PARTITION clause
11625+ match dialects. verified_stmt ( "LOAD DATA LOCAL INPATH '/local/path/to/data.txt' OVERWRITE INTO TABLE good.my_table PARTITION (year = 2024, month = 11) INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat' SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'" ) {
11626+ Statement :: LoadData { local, inpath, overwrite, table_name, partitioned, table_format} => {
11627+ assert_eq ! ( true , local) ;
11628+ assert_eq ! ( "/local/path/to/data.txt" , inpath) ;
11629+ assert_eq ! ( true , overwrite) ;
11630+ assert_eq ! ( ObjectName ( vec![ Ident :: new( "good" ) , Ident :: new( "my_table" ) ] ) , table_name) ;
11631+ assert_eq ! ( Some ( vec![
11632+ Expr :: BinaryOp {
11633+ left: Box :: new( Expr :: Identifier ( Ident :: new( "year" ) ) ) ,
11634+ op: BinaryOperator :: Eq ,
11635+ right: Box :: new( Expr :: Value ( Value :: Number ( "2024" . parse( ) . unwrap( ) , false ) ) ) ,
11636+ } ,
11637+ Expr :: BinaryOp {
11638+ left: Box :: new( Expr :: Identifier ( Ident :: new( "month" ) ) ) ,
11639+ op: BinaryOperator :: Eq ,
11640+ right: Box :: new( Expr :: Value ( Value :: Number ( "11" . parse( ) . unwrap( ) , false ) ) ) ,
11641+ } ] ) , partitioned) ;
11642+ assert_eq ! ( Some ( HiveLoadDataOption { serde: Expr :: Value ( Value :: SingleQuotedString ( "org.apache.hadoop.hive.serde2.OpenCSVSerde" . to_string( ) ) ) , input_format: Expr :: Value ( Value :: SingleQuotedString ( "org.apache.hadoop.mapred.TextInputFormat" . to_string( ) ) ) } ) , table_format) ;
11643+ }
11644+ _ => unreachable ! ( ) ,
11645+ } ;
11646+
11647+ let dialects = all_dialects_where ( |d| !d. supports_load_data ( ) && d. supports_load_extension ( ) ) ;
11648+
11649+ assert_eq ! (
11650+ dialects
11651+ . parse_sql_statements(
11652+ "LOAD DATA LOCAL INPATH '/local/path/to/data.txt' INTO TABLE test.my_table"
11653+ )
11654+ . unwrap_err( ) ,
11655+ ParserError :: ParserError ( "Expected: end of statement, found: LOCAL" . to_string( ) )
11656+ ) ;
11657+
11658+ assert_eq ! (
11659+ dialects
11660+ . parse_sql_statements(
11661+ "LOAD DATA INPATH '/local/path/to/data.txt' INTO TABLE test.my_table"
11662+ )
11663+ . unwrap_err( ) ,
11664+ ParserError :: ParserError ( "Expected: end of statement, found: INPATH" . to_string( ) )
11665+ ) ;
11666+
11667+ let dialects = all_dialects_where ( |d| !d. supports_load_data ( ) && !d. supports_load_extension ( ) ) ;
11668+
11669+ assert_eq ! (
11670+ dialects. parse_sql_statements( "LOAD DATA LOCAL INPATH '/local/path/to/data.txt' INTO TABLE test.my_table" ) . unwrap_err( ) ,
11671+ ParserError :: ParserError ( "Expected: Expected: dialect supports `LOAD DATA` or `LOAD extension` to parse `LOAD` statements, found: LOCAL" . to_string( ) )
11672+ ) ;
11673+
11674+ assert_eq ! (
11675+ dialects. parse_sql_statements( "LOAD DATA INPATH '/local/path/to/data.txt' INTO TABLE test.my_table" ) . unwrap_err( ) ,
11676+ ParserError :: ParserError ( "Expected: Expected: dialect supports `LOAD DATA` or `LOAD extension` to parse `LOAD` statements, found: INPATH" . to_string( ) )
11677+ ) ;
11678+ }
11679+
1152611680#[ test]
1152711681fn test_select_top ( ) {
1152811682 let dialects = all_dialects_where ( |d| d. supports_top_before_distinct ( ) ) ;
0 commit comments