don't look up a field by name to find out its name

If a field doesn't exist, looking up that field produces a nil,
and querying the name of a nil field fails. Don't do that. Instead,
just use the name you're looking it up by.

We could in theory return an error here, but we already handle
nonexistent fields elsewhere and checking this when we already have
checks for it seems unnecessary, I think?

Also, we add a test for this. The test is over in server/grpc_test.go
because we have infrastructure there for testing the SQL server
functionality, and you can't actually write reasonable self-contained
tests for the SQL stuff because it has no way to create a working
server.
This commit is contained in:
Seebs 2022-03-01 09:40:37 -06:00
parent 87300e27f1
commit 21a478a728
2 changed files with 5 additions and 2 deletions

View file

@ -1007,6 +1007,10 @@ func TestQuerySQLWithError(t *testing.T) {
sql: "select _id, age, field_not_found from grouper",
err: pilosa.ErrFieldNotFound,
},
{
sql: "select age, color, count(*) from grouper group by field_not_found, age, color",
err: pilosa.ErrFieldNotFound,
},
}
for i, test := range tests {

View file

@ -598,8 +598,7 @@ func (h handlerSelectGroupBy) Apply(stmt *sqlparser.Select, qm QueryMask, indexF
rowsQueries := []string{}
for _, fieldName := range groupByFieldNames {
field := index.Field(fieldName)
rowsQueries = append(rowsQueries, Rows(field.Name()))
rowsQueries = append(rowsQueries, Rows(fieldName))
}
var wherePQL string