Skip to content

Commit

Permalink
Update integration tests and minor fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
notbdu committed Mar 1, 2019
1 parent 9bdcea0 commit bad4b81
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 6 deletions.
12 changes: 10 additions & 2 deletions integration/groupby_query_multi_key_no_filter_no_order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ func TestGroupByQueryMultiKeyNoFilterNoOrder(t *testing.T) {
t.SkipNow()
}

ts := newTestServerSetup(t, testConfig1)
cfg := loadConfig(t, testConfig1)
ts := newTestServerSetup(t, cfg)
defer ts.close(t)

log := ts.dbOpts.InstrumentOptions().Logger()
Expand Down Expand Up @@ -60,6 +61,13 @@ func TestGroupByQueryMultiKeyNoFilterNoOrder(t *testing.T) {
"op": "COUNT"
}
],
"filters": [
{
"field": "st",
"op": "=",
"value": true
}
],
"group_by": [
"st",
"tt"
Expand Down Expand Up @@ -114,7 +122,7 @@ func TestGroupByQueryMultiKeyNoFilterNoOrder(t *testing.T) {
},
}

client := ts.newClient()
client := ts.newHTTPClient()
require.NoError(t, client.write([]byte(strings.TrimSpace(testData))))

for _, test := range tests {
Expand Down
142 changes: 142 additions & 0 deletions integration/groupby_query_multi_key_with_filter_no_order_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// +build integration

package integration

import (
"sort"
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestGroupByQueryMultiKeyWithFilterNoOrder(t *testing.T) {
if testing.Short() {
t.SkipNow()
}

cfg := loadConfig(t, testConfig1)
ts := newTestServerSetup(t, cfg)
defer ts.close(t)

log := ts.dbOpts.InstrumentOptions().Logger()
log.Info("testing groupby query w/ multi-keys, no filter and no order")
require.NoError(t, ts.startServer())
log.Info("server is now up")

testData := `
{"service":"testNamespace","@timestamp":"2019-01-22T13:25:42-08:00","st":true,"sid":{"foo":1,"bar":2},"tt":"active","tz":-6,"v":1.5}
{"service":"testNamespace","@timestamp":"2019-01-22T13:26:42-08:00","st":true,"sid":{"foo":1,"bar":2},"tt":"active","tz":-6,"v":1.5}
{"service":"testNamespace","@timestamp":"2019-01-22T13:27:42-08:00","st":true,"sid":{"foo":1,"bar":2},"tt":"active","tz":-6,"v":1.5}
{"service":"testNamespace","@timestamp":"2019-01-22T13:28:42-08:00","st":true,"sid":{"foo":1,"bar":2},"tt":"active","tz":-6,"v":1.5}
{"service":"testNamespace","@timestamp":"2019-01-22T13:29:42-08:00","st":true,"sid":{"foo":1,"bar":2},"tt":"active","tz":-6,"v":1.5}
{"service":"testNamespace","@timestamp":"2019-01-22T13:30:42-08:00","st":true,"sid":{"foo":2,"bar":4},"tt":"active","tz":-6,"v":1.5}
{"service":"testNamespace","@timestamp":"2019-01-22T13:31:42-08:00","st":true,"sid":{"foo":2,"bar":4},"tt":"active","tz":-6,"v":1.5}
{"service":"testNamespace","@timestamp":"2019-01-22T13:32:42-08:00","st":true,"sid":{"foo":2,"bar":4},"tt":"active","tz":-6,"v":1.5}
{"service":"testNamespace","@timestamp":"2019-01-22T13:33:42-08:00","st":true,"sid":{"foo":2,"bar":4},"tt":"active","tz":-6,"v":1.5}
{"service":"testNamespace","@timestamp":"2019-01-22T13:34:42-08:00","st":true,"sid":{"foo":2,"bar":4},"tt":"active","tz":-6,"v":1.5}
{"service":"testNamespace","@timestamp":"2019-01-22T13:35:42-08:00","st":false,"sid":{"foo":3,"bar":6},"tt":"inactive","tz":-6,"v":15}
{"service":"testNamespace","@timestamp":"2019-01-22T13:36:42-08:00","st":false,"sid":{"foo":3,"bar":6},"tt":"inactive","tz":-6,"v":15}
{"service":"testNamespace","@timestamp":"2019-01-22T13:37:42-08:00","st":false,"sid":{"foo":3,"bar":6},"tt":"inactive","tz":-6,"v":15}
{"service":"testNamespace","@timestamp":"2019-01-22T13:38:42-08:00","st":false,"sid":{"foo":3,"bar":6},"tt":"inactive","tz":-6,"v":15}
{"service":"testNamespace","@timestamp":"2019-01-22T13:39:42-08:00","st":false,"sid":{"foo":3,"bar":6},"tt":"inactive","tz":-6,"v":15}
{"service":"testNamespace","@timestamp":"2019-01-22T13:40:42-08:00","st":false,"sid":{"foo":4,"bar":8},"tt":"inactive","tz":-6,"v":15}
{"service":"testNamespace","@timestamp":"2019-01-22T13:41:42-08:00","st":false,"sid":{"foo":4,"bar":8},"tt":"inactive","tz":-6,"v":15}
{"service":"testNamespace","@timestamp":"2019-01-22T13:42:42-08:00","st":false,"sid":{"foo":4,"bar":8},"tt":"inactive","tz":-6,"v":15}
{"service":"testNamespace","@timestamp":"2019-01-22T13:43:42-08:00","st":false,"sid":{"foo":4,"bar":8},"tt":"inactive","tz":-6,"v":15}
{"service":"testNamespace","@timestamp":"2019-01-22T13:44:42-08:00","st":false,"sid":{"foo":4,"bar":8},"tt":"inactive","tz":-6,"v":15}`

tests := []struct {
queryJSON string
expectedResults groupByQueryMultiKeyResults
}{
{
queryJSON: `{
"namespace": "testNamespace",
"start_time": 1548115200,
"end_time": 1548201600,
"calculations": [
{
"op": "COUNT"
}
],
"filters": [
{
"filters": [
{
"field": "st",
"op": "=",
"value": true
}
],
"filter_combinator": "AND"
}
],
"group_by": [
"st",
"tt"
]}`,
expectedResults: groupByQueryMultiKeyResults{
Groups: []multiKeyResultGroup{
multiKeyResultGroup{
Key: []interface{}{true, "active"},
Values: []interface{}{float64(10)},
},
},
},
},
{
queryJSON: `{
"namespace": "testNamespace",
"start_time": 1548115200,
"end_time": 1548201600,
"calculations": [
{
"op": "COUNT"
}
],
"filters": [
{
"filters": [
{
"field": "st",
"op": "=",
"value": true
}
],
"filter_combinator": "AND"
}
],
"group_by": [
"sid.foo",
"tt"
]}`,
expectedResults: groupByQueryMultiKeyResults{
Groups: []multiKeyResultGroup{
multiKeyResultGroup{
Key: []interface{}{float64(1), "active"},
Values: []interface{}{float64(5)},
},
multiKeyResultGroup{
Key: []interface{}{float64(2), "active"},
Values: []interface{}{float64(5)},
},
},
},
},
}

client := ts.newHTTPClient()
require.NoError(t, client.write([]byte(strings.TrimSpace(testData))))

for _, test := range tests {
results, err := client.queryGroupByMultiKey([]byte(test.queryJSON))
assert.NoError(t, err)
sort.Sort(results)
assert.Equal(t, test.expectedResults, results)
}

require.NoError(t, ts.stopServer())
log.Info("server is now down")
}
14 changes: 11 additions & 3 deletions integration/groupby_query_single_key_no_filter_no_order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ func TestGroupByQuerySingleKeyNoFilterNoOrder(t *testing.T) {
t.SkipNow()
}

ts := newTestServerSetup(t, testConfig1)
cfg := loadConfig(t, testConfig1)
ts := newTestServerSetup(t, cfg)
defer ts.close(t)

log := ts.dbOpts.InstrumentOptions().Logger()
log.Info("testing groupby query w/ multi-keys, no filter and no order")
log.Info("testing groupby query w/ single-key, no filter and no order")
require.NoError(t, ts.startServer())
log.Info("server is now up")

Expand Down Expand Up @@ -60,6 +61,13 @@ func TestGroupByQuerySingleKeyNoFilterNoOrder(t *testing.T) {
"op": "COUNT"
}
],
"filters": [
{
"field": "st",
"op": "=",
"value": true
}
],
"group_by": [
"tt"
]}`,
Expand Down Expand Up @@ -112,7 +120,7 @@ func TestGroupByQuerySingleKeyNoFilterNoOrder(t *testing.T) {
},
}

client := ts.newClient()
client := ts.newHTTPClient()
require.NoError(t, client.write([]byte(strings.TrimSpace(testData))))

for _, test := range tests {
Expand Down
4 changes: 3 additions & 1 deletion storage/segment_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ func applyFilters(
fieldIdx := filterStartIdx
for _, fl := range filters {
var filterIter index.DocIDSetIterator
if len(fl.Filters) == 1 {
if len(fl.Filters) == 0 {
continue
} else if len(fl.Filters) == 1 {
var (
err error
allowedTypes = allowedFieldTypes[fieldIdx]
Expand Down

0 comments on commit bad4b81

Please sign in to comment.