Skip to content

Commit 052fd68

Browse files
committed
feat: support LeafFunction of StartsWith, EndsWith, Contains, Like
1 parent 37ba043 commit 052fd68

34 files changed

Lines changed: 824 additions & 122 deletions

include/paimon/predicate/function.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ class PAIMON_EXPORT Function {
3737
IN = 9,
3838
NOT_IN = 10,
3939
AND = 11,
40-
OR = 12
40+
OR = 12,
41+
STARTS_WITH = 13,
42+
ENDS_WITH = 14,
43+
CONTAINS = 15,
44+
LIKE = 16
4145
};
4246
virtual ~Function() = default;
4347
virtual Type GetType() const = 0;

include/paimon/predicate/predicate_builder.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,30 @@ class PAIMON_EXPORT PredicateBuilder {
133133
///
134134
/// @param predicate A shared pointer to the predicate to be negated, which must not be nullptr.
135135
static Result<std::shared_ptr<Predicate>> Not(const std::shared_ptr<Predicate>& predicate);
136+
137+
/// Create a starts-with predicate (field like 'abc%' or field like 'abc_').
138+
///
139+
/// Tests whether the field value starts with the provided literal value.
140+
static std::shared_ptr<Predicate> StartsWith(int32_t field_index, const std::string& field_name,
141+
const FieldType& field_type,
142+
const Literal& literal);
143+
144+
/// Create an ends-with predicate (field like '%abc' or field like '_abc').
145+
///
146+
/// Tests whether the field value ends with the provided literal value.
147+
static std::shared_ptr<Predicate> EndsWith(int32_t field_index, const std::string& field_name,
148+
const FieldType& field_type, const Literal& literal);
149+
150+
/// Create a contains predicate (field like '%abc%').
151+
///
152+
/// Tests whether the field value contains the provided literal value.
153+
static std::shared_ptr<Predicate> Contains(int32_t field_index, const std::string& field_name,
154+
const FieldType& field_type, const Literal& literal);
155+
156+
/// Create a like predicate (field like literal).
157+
///
158+
/// Tests whether the field value like the provided literal value.
159+
static std::shared_ptr<Predicate> Like(int32_t field_index, const std::string& field_name,
160+
const FieldType& field_type, const Literal& literal);
136161
};
137162
} // namespace paimon
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2026-present Alibaba Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
#include <string>
20+
21+
#include "paimon/common/predicate/string_leaf_binary_function.h"
22+
#include "paimon/result.h"
23+
24+
namespace paimon {
25+
/// A `StringLeafBinaryFunction` to eval filter like '%abc%'.
26+
class Contains : public StringLeafBinaryFunction {
27+
public:
28+
static const Contains& Instance() {
29+
static const Contains instance = Contains();
30+
return instance;
31+
}
32+
33+
Result<bool> TestString(const std::string& field, const std::string& pattern) const override {
34+
return field.find(pattern) != std::string::npos;
35+
}
36+
37+
Type GetType() const override {
38+
return Type::CONTAINS;
39+
}
40+
41+
std::string ToString() const override {
42+
return "Contains";
43+
}
44+
45+
private:
46+
Contains() = default;
47+
};
48+
} // namespace paimon
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2026-present Alibaba Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
#include <string>
20+
21+
#include "paimon/common/predicate/string_leaf_binary_function.h"
22+
#include "paimon/result.h"
23+
24+
namespace paimon {
25+
/// A `StringLeafBinaryFunction` to eval filter like '%abc' or filter like '_abc'.
26+
class EndsWith : public StringLeafBinaryFunction {
27+
public:
28+
static const EndsWith& Instance() {
29+
static const EndsWith instance = EndsWith();
30+
return instance;
31+
}
32+
33+
Result<bool> TestString(const std::string& field, const std::string& pattern) const override {
34+
return field.size() >= pattern.size() &&
35+
std::equal(pattern.rbegin(), pattern.rend(), field.rbegin());
36+
}
37+
38+
Type GetType() const override {
39+
return Type::ENDS_WITH;
40+
}
41+
42+
std::string ToString() const override {
43+
return "EndsWith";
44+
}
45+
46+
private:
47+
EndsWith() = default;
48+
};
49+
} // namespace paimon

src/paimon/common/predicate/equal.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
namespace paimon {
2222
class LeafFunction;
2323

24-
const LeafFunction& Equal::Negate() const {
25-
return NotEqual::Instance();
24+
const LeafFunction* Equal::Negate() const {
25+
return &NotEqual::Instance();
2626
}
2727

2828
} // namespace paimon

src/paimon/common/predicate/equal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Equal : public NullFalseLeafBinaryFunction {
5252
Type GetType() const override {
5353
return Type::EQUAL;
5454
}
55-
const LeafFunction& Negate() const override;
55+
const LeafFunction* Negate() const override;
5656
std::string ToString() const override {
5757
return "Equal";
5858
}

src/paimon/common/predicate/greater_or_equal.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
namespace paimon {
2222
class LeafFunction;
2323

24-
const LeafFunction& GreaterOrEqual::Negate() const {
25-
return LessThan::Instance();
24+
const LeafFunction* GreaterOrEqual::Negate() const {
25+
return &LessThan::Instance();
2626
}
2727

2828
} // namespace paimon

src/paimon/common/predicate/greater_or_equal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class GreaterOrEqual : public NullFalseLeafBinaryFunction {
4949
Type GetType() const override {
5050
return Type::GREATER_OR_EQUAL;
5151
}
52-
const LeafFunction& Negate() const override;
52+
const LeafFunction* Negate() const override;
5353
std::string ToString() const override {
5454
return "GreaterOrEqual";
5555
}

src/paimon/common/predicate/greater_than.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const GreaterThan& GreaterThan::Instance() {
2626
return kInstance;
2727
}
2828

29-
const LeafFunction& GreaterThan::Negate() const {
30-
return LessOrEqual::Instance();
29+
const LeafFunction* GreaterThan::Negate() const {
30+
return &LessOrEqual::Instance();
3131
}
3232
} // namespace paimon

src/paimon/common/predicate/greater_than.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class GreaterThan : public NullFalseLeafBinaryFunction {
4646
Type GetType() const override {
4747
return Type::GREATER_THAN;
4848
}
49-
const LeafFunction& Negate() const override;
49+
const LeafFunction* Negate() const override;
5050

5151
std::string ToString() const override {
5252
return "GreaterThan";

0 commit comments

Comments
 (0)