JingsongLi commented on code in PR #87:
URL: https://github.com/apache/flink-table-store/pull/87#discussion_r849388618
##########
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, and the following two conditions I can not
understand, and I am not sure there is no bug.
##########
flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/source/TableStoreSource.java:
##########
@@ -177,11 +181,36 @@ public String asSummaryString() {
@Override
public Result applyFilters(List<ResolvedExpression> filters) {
+ List<ResolvedExpression> partitionFilters = new ArrayList<>();
+ List<ResolvedExpression> fieldFilters = new ArrayList<>();
+
if (tableStore.partitioned()) {
- classifyFilters(filters);
+ classifyFilters(filters, partitionFilters, fieldFilters);
} else {
fieldFilters = filters;
}
+ fieldPredicate =
+ fieldFilters.stream()
+ .map(PredicateConverter::convert)
+ .filter(Either::isLeft)
+ .map(Either::left)
+ .reduce(And::new)
+ .orElse(null);
+ Stream<Either<Predicate, ResolvedExpression>> partitionStream =
Review Comment:
I think `Either` is not good to understand. I think we can just classify
them in a simple loop. For example:
```
List<Predicate> partitionFilters = new ArrayList<>();
List<Predicate> fieldFilters = new ArrayList<>();
List<ResolvedExpression> notAcceptedFilters = new ArrayList<>();
for (ResolvedExpression filter: filters) {
if (filter can be a partition filter) {
....
} else ....
}
```
--
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]