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