Skip to content

Commit

Permalink
Add an "isEmpty" method for "filter.Operation"
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerlucena committed Oct 5, 2020
1 parent aec46a9 commit e241717
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions bql/planner/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func (op Operation) String() string {
}
}

func (op Operation) IsEmpty() bool {
return op == Operation(0)
}

// String returns the string representation of Field.
func (f Field) String() string {
switch f {
Expand Down
6 changes: 3 additions & 3 deletions bql/semantic/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ func whereFilterClause() ElementHook {
if currFilter == nil {
return nil, fmt.Errorf("could not add filter function %q to nil filter clause", tkn.Text)
}
if currFilter.Operation != filter.Operation(0) {
if !currFilter.Operation.IsEmpty() {
return nil, fmt.Errorf("invalid filter function %q on filter clause since already set to %q", tkn.Text, currFilter.Operation)
}
lowercaseFilter := strings.ToLower(tkn.Text)
Expand All @@ -702,7 +702,7 @@ func whereFilterClause() ElementHook {
if currFilter == nil {
return nil, fmt.Errorf("could not add binding %q to nil filter clause", tkn.Text)
}
if currFilter.Operation == filter.Operation(0) {
if currFilter.Operation.IsEmpty() {
return nil, fmt.Errorf("could not add binding %q to a filter clause that does not have a filter function previously set", tkn.Text)
}
if currFilter.Binding != "" {
Expand All @@ -711,7 +711,7 @@ func whereFilterClause() ElementHook {
currFilter.Binding = tkn.Text
return f, nil
case lexer.ItemRPar:
if currFilter == nil || currFilter.Operation == filter.Operation(0) || currFilter.Binding == "" {
if currFilter == nil || currFilter.Operation.IsEmpty() || currFilter.Binding == "" {
return nil, fmt.Errorf("could not add invalid working filter %q to the statement filters list", currFilter)
}
st.AddWorkingFilterClause()
Expand Down

0 comments on commit e241717

Please sign in to comment.