Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
attempt to implement min and max row queries with tests
Browse files Browse the repository at this point in the history
shaqque committed Jul 8, 2019
1 parent ba1b0a8 commit 5bb24d7
Showing 3 changed files with 62 additions and 1 deletion.
37 changes: 37 additions & 0 deletions client_it_test.go
Original file line number Diff line number Diff line change
@@ -307,6 +307,43 @@ func TestTopNReturns(t *testing.T) {
}
}

func TestMinMaxRow(t *testing.T) {
client := getClient()
field := index.Field("test-field")
err := client.EnsureField(field)
if err != nil {
t.Fatal(err)
}
qry := index.BatchQuery(
field.Set(10, 5),
field.Set(10, 10),
field.Set(10, 15),
field.Set(20, 5),
field.Set(30, 5),
)
client.Query(qry)
// XXX: The following is required to make this test pass. See: https://github.com/pilosa/pilosa/issues/625
client.HttpRequest("POST", "/recalculate-caches", nil, nil)

response, err := client.Query(field.MinRow())
if err != nil {
t.Fatalf("error excecuting min: %v", err)
}
min := response.Result().Value()
response, err = client.Query(field.MaxRow())
if err != nil {
t.Fatalf("error excecuting max: %v", err)
}
max := response.Result().Value()

if min != 10 {
t.Fatalf("Min should be 10, got %v instead", min)
}
if max != 30 {
t.Fatalf("Max should be 30, got %v instead", max)
}
}

func TestSetMutexField(t *testing.T) {
client := getClient()
field := index.Field("mutex-test", OptFieldTypeMutex(CacheTypeDefault, 0))
14 changes: 13 additions & 1 deletion orm.go
Original file line number Diff line number Diff line change
@@ -1185,11 +1185,23 @@ func (f *Field) Min(row *PQLRowQuery) *PQLBaseQuery {
return f.valQuery("Min", row)
}

// Max creates a min query.
// Max creates a max query.
func (f *Field) Max(row *PQLRowQuery) *PQLBaseQuery {
return f.valQuery("Max", row)
}

// MinRow creates a min row query.
func (f *Field) MinRow() *PQLBaseQuery {
q := fmt.Sprintf("MinRow(field='%s')", f.name)
return NewPQLBaseQuery(q, f.index, nil)
}

// MaxRow creates a max row query.
func (f *Field) MaxRow() *PQLBaseQuery {
q := fmt.Sprintf("MaxRow(field='%s')", f.name)
return NewPQLBaseQuery(q, f.index, nil)
}

// SetIntValue creates a Set query.
func (f *Field) SetIntValue(colIDOrKey interface{}, value int) *PQLBaseQuery {
colStr, err := formatIDKey(colIDOrKey)
12 changes: 12 additions & 0 deletions orm_test.go
Original file line number Diff line number Diff line change
@@ -469,6 +469,18 @@ func TestFieldSum(t *testing.T) {
collabField.Sum(nil))
}

func TestMinRow(t *testing.T) {
comparePQL(t,
"MinRow(field='sample-field')",
sampleField.MinRow())
}

func TestMaxRow(t *testing.T) {
comparePQL(t,
"MaxRow(field='sample-field')",
sampleField.MaxRow())
}

func TestSetValue(t *testing.T) {
comparePQL(t,
"Set(50, collaboration=15)",

0 comments on commit 5bb24d7

Please sign in to comment.