From 3223be4cf95d0b6828196ac7a84277c18f3f5655 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 19 Sep 2021 13:22:59 +0300 Subject: move args to config package logger package rewrite as dlog --- internal/mapr/wherecondition.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'internal/mapr/wherecondition.go') diff --git a/internal/mapr/wherecondition.go b/internal/mapr/wherecondition.go index 7a60dba..c60c0a5 100644 --- a/internal/mapr/wherecondition.go +++ b/internal/mapr/wherecondition.go @@ -6,7 +6,7 @@ import ( "strconv" "strings" - "github.com/mimecast/dtail/internal/io/logger" + "github.com/mimecast/dtail/internal/io/dlog" ) // QueryOperation determines the mapreduce operation. @@ -168,7 +168,7 @@ func (wc *whereCondition) floatClause(lValue float64, rValue float64) bool { case FloatGe: return lValue >= rValue default: - logger.Error("Unknown float operation", lValue, wc.Operation, rValue) + dlog.Common.Error("Unknown float operation", lValue, wc.Operation, rValue) } return false @@ -193,7 +193,7 @@ func (wc *whereCondition) stringClause(lValue string, rValue string) bool { case StringNotHasSuffix: return !strings.HasSuffix(lValue, rValue) default: - logger.Error("Unknown string operation", lValue, wc.Operation, rValue) + dlog.Common.Error("Unknown string operation", lValue, wc.Operation, rValue) } return false -- cgit v1.2.3 From ea1de3044e129d419f4e807f2624a009343a128f Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 9 Oct 2021 21:10:29 +0300 Subject: vetting and linting and some code restyling --- internal/mapr/wherecondition.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'internal/mapr/wherecondition.go') diff --git a/internal/mapr/wherecondition.go b/internal/mapr/wherecondition.go index c60c0a5..280dcfb 100644 --- a/internal/mapr/wherecondition.go +++ b/internal/mapr/wherecondition.go @@ -46,15 +46,18 @@ type whereCondition struct { } func (wc *whereCondition) String() string { - return fmt.Sprintf("whereCondition(Operation:%v,lString:%s,lFloat:%v,lType:%s,rString:%s,rFloat:%v,rType:%s)", - wc.Operation, wc.lString, wc.lFloat, wc.lType.String(), wc.rString, wc.rFloat, wc.rType.String()) + return fmt.Sprintf("whereCondition(Operation:%v,lString:%s,lFloat:%v,"+ + "lType:%s,rString:%s,rFloat:%v,rType:%s)", + wc.Operation, wc.lString, wc.lFloat, wc.lType.String(), wc.rString, + wc.rFloat, wc.rType.String()) } func makeWhereConditions(tokens []token) (where []whereCondition, err error) { parse := func(tokens []token) (whereCondition, []token, error) { var wc whereCondition if len(tokens) < 3 { - return wc, nil, errors.New(invalidQuery + "Not enough arguments in 'where' clause") + err := errors.New(invalidQuery + "Not enough arguments in 'where' clause") + return wc, nil, err } whereOp := strings.ToLower(tokens[1].str) @@ -94,7 +97,8 @@ func makeWhereConditions(tokens []token) (where []whereCondition, err error) { case "nhassuffix": wc.Operation = StringNotHasSuffix default: - return wc, nil, errors.New(invalidQuery + "Unknown operation in 'where' clause: " + whereOp) + return wc, nil, errors.New(invalidQuery + + "Unknown operation in 'where' clause: " + whereOp) } wc.lString = tokens[0].str @@ -102,7 +106,8 @@ func makeWhereConditions(tokens []token) (where []whereCondition, err error) { if wc.Operation > FloatOperation { if !tokens[0].isBareword { - return wc, nil, errors.New(invalidQuery + "Expected bareword at 'where' clause's lValue: " + tokens[0].str) + return wc, nil, errors.New(invalidQuery + + "Expected bareword at 'where' clause's lValue: " + tokens[0].str) } if f, err := strconv.ParseFloat(wc.lString, 64); err == nil { wc.lFloat = f @@ -112,7 +117,8 @@ func makeWhereConditions(tokens []token) (where []whereCondition, err error) { } if !tokens[2].isBareword { - return wc, nil, errors.New(invalidQuery + "Expected bareword at 'where' clause's rValue: " + tokens[2].str) + return wc, nil, errors.New(invalidQuery + + "Expected bareword at 'where' clause's rValue: " + tokens[2].str) } if f, err := strconv.ParseFloat(wc.rString, 64); err == nil { wc.rFloat = f @@ -133,23 +139,19 @@ func makeWhereConditions(tokens []token) (where []whereCondition, err error) { } else { wc.rType = String } - return wc, tokens[3:], nil } for len(tokens) > 0 { var wc whereCondition var err error - wc, tokens, err = parse(tokens) if err != nil { return nil, err } - where = append(where, wc) tokens = tokensConsumeOptional(tokens, "and") } - return } @@ -170,7 +172,6 @@ func (wc *whereCondition) floatClause(lValue float64, rValue float64) bool { default: dlog.Common.Error("Unknown float operation", lValue, wc.Operation, rValue) } - return false } @@ -195,6 +196,5 @@ func (wc *whereCondition) stringClause(lValue string, rValue string) bool { default: dlog.Common.Error("Unknown string operation", lValue, wc.Operation, rValue) } - return false } -- cgit v1.2.3 From 0e3de397d8f36c150b8e8fc32a6ee38fa671bac4 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 8 Dec 2021 10:19:42 +0000 Subject: add where clause integration test to dmap1, all mapreduce token fields are lower case --- internal/mapr/wherecondition.go | 1 + 1 file changed, 1 insertion(+) (limited to 'internal/mapr/wherecondition.go') diff --git a/internal/mapr/wherecondition.go b/internal/mapr/wherecondition.go index 280dcfb..c2dd2a1 100644 --- a/internal/mapr/wherecondition.go +++ b/internal/mapr/wherecondition.go @@ -54,6 +54,7 @@ func (wc *whereCondition) String() string { func makeWhereConditions(tokens []token) (where []whereCondition, err error) { parse := func(tokens []token) (whereCondition, []token, error) { + var wc whereCondition if len(tokens) < 3 { err := errors.New(invalidQuery + "Not enough arguments in 'where' clause") -- cgit v1.2.3 From 29920f9a6b3eed9ee77f13edf6ffe1b17d49a1d0 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 14 Dec 2021 10:27:23 +0000 Subject: Refactor makeWhereConditions --- internal/mapr/wherecondition.go | 95 +++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 42 deletions(-) (limited to 'internal/mapr/wherecondition.go') diff --git a/internal/mapr/wherecondition.go b/internal/mapr/wherecondition.go index c2dd2a1..95e43d2 100644 --- a/internal/mapr/wherecondition.go +++ b/internal/mapr/wherecondition.go @@ -53,12 +53,12 @@ func (wc *whereCondition) String() string { } func makeWhereConditions(tokens []token) (where []whereCondition, err error) { - parse := func(tokens []token) (whereCondition, []token, error) { + // Helper to parse a where condition. + parse := func(tokens []token) (whereCondition, []token, error) { var wc whereCondition if len(tokens) < 3 { - err := errors.New(invalidQuery + "Not enough arguments in 'where' clause") - return wc, nil, err + return wc, nil, errors.New(invalidQuery + "Not enough arguments in 'where' clause") } whereOp := strings.ToLower(tokens[1].str) @@ -102,47 +102,12 @@ func makeWhereConditions(tokens []token) (where []whereCondition, err error) { "Unknown operation in 'where' clause: " + whereOp) } - wc.lString = tokens[0].str - wc.rString = tokens[2].str - - if wc.Operation > FloatOperation { - if !tokens[0].isBareword { - return wc, nil, errors.New(invalidQuery + - "Expected bareword at 'where' clause's lValue: " + tokens[0].str) - } - if f, err := strconv.ParseFloat(wc.lString, 64); err == nil { - wc.lFloat = f - wc.lType = Float - } else { - wc.lType = Field - } - - if !tokens[2].isBareword { - return wc, nil, errors.New(invalidQuery + - "Expected bareword at 'where' clause's rValue: " + tokens[2].str) - } - if f, err := strconv.ParseFloat(wc.rString, 64); err == nil { - wc.rFloat = f - wc.rType = Float - } else { - wc.rType = Field - } - return wc, tokens[3:], nil - } - - if tokens[0].isBareword { - wc.lType = Field - } else { - wc.lType = String - } - if tokens[2].isBareword { - wc.rType = Field - } else { - wc.rType = String - } - return wc, tokens[3:], nil + var err error + tokens, err = wc.fill(tokens) + return wc, tokens, err } + // Consume all where conditions. for len(tokens) > 0 { var wc whereCondition var err error @@ -156,6 +121,52 @@ func makeWhereConditions(tokens []token) (where []whereCondition, err error) { return } +// Fill a where condition. +func (wc *whereCondition) fill(tokens []token) ([]token, error) { + wc.lString = tokens[0].str + wc.rString = tokens[2].str + + if wc.Operation > FloatOperation { + if !tokens[0].isBareword { + return nil, errors.New(invalidQuery + + "Expected bareword at 'where' clause's lValue: " + tokens[0].str) + } + + if f, err := strconv.ParseFloat(wc.lString, 64); err == nil { + wc.lFloat = f + wc.lType = Float + } else { + wc.lType = Field + } + + if !tokens[2].isBareword { + return nil, errors.New(invalidQuery + + "Expected bareword at 'where' clause's rValue: " + tokens[2].str) + } + if f, err := strconv.ParseFloat(wc.rString, 64); err == nil { + wc.rFloat = f + wc.rType = Float + } else { + wc.rType = Field + } + return tokens[3:], nil + } + + if tokens[0].isBareword { + wc.lType = Field + } else { + wc.lType = String + } + + if tokens[2].isBareword { + wc.rType = Field + } else { + wc.rType = String + } + + return tokens[3:], nil +} + func (wc *whereCondition) floatClause(lValue float64, rValue float64) bool { switch wc.Operation { case FloatEq: -- cgit v1.2.3