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

bug when extracting sub-queries #469

Open
freedomlxin opened this issue Feb 25, 2024 · 0 comments
Open

bug when extracting sub-queries #469

freedomlxin opened this issue Feb 25, 2024 · 0 comments

Comments

@freedomlxin
Copy link

`from sql_metadata import Parser

sql_query = """select o_year, sum(case when nation = 'KENYA' then volume else 0 end) / sum(volume) as mkt_share from
( select extract(year from o_orderdate) as o_year, l_extendedprice * (1 - l_discount) as volume, n2.n_name as nation
from part, supplier, lineitem, orders, customer, nation n1, nation n2, region where p_partkey = l_partkey
and s_suppkey = l_suppkey and l_orderkey = o_orderkey and o_custkey = c_custkey and c_nationkey = n1.n_nationkey
and n1.n_regionkey = r_regionkey and r_name = 'AFRICA' and s_nationkey = n2.n_nationkey and o_orderdate
between date '1995-01-01' and date '1996-12-31' and p_type = 'PROMO POLISHED NICKEL' ) as all_nations group by o_year order by o_year;
"""
parser = Parser(sql_query)
print(parser.columns_dict)`

Traceback (most recent call last):
File "G:\my\index_selection\online\test.py", line 18, in
print(parser.columns_dict)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\liu\AppData\Local\Programs\Python\Python312\Lib\site-packages\sql_metadata\parser.py", line 241, in columns_dict
_ = self.columns
^^^^^^^^^^^^
File "C:\Users\liu\AppData\Local\Programs\Python\Python312\Lib\site-packages\sql_metadata\parser.py", line 205, in columns
columns_aliases_names=self.columns_aliases_names,
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\liu\AppData\Local\Programs\Python\Python312\Lib\site-packages\sql_metadata\parser.py", line 329, in columns_aliases_names
self._handle_column_alias_subquery_level_update(token=token)
File "C:\Users\liu\AppData\Local\Programs\Python\Python312\Lib\site-packages\sql_metadata\parser.py", line 681, in _handle_column_alias_subquery_level_update
self._add_to_columns_aliases_subsection(token=token)
File "C:\Users\liu\AppData\Local\Programs\Python\Python312\Lib\site-packages\sql_metadata\parser.py", line 747, in _add_to_columns_aliases_subsection
section = COLUMNS_SECTIONS[keyword]
~~~~~~~~~~~~~~~~^^^^^^^^^
KeyError: 'FROM'

using sql_metadata 2.10.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant