@@ -4,6 +4,7 @@ package planner
4
4
5
5
import (
6
6
"bufio"
7
+ "bytes"
7
8
"context"
8
9
"encoding/csv"
9
10
"encoding/json"
@@ -320,7 +321,7 @@ func (i *bulkInsertSourceCSVRowIter) Next(ctx context.Context) (types.Row, error
320
321
return nil , sql3 .NewErrTypeConversionOnMap (0 , 0 , evalValue , mapColumn .colType .TypeDescription ())
321
322
}
322
323
} else {
323
- //implicit conversion of int to timestamp will treat int as seconds since unix epoch
324
+ // implicit conversion of int to timestamp will treat int as seconds since unix epoch
324
325
result [idx ] = time .Unix (intVal , 0 ).UTC ()
325
326
}
326
327
@@ -448,7 +449,6 @@ func (i *bulkInsertSourceNDJsonRowIter) Next(ctx context.Context) (types.Row, er
448
449
return nil , sql3 .NewErrInternalf ("unexpected type for mapValue '%T'" , rawMapValue )
449
450
}
450
451
i .mapExpressionResults = append (i .mapExpressionResults , mapValue )
451
-
452
452
path , err := builder .NewEvaluable (mapValue )
453
453
if err != nil {
454
454
return nil , err
@@ -507,13 +507,14 @@ func (i *bulkInsertSourceNDJsonRowIter) Next(ctx context.Context) (types.Row, er
507
507
508
508
// parse the json
509
509
v := interface {}(nil )
510
- err := json .Unmarshal ([]byte (jsonValue ), & v )
510
+ dec := json .NewDecoder (bytes .NewReader ([]byte (jsonValue )))
511
+ dec .UseNumber ()
512
+ err := dec .Decode (& v )
511
513
if err != nil {
512
514
return nil , sql3 .NewErrParsingJSON (0 , 0 , jsonValue , err .Error ())
513
515
}
514
516
515
517
// type check against the output type of the map operation
516
-
517
518
for idx , expr := range i .pathExpressions {
518
519
519
520
evalValue , err := expr (ctx , v )
@@ -534,16 +535,14 @@ func (i *bulkInsertSourceNDJsonRowIter) Next(ctx context.Context) (types.Row, er
534
535
mapColumn := i .options .mapExpressions [idx ]
535
536
switch mapColumn .colType .(type ) {
536
537
case * parser.DataTypeID , * parser.DataTypeInt :
537
-
538
538
switch v := evalValue .(type ) {
539
- case float64 :
540
- // if v is a whole number then make it an int
541
- if v == float64 ( int64 ( v )) {
542
- result [idx ] = int64 ( v )
539
+ case json. Number :
540
+ n , err := v . Int64 ()
541
+ if err == nil {
542
+ result [idx ] = n
543
543
} else {
544
544
return nil , sql3 .NewErrTypeConversionOnMap (0 , 0 , v , mapColumn .colType .TypeDescription ())
545
545
}
546
-
547
546
case []interface {}:
548
547
return nil , sql3 .NewErrTypeConversionOnMap (0 , 0 , v , mapColumn .colType .TypeDescription ())
549
548
@@ -566,21 +565,21 @@ func (i *bulkInsertSourceNDJsonRowIter) Next(ctx context.Context) (types.Row, er
566
565
567
566
case * parser.DataTypeIDSet :
568
567
switch v := evalValue .(type ) {
569
- case float64 :
570
- // if v is a whole number then make it an int, and then turn that into an idset
571
- if v == float64 ( int64 ( v )) {
572
- result [idx ] = []int64 {int64 ( v ) }
568
+ case json. Number :
569
+ n , err := v . Int64 ()
570
+ if err == nil {
571
+ result [idx ] = []int64 {n }
573
572
} else {
574
573
return nil , sql3 .NewErrTypeConversionOnMap (0 , 0 , v , mapColumn .colType .TypeDescription ())
575
574
}
576
-
577
575
case []interface {}:
578
576
setValue := make ([]int64 , 0 )
579
577
for _ , i := range v {
580
578
switch v := i .(type ) {
581
- case float64 :
582
- if v == float64 (int64 (v )) {
583
- setValue = append (setValue , int64 (v ))
579
+ case json.Number :
580
+ i , e := v .Int64 ()
581
+ if e == nil {
582
+ setValue = append (setValue , i )
584
583
} else {
585
584
return nil , sql3 .NewErrTypeConversionOnMap (0 , 0 , v , mapColumn .colType .TypeDescription ())
586
585
}
@@ -616,13 +615,8 @@ func (i *bulkInsertSourceNDJsonRowIter) Next(ctx context.Context) (types.Row, er
616
615
617
616
case * parser.DataTypeStringSet :
618
617
switch v := evalValue .(type ) {
619
- case float64 :
620
- if v == float64 (int64 (v )) {
621
- result [idx ] = []string {fmt .Sprintf ("%d" , int64 (v ))}
622
- } else {
623
- result [idx ] = []string {fmt .Sprintf ("%f" , v )}
624
- }
625
-
618
+ case json.Number :
619
+ result [idx ] = []string {v .String ()}
626
620
case []interface {}:
627
621
setValue := make ([]string , 0 )
628
622
for _ , i := range v {
@@ -649,11 +643,12 @@ func (i *bulkInsertSourceNDJsonRowIter) Next(ctx context.Context) (types.Row, er
649
643
650
644
case * parser.DataTypeTimestamp :
651
645
switch v := evalValue .(type ) {
652
- case float64 :
646
+ case json.Number :
647
+ n , err := v .Int64 ()
653
648
// if v is a whole number then make it an int
654
- if v == float64 ( int64 ( v )) {
655
- //implicit conversion of int to timestamp will treat int as seconds since unix epoch
656
- result [idx ] = time .Unix (int64 ( v ) , 0 ).UTC ()
649
+ if err == nil {
650
+ // implicit conversion of int to timestamp will treat int as seconds since unix epoch
651
+ result [idx ] = time .Unix (n , 0 ).UTC ()
657
652
} else {
658
653
return nil , sql3 .NewErrTypeConversionOnMap (0 , 0 , v , mapColumn .colType .TypeDescription ())
659
654
}
@@ -684,14 +679,8 @@ func (i *bulkInsertSourceNDJsonRowIter) Next(ctx context.Context) (types.Row, er
684
679
685
680
case * parser.DataTypeString :
686
681
switch v := evalValue .(type ) {
687
- case float64 :
688
- // if a whole number make it an int
689
- if v == float64 (int64 (v )) {
690
- result [idx ] = fmt .Sprintf ("%d" , int64 (v ))
691
- } else {
692
- result [idx ] = fmt .Sprintf ("%f" , v )
693
- }
694
-
682
+ case json.Number :
683
+ result [idx ] = v .String ()
695
684
case []interface {}:
696
685
return nil , sql3 .NewErrTypeConversionOnMap (0 , 0 , v , mapColumn .colType .TypeDescription ())
697
686
@@ -710,10 +699,11 @@ func (i *bulkInsertSourceNDJsonRowIter) Next(ctx context.Context) (types.Row, er
710
699
711
700
case * parser.DataTypeBool :
712
701
switch v := evalValue .(type ) {
713
- case float64 :
702
+ case json. Number :
714
703
// if a whole number make it an int, and convert to a bool
715
- if v == float64 (int64 (v )) {
716
- result [idx ] = v > 0
704
+ n , err := v .Int64 ()
705
+ if err == nil {
706
+ result [idx ] = n > 0
717
707
} else {
718
708
return nil , sql3 .NewErrTypeConversionOnMap (0 , 0 , v , mapColumn .colType .TypeDescription ())
719
709
}
@@ -736,8 +726,12 @@ func (i *bulkInsertSourceNDJsonRowIter) Next(ctx context.Context) (types.Row, er
736
726
737
727
case * parser.DataTypeDecimal :
738
728
switch v := evalValue .(type ) {
739
- case float64 :
740
- result [idx ] = pql .FromFloat64 (v )
729
+ case json.Number :
730
+ f , err := v .Float64 ()
731
+ if err != nil {
732
+ return nil , sql3 .NewErrTypeConversionOnMap (0 , 0 , v , mapColumn .colType .TypeDescription ())
733
+ }
734
+ result [idx ] = pql .FromFloat64 (f )
741
735
742
736
case []interface {}:
743
737
return nil , sql3 .NewErrTypeConversionOnMap (0 , 0 , v , mapColumn .colType .TypeDescription ())
@@ -989,7 +983,6 @@ func (pr *parquetReader) Read() ([]interface{}, error) {
989
983
return nil , io .EOF // done
990
984
}
991
985
for i , col := range pr .columnOrder {
992
- // vprint.VV("check row:%v col:%v", pr.rowOffset, col.realColumn)
993
986
pr .row [i ] = pr .table .Get (col .realColumn , pr .rowOffset )
994
987
}
995
988
pr .rowOffset ++
@@ -1155,7 +1148,7 @@ func (i *bulkInsertSourceParquetRowIter) Next(ctx context.Context) (types.Row, e
1155
1148
1156
1149
case * parser.DataTypeTimestamp :
1157
1150
if intVal , ok := evalValue .(int64 ); ok {
1158
- //implicit conversion of int to timestamp will treat int as seconds since unix epoch
1151
+ // implicit conversion of int to timestamp will treat int as seconds since unix epoch
1159
1152
result [idx ] = time .Unix (intVal , 0 ).UTC ()
1160
1153
} else if stringVal , ok := evalValue .(string ); ok {
1161
1154
if tm , err := time .ParseInLocation (time .RFC3339Nano , stringVal , time .UTC ); err == nil {
0 commit comments