Skip to content

Commit

Permalink
make sure to handle eval and compilation similarly for LIKE
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Oct 12, 2024
1 parent c38c368 commit 867bc95
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 167 deletions.
35 changes: 13 additions & 22 deletions go/vt/vtgate/evalengine/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }()
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion go/vt/vtgate/evalengine/expr_compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
288 changes: 144 additions & 144 deletions go/vt/vtgate/evalengine/testcases/cases.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 867bc95

Please sign in to comment.