Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](paimon)fix like predicate #28803

Merged
merged 3 commits into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@

package org.apache.doris.planner.external.paimon;

import org.apache.doris.analysis.BinaryPredicate;
import org.apache.doris.analysis.CastExpr;
import org.apache.doris.analysis.CompoundPredicate;
import org.apache.doris.analysis.Expr;
import org.apache.doris.analysis.FunctionCallExpr;
import org.apache.doris.analysis.LiteralExpr;
import org.apache.doris.analysis.SlotRef;
import org.apache.doris.thrift.TExprOpcode;

import org.apache.paimon.data.BinaryString;
import org.apache.paimon.predicate.Predicate;
import org.apache.paimon.predicate.PredicateBuilder;
import org.apache.paimon.types.DataField;
Expand Down Expand Up @@ -84,10 +85,9 @@ public Predicate convertToPaimonExpr(Expr dorisExpr) {

private Predicate binaryExprDesc(Expr dorisExpr) {
TExprOpcode opcode = dorisExpr.getOpcode();
BinaryPredicate bp = (BinaryPredicate) dorisExpr;
// Make sure the col slot is always first
SlotRef slotRef = convertDorisExprToSlotRef(bp.getChild(0));
LiteralExpr literalExpr = convertDorisExprToLiteralExpr(bp.getChild(1));
SlotRef slotRef = convertDorisExprToSlotRef(dorisExpr.getChild(0));
LiteralExpr literalExpr = convertDorisExprToLiteralExpr(dorisExpr.getChild(1));
if (slotRef == null || literalExpr == null) {
return null;
}
Expand All @@ -113,6 +113,15 @@ private Predicate binaryExprDesc(Expr dorisExpr) {
return builder.lessOrEqual(idx, value);
case LT:
return builder.lessThan(idx, value);
case INVALID_OPCODE:
if (dorisExpr instanceof FunctionCallExpr) {
String name = dorisExpr.getExprName().toLowerCase();
String s = value.toString();
if (name.equals("like") && !s.startsWith("%") && s.endsWith("%")) {
return builder.startsWith(idx, BinaryString.fromString(s.substring(0, s.length() - 1)));
}
}
return null;
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@
2 2 3 4 5 6 7 8 9.1 10.1 11.10 2020-02-02 13str 14varchar a true aaaa 2023-12-21T10:02:32.747
10 20 30 40 50 60 70 80 90.1 100.1 110.10 2020-03-02 130str 140varchar b false bbbb 2023-12-21T10:02:37.527

-- !predict_like_1 --
1 2 3 4 5 6 7 8 9.1 10.1 11.10 2020-02-02 13str 14varchar a true aaaa 2023-08-13T09:32:38.530
10 20 30 40 50 60 70 80 90.1 100.1 110.10 2020-03-02 130str 140varchar b false bbbb 2023-08-14T08:32:52.821

-- !predict_like_2 --
1 2 3 4 5 6 7 8 9.1 10.1 11.10 2020-02-02 13str 14varchar a true aaaa 2023-08-13T09:32:38.530
10 20 30 40 50 60 70 80 90.1 100.1 110.10 2020-03-02 130str 140varchar b false bbbb 2023-08-14T08:32:52.821

-- !predict_like_3 --

-- !predict_like_4 --
10 20 30 40 50 60 70 80 90.1 100.1 110.10 2020-03-02 130str 140varchar b false bbbb 2023-08-14T08:32:52.821

-- !predict_like_5 --
10 20 30 40 50 60 70 80 90.1 100.1 110.10 2020-03-02 130str 140varchar b false bbbb 2023-08-14T08:32:52.821

-- !c1 --
1 2 3 4 5 6 7 8 9.1 10.1 11.10 2020-02-02 13str 14varchar a true aaaa 2023-08-13T09:32:38.530

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ suite("test_paimon_catalog", "p0,external,doris,external_docker,external_docker_
if (enabled != null && enabled.equalsIgnoreCase("true")) {
def all = """select * from all_table order by c1;"""
def all_with_parquet = """select * from all_table_with_parquet order by c1;"""
def predict_like_1 = """select * from all_table where c13 like '%3%' order by c1"""
def predict_like_2 = """select * from all_table where c13 like '13%' order by c1"""
def predict_like_3 = """select * from all_table where c13 like '13' order by c1"""
def predict_like_4 = """select * from all_table where c13 like '130str' order by c1"""
def predict_like_5 = """select * from all_table where c13 like '130str%' order by c1"""
def c1 = """select * from all_table where c1=1;"""
def c2 = """select * from all_table where c2=2;"""
def c3 = """select * from all_table where c3=3;"""
Expand Down Expand Up @@ -175,6 +180,11 @@ suite("test_paimon_catalog", "p0,external,doris,external_docker,external_docker_

qt_all all
qt_all_with_parquet all_with_parquet
qt_predict_like_1 predict_like_1
qt_predict_like_2 predict_like_2
qt_predict_like_3 predict_like_3
qt_predict_like_4 predict_like_4
qt_predict_like_5 predict_like_5
qt_c1 c1
qt_c2 c2
qt_c3 c3
Expand Down
Loading