From 867bc95b0560c924d39949fcb01750ae0c625c7d Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Sat, 12 Oct 2024 09:35:02 +0200 Subject: [PATCH] make sure to handle eval and compilation similarly for LIKE Signed-off-by: Andres Taylor --- go/vt/vtgate/evalengine/compiler_test.go | 35 +-- go/vt/vtgate/evalengine/expr_compare.go | 7 +- go/vt/vtgate/evalengine/testcases/cases.go | 288 ++++++++++----------- 3 files changed, 163 insertions(+), 167 deletions(-) diff --git a/go/vt/vtgate/evalengine/compiler_test.go b/go/vt/vtgate/evalengine/compiler_test.go index fbef6b017a9..67c9467de48 100644 --- a/go/vt/vtgate/evalengine/compiler_test.go +++ b/go/vt/vtgate/evalengine/compiler_test.go @@ -97,6 +97,7 @@ func (s *Tracker) String() string { } func TestCompilerReference(t *testing.T) { + // This test runs a lot of queries and compares the results of the evalengine in eval mode to the results of the compiler. now := time.Now() evalengine.SystemTime = func() time.Time { return now } defer func() { evalengine.SystemTime = time.Now }() @@ -144,29 +145,19 @@ func TestCompilerReference(t *testing.T) { res, vmErr = env.Evaluate(converted) }) - if vmErr != nil || evalErr != nil { - switch { - case vmErr == nil: - t.Errorf("failed evaluation from evalengine:\nSQL: %s\nError: %s", query, evalErr) - case evalErr == nil: - t.Errorf("failed evaluation from compiler:\nSQL: %s\nError: %s", query, vmErr) - case evalErr.Error() != vmErr.Error(): - t.Errorf("error mismatch:\nSQL: %s\nError eval: %s\nError comp: %s", query, evalErr, vmErr) - default: - supported++ - } - return - } - - eval := expected.String() - comp := res.String() - - if eval != comp { - t.Errorf("bad evaluation from compiler:\nSQL: %s\nEval: %s\nComp: %s", query, eval, comp) - return + switch { + case vmErr == nil && evalErr == nil: + eval := expected.String() + comp := res.String() + assert.Equalf(t, eval, comp, "bad evaluation from compiler:\nSQL: %s\nEval: %s\nComp: %s", query, eval, comp) + supported++ + case vmErr == nil: + t.Errorf("failed evaluation from evalengine:\nSQL: %s\nError: %s", query, evalErr) + case evalErr == nil: + t.Errorf("failed evaluation from compiler:\nSQL: %s\nError: %s", query, vmErr) + case evalErr.Error() != vmErr.Error(): + t.Errorf("error mismatch:\nSQL: %s\nError eval: %s\nError comp: %s", query, evalErr, vmErr) } - - supported++ }) track.Add(tc.Name(), supported, total) diff --git a/go/vt/vtgate/evalengine/expr_compare.go b/go/vt/vtgate/evalengine/expr_compare.go index 98ba5cd4462..43ebd9e3e19 100644 --- a/go/vt/vtgate/evalengine/expr_compare.go +++ b/go/vt/vtgate/evalengine/expr_compare.go @@ -596,11 +596,16 @@ func (l *LikeExpr) matchWildcard(left, right []byte, coll collations.ID) bool { } func (l *LikeExpr) eval(env *ExpressionEnv) (eval, error) { - left, right, err := l.arguments(env) + left, err := l.Left.eval(env) + if err != nil { + return nil, err + } + if left == nil { return nil, nil } + right, err := l.Right.eval(env) if err != nil { return nil, err } diff --git a/go/vt/vtgate/evalengine/testcases/cases.go b/go/vt/vtgate/evalengine/testcases/cases.go index bbacde3013e..ff6c0c0f311 100644 --- a/go/vt/vtgate/evalengine/testcases/cases.go +++ b/go/vt/vtgate/evalengine/testcases/cases.go @@ -29,151 +29,151 @@ import ( ) var Cases = []TestCase{ - // {Run: JSONExtract, Schema: JSONExtract_Schema}, - // {Run: JSONPathOperations}, - // {Run: JSONArray}, - // {Run: JSONObject}, - // {Run: CharsetConversionOperators}, - // {Run: CaseExprWithPredicate}, - // {Run: CaseExprWithValue}, - // {Run: If}, - // {Run: Base64}, - // {Run: Conversion}, - // {Run: LargeDecimals}, - // {Run: LargeIntegers}, - // {Run: DecimalClamping}, - // {Run: BitwiseOperatorsUnary}, - // {Run: BitwiseOperators}, - // {Run: WeightString}, - // {Run: FloatFormatting}, - // {Run: UnderscoreAndPercentage}, - // {Run: Types}, - // {Run: Arithmetic}, - // {Run: HexArithmetic}, - // {Run: NumericTypes}, - // {Run: NegateArithmetic}, - // {Run: CollationOperations}, + {Run: JSONExtract, Schema: JSONExtract_Schema}, + {Run: JSONPathOperations}, + {Run: JSONArray}, + {Run: JSONObject}, + {Run: CharsetConversionOperators}, + {Run: CaseExprWithPredicate}, + {Run: CaseExprWithValue}, + {Run: If}, + {Run: Base64}, + {Run: Conversion}, + {Run: LargeDecimals}, + {Run: LargeIntegers}, + {Run: DecimalClamping}, + {Run: BitwiseOperatorsUnary}, + {Run: BitwiseOperators}, + {Run: WeightString}, + {Run: FloatFormatting}, + {Run: UnderscoreAndPercentage}, + {Run: Types}, + {Run: Arithmetic}, + {Run: HexArithmetic}, + {Run: NumericTypes}, + {Run: NegateArithmetic}, + {Run: CollationOperations}, {Run: LikeComparison}, - // {Run: StrcmpComparison}, - // {Run: MultiComparisons}, - // {Run: IntervalStatement}, - // {Run: IsStatement}, - // {Run: NotStatement}, - // {Run: LogicalStatement}, - // {Run: TupleComparisons}, - // {Run: Comparisons}, - // {Run: InStatement}, - // {Run: FnField}, - // {Run: FnElt}, - // {Run: FnInsert}, - // {Run: FnLower}, - // {Run: FnUpper}, - // {Run: FnCharLength}, - // {Run: FnLength}, - // {Run: FnBitLength}, - // {Run: FnAscii}, - // {Run: FnReverse}, - // {Run: FnSpace}, - // {Run: FnOrd}, - // {Run: FnRepeat}, - // {Run: FnLeft}, - // {Run: FnLpad}, - // {Run: FnRight}, - // {Run: FnRpad}, - // {Run: FnLTrim}, - // {Run: FnRTrim}, - // {Run: FnTrim}, - // {Run: FnSubstr}, - // {Run: FnLocate}, - // {Run: FnReplace}, - // {Run: FnConcat}, - // {Run: FnConcatWs}, - // {Run: FnChar}, - // {Run: FnHex}, - // {Run: FnUnhex}, - // {Run: FnCeil}, - // {Run: FnFloor}, - // {Run: FnAbs}, - // {Run: FnPi}, - // {Run: FnAcos}, - // {Run: FnAsin}, - // {Run: FnAtan}, - // {Run: FnAtan2}, - // {Run: FnCos}, - // {Run: FnCot}, - // {Run: FnSin}, - // {Run: FnTan}, - // {Run: FnDegrees}, - // {Run: FnRadians}, - // {Run: FnNow, Compare: &Comparison{LooseTime: true}}, - // {Run: FnInfo}, - // {Run: FnExp}, - // {Run: FnLn}, - // {Run: FnLog}, - // {Run: FnLog10}, - // {Run: FnMod}, - // {Run: FnLog2}, - // {Run: FnPow}, - // {Run: FnSign}, - // {Run: FnSqrt}, - // {Run: FnRound}, - // {Run: FnTruncate}, - // {Run: FnCrc32}, - // {Run: FnConv}, - // {Run: FnBin}, - // {Run: FnOct}, - // {Run: FnMD5}, - // {Run: FnSHA1}, - // {Run: FnSHA2}, - // {Run: FnRandomBytes}, - // {Run: FnDateFormat}, - // {Run: FnConvertTz}, - // {Run: FnDate}, - // {Run: FnDayOfMonth}, - // {Run: FnDayOfWeek}, - // {Run: FnDayOfYear}, - // {Run: FnFromUnixtime}, - // {Run: FnHour}, - // {Run: FnMakedate}, - // {Run: FnMaketime}, - // {Run: FnMicroSecond}, - // {Run: FnMinute}, - // {Run: FnMonth}, - // {Run: FnMonthName}, - // {Run: FnLastDay}, - // {Run: FnToDays}, - // {Run: FnFromDays}, - // {Run: FnSecToTime}, - // {Run: FnTimeToSec}, - // {Run: FnToSeconds}, - // {Run: FnQuarter}, - // {Run: FnSecond}, - // {Run: FnTime}, - // {Run: FnUnixTimestamp}, - // {Run: FnWeek}, - // {Run: FnWeekDay}, - // {Run: FnWeekOfYear}, - // {Run: FnYear}, - // {Run: FnYearWeek}, - // {Run: FnPeriodAdd}, - // {Run: FnPeriodDiff}, - // {Run: FnInetAton}, - // {Run: FnInetNtoa}, - // {Run: FnInet6Aton}, - // {Run: FnInet6Ntoa}, - // {Run: FnIsIPv4}, - // {Run: FnIsIPv4Compat}, - // {Run: FnIsIPv4Mapped}, - // {Run: FnIsIPv6}, - // {Run: FnBinToUUID}, - // {Run: FnIsUUID}, - // {Run: FnUUID}, - // {Run: FnUUIDToBin}, - // {Run: DateMath}, - // {Run: RegexpLike}, - // {Run: RegexpInstr}, - // {Run: RegexpSubstr}, - // {Run: RegexpReplace}, + {Run: StrcmpComparison}, + {Run: MultiComparisons}, + {Run: IntervalStatement}, + {Run: IsStatement}, + {Run: NotStatement}, + {Run: LogicalStatement}, + {Run: TupleComparisons}, + {Run: Comparisons}, + {Run: InStatement}, + {Run: FnField}, + {Run: FnElt}, + {Run: FnInsert}, + {Run: FnLower}, + {Run: FnUpper}, + {Run: FnCharLength}, + {Run: FnLength}, + {Run: FnBitLength}, + {Run: FnAscii}, + {Run: FnReverse}, + {Run: FnSpace}, + {Run: FnOrd}, + {Run: FnRepeat}, + {Run: FnLeft}, + {Run: FnLpad}, + {Run: FnRight}, + {Run: FnRpad}, + {Run: FnLTrim}, + {Run: FnRTrim}, + {Run: FnTrim}, + {Run: FnSubstr}, + {Run: FnLocate}, + {Run: FnReplace}, + {Run: FnConcat}, + {Run: FnConcatWs}, + {Run: FnChar}, + {Run: FnHex}, + {Run: FnUnhex}, + {Run: FnCeil}, + {Run: FnFloor}, + {Run: FnAbs}, + {Run: FnPi}, + {Run: FnAcos}, + {Run: FnAsin}, + {Run: FnAtan}, + {Run: FnAtan2}, + {Run: FnCos}, + {Run: FnCot}, + {Run: FnSin}, + {Run: FnTan}, + {Run: FnDegrees}, + {Run: FnRadians}, + {Run: FnNow, Compare: &Comparison{LooseTime: true}}, + {Run: FnInfo}, + {Run: FnExp}, + {Run: FnLn}, + {Run: FnLog}, + {Run: FnLog10}, + {Run: FnMod}, + {Run: FnLog2}, + {Run: FnPow}, + {Run: FnSign}, + {Run: FnSqrt}, + {Run: FnRound}, + {Run: FnTruncate}, + {Run: FnCrc32}, + {Run: FnConv}, + {Run: FnBin}, + {Run: FnOct}, + {Run: FnMD5}, + {Run: FnSHA1}, + {Run: FnSHA2}, + {Run: FnRandomBytes}, + {Run: FnDateFormat}, + {Run: FnConvertTz}, + {Run: FnDate}, + {Run: FnDayOfMonth}, + {Run: FnDayOfWeek}, + {Run: FnDayOfYear}, + {Run: FnFromUnixtime}, + {Run: FnHour}, + {Run: FnMakedate}, + {Run: FnMaketime}, + {Run: FnMicroSecond}, + {Run: FnMinute}, + {Run: FnMonth}, + {Run: FnMonthName}, + {Run: FnLastDay}, + {Run: FnToDays}, + {Run: FnFromDays}, + {Run: FnSecToTime}, + {Run: FnTimeToSec}, + {Run: FnToSeconds}, + {Run: FnQuarter}, + {Run: FnSecond}, + {Run: FnTime}, + {Run: FnUnixTimestamp}, + {Run: FnWeek}, + {Run: FnWeekDay}, + {Run: FnWeekOfYear}, + {Run: FnYear}, + {Run: FnYearWeek}, + {Run: FnPeriodAdd}, + {Run: FnPeriodDiff}, + {Run: FnInetAton}, + {Run: FnInetNtoa}, + {Run: FnInet6Aton}, + {Run: FnInet6Ntoa}, + {Run: FnIsIPv4}, + {Run: FnIsIPv4Compat}, + {Run: FnIsIPv4Mapped}, + {Run: FnIsIPv6}, + {Run: FnBinToUUID}, + {Run: FnIsUUID}, + {Run: FnUUID}, + {Run: FnUUIDToBin}, + {Run: DateMath}, + {Run: RegexpLike}, + {Run: RegexpInstr}, + {Run: RegexpSubstr}, + {Run: RegexpReplace}, } func JSONPathOperations(yield Query) {