LadyForest commented on code in PR #87:
URL: https://github.com/apache/flink-table-store/pull/87#discussion_r849398939
##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/PredicateConverter.java:
##########
@@ -95,9 +105,91 @@ public Predicate visit(CallExpression call) {
.map(FieldReferenceExpression::getFieldIndex)
.map(IsNotNull::new)
.orElseThrow(UnsupportedExpression::new);
+ } else if (func == BuiltInFunctionDefinitions.LIKE) {
+ FieldReferenceExpression fieldRefExpr =
+
extractFieldReference(children.get(0)).orElseThrow(UnsupportedExpression::new);
+ if (fieldRefExpr
+ .getOutputDataType()
+ .getLogicalType()
+ .is(LogicalTypeFamily.CHARACTER_STRING)) {
+ String sqlPattern =
+ extractLiteral(fieldRefExpr.getOutputDataType(),
children.get(1))
+ .orElseThrow(UnsupportedExpression::new)
+ .value()
+ .toString();
+ String escape =
+ children.size() <= 2
+ ? null
+ :
extractLiteral(fieldRefExpr.getOutputDataType(), children.get(2))
+
.orElseThrow(UnsupportedExpression::new)
+ .value()
+ .toString();
+ String escapedSqlPattern = sqlPattern;
+ boolean allowQuick = false;
+ if (escape == null && !sqlPattern.contains("_")) {
+ allowQuick = true;
+ } else if (escape != null) {
+ if (escape.length() != 1) {
+ throw SqlLikeUtils.invalidEscapeCharacter(escape);
+ }
+ char escapeChar = escape.charAt(0);
+ boolean matched = true;
+ int i = 0;
+ StringBuilder sb = new StringBuilder();
+ while (i < sqlPattern.length() && matched) {
+ char c = sqlPattern.charAt(i);
+ if (c == escapeChar) {
+ if (i == (sqlPattern.length() - 1)) {
+ throw
SqlLikeUtils.invalidEscapeSequence(sqlPattern, i);
+ }
+ char nextChar = sqlPattern.charAt(i + 1);
+ if (nextChar == '%') {
+ matched = false;
+ } else if ((nextChar == '_') || (nextChar ==
escapeChar)) {
+ sb.append(nextChar);
+ i += 1;
+ } else {
+ throw
SqlLikeUtils.invalidEscapeSequence(sqlPattern, i);
+ }
+ } else if (c == '_') {
+ matched = false;
+ } else {
+ sb.append(c);
+ }
+ i = i + 1;
+ }
+ if (matched) {
+ allowQuick = true;
+ escapedSqlPattern = sb.toString();
+ }
+ }
+ if (allowQuick) {
+ Matcher beginMatcher =
BEGIN_PATTERN.matcher(escapedSqlPattern);
+ if (beginMatcher.matches()) {
+ return new StartsWith(
+ fieldRefExpr.getFieldIndex(),
+ new Literal(
+ VarCharType.STRING_TYPE,
+
BinaryStringData.fromString(beginMatcher.group(1))));
+ }
+ } else {
+ String regexPattern =
SqlLikeUtils.sqlToRegexLike(sqlPattern, escape);
+ if (!regexPattern.startsWith(".")
Review Comment:
> I think you want to support like '=%%' escape '='. This scene is very,
very little
Yes, the test case is `like '=%%' escape '='`
---
> and the following two conditions I can not understand, and I am not sure
there is no bug.
What about we do not support the complex situation
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]