@@ -175,15 +175,9 @@ pub async fn configure(
175
175
if let Some ( column) = columns. into_iter ( ) . next ( ) {
176
176
if let Some ( value) = column. value {
177
177
if let serde_json:: Value :: String ( str) = value {
178
- match serde_json:: from_str :: < TablesInfo > ( & str) {
179
- Ok ( table_info_map) => {
180
- // tables_info.merge(table_info_map);
181
- Ok ( table_info_map)
182
- }
183
- Err ( err) => {
184
- Err ( format ! ( "Failed to deserialize TablesInfo from JSON: {err}" ) )
185
- }
186
- }
178
+ serde_json:: from_str :: < TablesInfo > ( & str) . map_err ( |err| {
179
+ format ! ( "Failed to deserialize TablesInfo from JSON: {err}" )
180
+ } )
187
181
} else {
188
182
Err ( format ! ( "Expected a string value, found: {value:?}" ) )
189
183
}
@@ -288,7 +282,7 @@ struct TypeItem {
288
282
}
289
283
290
284
fn get_aggregate_functions_for_type (
291
- type_representation : & Option < database:: TypeRepresentation > ,
285
+ type_representation : & Option < database:: BigQueryType > ,
292
286
type_name : & ScalarTypeName ,
293
287
) -> BTreeMap < AggregateFunctionName , database:: AggregateFunction > {
294
288
let mut aggregate_functions = BTreeMap :: new ( ) ;
@@ -297,15 +291,15 @@ fn get_aggregate_functions_for_type(
297
291
Some ( type_rep) => {
298
292
if matches ! (
299
293
type_rep,
300
- database:: TypeRepresentation :: Int64
301
- | database:: TypeRepresentation :: Float64
302
- | database:: TypeRepresentation :: Numeric
303
- | database:: TypeRepresentation :: BigNumeric
304
- | database:: TypeRepresentation :: String
305
- | database:: TypeRepresentation :: Date
306
- | database:: TypeRepresentation :: Datetime
307
- | database:: TypeRepresentation :: Timestamp
308
- | database:: TypeRepresentation :: Time
294
+ database:: BigQueryType :: Int64
295
+ | database:: BigQueryType :: Float64
296
+ | database:: BigQueryType :: Numeric
297
+ | database:: BigQueryType :: BigNumeric
298
+ | database:: BigQueryType :: String
299
+ | database:: BigQueryType :: Date
300
+ | database:: BigQueryType :: Datetime
301
+ | database:: BigQueryType :: Timestamp
302
+ | database:: BigQueryType :: Time
309
303
) {
310
304
aggregate_functions. insert (
311
305
AggregateFunctionName :: new ( "MIN" . into ( ) ) ,
@@ -323,10 +317,10 @@ fn get_aggregate_functions_for_type(
323
317
324
318
if matches ! (
325
319
type_rep,
326
- database:: TypeRepresentation :: Int64
327
- | database:: TypeRepresentation :: Float64
328
- | database:: TypeRepresentation :: Numeric
329
- | database:: TypeRepresentation :: BigNumeric
320
+ database:: BigQueryType :: Int64
321
+ | database:: BigQueryType :: Float64
322
+ | database:: BigQueryType :: Numeric
323
+ | database:: BigQueryType :: BigNumeric
330
324
) {
331
325
aggregate_functions. insert (
332
326
AggregateFunctionName :: new ( "AVG" . into ( ) ) ,
@@ -378,7 +372,6 @@ fn get_scalar_types(type_names: &Vec<TypeItem>, schema_name: String) -> database
378
372
aggregate_functions : get_aggregate_functions_for_type ( & type_rep, & scalar_type_name) ,
379
373
description : None ,
380
374
type_representation : type_rep. clone ( ) ,
381
- full_type_representation : type_rep. clone ( ) ,
382
375
} ,
383
376
) ;
384
377
}
@@ -390,7 +383,7 @@ fn get_scalar_types(type_names: &Vec<TypeItem>, schema_name: String) -> database
390
383
// we look up available types in `sys.types` but hard code their behaviour by looking them up below
391
384
// categories taken from https://learn.microsoft.com/en-us/sql/t-sql/data-types/data-types-transact-sql
392
385
fn get_comparison_operators_for_type (
393
- type_representation : & Option < database:: TypeRepresentation > ,
386
+ type_representation : & Option < database:: BigQueryType > ,
394
387
type_name : & ScalarTypeName ,
395
388
) -> BTreeMap < ComparisonOperatorName , database:: ComparisonOperator > {
396
389
let mut comparison_operators = BTreeMap :: new ( ) ;
@@ -399,11 +392,11 @@ fn get_comparison_operators_for_type(
399
392
Some ( type_rep) => {
400
393
if !matches ! (
401
394
type_rep,
402
- database:: TypeRepresentation :: Array ( _)
403
- | database:: TypeRepresentation :: Bytes
404
- | database:: TypeRepresentation :: Json
405
- | database:: TypeRepresentation :: Geography
406
- | database:: TypeRepresentation :: Struct ( _)
395
+ database:: BigQueryType :: Array ( _)
396
+ | database:: BigQueryType :: Bytes
397
+ | database:: BigQueryType :: Json
398
+ | database:: BigQueryType :: Geography
399
+ | database:: BigQueryType :: Struct ( _)
407
400
) {
408
401
comparison_operators. insert (
409
402
ComparisonOperatorName :: new ( "_eq" . into ( ) ) ,
@@ -428,7 +421,7 @@ fn get_comparison_operators_for_type(
428
421
429
422
if matches ! (
430
423
type_rep,
431
- database:: TypeRepresentation :: String | database:: TypeRepresentation :: Bytes
424
+ database:: BigQueryType :: String | database:: BigQueryType :: Bytes
432
425
) {
433
426
comparison_operators. insert (
434
427
ComparisonOperatorName :: new ( "_like" . into ( ) ) ,
@@ -452,11 +445,11 @@ fn get_comparison_operators_for_type(
452
445
453
446
if !matches ! (
454
447
type_rep,
455
- database:: TypeRepresentation :: Array ( _)
456
- | database:: TypeRepresentation :: Json
457
- | database:: TypeRepresentation :: Bytes
458
- | database:: TypeRepresentation :: Geography
459
- | database:: TypeRepresentation :: Struct ( _)
448
+ database:: BigQueryType :: Array ( _)
449
+ | database:: BigQueryType :: Json
450
+ | database:: BigQueryType :: Bytes
451
+ | database:: BigQueryType :: Geography
452
+ | database:: BigQueryType :: Struct ( _)
460
453
) {
461
454
comparison_operators. insert (
462
455
ComparisonOperatorName :: new ( "_neq" . into ( ) ) ,
@@ -512,21 +505,21 @@ fn get_comparison_operators_for_type(
512
505
comparison_operators
513
506
}
514
507
515
- fn get_type_representation ( type_item : & TypeItem ) -> Option < database:: TypeRepresentation > {
508
+ fn get_type_representation ( type_item : & TypeItem ) -> Option < database:: BigQueryType > {
516
509
match type_item. name . as_str ( ) . to_lowercase ( ) . as_str ( ) {
517
- "string" => Some ( database:: TypeRepresentation :: String ) ,
518
- "bytes" => Some ( database:: TypeRepresentation :: Bytes ) ,
519
- "int64" => Some ( database:: TypeRepresentation :: Int64 ) ,
520
- "float64" => Some ( database:: TypeRepresentation :: Float64 ) ,
521
- "bool" => Some ( database:: TypeRepresentation :: Boolean ) ,
522
- "numeric" => Some ( database:: TypeRepresentation :: Numeric ) ,
523
- "bignumeric" => Some ( database:: TypeRepresentation :: BigNumeric ) ,
524
- "geography" => Some ( database:: TypeRepresentation :: Geography ) ,
525
- "date" => Some ( database:: TypeRepresentation :: Date ) ,
526
- "datetime" => Some ( database:: TypeRepresentation :: Datetime ) ,
527
- "time" => Some ( database:: TypeRepresentation :: Time ) ,
528
- "timestamp" => Some ( database:: TypeRepresentation :: Timestamp ) ,
529
- "json" => Some ( database:: TypeRepresentation :: Json ) ,
510
+ "string" => Some ( database:: BigQueryType :: String ) ,
511
+ "bytes" => Some ( database:: BigQueryType :: Bytes ) ,
512
+ "int64" => Some ( database:: BigQueryType :: Int64 ) ,
513
+ "float64" => Some ( database:: BigQueryType :: Float64 ) ,
514
+ "bool" => Some ( database:: BigQueryType :: Boolean ) ,
515
+ "numeric" => Some ( database:: BigQueryType :: Numeric ) ,
516
+ "bignumeric" => Some ( database:: BigQueryType :: BigNumeric ) ,
517
+ "geography" => Some ( database:: BigQueryType :: Geography ) ,
518
+ "date" => Some ( database:: BigQueryType :: Date ) ,
519
+ "datetime" => Some ( database:: BigQueryType :: Datetime ) ,
520
+ "time" => Some ( database:: BigQueryType :: Time ) ,
521
+ "timestamp" => Some ( database:: BigQueryType :: Timestamp ) ,
522
+ "json" => Some ( database:: BigQueryType :: Json ) ,
530
523
t if t. starts_with ( "range<" ) => {
531
524
let inner_type = t. trim_start_matches ( "range<" ) . trim_end_matches ( '>' ) ;
532
525
let range_type = match inner_type {
@@ -535,15 +528,15 @@ fn get_type_representation(type_item: &TypeItem) -> Option<database::TypeReprese
535
528
"timestamp" => database:: TypeRange :: Timestamp ,
536
529
_ => database:: TypeRange :: Date , // Default to Date if unrecognized
537
530
} ;
538
- Some ( database:: TypeRepresentation :: Range ( Box :: new ( range_type) ) )
531
+ Some ( database:: BigQueryType :: Range ( Box :: new ( range_type) ) )
539
532
}
540
533
t if t. starts_with ( "array<" ) => {
541
534
let inner_type = t. trim_start_matches ( "array<" ) . trim_end_matches ( '>' ) ;
542
535
let inner_repr = get_type_representation ( & TypeItem {
543
536
name : ScalarTypeName :: new ( inner_type. into ( ) ) ,
544
537
} )
545
- . unwrap_or ( database:: TypeRepresentation :: String ) ;
546
- Some ( database:: TypeRepresentation :: Array ( Box :: new ( inner_repr) ) )
538
+ . unwrap_or ( database:: BigQueryType :: String ) ;
539
+ Some ( database:: BigQueryType :: Array ( Box :: new ( inner_repr) ) )
547
540
}
548
541
t if t. starts_with ( "struct<" ) => {
549
542
let fields = t. trim_start_matches ( "struct<" ) . trim_end_matches ( '>' ) ;
@@ -555,11 +548,11 @@ fn get_type_representation(type_item: &TypeItem) -> Option<database::TypeReprese
555
548
let field_type = get_type_representation ( & TypeItem {
556
549
name : ScalarTypeName :: new ( parts[ 1 ] . into ( ) ) ,
557
550
} )
558
- . unwrap_or ( database:: TypeRepresentation :: String ) ;
551
+ . unwrap_or ( database:: BigQueryType :: String ) ;
559
552
struct_fields. insert ( field_name, Box :: new ( field_type) ) ;
560
553
}
561
554
}
562
- Some ( database:: TypeRepresentation :: Struct ( struct_fields) )
555
+ Some ( database:: BigQueryType :: Struct ( struct_fields) )
563
556
}
564
557
_ => None ,
565
558
}
0 commit comments