From 4fba6bea82f00ac811093681130ccf83a79dee63 Mon Sep 17 00:00:00 2001 From: Alan Bernstein Date: Fri, 29 Jan 2021 09:39:01 -0600 Subject: [PATCH 1/2] Prevent nil pointer exception during Distinct key translation --- executor.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/executor.go b/executor.go index 9fa829aac..9b4ad515e 100644 --- a/executor.go +++ b/executor.go @@ -6572,6 +6572,9 @@ func (e *executor) translateResult(ctx context.Context, index string, idx *Index if field.Keys() { rslt := result.Pos + if rslt == nil { + return &SignedRow{Pos: &Row{}}, nil + } other := &Row{Attrs: rslt.Attrs} for _, segment := range rslt.Segments() { keys, err := e.Cluster.translateIndexIDs(context.Background(), field.ForeignIndex(), segment.Columns()) From c4455acbd8df8bcdefc8c103f84673697f340fb3 Mon Sep 17 00:00:00 2001 From: Alan Bernstein Date: Fri, 29 Jan 2021 09:39:31 -0600 Subject: [PATCH 2/2] Use inconsistent JSON schema to reach Distinct translation error condition --- executor_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/executor_test.go b/executor_test.go index 6a202ca3a..17ebbfc95 100644 --- a/executor_test.go +++ b/executor_test.go @@ -5397,6 +5397,19 @@ func TestExecutor_ForeignIndex(t *testing.T) { pilosa.OptFieldKeys(), ) + // stepchild/other field needs to have usesKeys=true + crashSchemaJson := `{"indexes": [{"name": "stepparent","createdAt": 1611247966371721700,"options": {"keys": true,"trackExistence": true},"shardWidth": 1048576},{"name": "stepchild","createdAt": 1611247953796662800,"options": {"keys": true,"trackExistence": true},"shardWidth": 1048576,"fields": [{"name": "parent_id","createdAt": 1611247953797265700,"options": {"type": "int","base": 0,"bitDepth": 28,"min": -9223372036854776000,"max": 9223372036854776000,"keys": false,"foreignIndex": "stepparent"}},{"name": "other","createdAt": 1611247953796814000,"options": {"type": "int","base": 0,"bitDepth": 17,"min": -9223372036854776000,"max": 9223372036854776000,"keys": true,"foreignIndex": ""}}]}]}` + + crashSchema := &pilosa.Schema{} + err := json.Unmarshal([]byte(crashSchemaJson), &crashSchema) + if err != nil { + t.Fatalf("json unmarshall: %v", err) + } + err = c.GetNode(0).API.ApplySchema(context.Background(), crashSchema, false) + if err != nil { + t.Fatalf("applying JSON schema: %v", err) + } + // Populate parent data. c.Query(t, "parent", fmt.Sprintf(` Set("one", general=1) @@ -5442,6 +5455,12 @@ func TestExecutor_ForeignIndex(t *testing.T) { t.Fatalf("unexpected keys: %v", row.Keys) } + crash := c.Query(t, "stepchild", `Distinct(Row(parent_id=3), field=other)`).Results[0].(pilosa.SignedRow) + if !sameStringSlice(crash.Pos.Keys, []string{}) { + // empty result; error condition does not require data + t.Fatalf("unexpected columns: %v", crash.Pos.Keys) + } + eq := c.Query(t, "child", `Row(parent_id=="one")`).Results[0].(*pilosa.Row) if !reflect.DeepEqual(eq.Columns(), []uint64{1, ShardWidth}) { t.Fatalf("unexpected columns: %v", eq.Columns())