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" ) ) ]
@@ -516,6 +518,7 @@ fn parse_alter_session(parser: &mut Parser, set: bool) -> Result<Statement, Pars
516
518
set,
517
519
session_params : KeyValueOptions {
518
520
options : session_options,
521
+ delimiter : KeyValueOptionsDelimiter :: Space ,
519
522
} ,
520
523
} )
521
524
}
@@ -777,19 +780,19 @@ pub fn parse_create_stage(
777
780
// [ directoryTableParams ]
778
781
if parser. parse_keyword ( Keyword :: DIRECTORY ) {
779
782
parser. expect_token ( & Token :: Eq ) ?;
780
- directory_table_params = parse_parentheses_options ( parser) ?;
783
+ directory_table_params = parser. parse_key_value_options ( true , & [ ] ) ?;
781
784
}
782
785
783
786
// [ file_format]
784
787
if parser. parse_keyword ( Keyword :: FILE_FORMAT ) {
785
788
parser. expect_token ( & Token :: Eq ) ?;
786
- file_format = parse_parentheses_options ( parser) ?;
789
+ file_format = parser. parse_key_value_options ( true , & [ ] ) ?;
787
790
}
788
791
789
792
// [ copy_options ]
790
793
if parser. parse_keyword ( Keyword :: COPY_OPTIONS ) {
791
794
parser. expect_token ( & Token :: Eq ) ?;
792
- copy_options = parse_parentheses_options ( parser) ?;
795
+ copy_options = parser. parse_key_value_options ( true , & [ ] ) ?;
793
796
}
794
797
795
798
// [ comment ]
@@ -806,12 +809,15 @@ pub fn parse_create_stage(
806
809
stage_params,
807
810
directory_table_params : KeyValueOptions {
808
811
options : directory_table_params,
812
+ delimiter : KeyValueOptionsDelimiter :: Space ,
809
813
} ,
810
814
file_format : KeyValueOptions {
811
815
options : file_format,
816
+ delimiter : KeyValueOptionsDelimiter :: Space ,
812
817
} ,
813
818
copy_options : KeyValueOptions {
814
819
options : copy_options,
820
+ delimiter : KeyValueOptionsDelimiter :: Space ,
815
821
} ,
816
822
comment,
817
823
} )
@@ -879,10 +885,16 @@ pub fn parse_copy_into(parser: &mut Parser) -> Result<Statement, ParserError> {
879
885
let mut from_stage = None ;
880
886
let mut stage_params = StageParamsObject {
881
887
url : None ,
882
- encryption : KeyValueOptions { options : vec ! [ ] } ,
888
+ encryption : KeyValueOptions {
889
+ options : vec ! [ ] ,
890
+ delimiter : KeyValueOptionsDelimiter :: Space ,
891
+ } ,
883
892
endpoint : None ,
884
893
storage_integration : None ,
885
- credentials : KeyValueOptions { options : vec ! [ ] } ,
894
+ credentials : KeyValueOptions {
895
+ options : vec ! [ ] ,
896
+ delimiter : KeyValueOptionsDelimiter :: Space ,
897
+ } ,
886
898
} ;
887
899
let mut from_query = None ;
888
900
let mut partition = None ;
@@ -944,7 +956,7 @@ pub fn parse_copy_into(parser: &mut Parser) -> Result<Statement, ParserError> {
944
956
// FILE_FORMAT
945
957
if parser. parse_keyword ( Keyword :: FILE_FORMAT ) {
946
958
parser. expect_token ( & Token :: Eq ) ?;
947
- file_format = parse_parentheses_options ( parser) ?;
959
+ file_format = parser. parse_key_value_options ( true , & [ ] ) ?;
948
960
// PARTITION BY
949
961
} else if parser. parse_keywords ( & [ Keyword :: PARTITION , Keyword :: BY ] ) {
950
962
partition = Some ( Box :: new ( parser. parse_expr ( ) ?) )
@@ -982,14 +994,14 @@ pub fn parse_copy_into(parser: &mut Parser) -> Result<Statement, ParserError> {
982
994
// COPY OPTIONS
983
995
} else if parser. parse_keyword ( Keyword :: COPY_OPTIONS ) {
984
996
parser. expect_token ( & Token :: Eq ) ?;
985
- copy_options = parse_parentheses_options ( parser) ?;
997
+ copy_options = parser. parse_key_value_options ( true , & [ ] ) ?;
986
998
} else {
987
999
match parser. next_token ( ) . token {
988
1000
Token :: SemiColon | Token :: EOF => break ,
989
1001
Token :: Comma => continue ,
990
1002
// In `COPY INTO <location>` the copy options do not have a shared key
991
1003
// like in `COPY INTO <table>`
992
- Token :: Word ( key) => copy_options. push ( parse_option ( parser, key) ?) ,
1004
+ Token :: Word ( key) => copy_options. push ( parser. parse_key_value_option ( key) ?) ,
993
1005
_ => return parser. expected ( "another copy option, ; or EOF'" , parser. peek_token ( ) ) ,
994
1006
}
995
1007
}
@@ -1008,9 +1020,11 @@ pub fn parse_copy_into(parser: &mut Parser) -> Result<Statement, ParserError> {
1008
1020
pattern,
1009
1021
file_format : KeyValueOptions {
1010
1022
options : file_format,
1023
+ delimiter : KeyValueOptionsDelimiter :: Space ,
1011
1024
} ,
1012
1025
copy_options : KeyValueOptions {
1013
1026
options : copy_options,
1027
+ delimiter : KeyValueOptionsDelimiter :: Space ,
1014
1028
} ,
1015
1029
validation_mode,
1016
1030
partition,
@@ -1110,8 +1124,14 @@ fn parse_select_item_for_data_load(
1110
1124
1111
1125
fn parse_stage_params ( parser : & mut Parser ) -> Result < StageParamsObject , ParserError > {
1112
1126
let ( mut url, mut storage_integration, mut endpoint) = ( None , None , None ) ;
1113
- let mut encryption: KeyValueOptions = KeyValueOptions { options : vec ! [ ] } ;
1114
- let mut credentials: KeyValueOptions = KeyValueOptions { options : vec ! [ ] } ;
1127
+ let mut encryption: KeyValueOptions = KeyValueOptions {
1128
+ options : vec ! [ ] ,
1129
+ delimiter : KeyValueOptionsDelimiter :: Space ,
1130
+ } ;
1131
+ let mut credentials: KeyValueOptions = KeyValueOptions {
1132
+ options : vec ! [ ] ,
1133
+ delimiter : KeyValueOptionsDelimiter :: Space ,
1134
+ } ;
1115
1135
1116
1136
// URL
1117
1137
if parser. parse_keyword ( Keyword :: URL ) {
@@ -1141,15 +1161,17 @@ fn parse_stage_params(parser: &mut Parser) -> Result<StageParamsObject, ParserEr
1141
1161
if parser. parse_keyword ( Keyword :: CREDENTIALS ) {
1142
1162
parser. expect_token ( & Token :: Eq ) ?;
1143
1163
credentials = KeyValueOptions {
1144
- options : parse_parentheses_options ( parser) ?,
1164
+ options : parser. parse_key_value_options ( true , & [ ] ) ?,
1165
+ delimiter : KeyValueOptionsDelimiter :: Space ,
1145
1166
} ;
1146
1167
}
1147
1168
1148
1169
// ENCRYPTION
1149
1170
if parser. parse_keyword ( Keyword :: ENCRYPTION ) {
1150
1171
parser. expect_token ( & Token :: Eq ) ?;
1151
1172
encryption = KeyValueOptions {
1152
- options : parse_parentheses_options ( parser) ?,
1173
+ options : parser. parse_key_value_options ( true , & [ ] ) ?,
1174
+ delimiter : KeyValueOptionsDelimiter :: Space ,
1153
1175
} ;
1154
1176
}
1155
1177
@@ -1183,7 +1205,7 @@ fn parse_session_options(
1183
1205
Token :: Word ( key) => {
1184
1206
parser. advance_token ( ) ;
1185
1207
if set {
1186
- let option = parse_option ( parser, key) ?;
1208
+ let option = parser. parse_key_value_option ( key) ?;
1187
1209
options. push ( option) ;
1188
1210
} else {
1189
1211
options. push ( KeyValueOption {
@@ -1207,63 +1229,6 @@ fn parse_session_options(
1207
1229
}
1208
1230
}
1209
1231
1210
- /// Parses options provided within parentheses like:
1211
- /// ( ENABLE = { TRUE | FALSE }
1212
- /// [ AUTO_REFRESH = { TRUE | FALSE } ]
1213
- /// [ REFRESH_ON_CREATE = { TRUE | FALSE } ]
1214
- /// [ NOTIFICATION_INTEGRATION = '<notification_integration_name>' ] )
1215
- ///
1216
- fn parse_parentheses_options ( parser : & mut Parser ) -> Result < Vec < KeyValueOption > , ParserError > {
1217
- let mut options: Vec < KeyValueOption > = Vec :: new ( ) ;
1218
- parser. expect_token ( & Token :: LParen ) ?;
1219
- loop {
1220
- match parser. next_token ( ) . token {
1221
- Token :: RParen => break ,
1222
- Token :: Comma => continue ,
1223
- Token :: Word ( key) => options. push ( parse_option ( parser, key) ?) ,
1224
- _ => return parser. expected ( "another option or ')'" , parser. peek_token ( ) ) ,
1225
- } ;
1226
- }
1227
- Ok ( options)
1228
- }
1229
-
1230
- /// Parses a `KEY = VALUE` construct based on the specified key
1231
- fn parse_option ( parser : & mut Parser , key : Word ) -> Result < KeyValueOption , ParserError > {
1232
- parser. expect_token ( & Token :: Eq ) ?;
1233
- if parser. parse_keyword ( Keyword :: TRUE ) {
1234
- Ok ( KeyValueOption {
1235
- option_name : key. value ,
1236
- option_type : KeyValueOptionType :: BOOLEAN ,
1237
- value : "TRUE" . to_string ( ) ,
1238
- } )
1239
- } else if parser. parse_keyword ( Keyword :: FALSE ) {
1240
- Ok ( KeyValueOption {
1241
- option_name : key. value ,
1242
- option_type : KeyValueOptionType :: BOOLEAN ,
1243
- value : "FALSE" . to_string ( ) ,
1244
- } )
1245
- } else {
1246
- match parser. next_token ( ) . token {
1247
- Token :: SingleQuotedString ( value) => Ok ( KeyValueOption {
1248
- option_name : key. value ,
1249
- option_type : KeyValueOptionType :: STRING ,
1250
- value,
1251
- } ) ,
1252
- Token :: Word ( word) => Ok ( KeyValueOption {
1253
- option_name : key. value ,
1254
- option_type : KeyValueOptionType :: ENUM ,
1255
- value : word. value ,
1256
- } ) ,
1257
- Token :: Number ( n, _) => Ok ( KeyValueOption {
1258
- option_name : key. value ,
1259
- option_type : KeyValueOptionType :: NUMBER ,
1260
- value : n,
1261
- } ) ,
1262
- _ => parser. expected ( "expected option value" , parser. peek_token ( ) ) ,
1263
- }
1264
- }
1265
- }
1266
-
1267
1232
/// Parsing a property of identity or autoincrement column option
1268
1233
/// Syntax:
1269
1234
/// ```sql
0 commit comments