@@ -11522,10 +11522,13 @@ fn parse_notify_channel() {
11522
11522
#[ test]
11523
11523
fn parse_load_data ( ) {
11524
11524
let dialects = all_dialects_where ( |d| d. supports_load_data ( ) ) ;
11525
+ let only_supports_load_extension_dialects =
11526
+ all_dialects_where ( |d| !d. supports_load_data ( ) && d. supports_load_extension ( ) ) ;
11527
+ let not_supports_load_dialects =
11528
+ all_dialects_where ( |d| !d. supports_load_data ( ) && !d. supports_load_extension ( ) ) ;
11525
11529
11526
- match dialects
11527
- . verified_stmt ( "LOAD DATA INPATH '/local/path/to/data.txt' INTO TABLE test.my_table" )
11528
- {
11530
+ let sql = "LOAD DATA INPATH '/local/path/to/data.txt' INTO TABLE test.my_table" ;
11531
+ match dialects. verified_stmt ( sql) {
11529
11532
Statement :: LoadData {
11530
11533
local,
11531
11534
inpath,
@@ -11548,9 +11551,8 @@ fn parse_load_data() {
11548
11551
} ;
11549
11552
11550
11553
// with OVERWRITE keyword
11551
- match dialects
11552
- . verified_stmt ( "LOAD DATA INPATH '/local/path/to/data.txt' OVERWRITE INTO TABLE my_table" )
11553
- {
11554
+ let sql = "LOAD DATA INPATH '/local/path/to/data.txt' OVERWRITE INTO TABLE my_table" ;
11555
+ match dialects. verified_stmt ( sql) {
11554
11556
Statement :: LoadData {
11555
11557
local,
11556
11558
inpath,
@@ -11569,10 +11571,19 @@ fn parse_load_data() {
11569
11571
_ => unreachable ! ( ) ,
11570
11572
} ;
11571
11573
11574
+ assert_eq ! (
11575
+ only_supports_load_extension_dialects
11576
+ . parse_sql_statements( sql)
11577
+ . unwrap_err( ) ,
11578
+ ParserError :: ParserError ( "Expected: end of statement, found: INPATH" . to_string( ) )
11579
+ ) ;
11580
+ assert_eq ! ( not_supports_load_dialects. parse_sql_statements( sql) . unwrap_err( ) ,
11581
+ ParserError :: ParserError ( "Expected: dialect supports `LOAD DATA` or `LOAD extension` to parse `LOAD` statements, found: INPATH" . to_string( ) )
11582
+ ) ;
11583
+
11572
11584
// with LOCAL keyword
11573
- match dialects
11574
- . verified_stmt ( "LOAD DATA LOCAL INPATH '/local/path/to/data.txt' INTO TABLE test.my_table" )
11575
- {
11585
+ let sql = "LOAD DATA LOCAL INPATH '/local/path/to/data.txt' INTO TABLE test.my_table" ;
11586
+ match dialects. verified_stmt ( sql) {
11576
11587
Statement :: LoadData {
11577
11588
local,
11578
11589
inpath,
@@ -11594,93 +11605,108 @@ fn parse_load_data() {
11594
11605
_ => unreachable ! ( ) ,
11595
11606
} ;
11596
11607
11608
+ assert_eq ! (
11609
+ only_supports_load_extension_dialects
11610
+ . parse_sql_statements( sql)
11611
+ . unwrap_err( ) ,
11612
+ ParserError :: ParserError ( "Expected: end of statement, found: LOCAL" . to_string( ) )
11613
+ ) ;
11614
+ assert_eq ! (
11615
+ not_supports_load_dialects. parse_sql_statements( sql) . unwrap_err( ) ,
11616
+ ParserError :: ParserError ( "Expected: dialect supports `LOAD DATA` or `LOAD extension` to parse `LOAD` statements, found: LOCAL" . to_string( ) )
11617
+ ) ;
11618
+
11597
11619
// with PARTITION clause
11598
- match dialects. verified_stmt ( "LOAD DATA LOCAL INPATH '/local/path/to/data.txt' INTO TABLE my_table PARTITION (year = 2024, month = 11)" ) {
11599
- Statement :: LoadData { local, inpath, overwrite, table_name, partitioned, table_format} => {
11620
+ let sql = "LOAD DATA LOCAL INPATH '/local/path/to/data.txt' INTO TABLE my_table PARTITION (year = 2024, month = 11)" ;
11621
+ match dialects. verified_stmt ( sql) {
11622
+ Statement :: LoadData {
11623
+ local,
11624
+ inpath,
11625
+ overwrite,
11626
+ table_name,
11627
+ partitioned,
11628
+ table_format,
11629
+ } => {
11600
11630
assert_eq ! ( true , local) ;
11601
11631
assert_eq ! ( "/local/path/to/data.txt" , inpath) ;
11602
11632
assert_eq ! ( false , overwrite) ;
11603
11633
assert_eq ! ( ObjectName ( vec![ Ident :: new( "my_table" ) ] ) , table_name) ;
11604
- assert_eq ! ( Some ( vec![
11605
- Expr :: BinaryOp {
11606
- left: Box :: new( Expr :: Identifier ( Ident :: new( "year" ) ) ) ,
11607
- op: BinaryOperator :: Eq ,
11608
- right: Box :: new( Expr :: Value ( Value :: Number ( "2024" . parse( ) . unwrap( ) , false ) ) ) ,
11609
- } ,
11610
- Expr :: BinaryOp {
11611
- left: Box :: new( Expr :: Identifier ( Ident :: new( "month" ) ) ) ,
11612
- op: BinaryOperator :: Eq ,
11613
- right: Box :: new( Expr :: Value ( Value :: Number ( "11" . parse( ) . unwrap( ) , false ) ) ) ,
11614
- } ] ) , partitioned) ;
11634
+ assert_eq ! (
11635
+ Some ( vec![
11636
+ Expr :: BinaryOp {
11637
+ left: Box :: new( Expr :: Identifier ( Ident :: new( "year" ) ) ) ,
11638
+ op: BinaryOperator :: Eq ,
11639
+ right: Box :: new( Expr :: Value ( Value :: Number ( "2024" . parse( ) . unwrap( ) , false ) ) ) ,
11640
+ } ,
11641
+ Expr :: BinaryOp {
11642
+ left: Box :: new( Expr :: Identifier ( Ident :: new( "month" ) ) ) ,
11643
+ op: BinaryOperator :: Eq ,
11644
+ right: Box :: new( Expr :: Value ( Value :: Number ( "11" . parse( ) . unwrap( ) , false ) ) ) ,
11645
+ }
11646
+ ] ) ,
11647
+ partitioned
11648
+ ) ;
11615
11649
assert_eq ! ( None , table_format) ;
11616
11650
}
11617
11651
_ => unreachable ! ( ) ,
11618
11652
} ;
11619
11653
11620
11654
// with PARTITION clause
11621
- 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'" ) {
11622
- Statement :: LoadData { local, inpath, overwrite, table_name, partitioned, table_format} => {
11623
- assert_eq ! ( true , local) ;
11624
- assert_eq ! ( "/local/path/to/data.txt" , inpath) ;
11625
- assert_eq ! ( true , overwrite) ;
11626
- assert_eq ! ( ObjectName ( vec![ Ident :: new( "good" ) , Ident :: new( "my_table" ) ] ) , table_name) ;
11627
- assert_eq ! ( Some ( vec![
11628
- Expr :: BinaryOp {
11655
+ let sql = "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'" ;
11656
+ match dialects. verified_stmt ( sql) {
11657
+ Statement :: LoadData {
11658
+ local,
11659
+ inpath,
11660
+ overwrite,
11661
+ table_name,
11662
+ partitioned,
11663
+ table_format,
11664
+ } => {
11665
+ assert_eq ! ( true , local) ;
11666
+ assert_eq ! ( "/local/path/to/data.txt" , inpath) ;
11667
+ assert_eq ! ( true , overwrite) ;
11668
+ assert_eq ! (
11669
+ ObjectName ( vec![ Ident :: new( "good" ) , Ident :: new( "my_table" ) ] ) ,
11670
+ table_name
11671
+ ) ;
11672
+ assert_eq ! (
11673
+ Some ( vec![
11674
+ Expr :: BinaryOp {
11629
11675
left: Box :: new( Expr :: Identifier ( Ident :: new( "year" ) ) ) ,
11630
11676
op: BinaryOperator :: Eq ,
11631
- right: Box :: new( Expr :: Value ( Value :: Number ( "2024" . parse( ) . unwrap( ) , false ) ) ) ,
11677
+ right: Box :: new( Expr :: Value ( Value :: Number ( "2024" . parse( ) . unwrap( ) , false ) ) ) ,
11632
11678
} ,
11633
- Expr :: BinaryOp {
11679
+ Expr :: BinaryOp {
11634
11680
left: Box :: new( Expr :: Identifier ( Ident :: new( "month" ) ) ) ,
11635
11681
op: BinaryOperator :: Eq ,
11636
- right: Box :: new( Expr :: Value ( Value :: Number ( "11" . parse( ) . unwrap( ) , false ) ) ) ,
11637
- } ] ) , partitioned) ;
11638
- assert_eq ! ( Some ( HiveLoadDataFormat { 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) ;
11639
- }
11640
- _ => unreachable ! ( ) ,
11641
- } ;
11682
+ right: Box :: new( Expr :: Value ( Value :: Number ( "11" . parse( ) . unwrap( ) , false ) ) ) ,
11683
+ }
11684
+ ] ) ,
11685
+ partitioned
11686
+ ) ;
11687
+ assert_eq ! (
11688
+ Some ( HiveLoadDataFormat {
11689
+ serde: Expr :: Value ( Value :: SingleQuotedString (
11690
+ "org.apache.hadoop.hive.serde2.OpenCSVSerde" . to_string( )
11691
+ ) ) ,
11692
+ input_format: Expr :: Value ( Value :: SingleQuotedString (
11693
+ "org.apache.hadoop.mapred.TextInputFormat" . to_string( )
11694
+ ) )
11695
+ } ) ,
11696
+ table_format
11697
+ ) ;
11698
+ }
11699
+ _ => unreachable ! ( ) ,
11700
+ } ;
11642
11701
11643
11702
// negative test case
11703
+ let sql = "LOAD DATA2 LOCAL INPATH '/local/path/to/data.txt' INTO TABLE test.my_table" ;
11644
11704
assert_eq ! (
11645
11705
dialects
11646
- . parse_sql_statements(
11647
- "LOAD DATA2 LOCAL INPATH '/local/path/to/data.txt' INTO TABLE test.my_table"
11648
- )
11706
+ . parse_sql_statements( sql)
11649
11707
. unwrap_err( ) ,
11650
11708
ParserError :: ParserError ( "Expected: dialect supports `LOAD DATA` or `LOAD extension` to parse `LOAD` statements, found: DATA2" . to_string( ) )
11651
11709
) ;
11652
-
11653
- let dialects = all_dialects_where ( |d| !d. supports_load_data ( ) && d. supports_load_extension ( ) ) ;
11654
-
11655
- assert_eq ! (
11656
- dialects
11657
- . parse_sql_statements(
11658
- "LOAD DATA LOCAL INPATH '/local/path/to/data.txt' INTO TABLE test.my_table"
11659
- )
11660
- . unwrap_err( ) ,
11661
- ParserError :: ParserError ( "Expected: end of statement, found: LOCAL" . to_string( ) )
11662
- ) ;
11663
-
11664
- assert_eq ! (
11665
- dialects
11666
- . parse_sql_statements(
11667
- "LOAD DATA INPATH '/local/path/to/data.txt' INTO TABLE test.my_table"
11668
- )
11669
- . unwrap_err( ) ,
11670
- ParserError :: ParserError ( "Expected: end of statement, found: INPATH" . to_string( ) )
11671
- ) ;
11672
-
11673
- let dialects = all_dialects_where ( |d| !d. supports_load_data ( ) && !d. supports_load_extension ( ) ) ;
11674
-
11675
- assert_eq ! (
11676
- dialects. parse_sql_statements( "LOAD DATA LOCAL INPATH '/local/path/to/data.txt' INTO TABLE test.my_table" ) . unwrap_err( ) ,
11677
- ParserError :: ParserError ( "Expected: dialect supports `LOAD DATA` or `LOAD extension` to parse `LOAD` statements, found: LOCAL" . to_string( ) )
11678
- ) ;
11679
-
11680
- assert_eq ! (
11681
- dialects. parse_sql_statements( "LOAD DATA INPATH '/local/path/to/data.txt' INTO TABLE test.my_table" ) . unwrap_err( ) ,
11682
- ParserError :: ParserError ( "Expected: dialect supports `LOAD DATA` or `LOAD extension` to parse `LOAD` statements, found: INPATH" . to_string( ) )
11683
- ) ;
11684
11710
}
11685
11711
11686
11712
#[ test]
0 commit comments