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


##########
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) {

Review Comment:
   Family is `LogicalTypeFamily.CHARACTER_STRING`.
   Char also is OK.



##########
flink-table-store-connector/src/test/java/org/apache/flink/table/store/connector/ReadWriteTableITCase.java:
##########
@@ -1224,6 +1226,144 @@ public void testQueryContainsDefaultFieldName() throws 
Exception {
                 .containsOnly(changelogRow("+I", 1, "abc"));
     }
 
+    @Test
+    public void testLike() throws Exception {
+        rootPath = TEMPORARY_FOLDER.newFolder().getPath();
+        tEnv = StreamTableEnvironment.create(buildBatchEnv(), 
EnvironmentSettings.inBatchMode());
+        List<Row> input =
+                Arrays.asList(
+                        changelogRow("+I", 1, "test_1"),
+                        changelogRow("+I", 2, "test_2"),
+                        changelogRow("+I", 1, "test_%"),
+                        changelogRow("+I", 2, "test%2"),
+                        changelogRow("+I", 3, "university"),
+                        changelogRow("+I", 4, "very"),
+                        changelogRow("+I", 5, "yield"));
+        String id = registerData(input);
+        UUID randomSourceId = UUID.randomUUID();
+        tEnv.executeSql(
+                String.format(
+                        "create table `helper_source_%s` (f0 int, f1 string) 
with ("
+                                + "'connector' = 'values', "
+                                + "'bounded' = 'true', "
+                                + "'data-id' = '%s')",
+                        randomSourceId, id));
+
+        UUID randomSinkId = UUID.randomUUID();
+        tEnv.executeSql(
+                String.format(
+                        "create table `managed_table_%s` with ("
+                                + "'%s' = '%s'"
+                                + ") like `helper_source_%s` "
+                                + "(excluding options)",
+                        randomSinkId, FileStoreOptions.PATH.key(), rootPath, 
randomSourceId));
+        tEnv.executeSql(

Review Comment:
   To test the filter, the best way is to insert it multiple times so that 
multiple files are generated to achieve the effect we want to filter the files.



##########
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?



-- 
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]

Reply via email to