Skip to content

Commit 217b1a7

Browse files
committed
fix(embedded/sql): return invalid value when using aggregated col selector in temporal queries
Signed-off-by: Jeronimo Irazabal <[email protected]>
1 parent 740ba5c commit 217b1a7

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

embedded/sql/engine_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5085,6 +5085,18 @@ func TestTemporalQueriesEdgeCases(t *testing.T) {
50855085
params: map[string]interface{}{"tx": -1},
50865086
err: ErrIllegalArguments,
50875087
},
5088+
{
5089+
title: "querying data with col selector as tx id should return error",
5090+
query: "SELECT id, title FROM table1 SINCE TX id",
5091+
params: nil,
5092+
err: ErrInvalidValue,
5093+
},
5094+
{
5095+
title: "querying data with aggregations as tx id should return error",
5096+
query: "SELECT id, title FROM table1 SINCE TX COUNT(*)",
5097+
params: nil,
5098+
err: ErrInvalidValue,
5099+
},
50885100
{
50895101
title: "querying data with invalid tx id should return error",
50905102
query: "SELECT id, title FROM table1 AFTER TX @tx",

embedded/sql/stmt.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2599,7 +2599,7 @@ func (sel *ColSelector) substitute(params map[string]interface{}) (ValueExp, err
25992599

26002600
func (sel *ColSelector) reduce(catalog *Catalog, row *Row, implicitDB, implicitTable string) (TypedValue, error) {
26012601
if row == nil {
2602-
return nil, ErrInvalidValue
2602+
return nil, fmt.Errorf("%w: no row to evaluate in current context", ErrInvalidValue)
26032603
}
26042604

26052605
aggFn, db, table, col := sel.resolve(implicitDB, implicitTable)
@@ -2706,6 +2706,10 @@ func (sel *AggColSelector) substitute(params map[string]interface{}) (ValueExp,
27062706
}
27072707

27082708
func (sel *AggColSelector) reduce(catalog *Catalog, row *Row, implicitDB, implicitTable string) (TypedValue, error) {
2709+
if row == nil {
2710+
return nil, fmt.Errorf("%w: no row to evaluate aggregation (%s) in current context", ErrInvalidValue, sel.aggFn)
2711+
}
2712+
27092713
v, ok := row.ValuesBySelector[EncodeSelector(sel.resolve(implicitDB, implicitTable))]
27102714
if !ok {
27112715
return nil, fmt.Errorf("%w (%s)", ErrColumnDoesNotExist, sel.col)

0 commit comments

Comments
 (0)