@@ -83,15 +83,14 @@ impl JsonEncoder {
83
83
pub fn new_with_doris (
84
84
schema : Schema ,
85
85
col_indices : Option < Vec < usize > > ,
86
- timestamp_handling_mode : TimestampHandlingMode ,
87
86
map : HashMap < String , ( u8 , u8 ) > ,
88
87
) -> Self {
89
88
Self {
90
89
schema,
91
90
col_indices,
92
91
time_handling_mode : TimeHandlingMode :: Milli ,
93
92
date_handling_mode : DateHandlingMode :: String ,
94
- timestamp_handling_mode,
93
+ timestamp_handling_mode : TimestampHandlingMode :: String ,
95
94
timestamptz_handling_mode : TimestamptzHandlingMode :: UtcWithoutSuffix ,
96
95
custom_json_type : CustomJsonType :: Doris ( map) ,
97
96
kafka_connect : None ,
@@ -101,21 +100,33 @@ impl JsonEncoder {
101
100
pub fn new_with_starrocks (
102
101
schema : Schema ,
103
102
col_indices : Option < Vec < usize > > ,
104
- timestamp_handling_mode : TimestampHandlingMode ,
105
103
map : HashMap < String , ( u8 , u8 ) > ,
106
104
) -> Self {
107
105
Self {
108
106
schema,
109
107
col_indices,
110
108
time_handling_mode : TimeHandlingMode :: Milli ,
111
109
date_handling_mode : DateHandlingMode :: String ,
112
- timestamp_handling_mode,
110
+ timestamp_handling_mode : TimestampHandlingMode :: String ,
113
111
timestamptz_handling_mode : TimestamptzHandlingMode :: UtcWithoutSuffix ,
114
112
custom_json_type : CustomJsonType :: StarRocks ( map) ,
115
113
kafka_connect : None ,
116
114
}
117
115
}
118
116
117
+ pub fn new_with_bigquery ( schema : Schema , col_indices : Option < Vec < usize > > ) -> Self {
118
+ Self {
119
+ schema,
120
+ col_indices,
121
+ time_handling_mode : TimeHandlingMode :: Milli ,
122
+ date_handling_mode : DateHandlingMode :: String ,
123
+ timestamp_handling_mode : TimestampHandlingMode :: String ,
124
+ timestamptz_handling_mode : TimestamptzHandlingMode :: UtcString ,
125
+ custom_json_type : CustomJsonType :: BigQuery ,
126
+ kafka_connect : None ,
127
+ }
128
+ }
129
+
119
130
pub fn with_kafka_connect ( self , kafka_connect : KafkaConnectParams ) -> Self {
120
131
Self {
121
132
kafka_connect : Some ( Arc :: new ( kafka_connect) ) ,
@@ -192,7 +203,16 @@ fn datum_to_json_object(
192
203
custom_json_type : & CustomJsonType ,
193
204
) -> ArrayResult < Value > {
194
205
let scalar_ref = match datum {
195
- None => return Ok ( Value :: Null ) ,
206
+ None => {
207
+ if let CustomJsonType :: BigQuery = custom_json_type
208
+ && matches ! ( field. data_type( ) , DataType :: List ( _) )
209
+ {
210
+ // Bigquery need to convert null of array to empty array https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types
211
+ return Ok ( Value :: Array ( vec ! [ ] ) ) ;
212
+ } else {
213
+ return Ok ( Value :: Null ) ;
214
+ }
215
+ }
196
216
Some ( datum) => datum,
197
217
} ;
198
218
@@ -239,7 +259,7 @@ fn datum_to_json_object(
239
259
}
240
260
json ! ( v_string)
241
261
}
242
- CustomJsonType :: Es | CustomJsonType :: None => {
262
+ CustomJsonType :: Es | CustomJsonType :: None | CustomJsonType :: BigQuery => {
243
263
json ! ( v. to_text( ) )
244
264
}
245
265
} ,
@@ -291,7 +311,7 @@ fn datum_to_json_object(
291
311
}
292
312
( DataType :: Jsonb , ScalarRefImpl :: Jsonb ( jsonb_ref) ) => match custom_json_type {
293
313
CustomJsonType :: Es | CustomJsonType :: StarRocks ( _) => JsonbVal :: from ( jsonb_ref) . take ( ) ,
294
- CustomJsonType :: Doris ( _) | CustomJsonType :: None => {
314
+ CustomJsonType :: Doris ( _) | CustomJsonType :: None | CustomJsonType :: BigQuery => {
295
315
json ! ( jsonb_ref. to_string( ) )
296
316
}
297
317
} ,
@@ -342,7 +362,7 @@ fn datum_to_json_object(
342
362
"starrocks can't support struct" . to_string ( ) ,
343
363
) ) ;
344
364
}
345
- CustomJsonType :: Es | CustomJsonType :: None => {
365
+ CustomJsonType :: Es | CustomJsonType :: None | CustomJsonType :: BigQuery => {
346
366
let mut map = Map :: with_capacity ( st. len ( ) ) ;
347
367
for ( sub_datum_ref, sub_field) in struct_ref. iter_fields_ref ( ) . zip_eq_debug (
348
368
st. iter ( )
0 commit comments