|
|
@ -122,9 +122,35 @@ func (e *SelectStatement) AggregateResult(output Record) error { |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (e *SelectStatement) isPassingWhereClause(input Record) (bool, error) { |
|
|
|
|
|
|
|
if e.selectAST.Where == nil { |
|
|
|
|
|
|
|
return true, nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
value, err := e.selectAST.Where.evalNode(input) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return false, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
b, ok := value.ToBool() |
|
|
|
|
|
|
|
if !ok { |
|
|
|
|
|
|
|
err = fmt.Errorf("WHERE expression did not return bool") |
|
|
|
|
|
|
|
return false, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return b, nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// AggregateRow - aggregates the input record. Applies only to
|
|
|
|
// AggregateRow - aggregates the input record. Applies only to
|
|
|
|
// aggregation queries.
|
|
|
|
// aggregation queries.
|
|
|
|
func (e *SelectStatement) AggregateRow(input Record) error { |
|
|
|
func (e *SelectStatement) AggregateRow(input Record) error { |
|
|
|
|
|
|
|
ok, err := e.isPassingWhereClause(input) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if !ok { |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for _, expr := range e.selectAST.Expression.Expressions { |
|
|
|
for _, expr := range e.selectAST.Expression.Expressions { |
|
|
|
err := expr.aggregateRow(input) |
|
|
|
err := expr.aggregateRow(input) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -137,23 +163,13 @@ func (e *SelectStatement) AggregateRow(input Record) error { |
|
|
|
// Eval - evaluates the Select statement for the given record. It
|
|
|
|
// Eval - evaluates the Select statement for the given record. It
|
|
|
|
// applies only to non-aggregation queries.
|
|
|
|
// applies only to non-aggregation queries.
|
|
|
|
func (e *SelectStatement) Eval(input, output Record) (Record, error) { |
|
|
|
func (e *SelectStatement) Eval(input, output Record) (Record, error) { |
|
|
|
if whereExpr := e.selectAST.Where; whereExpr != nil { |
|
|
|
ok, err := e.isPassingWhereClause(input) |
|
|
|
value, err := whereExpr.evalNode(input) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
b, ok := value.ToBool() |
|
|
|
|
|
|
|
if !ok { |
|
|
|
if !ok { |
|
|
|
err = fmt.Errorf("WHERE expression did not return bool") |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !b { |
|
|
|
|
|
|
|
// Where clause is not satisfied by the row
|
|
|
|
|
|
|
|
return nil, nil |
|
|
|
return nil, nil |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if e.selectAST.Expression.All { |
|
|
|
if e.selectAST.Expression.All { |
|
|
|
// Return the input record for `SELECT * FROM
|
|
|
|
// Return the input record for `SELECT * FROM
|
|
|
|