Merge pull request #175 from travisturner/int-min-max-with-offset

Fixes the min/max bug for `int` fields with offset.
This commit is contained in:
Travis Turner 2020-03-14 15:18:48 -05:00 committed by GitHub
commit 334eb3cd08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 2 deletions

View file

@ -1407,6 +1407,64 @@ func TestExecutor_Execute_TopN_Attr_Src(t *testing.T) {
// Ensure Min() and Max() queries can be executed.
func TestExecutor_Execute_MinMax(t *testing.T) {
t.Run("WithOffset", func(t *testing.T) {
t.Run("Int", func(t *testing.T) {
c := test.MustRunCluster(t, 1)
defer c.Close()
hldr := test.Holder{Holder: c[0].Server.Holder()}
idx, err := hldr.CreateIndex("i", pilosa.IndexOptions{})
if err != nil {
t.Fatal(err)
}
tests := []struct {
min int64
max int64
set int64
}{
{10, 20, 11},
{-10, 20, 11},
{-10, 20, -9},
{-20, -10, -11},
}
for i, test := range tests {
fld := fmt.Sprintf("f%d", i)
t.Run("MinMaxField_"+fld, func(t *testing.T) {
if _, err := idx.CreateField(fld, pilosa.OptFieldTypeInt(test.min, test.max)); err != nil {
t.Fatal(err)
}
if _, err := c[0].API.Query(context.Background(), &pilosa.QueryRequest{Index: "i", Query: fmt.Sprintf(`
Set(10, %s=%d)
`, fld, test.set)}); err != nil {
t.Fatal(err)
}
var pql string
t.Run("Min", func(t *testing.T) {
pql = fmt.Sprintf(`Min(field=%s)`, fld)
if result, err := c[0].API.Query(context.Background(), &pilosa.QueryRequest{Index: "i", Query: pql}); err != nil {
t.Fatal(err)
} else if !reflect.DeepEqual(result.Results[0], pilosa.ValCount{Val: test.set, Count: 1}) {
t.Fatalf("unexpected min result, test %d: %s", i, spew.Sdump(result))
}
})
t.Run("Max", func(t *testing.T) {
pql = fmt.Sprintf(`Max(field=%s)`, fld)
if result, err := c[0].API.Query(context.Background(), &pilosa.QueryRequest{Index: "i", Query: pql}); err != nil {
t.Fatal(err)
} else if !reflect.DeepEqual(result.Results[0], pilosa.ValCount{Val: test.set, Count: 1}) {
t.Fatalf("unexpected max result, test %d: %s", i, spew.Sdump(result))
}
})
})
}
})
})
t.Run("ColumnID", func(t *testing.T) {
c := test.MustRunCluster(t, 1)
defer c.Close()

View file

@ -1449,7 +1449,7 @@ func (f *Field) MaxForShard(shard uint64, filter *Row) (ValCount, error) {
if f.Options().Type == FieldTypeDecimal {
valCount.FloatVal = float64(max) / math.Pow10(int(bsig.Scale))
} else {
valCount.Val = max
valCount.Val = max + bsig.Base
}
return valCount, nil
@ -1484,7 +1484,7 @@ func (f *Field) MinForShard(shard uint64, filter *Row) (ValCount, error) {
if f.Options().Type == FieldTypeDecimal {
valCount.FloatVal = float64(min) / math.Pow10(int(bsig.Scale))
} else {
valCount.Val = min
valCount.Val = min + bsig.Base
}
return valCount, nil