From e7b239d2d83ea7b50759e297a22523000e94f496 Mon Sep 17 00:00:00 2001 From: Seebs Date: Wed, 9 Sep 2020 16:17:41 -0500 Subject: [PATCH] Test cases for Store(Distinct) This adds testing for Store(Distinct(...)) with and without filters, to verify that we can, in fact, store the results of a Distinct() query directly. This was at one point unsupported, now we think it should work so we're testing it. The change to the testdata is because the specific structure used for this test doesn't work with a keyed index, and changing things to be "foreign keys" seems annoying and more complicated, but possibly that should become part of a future test. There was talk of testing this with non-BSI fields, but they don't seem to actually work with Distinct right now, so that will be later. --- executor_test.go | 71 ++++++++++++++++++++++++++++++++++++++++---- testdata/schema.json | 2 +- 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/executor_test.go b/executor_test.go index eb9abb18c..07c57b112 100644 --- a/executor_test.go +++ b/executor_test.go @@ -6233,7 +6233,18 @@ func TestExecutor_Execute_CountDistinct(t *testing.T) { } // AntitodePoint == row 1 b/c keys field. - writeQuery := `Set(100, type=AntidotePoint)Set(100, equip_id=100)Set(100, site_id=100)Set(100, id=100)` + // Note: type=TwoPoints should match 100/101, and no row in type + // matches 102, but 102 is present in equip_id at all. + writeQuery := ` + Set(100, type=AntidotePoint) + Set(100, type=TwoPoints) + Set(101, type=TwoPoints) + Set(100, equip_id=100) + Set(101, equip_id=101) + Set(102, equip_id=102) + Set(100, site_id=100) + Set(100, id=100) + ` for k, i := range schema.Indexes { _ = k if _, err := api.Query(context.TODO(), &pilosa.QueryRequest{Index: i.Name, Query: writeQuery}); err != nil { @@ -6248,7 +6259,7 @@ func TestExecutor_Execute_CountDistinct(t *testing.T) { Intersect(Row(type=AntidotePoint)), index=equipment, field=equip_id), Distinct( - Intersect(Row(type=AntidotePoint)), + Intersect(Row(type=TwoPoints)), index=sites, field=equip_id) ), index=power_ts, field=site_id)` @@ -6308,11 +6319,61 @@ func TestExecutor_Execute_CountDistinct(t *testing.T) { if !ok { t.Fatalf("invalid response type, expected: []pilosa.GroupCount, got: %T", resp.Results[0]) } - if len(gc) != 1 { - t.Fatalf("invalid group count length, expected: 1, got: %v", len(gc)) + if len(gc) != 2 { + t.Fatalf("invalid group count length, expected: 2, got: %v", len(gc)) } if gc[0].Count != 1 { - t.Fatalf("invalid group count count, expected: 1, got: %v", gc[0].Count) + t.Fatalf("invalid group-by count for %d, expected: 1, got: %v", gc[0].Group[0].RowID, gc[0].Count) + } + if gc[1].Count != 1 { + t.Fatalf("invalid group-by count for %d, expected: 1, got: %v", gc[1].Group[0].RowID, gc[1].Count) + } + }) + t.Run("Store(Distinct)", func(t *testing.T) { + _, err = api.Query(context.TODO(), &pilosa.QueryRequest{ + Index: "sites", + Query: `Store(Distinct(field=equip_id), type="a")`, + }) + if err != nil { + t.Fatal(err) + } + resp, err := api.Query(context.TODO(), &pilosa.QueryRequest{ + Index: "sites", + Query: `Row(type="a")`, + }) + if err != nil { + t.Fatal(err) + } + res, ok := resp.Results[0].(*pilosa.Row) + if !ok { + t.Fatalf("invalid response type, expected: *pilosa.Row, got: %T", resp.Results[0]) + } + cols := res.Columns() + if !eq(cols, []uint64{100, 101, 102}) { + t.Fatalf("expected [100, 101, 102], got %d", cols) + } + + _, err = api.Query(context.TODO(), &pilosa.QueryRequest{ + Index: "sites", + Query: `Store(Distinct(Row(type="TwoPoints"), field=equip_id), type="b")`, + }) + if err != nil { + t.Fatal(err) + } + resp, err = api.Query(context.TODO(), &pilosa.QueryRequest{ + Index: "sites", + Query: `Row(type="b")`, + }) + if err != nil { + t.Fatal(err) + } + res, ok = resp.Results[0].(*pilosa.Row) + if !ok { + t.Fatalf("invalid response type, expected: *pilosa.Row, got: %T", resp.Results[0]) + } + cols = res.Columns() + if !eq(cols, []uint64{100, 101}) { + t.Fatalf("expected [100, 101], got %d", cols) } }) } diff --git a/testdata/schema.json b/testdata/schema.json index 4bd36a3a9..387336963 100644 --- a/testdata/schema.json +++ b/testdata/schema.json @@ -287,7 +287,7 @@ { "name": "sites", "options": { - "keys": true, + "keys": false, "trackExistence": true }, "fields": [