Skip to content

Commit

Permalink
Count(*) to give integer value (minio#6564)
Browse files Browse the repository at this point in the history
The Max, Min functions were giving float value even when they were integers.  
Resolved max and Min to return integers in that scenario.

Fixes minio#6472
  • Loading branch information
sinhaashish authored and kannappanr committed Oct 5, 2018
1 parent f187a16 commit 670f978
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
16 changes: 14 additions & 2 deletions pkg/s3select/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package s3select

import (
"fmt"
"math"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions pkg/s3select/select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 670f978

Please sign in to comment.