mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
Count(*) to give integer value (#6564)
The Max, Min functions were giving float value even when they were integers. Resolved max and Min to return integers in that scenario. Fixes #6472
This commit is contained in:
parent
f187a16962
commit
670f9788e3
@ -18,6 +18,7 @@ package s3select
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -677,9 +678,20 @@ func (reader *Input) colNameErrs(columnNames []string) error {
|
|||||||
|
|
||||||
// aggFuncToStr converts an array of floats into a properly formatted string.
|
// aggFuncToStr converts an array of floats into a properly formatted string.
|
||||||
func (reader *Input) aggFuncToStr(myAggVals []float64) 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++ {
|
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
|
myRow = myRow + reader.options.OutputFieldDelimiter + aggregateval
|
||||||
}
|
}
|
||||||
return myRow
|
return myRow
|
||||||
|
@ -368,8 +368,11 @@ func TestToStringAgg(t *testing.T) {
|
|||||||
myAggVal []float64
|
myAggVal []float64
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{[]float64{10, 11, 12, 13, 14}, "10.000000,11.000000,12.000000,13.000000,14.000000"},
|
{[]float64{10, 11, 12, 13, 14}, "10,11,12,13,14"},
|
||||||
{[]float64{10}, "10.000000"},
|
{[]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 {
|
for _, table := range tables {
|
||||||
val := s3s.aggFuncToStr(table.myAggVal)
|
val := s3s.aggFuncToStr(table.myAggVal)
|
||||||
|
Loading…
Reference in New Issue
Block a user