mirror of
https://github.com/minio/minio.git
synced 2025-01-23 12:43:16 -05:00
Evaluate where clause in aggregation queries (#7235)
This commit is contained in:
parent
14544d8d84
commit
ee5b3622a5
@ -122,9 +122,35 @@ func (e *SelectStatement) AggregateResult(output Record) error {
|
||||
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
|
||||
// aggregation queries.
|
||||
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 {
|
||||
err := expr.aggregateRow(input)
|
||||
if err != nil {
|
||||
@ -137,22 +163,12 @@ func (e *SelectStatement) AggregateRow(input Record) error {
|
||||
// Eval - evaluates the Select statement for the given record. It
|
||||
// applies only to non-aggregation queries.
|
||||
func (e *SelectStatement) Eval(input, output Record) (Record, error) {
|
||||
if whereExpr := e.selectAST.Where; whereExpr != nil {
|
||||
value, err := whereExpr.evalNode(input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
b, ok := value.ToBool()
|
||||
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
|
||||
}
|
||||
ok, err := e.isPassingWhereClause(input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if e.selectAST.Expression.All {
|
||||
|
Loading…
x
Reference in New Issue
Block a user