Skip to content

Commit

Permalink
Correct return value when substr is not found in INSTR method
Browse files Browse the repository at this point in the history
  • Loading branch information
miland-db committed Mar 22, 2024
1 parent 834be70 commit db2453a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ private int collatedIndexOf(UTF8String substring, int collationId) {
}
}

return 0;
return -1;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,18 @@ class CollationStringExpressionsSuite extends QueryTest
Literal.create("Aa", StringType(1))), 1)
checkEvaluation(StringInstr(Collate(Literal("aaads"), "UTF8_BINARY_LCASE"),
Collate(Literal("Aa"), "UTF8_BINARY_LCASE")), 1)
checkEvaluation(StringInstr(Collate(Literal("aaads"), "UTF8_BINARY_LCASE"),
Collate(Literal("de"), "UTF8_BINARY_LCASE")), 0)
// UNICODE
checkEvaluation(StringInstr(Literal.create("aaads", StringType(2)),
Literal.create("Aa", StringType(2))), 0)
checkEvaluation(StringInstr(Collate(Literal("aaads"), "UNICODE"),
Collate(Literal("Aa"), "UNICODE")), 0)
Collate(Literal("de"), "UNICODE")), 0)
// UNICODE_CI
checkEvaluation(StringInstr(Literal.create("aaads", StringType(3)),
Literal.create("de", StringType(3))), 0)
checkEvaluation(StringInstr(Collate(Literal("aaads"), "UNICODE_CI"),
Collate(Literal("Aa"), "UNICODE_CI")), 0)
Collate(Literal("AD"), "UNICODE_CI")), 3)
}

test("INSTR fail mismatched collation types") {
Expand Down Expand Up @@ -175,6 +177,8 @@ class CollationStringExpressionsSuite extends QueryTest
Collate(Literal("abc,b,ab,c,dEf"), "UNICODE_CI")), 5)
checkEvaluation(FindInSet(Collate(Literal("DEFG"), "UNICODE_CI"),
Collate(Literal("abc,b,ab,c,def"), "UNICODE_CI")), 0)
checkEvaluation(FindInSet(Collate(Literal("dsf"), "UNICODE_CI"),
Collate(Literal("abc,b,ab,c,def"), "UNICODE_CI")), 0)
}

test("FIND_IN_SET fail mismatched collation types") {
Expand Down

0 comments on commit db2453a

Please sign in to comment.