Skip to content
Open
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
7 changes: 4 additions & 3 deletions docs/source/user_guide/file_index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ whose query uses the same JSON DSL as ``FullTextSearch``. Do not modify a reques
after passing it to a predicate or read context.

Compose full-text and scalar predicates with the existing
``PredicateBuilder::And`` and ``PredicateBuilder::Or`` factories. Every field
referenced by this tree must appear in the read schema; field indices refer to
positions in that schema. For example, the following constructs
``PredicateBuilder::And`` and ``PredicateBuilder::Or`` factories. Referenced fields
need not appear in the output projection. Table reads resolve predicate fields by
name and rebind their execution indices; supplied ``field_index`` values are not
validated. For a table containing ``body`` and ``price``, the following constructs
``body matches "apple" OR price < 10``:

.. code-block:: cpp
Expand Down
5 changes: 3 additions & 2 deletions docs/source/user_guide/format_table.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ is read past. A column the file does not hold is filled with nulls, which is how
before a column was added is still read - unless the table declares that column ``NOT NULL``, when
the file is refused instead, as Java's ``VectorizedParquetRecordReader`` refuses it. Only the
columns a read actually asks a file for are held to the table's schema: a partition column is
rebuilt from the directory name whether or not the file stores one of its own, and a column
outside the projection is never read, which is how Java scopes the same checks.
rebuilt from the directory name whether or not the file stores one of its own. The internal
read schema includes both projected columns and predicate dependencies; columns needed only
for a predicate are removed from the final output after filtering.

``FormatTable`` is the only format-table type in the public API. The classes behind it -
``FormatTableScan``, ``FormatTableRead``, ``FormatTableWrite``, ``FormatTableCommit``,
Expand Down
6 changes: 4 additions & 2 deletions docs/source/user_guide/realtime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,10 @@ For ``id = 7 AND score > 100``, an index supporting equality on ``id`` selects
candidate offsets; statistics can then skip batches whose maximum ``score``
is at most 100.
Statistics cover entire batches, so mixed batches still need row-level
filtering. Keep predicate fields in the read schema and enable
``ReadContextBuilder::EnablePredicateFilter(true)`` for exact filtering.
filtering. Enable ``ReadContextBuilder::EnablePredicateFilter(true)`` for exact
filtering. Predicate fields are resolved by name; supplied ``field_index`` values
are not validated, and execution indices are rebound internally. The reader
fetches any unprojected predicate columns internally.

In-memory and disk indexes are configured independently. Use
``file-index.<type>.columns`` to enable indexes for committed files.
Expand Down
8 changes: 5 additions & 3 deletions include/paimon/predicate/predicate_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ enum class FieldType;
///
/// PredicateBuilder provides static factory methods to create various types of predicates
/// that can be used for filtering data in Paimon tables.
/// Table scans and reads resolve predicate fields by name and rebind their execution indices.
/// They do not validate the supplied field_index values.
class PAIMON_EXPORT PredicateBuilder {
public:
PredicateBuilder() = delete;
Expand All @@ -43,15 +45,15 @@ class PAIMON_EXPORT PredicateBuilder {
/// Create a full-text predicate returning all matching rows without TopK truncation.
/// The field must have STRING type and a full-text index.
/// Project `_<field>_INDEX_SCORE` in the read schema to request score output.
/// @param field_index The index of the field in read schema (0-based).
/// @param field_index Field index stored in the predicate; table queries rebind it by name.
/// @param match The full-text request, including the field name, JSON DSL query and
/// optional eligible row ids.
static Result<std::shared_ptr<Predicate>> FullTextMatch(
int32_t field_index, const std::shared_ptr<FullTextMatch>& match);

/// Create an equality predicate (field == literal).
///
/// @param field_index The index of the field in read schema (0-based).
/// @param field_index Field index stored in the predicate; table queries rebind it by name.
/// @param field_name The name of the field.
/// @param field_type The data type of the field.
/// @param literal The literal value to compare against.
Expand Down Expand Up @@ -113,7 +115,7 @@ class PAIMON_EXPORT PredicateBuilder {
///
/// Tests whether the field value falls within the specified range (inclusive on both ends).
///
/// @param field_index The index of the field in read schema (0-based).
/// @param field_index Field index stored in the predicate; table queries rebind it by name.
/// @param field_name The name of the field.
/// @param field_type The data type of the field.
/// @param included_lower_bound The lower bound of the range (inclusive).
Expand Down
11 changes: 5 additions & 6 deletions include/paimon/read_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,12 @@ class PAIMON_EXPORT ReadContextBuilder {
/// It can significantly improve performance by reducing the amount of data
/// that needs to be read and processed.
///
/// All referenced fields, including full-text match fields, must be projected in the read
/// schema.
/// TODO(lisizhuo.lsz): Align with Java Paimon so fields referenced by predicates no longer need
/// to appear in the projection.
/// Referenced fields, including full-text match fields, need not be projected.
/// Predicate fields are resolved by name; supplied field_index values are not validated,
/// and execution indices are rebound internally.
/// Full-text matches can be combined with scalar predicates using PredicateBuilder::And/Or.
/// Predicates on virtual index score columns (_INDEX_SCORE or _<field>_INDEX_SCORE) are not
/// supported.
/// Among system fields, only _ROW_ID and _SEQUENCE_NUMBER support user predicates, subject
/// to their option requirements.
///
/// @param predicate Shared pointer to the predicate for data filtering.
/// @return Reference to this builder for method chaining.
Expand Down
3 changes: 2 additions & 1 deletion include/paimon/scan_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ class PAIMON_EXPORT ScanContextBuilder {
/// partition_filters is {{k1=1,k2=10}, {k1=2,k2=20}} => OR(AND(k1=1,k2=10), AND(k1=2,k2=20))
ScanContextBuilder& SetPartitionFilter(
const std::vector<std::map<std::string, std::string>>& partition_filters);
/// Set a predicate for filtering data.
/// Set a predicate for filtering data. Predicate fields are resolved by name; supplied
/// field_index values are not validated, and execution indices are rebound internally.
ScanContextBuilder& SetPredicate(const std::shared_ptr<Predicate>& predicate);
/// Set the columns the query reads. A table with `query-auth.enabled=true` asks its catalog
/// for the rules of these columns plus those of the predicate and the partition filter; by
Expand Down
2 changes: 2 additions & 0 deletions src/paimon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ set(PAIMON_COMMON_SRCS
common/reader/late_materializing_file_batch_reader.cpp
common/reader/data_file_reader_factory.cpp
common/reader/predicate_batch_reader.cpp
common/reader/projection_batch_reader.cpp
common/reader/prefetch_file_batch_reader_impl.cpp
common/reader/reader_utils.cpp
common/reader/blob_fallback_batch_reader.cpp
Expand Down Expand Up @@ -750,6 +751,7 @@ if(PAIMON_BUILD_TESTS)
common/reader/data_file_reader_factory_test.cpp
common/reader/late_materializing_file_batch_reader_test.cpp
common/reader/predicate_batch_reader_test.cpp
common/reader/projection_batch_reader_test.cpp
common/reader/prefetch_file_batch_reader_impl_test.cpp
common/reader/reader_utils_test.cpp
common/reader/complete_row_kind_batch_reader_test.cpp
Expand Down
19 changes: 5 additions & 14 deletions src/paimon/common/predicate/predicate_validator.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ class PredicateValidator {
~PredicateValidator() = delete;

static Status ValidatePredicateWithSchema(const arrow::Schema& schema,
const std::shared_ptr<Predicate>& predicate,
bool validate_field_idx) {
const std::shared_ptr<Predicate>& predicate) {
PAIMON_RETURN_NOT_OK(ValidatePredicateWithLiterals(predicate));
return ValidatePredicateWithSchemaImpl(schema, predicate, validate_field_idx);
return ValidatePredicateWithSchemaImpl(schema, predicate);
}

private:
Expand Down Expand Up @@ -90,22 +89,15 @@ class PredicateValidator {
}

static Status ValidatePredicateWithSchemaImpl(const arrow::Schema& schema,
const std::shared_ptr<Predicate>& predicate,
bool validate_field_idx) {
const std::shared_ptr<Predicate>& predicate) {
if (auto leaf_predicate = std::dynamic_pointer_cast<LeafPredicate>(predicate)) {
const auto& field_name = leaf_predicate->FieldName();
// check field index
// check field existence
int32_t schema_field_idx = schema.GetFieldIndex(field_name);
if (schema_field_idx == -1) {
return Status::Invalid(
fmt::format("field {} does not exist in schema", field_name));
}
if (validate_field_idx && schema_field_idx != leaf_predicate->FieldIndex()) {
return Status::Invalid(
fmt::format("field {} has field idx {} in input schema, mismatch field idx "
"{} in predicate",
field_name, schema_field_idx, leaf_predicate->FieldIndex()));
}
// check field type (schema vs. predicate)
const std::shared_ptr<arrow::DataType>& schema_type =
schema.field(schema_field_idx)->type();
Expand All @@ -121,8 +113,7 @@ class PredicateValidator {
std::dynamic_pointer_cast<CompoundPredicate>(predicate)) {
const auto& children = compound_predicate->Children();
for (const auto& child : children) {
PAIMON_RETURN_NOT_OK(
ValidatePredicateWithSchemaImpl(schema, child, validate_field_idx));
PAIMON_RETURN_NOT_OK(ValidatePredicateWithSchemaImpl(schema, child));
}
}
return Status::OK();
Expand Down
Loading
Loading