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.
This commit is contained in:
reesporte 2022-06-13 16:44:20 -05:00 • committed by reesporte
parent 630d510f85
commit 9e17579a76
2 changed files with 7 additions and 0 deletions

View file

@ -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 {

View file

@ -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() {