JSQLParser / JSqlParser

JSqlParser parses an SQL statement and translate it into a hierarchy of Java classes. The generated hierarchy can be navigated using the Visitor Pattern
https://github.com/JSQLParser/JSqlParser/wiki
Apache License 2.0
5.43k stars 1.35k forks source link

[BUG] 4.5: SNOWFLAKE : Lateral flatten failing parsing #1835

Closed anilpuliyeril closed 1 year ago

anilpuliyeril commented 1 year ago

Always check against the Latest SNAPSHOT of JSQLParser and the Syntax Diagram

Failing SQL Feature:

SQL Example:

WITH t AS (
  SELECT 
    'ABC' AS dim, 
    ARRAY_CONSTRUCT('item1', 'item2', 'item3') AS user_items
)
SELECT DIM, count(value) as COUNT_
FROM t a,
LATERAL FLATTEN(input => a.user_items) b
group by 1

Software Information:

Tips:

Lateral flatten is similar to explode used to flatten a json structure. https://docs.snowflake.com/en/sql-reference/functions/flatten

http://jsqlformatter.manticore-projects.com/jsqlformatter/demo.html?args=-c%20OoSQKgEgBALlCCBlKAKAUFKiCiAZbAwmFBplAOTwBCB5CyAJgJYC2ANCWQgErfwCaAfQIB5AHKIw3AKpEU5JjACmLAIzkOC5SwBMGiopUBmcgEp6UAK4BnJQCdBhltbSm0OfESgAREAFkOAGMAe0sAOxgUADcAQwAbSyVzGOsoUWkxMEE0ADFuET9YKBi2NFx4MGw+XCgc8rBKsRQmMIAHSzgAXgA+YoA6G3tHbWtzACM0AHM7UNaoMYBPKFUgA

manticore-projects commented 1 year ago

Greetings,

only LATERAL subquery is supported: http://217.160.215.75:8080/jsqlformatter/JSQLParser/syntax_snapshot.html#lateralview although this certainly can be changed into a LATERAL expression which would cover Function and Select objects.

manticore-projects commented 1 year ago

This one works already

-- subquery
select * from lateral (select 1)

-- expression
select * from lateral (select * from flatten(input => a.user_items))
anilpuliyeril commented 1 year ago

Thanks that worked. Do you think adding support for lateral flatten would be done in the future? I can try looking through the code to see if i can create a PR for the same.

manticore-projects commented 1 year ago

Certainly today in the afternoon.

Changing Query to Expression is a minor thing. I was not aware that LATERAL works with both Query and Function. The documentation is never really verbose.

anilpuliyeril commented 1 year ago

Hi @manticore-projects were you able to add it in? Is there a PR i can probably use for my local testing? Thanks in advance

anilpuliyeril commented 1 year ago

@manticore-projects quickly checking again if this is still being planned

manticore-projects commented 1 year ago

Thank you for the reminders and sorry for taking that long. Cheers!

anilpuliyeril commented 1 year ago

Thanks a lot 🙏