From 9e17579a76903e7e671f367da6af811a3d1c0747 Mon Sep 17 00:00:00 2001 From: reesporte Date: Mon, 13 Jun 2022 16:44:20 -0500 Subject: [PATCH] don't panic on nil field during inner join when running a select statement with an inner join where the secondary field is non-existent, we get a panic. this commit fixes that. see [fb-766](https://molecula.atlassian.net/browse/FB-766) for more information. --- server/grpc_test.go | 4 ++++ sql/select.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/server/grpc_test.go b/server/grpc_test.go index 1124f332f..d29c8df2e 100644 --- a/server/grpc_test.go +++ b/server/grpc_test.go @@ -1072,6 +1072,10 @@ func TestQuerySQLWithError(t *testing.T) { sql: "select age, color, count(*) from grouper group by field_not_found, age, color", err: pilosa.ErrFieldNotFound, }, + { + sql: "select count(*) from grouper inner join joiner on grouper._id = joiner.field_not_found", + err: pilosa.ErrFieldNotFound, + }, } for i, test := range tests { diff --git a/sql/select.go b/sql/select.go index 4ba0349b5..66e4d4371 100644 --- a/sql/select.go +++ b/sql/select.go @@ -772,6 +772,9 @@ func (h handlerSelectJoin) Apply(stmt *sqlparser.Select, qm QueryMask, indexFunc return nil, fmt.Errorf("nonexistent index %q", secondaryIndexName) } secondaryField := secondaryIndex.Field(secondary.column.name) + if secondaryField == nil { + return nil, errors.Wrap(pilosa.ErrFieldNotFound, fmt.Sprintf("non-existent field %s for index %s", secondary.column.name, secondaryIndexName)) + } var wheres tableWheres if qm.HasWhere() {