@@ -611,13 +611,30 @@ func joinAndSortRows(rowMatrix1, rowMatrix2 [][]string, sep string) (rows1, rows
611
611
return rows1 , rows2
612
612
}
613
613
614
+ func isFloatArray (colType string ) bool {
615
+ switch colType {
616
+ case "[]FLOAT4" , "[]FLOAT8" , "_FLOAT4" , "_FLOAT8" :
617
+ return true
618
+ default :
619
+ return false
620
+ }
621
+ }
622
+
623
+ func isDecimalArray (colType string ) bool {
624
+ switch colType {
625
+ case "[]DECIMAL" , "_DECIMAL" :
626
+ return true
627
+ default :
628
+ return false
629
+ }
630
+ }
631
+
614
632
func needApproximateMatch (colType string ) bool {
615
633
// On s390x, check that values for both float and decimal coltypes are
616
634
// approximately equal to take into account platform differences in floating
617
635
// point calculations. On other architectures, check float values only.
618
- return (runtime .GOARCH == "s390x" && (colType == "DECIMAL" || colType == "[]DECIMAL" )) ||
619
- colType == "FLOAT4" || colType == "[]FLOAT4" ||
620
- colType == "FLOAT8" || colType == "[]FLOAT8"
636
+ return (runtime .GOARCH == "s390x" && (colType == "DECIMAL" || isDecimalArray (colType ))) ||
637
+ colType == "FLOAT4" || colType == "FLOAT8" || isFloatArray (colType )
621
638
}
622
639
623
640
// sortRowsWithFloatComp is similar to joinAndSortRows, but it uses float
@@ -627,7 +644,7 @@ func sortRowsWithFloatComp(rowMatrix1, rowMatrix2 [][]string, colTypes []string)
627
644
for idx := range colTypes {
628
645
if needApproximateMatch (colTypes [idx ]) {
629
646
cmpFn := floatcmp .FloatsCmp
630
- if strings . HasPrefix (colTypes [idx ], "[]" ) {
647
+ if isFloatArray (colTypes [idx ]) || isDecimalArray ( colTypes [ idx ] ) {
631
648
cmpFn = floatcmp .FloatArraysCmp
632
649
}
633
650
res , err := cmpFn (rowMatrix [i ][idx ], rowMatrix [j ][idx ])
@@ -697,7 +714,7 @@ func unsortedMatricesDiffWithFloatComp(
697
714
}
698
715
var needCustomMatch bool
699
716
for _ , colType := range colTypes {
700
- if needApproximateMatch (colType ) || colType == "DECIMAL" || colType == "[]DECIMAL" {
717
+ if needApproximateMatch (colType ) || colType == "DECIMAL" || isDecimalArray ( colType ) {
701
718
needCustomMatch = true
702
719
break
703
720
}
@@ -712,13 +729,14 @@ func unsortedMatricesDiffWithFloatComp(
712
729
713
730
for j , colType := range colTypes {
714
731
if needApproximateMatch (colType ) {
732
+ isFloatOrDecimalArray := isFloatArray (colType ) || isDecimalArray (colType )
715
733
cmpFn := floatcmp .FloatsMatch
716
734
switch {
717
- case runtime .GOARCH == "s390x" && strings . HasPrefix ( colType , "[]" ) :
735
+ case runtime .GOARCH == "s390x" && isFloatOrDecimalArray :
718
736
cmpFn = floatcmp .FloatArraysMatchApprox
719
- case runtime .GOARCH == "s390x" && ! strings . HasPrefix ( colType , "[]" ) :
737
+ case runtime .GOARCH == "s390x" && ! isFloatOrDecimalArray :
720
738
cmpFn = floatcmp .FloatsMatchApprox
721
- case strings . HasPrefix ( colType , "[]" ) :
739
+ case isFloatOrDecimalArray :
722
740
cmpFn = floatcmp .FloatArraysMatch
723
741
}
724
742
match , err := cmpFn (row1 [j ], row2 [j ])
@@ -729,12 +747,12 @@ func unsortedMatricesDiffWithFloatComp(
729
747
return result , nil
730
748
}
731
749
} else {
732
- switch colType {
733
- case "DECIMAL" :
750
+ switch {
751
+ case colType == "DECIMAL" :
734
752
// For decimals, remove any trailing zeroes.
735
753
row1 [j ] = trimDecimalTrailingZeroes (row1 [j ])
736
754
row2 [j ] = trimDecimalTrailingZeroes (row2 [j ])
737
- case "[]DECIMAL" :
755
+ case isDecimalArray ( colType ) :
738
756
// For decimal arrays, remove any trailing zeroes from each
739
757
// decimal.
740
758
row1 [j ] = trimDecimalsTrailingZeroesInArray (row1 [j ])
0 commit comments