Predicate#

Interface#

class Predicate#

Predicate interface.

To create a predicate, please use PredicateBuilder.

See also

PredicateBuilder

Subclassed by paimon::CompoundPredicate, paimon::LeafPredicate

Public Functions

virtual ~Predicate() = default#
virtual bool operator==(const Predicate &other) const = 0#
virtual const Function &GetFunction() const = 0#
virtual std::shared_ptr<Predicate> Negate() const = 0#
Returns:

The negation predicate of this predicate if possible.

virtual std::string ToString() const = 0#
class LeafPredicate : public virtual paimon::Predicate#

Leaf node of a Predicate tree. Compares a field with literals.

Public Functions

inline int32_t FieldIndex() const#
inline const std::string &FieldName() const#
inline FieldType GetFieldType() const#
inline const std::vector<Literal> &Literals() const#
virtual const Function &GetFunction() const override#
virtual std::string ToString() const override#
virtual std::shared_ptr<Predicate> Negate() const override#
Returns:

The negation predicate of this predicate if possible.

virtual bool operator==(const Predicate &other) const override#
class CompoundPredicate : public virtual paimon::Predicate#

Non-leaf node in a Predicate tree.

Its evaluation result depends on the results of its children.

Public Functions

virtual const Function &GetFunction() const override#
inline const std::vector<std::shared_ptr<Predicate>> &Children() const#
virtual std::shared_ptr<Predicate> Negate() const override#
Returns:

The negation predicate of this predicate if possible.

virtual std::string ToString() const override#
virtual bool operator==(const Predicate &other) const override#
class Function#

Function represents a predicate function used in query expressions and filtering operations.

It serves as the base class for all predicate functions in Paimon.

Public Types

enum class Type#

Values:

enumerator IS_NULL#
enumerator IS_NOT_NULL#
enumerator EQUAL#
enumerator NOT_EQUAL#
enumerator GREATER_THAN#
enumerator GREATER_OR_EQUAL#
enumerator LESS_THAN#
enumerator LESS_OR_EQUAL#
enumerator IN#
enumerator NOT_IN#
enumerator AND#
enumerator OR#

Public Functions

virtual ~Function() = default#
virtual Type GetType() const = 0#
virtual std::string ToString() const = 0#
template<typename T>
class FunctionVisitor#

A visitor interface for evaluating filter predicates on indexed columns.

Template Parameters:

T – The result type produced by each visit method (e.g., a file index result or global index result).

Public Functions

virtual ~FunctionVisitor() = default#
virtual Result<T> VisitIsNotNull() = 0#

Evaluates the IS NOT NULL predicate on the indexed column.

virtual Result<T> VisitIsNull() = 0#

Evaluates the IS NULL predicate on the indexed column.

virtual Result<T> VisitEqual(const Literal &literal) = 0#

Evaluates the equality (==) predicate against the given literal.

virtual Result<T> VisitNotEqual(const Literal &literal) = 0#

Evaluates the inequality (!=) predicate against the given literal.

virtual Result<T> VisitLessThan(const Literal &literal) = 0#

Evaluates the less-than (<) predicate against the given literal.

virtual Result<T> VisitLessOrEqual(const Literal &literal) = 0#

Evaluates the less-than-or-equal (<=) predicate against the given literal.

virtual Result<T> VisitGreaterThan(const Literal &literal) = 0#

Evaluates the greater-than (>) predicate against the given literal.

virtual Result<T> VisitGreaterOrEqual(const Literal &literal) = 0#

Evaluates the greater-than-or-equal (>=) predicate against the given literal.

virtual Result<T> VisitIn(const std::vector<Literal> &literals) = 0#

Evaluates the IN predicate against a list of literals.

virtual Result<T> VisitNotIn(const std::vector<Literal> &literals) = 0#

Evaluates the NOT IN predicate against a list of literals.

virtual Result<T> VisitStartsWith(const Literal &prefix) = 0#

Evaluates whether string values start with the given prefix.

virtual Result<T> VisitEndsWith(const Literal &suffix) = 0#

Evaluates whether string values end with the given prefix.

virtual Result<T> VisitContains(const Literal &literal) = 0#

Evaluates whether string values contain the given substring.

class Literal#

Literal represents a constant value used in predicate expressions.

Literal support BOOLEAN, TINYINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, STRING, BINARY, TIMESTAMP, DECIMAL, DATE.

Public Functions

explicit Literal(FieldType type)#

Creates a null literal of the specified type.

Parameters:

type – The field type for this null literal.

template<typename T>
explicit Literal(const T &val)#

Creates a literal from a typed value.

The template parameter T must be compatible with one of the supported field types.

Template Parameters:

T – The C++ type of the value (must match a supported FieldType).

Parameters:

val – The value to store in the literal.

Literal(FieldType binary_type, const char *str, size_t size)#

Creates a literal from binary data (string or binary type).

The data is copied into the literal’s internal storage.

Note

BLOB type is not supported by literal

Parameters:
  • binary_type – Must be either STRING or BINARY field type.

  • str – Pointer to the binary data.

  • size – Size of the binary data in bytes.

Literal(FieldType binary_type, const char *str, size_t size, bool own_data)#

Creates a literal from binary data with optional data ownership.

Parameters:
  • binary_type – Must be either STRING or BINARY field type.

  • str – Pointer to the binary data.

  • size – Size of the binary data in bytes.

  • own_data – If true, the literal takes ownership and will free the data; if false, the caller must ensure the data remains valid.

Literal(FieldType date_type, int32_t date_value)#

Creates a date literal from an integer value.

Parameters:
  • date_type – Must be DATE field type.

  • date_value – Date value as days since epoch (1970-01-01).

Literal(const Literal &other)#
~Literal()#
Literal(Literal &&other)#
Literal &operator=(Literal &&other)#
Literal &operator=(const Literal &other)#
bool operator==(const Literal &other) const#
bool operator!=(const Literal &other) const#
bool IsNull() const#

Checks if this literal represents a null value.

template<typename T>
T GetValue() const#

Gets the typed value stored in this literal.

Warning

This method is unsafe - caller must verify the type and null status first.

Template Parameters:

T – The expected C++ type of the value.

Returns:

The value of type T.

FieldType GetType() const#

Gets the field type of this literal.

std::string ToString() const#
size_t HashCode() const#

Gets the hash code for this literal.

Result<int32_t> CompareTo(const Literal &other) const#

Compares this literal with another literal.

The comparison follows SQL semantics for the respective data types.

Parameters:

other – The literal to compare with.

Returns:

Result containing -1 (this < other), 0 (this == other), or 1 (this > other), or an error if the literals are not comparable.

class PredicateBuilder#

A utility class to create Predicate object for common filter conditions.

PredicateBuilder provides static factory methods to create various types of predicates that can be used for filtering data in Paimon tables.

Public Functions

PredicateBuilder() = delete#
~PredicateBuilder() = delete#

Public Static Functions

static std::shared_ptr<Predicate> Equal(int32_t field_index, const std::string &field_name, const FieldType &field_type, const Literal &literal)#

Create an equality predicate (field == literal).

Parameters:
  • field_index – The index of the field in read schema (0-based).

  • field_name – The name of the field.

  • field_type – The data type of the field.

  • literal – The literal value to compare against.

Returns:

A shared pointer to the created Predicate object.

static std::shared_ptr<Predicate> NotEqual(int32_t field_index, const std::string &field_name, const FieldType &field_type, const Literal &literal)#

Create a not-equal predicate (field != literal).

static std::shared_ptr<Predicate> LessThan(int32_t field_index, const std::string &field_name, const FieldType &field_type, const Literal &literal)#

Create a less-than predicate (field < literal).

static std::shared_ptr<Predicate> LessOrEqual(int32_t field_index, const std::string &field_name, const FieldType &field_type, const Literal &literal)#

Create a less-than-or-equal predicate (field <= literal).

static std::shared_ptr<Predicate> GreaterThan(int32_t field_index, const std::string &field_name, const FieldType &field_type, const Literal &literal)#

Create a greater-than predicate (field > literal).

static std::shared_ptr<Predicate> GreaterOrEqual(int32_t field_index, const std::string &field_name, const FieldType &field_type, const Literal &literal)#

Create a greater-than-or-equal predicate (field >= literal).

static std::shared_ptr<Predicate> IsNull(int32_t field_index, const std::string &field_name, const FieldType &field_type)#

Create an IS NULL predicate (field IS NULL).

static std::shared_ptr<Predicate> IsNotNull(int32_t field_index, const std::string &field_name, const FieldType &field_type)#

Create an IS NOT NULL predicate (field IS NOT NULL).

static std::shared_ptr<Predicate> In(int32_t field_index, const std::string &field_name, const FieldType &field_type, const std::vector<Literal> &literals)#

Create an IN predicate (field IN (literal1, literal2, …)).

Tests whether the field value matches any of the provided literal values.

static std::shared_ptr<Predicate> NotIn(int32_t field_index, const std::string &field_name, const FieldType &field_type, const std::vector<Literal> &literals)#

Create a NOT IN predicate (field NOT IN (literal1, literal2, …)).

Tests whether the field value does not match any of the provided literal values.

static std::shared_ptr<Predicate> Between(int32_t field_index, const std::string &field_name, const FieldType &field_type, const Literal &included_lower_bound, const Literal &included_upper_bound)#

Create a BETWEEN predicate (field BETWEEN lower_bound AND upper_bound).

Tests whether the field value falls within the specified range (inclusive on both ends).

Parameters:
  • field_index – The index of the field in read schema (0-based).

  • field_name – The name of the field.

  • field_type – The data type of the field.

  • included_lower_bound – The lower bound of the range (inclusive).

  • included_upper_bound – The upper bound of the range (inclusive).

static Result<std::shared_ptr<Predicate>> And(const std::vector<std::shared_ptr<Predicate>> &predicates)#

Create an AND predicate combining multiple predicates.

Creates a logical AND operation that evaluates to true only when all input predicates evaluate to true.

Parameters:

predicates – A vector of shared pointers to the predicates, which must not be empty.

static Result<std::shared_ptr<Predicate>> Or(const std::vector<std::shared_ptr<Predicate>> &predicates)#

Create an OR predicate combining multiple predicates.

Creates a logical OR operation that evaluates to true when at least one of the input predicates evaluates to true.

Parameters:

predicates – A vector of shared pointers to the predicates, which must not be empty.