Fix ignored alias for aggregate result in S3 Select (#7849)

The SQL parser as it stands right now ignores alias for aggregate
result, e.g. `SELECT COUNT(*) AS thing FROM s3object` doesn't actually
return record like `{"thing": 42}`, it returns a record like `{"_1": 42}`.
Column alias for aggregate result is supported in AWS's S3 Select, so
this commit fixes that by respecting the `expr.As` in the expression.

Also improve test for S3 select

On top of testing a simple `SELECT` query, we want to test a few more
"advanced" queries (e.g. aggregation).

Convert existing tests into table driven tests[1], and add the new test
cases with "advanced" queries into them.

[1] - https://github.com/golang/go/wiki/TableDrivenTests
This commit is contained in:
Ryan Tam
2019-07-04 00:34:54 +01:00
committed by kannappanr
parent a39e810965
commit bd56f80250
2 changed files with 177 additions and 78 deletions

View File

@@ -170,7 +170,11 @@ func (e *SelectStatement) AggregateResult(output Record) error {
if err != nil {
return err
}
output.Set(fmt.Sprintf("_%d", i+1), v)
if expr.As != "" {
output.Set(expr.As, v)
} else {
output.Set(fmt.Sprintf("_%d", i+1), v)
}
}
return nil
}