You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/04/12 02:33:28 UTC

[GitHub] [flink-table-store] LadyForest commented on a diff in pull request #87: [FLINK-27123] Introduce filter predicate for 'LIKE'

LadyForest commented on code in PR #87:
URL: https://github.com/apache/flink-table-store/pull/87#discussion_r847890543


##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/predicate/PredicateConverter.java:
##########
@@ -95,9 +102,46 @@ 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().getTypeRoot()
+                    == LogicalTypeRoot.VARCHAR) {
+                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();
+                if (escape == null) {
+                    Matcher matcher = BEGIN_PATTERN.matcher(sqlPattern);
+                    if (matcher.matches()) {
+                        return new StartsWith(
+                                fieldRefExpr.getFieldIndex(),
+                                matcher.group(1),
+                                sqlPattern.endsWith("_"));

Review Comment:
   > `sqlPattern.endsWith("_")` what it is mean?
   
   match one or more characters



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org