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

Support for lateral view explode clause #161

Open
abecus opened this issue Jun 10, 2021 · 5 comments
Open

Support for lateral view explode clause #161

abecus opened this issue Jun 10, 2021 · 5 comments
Milestone

Comments

@abecus
Copy link

abecus commented Jun 10, 2021

getting error when trying to get the tables for sql below,

sql = """
WITH uisd_filter_table as (
    select
        session_id,
        srch_id,
        srch_ci,
        srch_co,
        srch_los,
        srch_sort_type,
        impr_list
    from
        uisd
    where
        datem <= date_sub(date_add(current_date(), 92), 7 * 52)
        and lower(srch_sort_type) in ('expertpicks', 'recommended')
        and srch_ci <= date_sub(date_add(current_date(), 92), 7 * 52)
        and srch_co >= date_sub(date_add(current_date(), 1), 7 * 52)
)
select
    DISTINCT session_id,
    srch_id,
    srch_ci,
    srch_co,
    srch_los,
    srch_sort_type,
    l.impr_property_id as expe_property_id,
    l.impr_position_across_pages
from
    uisd_filter_table lateral view explode(impr_list) table as l
"""

How to reproduce the error:

p = Parser(sql)
print(p.tables)

Error:

Traceback (most recent call last):
  File "/Users/asalam/vscode/new/source_analyser/utils.py", line 152, in <module>
    print(p.tables)
  File "/Users/asalam/Library/Python/3.8/lib/python/site-packages/sql_metadata/parser.py", line 398, in tables
    with_names = self.with_names
  File "/Users/asalam/Library/Python/3.8/lib/python/site-packages/sql_metadata/parser.py", line 544, in with_names
    if token.next_token.normalized in WITH_ENDING_KEYWORDS:
AttributeError: 'NoneType' object has no attribute 'normalized'
@collerek collerek added the bug label Jun 10, 2021
@macbre macbre added this to the v2.3 milestone Jun 10, 2021
collerek added a commit to collerek/sql-metadata that referenced this issue Jun 10, 2021
@collerek
Copy link
Collaborator

@macbre I need your opinion on this, we do not support lateral view explode keyword as of now, the question is if we should?

https://spark.apache.org/docs/latest/sql-ref-syntax-qry-select-lateral-view.html

in a part lateral view explode(impr_list) table as l :

If i'm not mistaken this only refers to hive/spark sql dialect.

What should we do with this?

@macbre macbre modified the milestones: v2.3, v2.2.1 Jun 10, 2021
macbre added a commit that referenced this issue Jun 10, 2021
Fix parsing with clauses, fix for #161
@macbre macbre modified the milestones: v2.2.1, v2.3 Jun 10, 2021
@macbre
Copy link
Owner

macbre commented Jun 10, 2021

Tricky one. Then comes the question if we should for instance support PIVOT as well?

Let's deal with this one in a separate PR / GitHub discussions thread.

@collerek
Copy link
Collaborator

collerek commented Jun 10, 2021

Created a discussion: #166

@collerek
Copy link
Collaborator

@macbre - I think we should either close this one and open a new one with enhancement for lateral view, or rename this one and change the labels, what do you think?

@collerek collerek changed the title AttributeError: 'NoneType' object has no attribute 'normalized' Support for lateral view explode clause Jun 22, 2021
@collerek
Copy link
Collaborator

@abecus The original bug was resolved but the tables still will return wrong data as the lateral view explode is not yet supported.
Therefore I changed the name and label of this issue.

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

No branches or pull requests

3 participants