Skip to content

feat: Expose fixed-array inner product in SQL - #29033

Merged
ritchie46 merged 2 commits into
pola-rs:mainfrom
0guban0v:feat/sql-array-inner-product
Aug 31, 2026
Merged

ritchie46 merged 2 commits into
pola-rs:mainfrom
0guban0v:feat/sql-array-inner-product

Conversation

@0guban0v

@0guban0v 0guban0v commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes #28928

Adds ARRAY_INNER_PRODUCT(lhs, rhs) and ARRAY_DOT_PRODUCT as SQL entry points to native fixed-size Array dot path introduced in #28504 and extended across integer dtypes in #28829.

Lowering deliberately ends at Expr::arr().dot() instead of rebuilding (lhs * rhs).arr.sum(). SQL inherits supertype coercion, output dtype, integer wrapping, null behavior, execution-engine behavior, and allocation improvements from #28980 while avoiding intermediate product Array.

Direct SQL array literals passed to this function are represented as scalar fixed-size Arrays. Everywhere else, SQL array literals remain List-backed, avoiding global coercion changes. Query-vector form matches native one-row broadcasting, and #29000 can preserve scalar through dispatch and broadcast result without SQL-specific follow-up.

Coverage includes both aliases, mixed inner dtypes, literal syntax and argument position, all-null and constant literals, projection-height broadcasting, native plan shape, non-Array rejection, arity, and width validation.

Example:

import polars as pl

dtype = pl.Array(pl.Float64, 2)
df = pl.DataFrame(
    {
        "lhs": [[1.0, 2.0], [3.0, 4.0]],
        "rhs": [[10.0, 20.0], [30.0, 40.0]],
    },
    schema={"lhs": dtype, "rhs": dtype},
)

result = df.sql("""
SELECT
  ARRAY_INNER_PRODUCT(lhs, rhs) AS rowwise_dot,
  ARRAY_DOT_PRODUCT(lhs, [10.0, 20.0]) AS query_dot
FROM self
""")

print(result)

Output:

shape: (2, 2)
┌─────────────┬───────────┐
│ rowwise_dot ┆ query_dot │
│ ---         ┆ ---       │
│ f64         ┆ f64       │
╞═════════════╪═══════════╡
│ 50.0        ┆ 50.0      │
│ 250.0       ┆ 110.0     │
└─────────────┴───────────┘

@github-actions github-actions Bot added A-sql Area: Polars SQL functionality enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars labels Aug 29, 2026
@0guban0v
0guban0v marked this pull request as draft August 29, 2026 21:54
@0guban0v
0guban0v marked this pull request as ready for review August 29, 2026 22:42
@codecov

codecov Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.47%. Comparing base (5fb8434) to head (ea68b05).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #29033      +/-   ##
==========================================
+ Coverage   81.40%   81.47%   +0.06%     
==========================================
  Files        1888     1888              
  Lines      267825   267855      +30     
  Branches     3061     3061              
==========================================
+ Hits       218012   218222     +210     
+ Misses      49033    48854     -179     
+ Partials      780      779       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ritchie46
ritchie46 merged commit 39f0904 into pola-rs:main Aug 31, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-sql Area: Polars SQL functionality enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose fixed-size Array inner product in Polars SQL

2 participants