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

ColumnNotFoundError when doing SQL GROUP BY on a column projection (function on column) #16258

Open
2 tasks done
jaihind213 opened this issue May 16, 2024 · 0 comments
Open
2 tasks done
Assignees
Labels
A-sql Area: Polars SQL functionality bug Something isn't working python Related to Python Polars

Comments

@jaihind213
Copy link

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

import polars as pl
from io import StringIO
my_csv = StringIO(
"""
"run_id","taxi_color","ride_time"
1,Red,2024-05-13 08:30:00
2,Yellow,2024-05-13 10:45:00
3,Green,2024-05-13 13:15:00
4,Blue,2024-05-13 16:20:00
5,Blue,2025-05-13 16:20:00
"""
)
df = pl.read_csv(my_csv, try_parse_dates=True)
ctx = pl.SQLContext(register_globals=True, eager_execution=False)
ctx.register("taxis", df)
query = """SELECT count(*) as total, 
EXTRACT(YEAR FROM ride_time) AS yr 
from taxis group by yr;
"""
sql_result = ctx.execute(query)
sql_result_collected = sql_result.collect()
print(sql_result_collected)

Log output

Traceback (most recent call last):
  File "/Users/vishnuch/work/gitcode/duckberg/polar2.py", line 20, in <module>
    sql_result = ctx.execute(query)
  File "/Users/vishnuch/work/utils/mamba/envs/duckberg/lib/python3.10/site-packages/polars/sql/context.py", line 269, in execute
    res = wrap_ldf(self._ctxt.execute(query))
polars.exceptions.ColumnNotFoundError: yr

Issue description

when we apply a function on a column and try to do group by on that projection, we get column not found.

Expected behavior

the query should return:

yr, total
2024, 4
2025, 1

ps: the query works in postgres and duckdb

Installed versions

--------Version info---------
Polars:               0.20.26
Index type:           UInt32
Platform:             macOS-12.6.4-arm64-arm-64bit
Python:               3.10.14 | packaged by conda-forge | (main, Mar 20 2024, 12:51:49) [Clang 16.0.6 ]

----Optional dependencies----
adbc_driver_manager:  <not installed>
cloudpickle:          <not installed>
connectorx:           <not installed>
deltalake:            <not installed>
fastexcel:            <not installed>
fsspec:               <not installed>
gevent:               <not installed>
hvplot:               <not installed>
matplotlib:           <not installed>
nest_asyncio:         <not installed>
numpy:                1.26.4
openpyxl:             <not installed>
pandas:               2.2.1
pyarrow:              15.0.2
pydantic:             <not installed>
pyiceberg:            <not installed>
pyxlsb:               <not installed>
sqlalchemy:           <not installed>
torch:                <not installed>
xlsx2csv:             <not installed>
xlsxwriter:           <not installed>

@jaihind213 jaihind213 added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels May 16, 2024
@alexander-beedie alexander-beedie added A-sql Area: Polars SQL functionality and removed needs triage Awaiting prioritization by a maintainer labels May 16, 2024
@alexander-beedie alexander-beedie changed the title ColumnNotFoundError when doing group by on a column projection (function on column) ColumnNotFoundError when doing SQL GROUP BY on a column projection (function on column) May 16, 2024
@alexander-beedie alexander-beedie self-assigned this May 16, 2024
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 bug Something isn't working python Related to Python Polars
Projects
None yet
Development

No branches or pull requests

2 participants