klahnakoski / mo-sql-parsing

Let's make a SQL parser so we can provide a familiar interface to non-sql datastores!
Mozilla Public License 2.0
255 stars 58 forks source link

ClickHouse Queries #203

Closed VivekBuzruk closed 10 months ago

VivekBuzruk commented 12 months ago

Library version 8.205...

Python throws error while checking columns using results of "parse" function, Errors are -> unhashable type: 'dict' or unhashable type: 'list'

=============== 1] Gives error for many window functions - https://clickhouse.com/docs/en/sql-reference/window-functions Query which generated error - select emp_id, sep_id, programid, row_number() over( partition by emp_id order by sep_id desc) as ord from bidg_1.crs_fact

Query which worked - select rscf.emp_id, rscf.sep_id, rscf.programid, row_number() over w1 as rn_1 from bidg_1.crs_fact rscf Window w1 as (partition by rscf.emp_id order by rscf.sep_id desc)

2] Others which give error - select toDateTime(sc.end_date) as "End Date", sc.emp_id, sc.crs_name as "CRS Name" from "DashGrid4"."stdnt_crs" sc where (toYear(toDate(sc.end_date)) >= 1970)

and

select toDateTime64(end_date, 0) as "End Date", emp_id, crs_name as "CRS Name" from "DashGrid4"."stdnt_crs"

klahnakoski commented 11 months ago

@VivekBuzruk sorry for the late reply. What version does this happen on? The current version (https://pypi.org/project/mo-sql-parsing/9.437.23251/) can parse the SQL fine.

VivekBuzruk commented 11 months ago

Currently using 8.205.22260

OK. will try with latest version

Thanks & Regards

klahnakoski commented 11 months ago

Version 8.205.22260 appears to work on the SQL. you provided.

Given your sentence

Python throws error while checking columns using results of "parse" function

maybe the error is coming from some post processing?

You may consider using parse() with calls=normal_op, which will be in a standard form for easier post processing. Eg

parse("select trim(' ' from b+c)", calls=normal_op)

https://github.com/klahnakoski/mo-sql-parsing#normalized-function-call-form