Skip to content

feat(scanner): allow filtering on projected columns - #11738

Open
PenguinLoafs wants to merge 2 commits into
lance-format:mainfrom
PenguinLoafs:feat/filter-projected-columns
Open

PenguinLoafs wants to merge 2 commits into
lance-format:mainfrom
PenguinLoafs:feat/filter-projected-columns

Conversation

@PenguinLoafs

Copy link
Copy Markdown

Summary

Filters cannot reference projection aliases because they are compiled against physical and system columns:

ds.to_table(columns={"double_y": "y * 2"}, filter="double_y > 10")
# FieldNotFound: double_y

This PR resolves eligible aliases by inlining their definitions into the filter at compile time:

Projection: double_y := y * 2
Filter:     double_y > 10
                 ↓ inline
Filter:     (y * 2) > 10

The existing execution order is preserved:

scan / filter → … → limit / offset → final projection
(y * 2) > 10                        double_y := y * 2

Closes #2971

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added A-python Python bindings enhancement New feature or request labels Dec 2, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Dec 2, 2026
let filter_schema =
self.filterable_schema_with_fts_granularity(fts_document_granularity)?;
let planner = Planner::new(Arc::new(filter_schema.as_ref().into()));
let derived_columns = inlinable_derived_columns(

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.

[AI-generated review] inlinable_derived_columns runs before checking self.filter.expr_filter, even though derived_columns is only used inside that branch. The default full projection contains one output per physical column, and Arrow’s Schema::field_with_name performs a linear search. An unfiltered scan of all 4,096 columns therefore adds 8,390,656 field-name comparisons during planning. Moving this call inside if let Some(filter) would let unfiltered scans skip that work, as get_expr_filter already does.

@lance-gatekeeper lance-gatekeeper Bot removed K-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels Dec 2, 2026

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Gate recommendation: approve with a non-blocking risk.

The schema-sensitive alias failures are fixed. The reported wide-schema planning overhead remains a non-blocking risk for scans without filters. Computing alias candidates only when an expression filter exists would avoid that cost.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Dec 2, 2026

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

A-python Python bindings enhancement New feature or request K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow filtering of projected fields

2 participants