feat: per-element predicates on list<struct> in filters (lambda support for array_any_match)
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start with rust/lance-datafusion/src/sql.rs and the filter parsing and Substrait tests. The issue’s update says the filter-only syntax is being handled separately in #10901, while general lambda support depends on DataFusion changes. Check that plan and the DataFusion version in use before choosing a track; done means the selected lambda form parses and passes the listed edge case, index, and Substrait tests.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Update: plan (Nov 10)
We're splitting this into two tracks.
-
Lambda syntax for per-element filters, rewritten to
any_element. #10901 addsany_element(list, 'predicate'). Lance would acceptarray_any_match(list, d -> <predicate over d's fields>)and rewrite it toany_elementwhile parsing the filter.- The lambda never reaches DataFusion's lambda planning, Substrait or execution, so none of the gaps below apply.
- Lance's own literal handling applies inside the predicate.
- Other lambda shapes get a clear error.
-
General lambda support waits on DataFusion. That covers other higher-order functions, and lambdas outside filters. The upstream work:
- apache/datafusion#27088: field access on lambda parameters;
- apache/datafusion#25960: lambdas with the default dialect;
- the Substrait parameter-name fix in apache/datafusion#27086, merged but not yet released.
The prototype hit two more gaps, and both are already fixed on DataFusion main:
get_fieldnow keeps a struct's nulls (apache/datafusion#25122), and a lambda parameter may shadow a column. They arrive with DataFusion 56. The original proposal below is the prototype for this track.
Summary
Filters can't express a predicate that must hold on the same element of a list<struct> column, such as "any detection with label = 'car' AND confidence > 0.9". DataFusion already ships higher-order functions for this (array_any_match, array_filter, array_transform, array_first). Lance's filter dialect doesn't parse lambdas, so they can't be used:
array_any_match(detections, d -> d.label = 'car' AND d.confidence > 0.9)
-- Schema error: No field named d
LanceDialect (rust/lance-datafusion/src/sql.rs) wraps GenericDialect and doesn't override supports_lambda_functions(), which defaults to false in sqlparser 0.62. So d -> ... is read as the JSON arrow operator. Lance already rejects JSON -> access ("JSON access is not supported"), so enabling lambdas doesn't change the meaning of any filter accepted today.
Workarounds today are a separate one-row-per-element table plus a join, or fixed positions (detections[1].label, 1-based), which can't express "any element".
What a working prototype needed
We prototyped this on top of v15.0.0-beta.14 (DataFusion 55.2, sqlparser 0.62). It works end to end through the LanceDB Python API. On synthetic data with about 10 structs per list (1M and 10M rows), it returned exactly the right rows for 6 predicates, including three attributes on one element and combinations with an indexed column, and their NOT complements.
Changes:
LanceDialect::supports_lambda_functions() -> true.- Field access on the lambda parameter. DataFusion's
sql_compound_identifier_to_exprignores lambda scope, sod.labelfails with "No field named d.label". The prototype rewritesd.a.bandd.a[1].bon in-scope lambda parameters into subscripts (d['a']), which plan asget_fieldon the lambda variable. This works around an upstream gap. - Substrait, encode side.
normalize_exprrejectsRexType::Lambda. The prototype walks the lambda body and skipsLambdaParameterReferencewhen remapping fields;LambdaInvocationstays rejected. - Substrait, decode side. Substrait types carry no names, so lambda parameters decode as structs without field names, and planning fails with "Field label not found in struct". The prototype derives the named lambda parameters from the higher-order function's decoded value arguments, as the SQL planner does.
No change was needed in physical planning or higher-order function registration. The scalar-index planner treats the call as non-sargable, so it becomes the refine filter. With AND width > 1920, the width BTree still prefilters and the lambda refines.
Tests in the prototype, all passing:
lance-datafusionwith--features substrait, including 7 Substrait round-trips;lance-indexexpression tests;- a new dataset test covering scan with and without an index,
count_rows,deleteandupdate_wherewith a lambda predicate, and Substrait; - the existing scanner and filtered-read suites.
Proposal
Enable lambda parsing in the filter dialect and land the fixes above, with tests for:
- the "same element" trap: a low-confidence
carnext to a high-confidencepersonmust not match; - null and empty lists, null elements, a predicate that evaluates to null;
NOT array_any_match(...);- combination with indexed columns.
Upstream DataFusion issues for gaps 2 and 4 would let the workarounds go.
We have the prototype as a patch and can open a PR if this direction is welcome.
Related: #1569 (indexing fields inside complex types). An index on list elements would plan against this syntax, or against a plain function form.
- Ngôn ngữ chính
- Rust
- Star
- 7.3k
- Fork
- 929
- Merge trung bình
- 2 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 572
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của lance-format/lance
-
bug(python): read_transaction raises TypeError on a Rewrite with rewritten indicesCó thể đã có người làm @Borg93 đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
lance-format/lance#11117 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
lance-format/lance#10782 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Upgrade DataFusion for the unparser stack-overflow fixCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
lance-format/lance#8225 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
enhancement
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 84/100
lance-format/lance#6425 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Expose compute_pq_distanceCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởenhancement
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 62/100
lance-format/lance#5675 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của lance-format/lance
Issue tương tự
-
area:cli area:security bug priority:medium
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
rtk-ai/rtk#5127 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
status: new topic: ga4gh-sdk type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
comp-rbac
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
ClickHouse/ClickHouse#131875 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
`gws auth login` keeps the old token cache, so API calls use a token from the previous grantĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
googleworkspace/cli#984 ·
Maintainer thường phản hồi trong vòng 1 ngày