diff --git a/pkg/s3select/helpers.go b/pkg/s3select/helpers.go index f832349f9..4d8ae7f5f 100644 --- a/pkg/s3select/helpers.go +++ b/pkg/s3select/helpers.go @@ -18,6 +18,7 @@ package s3select import ( "fmt" + "math" "reflect" "strconv" "strings" @@ -677,9 +678,20 @@ func (reader *Input) colNameErrs(columnNames []string) error { // aggFuncToStr converts an array of floats into a properly formatted string. func (reader *Input) aggFuncToStr(myAggVals []float64) string { - myRow := strconv.FormatFloat(myAggVals[0], 'f', 6, 64) + var myRow string + var aggregateval string + if myAggVals[0] == math.Trunc(myAggVals[0]) { + myRow = strconv.FormatInt(int64(myAggVals[0]), 10) + } else { + myRow = strconv.FormatFloat(myAggVals[0], 'f', 6, 64) + } + for i := 1; i < len(myAggVals); i++ { - aggregateval := strconv.FormatFloat(myAggVals[i], 'f', 6, 64) + if myAggVals[i] == math.Trunc(myAggVals[i]) { + aggregateval = strconv.FormatInt(int64(myAggVals[i]), 10) + } else { + aggregateval = strconv.FormatFloat(myAggVals[i], 'f', 6, 64) + } myRow = myRow + reader.options.OutputFieldDelimiter + aggregateval } return myRow diff --git a/pkg/s3select/select_test.go b/pkg/s3select/select_test.go index f3da4b2b1..52adb066b 100644 --- a/pkg/s3select/select_test.go +++ b/pkg/s3select/select_test.go @@ -368,8 +368,11 @@ func TestToStringAgg(t *testing.T) { myAggVal []float64 expected string }{ - {[]float64{10, 11, 12, 13, 14}, "10.000000,11.000000,12.000000,13.000000,14.000000"}, - {[]float64{10}, "10.000000"}, + {[]float64{10, 11, 12, 13, 14}, "10,11,12,13,14"}, + {[]float64{10, 11.3, 12, 13, 14}, "10,11.300000,12,13,14"}, + {[]float64{10.235, 11.3, 12, 13, 14}, "10.235000,11.300000,12,13,14"}, + {[]float64{10.235, 11.3, 12.123, 13.456, 14.789}, "10.235000,11.300000,12.123000,13.456000,14.789000"}, + {[]float64{10}, "10"}, } for _, table := range tables { val := s3s.aggFuncToStr(table.myAggVal)