17
17
18
18
#[ cfg( not( feature = "std" ) ) ]
19
19
use crate :: alloc:: string:: ToString ;
20
- use crate :: ast:: helpers:: key_value_options:: { KeyValueOption , KeyValueOptionType , KeyValueOptions } ;
20
+ use crate :: ast:: helpers:: key_value_options:: {
21
+ KeyValueOption , KeyValueOptionType , KeyValueOptions , KeyValueOptionsDelimiter ,
22
+ } ;
21
23
use crate :: ast:: helpers:: stmt_create_table:: CreateTableBuilder ;
22
24
use crate :: ast:: helpers:: stmt_data_loading:: {
23
25
FileStagingCommand , StageLoadSelectItem , StageLoadSelectItemKind , StageParamsObject ,
@@ -31,7 +33,7 @@ use crate::ast::{
31
33
use crate :: dialect:: { Dialect , Precedence } ;
32
34
use crate :: keywords:: Keyword ;
33
35
use crate :: parser:: { IsOptional , Parser , ParserError } ;
34
- use crate :: tokenizer:: { Token , Word } ;
36
+ use crate :: tokenizer:: Token ;
35
37
#[ cfg( not( feature = "std" ) ) ]
36
38
use alloc:: boxed:: Box ;
37
39
#[ cfg( not( feature = "std" ) ) ]
@@ -500,6 +502,7 @@ fn parse_alter_session(parser: &mut Parser, set: bool) -> Result<Statement, Pars
500
502
set,
501
503
session_params : KeyValueOptions {
502
504
options : session_options,
505
+ delimiter : KeyValueOptionsDelimiter :: Space ,
503
506
} ,
504
507
} )
505
508
}
@@ -761,19 +764,19 @@ pub fn parse_create_stage(
761
764
// [ directoryTableParams ]
762
765
if parser. parse_keyword ( Keyword :: DIRECTORY ) {
763
766
parser. expect_token ( & Token :: Eq ) ?;
764
- directory_table_params = parse_parentheses_options ( parser) ?;
767
+ directory_table_params = parser. parse_key_value_options ( true , & [ ] ) ?;
765
768
}
766
769
767
770
// [ file_format]
768
771
if parser. parse_keyword ( Keyword :: FILE_FORMAT ) {
769
772
parser. expect_token ( & Token :: Eq ) ?;
770
- file_format = parse_parentheses_options ( parser) ?;
773
+ file_format = parser. parse_key_value_options ( true , & [ ] ) ?;
771
774
}
772
775
773
776
// [ copy_options ]
774
777
if parser. parse_keyword ( Keyword :: COPY_OPTIONS ) {
775
778
parser. expect_token ( & Token :: Eq ) ?;
776
- copy_options = parse_parentheses_options ( parser) ?;
779
+ copy_options = parser. parse_key_value_options ( true , & [ ] ) ?;
777
780
}
778
781
779
782
// [ comment ]
@@ -790,12 +793,15 @@ pub fn parse_create_stage(
790
793
stage_params,
791
794
directory_table_params : KeyValueOptions {
792
795
options : directory_table_params,
796
+ delimiter : KeyValueOptionsDelimiter :: Space ,
793
797
} ,
794
798
file_format : KeyValueOptions {
795
799
options : file_format,
800
+ delimiter : KeyValueOptionsDelimiter :: Space ,
796
801
} ,
797
802
copy_options : KeyValueOptions {
798
803
options : copy_options,
804
+ delimiter : KeyValueOptionsDelimiter :: Space ,
799
805
} ,
800
806
comment,
801
807
} )
@@ -863,10 +869,16 @@ pub fn parse_copy_into(parser: &mut Parser) -> Result<Statement, ParserError> {
863
869
let mut from_stage = None ;
864
870
let mut stage_params = StageParamsObject {
865
871
url : None ,
866
- encryption : KeyValueOptions { options : vec ! [ ] } ,
872
+ encryption : KeyValueOptions {
873
+ options : vec ! [ ] ,
874
+ delimiter : KeyValueOptionsDelimiter :: Space ,
875
+ } ,
867
876
endpoint : None ,
868
877
storage_integration : None ,
869
- credentials : KeyValueOptions { options : vec ! [ ] } ,
878
+ credentials : KeyValueOptions {
879
+ options : vec ! [ ] ,
880
+ delimiter : KeyValueOptionsDelimiter :: Space ,
881
+ } ,
870
882
} ;
871
883
let mut from_query = None ;
872
884
let mut partition = None ;
@@ -928,7 +940,7 @@ pub fn parse_copy_into(parser: &mut Parser) -> Result<Statement, ParserError> {
928
940
// FILE_FORMAT
929
941
if parser. parse_keyword ( Keyword :: FILE_FORMAT ) {
930
942
parser. expect_token ( & Token :: Eq ) ?;
931
- file_format = parse_parentheses_options ( parser) ?;
943
+ file_format = parser. parse_key_value_options ( true , & [ ] ) ?;
932
944
// PARTITION BY
933
945
} else if parser. parse_keywords ( & [ Keyword :: PARTITION , Keyword :: BY ] ) {
934
946
partition = Some ( Box :: new ( parser. parse_expr ( ) ?) )
@@ -966,14 +978,14 @@ pub fn parse_copy_into(parser: &mut Parser) -> Result<Statement, ParserError> {
966
978
// COPY OPTIONS
967
979
} else if parser. parse_keyword ( Keyword :: COPY_OPTIONS ) {
968
980
parser. expect_token ( & Token :: Eq ) ?;
969
- copy_options = parse_parentheses_options ( parser) ?;
981
+ copy_options = parser. parse_key_value_options ( true , & [ ] ) ?;
970
982
} else {
971
983
match parser. next_token ( ) . token {
972
984
Token :: SemiColon | Token :: EOF => break ,
973
985
Token :: Comma => continue ,
974
986
// In `COPY INTO <location>` the copy options do not have a shared key
975
987
// like in `COPY INTO <table>`
976
- Token :: Word ( key) => copy_options. push ( parse_option ( parser, key) ?) ,
988
+ Token :: Word ( key) => copy_options. push ( parser. parse_key_value_option ( key) ?) ,
977
989
_ => return parser. expected ( "another copy option, ; or EOF'" , parser. peek_token ( ) ) ,
978
990
}
979
991
}
@@ -992,9 +1004,11 @@ pub fn parse_copy_into(parser: &mut Parser) -> Result<Statement, ParserError> {
992
1004
pattern,
993
1005
file_format : KeyValueOptions {
994
1006
options : file_format,
1007
+ delimiter : KeyValueOptionsDelimiter :: Space ,
995
1008
} ,
996
1009
copy_options : KeyValueOptions {
997
1010
options : copy_options,
1011
+ delimiter : KeyValueOptionsDelimiter :: Space ,
998
1012
} ,
999
1013
validation_mode,
1000
1014
partition,
@@ -1094,8 +1108,14 @@ fn parse_select_item_for_data_load(
1094
1108
1095
1109
fn parse_stage_params ( parser : & mut Parser ) -> Result < StageParamsObject , ParserError > {
1096
1110
let ( mut url, mut storage_integration, mut endpoint) = ( None , None , None ) ;
1097
- let mut encryption: KeyValueOptions = KeyValueOptions { options : vec ! [ ] } ;
1098
- let mut credentials: KeyValueOptions = KeyValueOptions { options : vec ! [ ] } ;
1111
+ let mut encryption: KeyValueOptions = KeyValueOptions {
1112
+ options : vec ! [ ] ,
1113
+ delimiter : KeyValueOptionsDelimiter :: Space ,
1114
+ } ;
1115
+ let mut credentials: KeyValueOptions = KeyValueOptions {
1116
+ options : vec ! [ ] ,
1117
+ delimiter : KeyValueOptionsDelimiter :: Space ,
1118
+ } ;
1099
1119
1100
1120
// URL
1101
1121
if parser. parse_keyword ( Keyword :: URL ) {
@@ -1125,15 +1145,17 @@ fn parse_stage_params(parser: &mut Parser) -> Result<StageParamsObject, ParserEr
1125
1145
if parser. parse_keyword ( Keyword :: CREDENTIALS ) {
1126
1146
parser. expect_token ( & Token :: Eq ) ?;
1127
1147
credentials = KeyValueOptions {
1128
- options : parse_parentheses_options ( parser) ?,
1148
+ options : parser. parse_key_value_options ( true , & [ ] ) ?,
1149
+ delimiter : KeyValueOptionsDelimiter :: Space ,
1129
1150
} ;
1130
1151
}
1131
1152
1132
1153
// ENCRYPTION
1133
1154
if parser. parse_keyword ( Keyword :: ENCRYPTION ) {
1134
1155
parser. expect_token ( & Token :: Eq ) ?;
1135
1156
encryption = KeyValueOptions {
1136
- options : parse_parentheses_options ( parser) ?,
1157
+ options : parser. parse_key_value_options ( true , & [ ] ) ?,
1158
+ delimiter : KeyValueOptionsDelimiter :: Space ,
1137
1159
} ;
1138
1160
}
1139
1161
@@ -1167,7 +1189,7 @@ fn parse_session_options(
1167
1189
Token :: Word ( key) => {
1168
1190
parser. advance_token ( ) ;
1169
1191
if set {
1170
- let option = parse_option ( parser, key) ?;
1192
+ let option = parser. parse_key_value_option ( key) ?;
1171
1193
options. push ( option) ;
1172
1194
} else {
1173
1195
options. push ( KeyValueOption {
@@ -1191,63 +1213,6 @@ fn parse_session_options(
1191
1213
}
1192
1214
}
1193
1215
1194
- /// Parses options provided within parentheses like:
1195
- /// ( ENABLE = { TRUE | FALSE }
1196
- /// [ AUTO_REFRESH = { TRUE | FALSE } ]
1197
- /// [ REFRESH_ON_CREATE = { TRUE | FALSE } ]
1198
- /// [ NOTIFICATION_INTEGRATION = '<notification_integration_name>' ] )
1199
- ///
1200
- fn parse_parentheses_options ( parser : & mut Parser ) -> Result < Vec < KeyValueOption > , ParserError > {
1201
- let mut options: Vec < KeyValueOption > = Vec :: new ( ) ;
1202
- parser. expect_token ( & Token :: LParen ) ?;
1203
- loop {
1204
- match parser. next_token ( ) . token {
1205
- Token :: RParen => break ,
1206
- Token :: Comma => continue ,
1207
- Token :: Word ( key) => options. push ( parse_option ( parser, key) ?) ,
1208
- _ => return parser. expected ( "another option or ')'" , parser. peek_token ( ) ) ,
1209
- } ;
1210
- }
1211
- Ok ( options)
1212
- }
1213
-
1214
- /// Parses a `KEY = VALUE` construct based on the specified key
1215
- fn parse_option ( parser : & mut Parser , key : Word ) -> Result < KeyValueOption , ParserError > {
1216
- parser. expect_token ( & Token :: Eq ) ?;
1217
- if parser. parse_keyword ( Keyword :: TRUE ) {
1218
- Ok ( KeyValueOption {
1219
- option_name : key. value ,
1220
- option_type : KeyValueOptionType :: BOOLEAN ,
1221
- value : "TRUE" . to_string ( ) ,
1222
- } )
1223
- } else if parser. parse_keyword ( Keyword :: FALSE ) {
1224
- Ok ( KeyValueOption {
1225
- option_name : key. value ,
1226
- option_type : KeyValueOptionType :: BOOLEAN ,
1227
- value : "FALSE" . to_string ( ) ,
1228
- } )
1229
- } else {
1230
- match parser. next_token ( ) . token {
1231
- Token :: SingleQuotedString ( value) => Ok ( KeyValueOption {
1232
- option_name : key. value ,
1233
- option_type : KeyValueOptionType :: STRING ,
1234
- value,
1235
- } ) ,
1236
- Token :: Word ( word) => Ok ( KeyValueOption {
1237
- option_name : key. value ,
1238
- option_type : KeyValueOptionType :: ENUM ,
1239
- value : word. value ,
1240
- } ) ,
1241
- Token :: Number ( n, _) => Ok ( KeyValueOption {
1242
- option_name : key. value ,
1243
- option_type : KeyValueOptionType :: NUMBER ,
1244
- value : n,
1245
- } ) ,
1246
- _ => parser. expected ( "expected option value" , parser. peek_token ( ) ) ,
1247
- }
1248
- }
1249
- }
1250
-
1251
1216
/// Parsing a property of identity or autoincrement column option
1252
1217
/// Syntax:
1253
1218
/// ```sql
0 commit comments