Skip to content

Commit 2cd4850

Browse files
Handle FLOAT values as float32 (#78)
Thrift server is returning both FLOAT and DOUBLE values as float64. However, FLOAT is defined as a 32 bit float so we should be converting to float32. Signed-off-by: Raymond Cypher <[email protected]>
2 parents bfac521 + a82fb9a commit 2cd4850

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

rows.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,15 @@ func value(tColumn *cli_service.TColumn, tColumnDesc *cli_service.TColumnDesc, r
481481
} else if tVal := tColumn.GetBoolVal(); tVal != nil && !isNull(tVal.Nulls, rowNum) {
482482
val = tVal.Values[rowNum]
483483
} else if tVal := tColumn.GetDoubleVal(); tVal != nil && !isNull(tVal.Nulls, rowNum) {
484-
val = tVal.Values[rowNum]
484+
if dbtype == "FLOAT" {
485+
// database types FLOAT and DOUBLE are both returned as a float64
486+
// convert to a float32 is valid because the FLOAT type would have
487+
// only been four bytes on the server
488+
val = float32(tVal.Values[rowNum])
489+
} else {
490+
val = tVal.Values[rowNum]
491+
}
492+
485493
} else if tVal := tColumn.GetBinaryVal(); tVal != nil && !isNull(tVal.Nulls, rowNum) {
486494
val = tVal.Values[rowNum]
487495
}

rows_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ func TestNextNoDirectResults(t *testing.T) {
547547
int16(0),
548548
int32(0),
549549
int64(0),
550-
float64(0),
550+
float32(0),
551551
float64(0),
552552
"s0",
553553
timestamp,
@@ -602,7 +602,7 @@ func TestNextWithDirectResults(t *testing.T) {
602602
int16(0),
603603
int32(0),
604604
int64(0),
605-
float64(0),
605+
float32(0),
606606
float64(0),
607607
"s0",
608608
timestamp,

0 commit comments

Comments
 (0)