Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy cross join + filter not optimized in non-equi join #18753

Closed
2 tasks done
ion-elgreco opened this issue Sep 15, 2024 · 1 comment · Fixed by #18633
Closed
2 tasks done

Lazy cross join + filter not optimized in non-equi join #18753

ion-elgreco opened this issue Sep 15, 2024 · 1 comment · Fixed by #18633
Assignees
Labels
accepted Ready for implementation bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@ion-elgreco
Copy link
Contributor

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

print(df.lazy().join(
    parts.lazy(),
    how='cross'
).filter(
    (pl.col('id') == pl.col('id')) & 
    (pl.col('start_date') <= pl.col('date') ) &
    (pl.col('end_date') >= pl.col('date'))
).explain(optimized=True))


FILTER [([([(col("id")) == (col("id"))]) & ([(col("end_date")) >= (col("date"))])]) & ([(col("start_date")) <= (col("date"))])] FROM
  CROSS JOIN:
  LEFT PLAN ON: []
    DF ["id", "start_date", "end_date"]; PROJECT */3 COLUMNS; SELECTION: None
  RIGHT PLAN ON: []
    DF ["id", "date"]; PROJECT */2 COLUMNS; SELECTION: None
  END CROSS JOIN

Log output

No response

Issue description

DuckDB optimizes this cross join into a non-equi join, polars is keeping it currently as a cross join.

Expected behavior

If possible optimize the cross join + filter in a non-equi join

Installed versions

--------Version info---------
Polars:              1.7.1
Index type:          UInt32
Platform:            Linux-5.15.153.1-microsoft-standard-WSL2-x86_64-with-glibc2.39
Python:              3.10.14 (main, Aug 14 2024, 05:11:29) [Clang 18.1.8 ]

----Optional dependencies----
adbc_driver_manager  <not installed>
altair               <not installed>
cloudpickle          <not installed>
connectorx           <not installed>
deltalake            0.19.1
fastexcel            <not installed>
fsspec               <not installed>
gevent               <not installed>
great_tables         <not installed>
matplotlib           <not installed>
nest_asyncio         1.6.0
numpy                1.22.2
openpyxl             <not installed>
pandas               <not installed>
pyarrow              17.0.0
pydantic             <not installed>
pyiceberg            <not installed>
sqlalchemy           <not installed>
torch                <not installed>
xlsx2csv             <not installed>
xlsxwriter           <not installed>
@ion-elgreco ion-elgreco added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Sep 15, 2024
@coastalwhite
Copy link
Collaborator

We are already on it 😄

#18633

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants