Skip to content

feat(read): support predicates on non-projected fields - #599

Open
lszskye wants to merge 2 commits into
apache:mainfrom
lszskye:unbind_predicate_field_in_projection
Open

lszskye wants to merge 2 commits into
apache:mainfrom
lszskye:unbind_predicate_field_in_projection

Conversation

@lszskye

@lszskye lszskye commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Purpose

Remove the requirement that predicate fields must appear in the output projection. For example, a read can now return only name while filtering on age, without exposing age in the result. This also applies to full-text predicate fields.

Introduce ReadSchemaPlan to separate the requested output schema from the internal schema containing predicate and authorization dependencies. Use ProjectionBatchReader to remove these dependencies after filtering, merging, or masking. Apply this consistently across append, primary-key, data-evolution, realtime, precise-index, query-auth, and format-table reads.

The change also addresses several predicate-handling issues:

  • AbstractSplitRead: Pass only predicates on fields present in the data schema to file-index evaluation, excluding virtual system fields. Preserve the original predicate for subsequent reading and filtering.
  • CompleteRowTrackingFieldsBatchReader: Stop pushing predicates on missing _ROW_ID and _SEQUENCE_NUMBER columns into the physical format reader. Keep these predicates for the existing filtering stage after the values are completed. Predicates on columns already present in the file remain eligible for pushdown.
  • FileStoreScan: Exclude predicates requiring virtual row-tracking fields from manifest-statistics pruning. Drop the entire affected conjunct, including mixed OR expressions, to avoid incorrectly pruning matching files.
  • Predicate validation: Remove field-index equality checks while retaining field existence, type, and literal validation. Bind execution positions by field name so existing callers using projection-relative indices remain compatible.

Tests

Add or update coverage for:

  • Unprojected data and partition predicates in append and primary-key reads, including schema evolution.
  • Data-evolution, precise scalar/full-text index reads, score output, and realtime disk/memory reads.
  • Realtime deduplication and primary-key merging before filtering and projection.
  • Query-auth predicates on unprojected masked columns and format-table predicates on unprojected columns.
  • Projection behavior with selection bitmaps, dictionary arrays, metadata, nulls, and empty projections.

API and Format

No public API signature, storage format, or protocol changes.

Documentation

Update predicate API comments and the file-index, realtime, and format-table guides to describe predicates on non-projected fields.

Generative AI tooling

Generated-by: OpenAI Codex (GPT-6)

@SteNicholas SteNicholas left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lszskye, I left two comments for read correctness issues. PTAL.

completed_fields.insert(SpecialFields::SequenceNumber().Name());
}
PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<Predicate> physical_predicate,
PredicateUtils::ExcludePredicateWithFields(predicate, completed_fields));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exclude predicates on row-tracking values that the reader can fill in. ConvertRowTrackingField() replaces NULLs even when the column is physically present. For example, an ORC stripe with a stored NULL _SEQUENCE_NUMBER can be skipped by _SEQUENCE_NUMBER = 8 before the reader fills that NULL from a file sequence number of 8. The residual filter then never sees the matching row. Please keep these conjuncts out of physical pushdown unless the file proves the relevant values are non-null, and cover both all-null and mixed-null physical columns.

DataField::ConvertDataFieldToArrowField(SpecialFields::SequenceNumber()));
}
PAIMON_RETURN_NOT_OK(
SpecialFields::ValidatePredicateFieldNames(field_names, allowed_system_fields));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preserve predicates on an explicitly projected _VALUE_KIND for primary-key reads. The base accepts SetReadFieldNames({"_VALUE_KIND"}) with _VALUE_KIND = 0 and residual filtering enabled. The primary-key read paths already carry the real row kind to the residual filter. The new allowlist rejects the same request at TableRead::Create(). Please retain this previously supported case and cover it with a primary-key read test.

ArrowSchema c_schema;
PAIMON_RETURN_NOT_OK_FROM_ARROW(arrow::ExportSchema(*arrow_schema, &c_schema));
return reader_->SetReadSchema(&c_schema, predicate, selection_bitmap);
return reader_->SetReadSchema(&c_schema, physical_predicate, selection_bitmap);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For completed_fields, do you mean it’s supposed to represent fields that are missing in the file and should be removed? As it stands now, it looks more like it’s being added rather than removed.

ScopeGuard release([batch]() { ReaderUtils::ReleaseReadBatch(std::move(*batch)); });
auto& [c_array, c_schema] = *batch;
PAIMON_ASSIGN_OR_RAISE_FROM_ARROW(std::shared_ptr<arrow::Field> root,
arrow::ImportField(c_schema.get()));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m a bit confused—didn’t we previously use ImportArray to import both c_schema and c_array together?

PAIMON_RETURN_NOT_OK_FROM_ARROW(arrow::ExportArray(*output, c_array.get()));
PAIMON_RETURN_NOT_OK_FROM_ARROW(
arrow::ExportField(*root->WithType(output->type()), c_schema.get()));
PAIMON_RETURN_NOT_OK(AddArrowArrayLifetime(c_array.get(), c_schema.get(), array));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure ExportField is the right choice here. Can we use ExportArray directly, since it can reset both c_schema and c_array? Also, why do we need AddArrowArrayLifetime and pass array? I understand this class is for trimming fields and doesn’t involve any new memory allocation, so we probably don’t need to add array lifetime. In general, AddArrowArrayLifetime is used when attaching a pool.


/// Drops dependency columns after filtering/merging, preserving the actual batch fields and
/// the leading _VALUE_KIND. Retains implicit index scores until the outer TopK reader consumes
/// them and removes scores absent from the output schema.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the caller explicitly specify which score columns to retain? Keeping all _<field>_INDEX_SCORE columns here couples projection to the outer TopK reader.


/// Separates the requested output from the columns needed to produce it.
class ReadSchemaPlan {
public:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In precise mode, if the corresponding predicate already has an exact index result, please don’t do any further I/O for that field in data file (unless the user has requested recall).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants