You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the use-case to extract all table names used by complex queries. Obviously the SqlParser, respectively the QuerySpecification has trouble when the Query stars with a WITH clause.
This is how I parse the Query
importcom.facebook.presto.sql.parser.SqlParserimportcom.facebook.presto.sql.tree.Queryimportcom.facebook.presto.sql.tree.QuerySpecificationval parser =SqlParser()
val query = parser.createStatement(sql, ParsingOptions()) asQueryval body = query.queryBody asQuerySpecificationprintln(body.from.get())
The following query
WITH query AS (
select a fromdb1.table1
)
( select*from query )
throws the Exception
java.lang.ClassCastException: class com.facebook.presto.sql.tree.Union cannot be cast to class com.facebook.presto.sql.tree.QuerySpecification (com.facebook.presto.sql.tree.Union and com.facebook.presto.sql.tree.QuerySpecification are in unnamed module of loader 'app')
Interestingly I was able to solve this by wrapping the query with a dummy SELECT *-Statement
SELECT*FROM (
WITH query AS (
select a fromdb1.table1
)
( select*from query )
)
By that the Statement the SqlParser/QuerySpecification can successfully everything via the created TableSubquery
I have the use-case to extract all table names used by complex queries. Obviously the
SqlParser
, respectively theQuerySpecification
has trouble when the Query stars with aWITH
clause.This is how I parse the Query
The following query
throws the Exception
Interestingly I was able to solve this by wrapping the query with a dummy
SELECT *
-StatementBy that the Statement the
SqlParser
/QuerySpecification
can successfully everything via the createdTableSubquery
The Question is if it could be possible to improve the parser to it could works without the workaround.
The text was updated successfully, but these errors were encountered: