[jira] [Commented] (CALCITE-2844) Babel parser should parse PostgreSQL table functions

2019-04-05 Thread Muhammad Gelbana (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2844?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16810950#comment-16810950
 ] 

Muhammad Gelbana commented on CALCITE-2844:
---

Thanks a lot! Your suggestions were extremely helpful. They helped me progress 
a lot until the this query failed
{code:sql}
select * from emp (x int, y varchar(10) not null) t(a, b){code}
this made me think that what I'm doing should end because it's so untidy 
already so I did what I mentioned on the mailing list, which is to extend the 
first choice for {{TableRef2}} that starts with consuming the table name, and 
later on would decide if that's a table name or a function name. So no other 
choices added here.

My work is located 
[here|https://github.com/MGelbana/calcite/commits/CALCITE-2844].

I'll see what I can do further to clean things up a bit in the parser where I 
did my changes becuase I duplicated some of the {{TableFunctionCall}} logic.

> Babel parser should parse PostgreSQL table functions
> 
>
> Key: CALCITE-2844
> URL: https://issues.apache.org/jira/browse/CALCITE-2844
> Project: Calcite
>  Issue Type: Bug
>  Components: babel
>Affects Versions: 1.18.0
>Reporter: Muhammad Gelbana
>Priority: Major
>
> *Code to reproduce the problem*
> {code:java}
> public static void main(String[] args) throws Exception {
> Config parserConfig = 
> configBuilder().setConformance(SqlConformanceEnum.BABEL).setParserFactory(SqlBabelParserImpl.FACTORY).build();
> FrameworkConfig frameworkConfig = 
> Frameworks.newConfigBuilder().parserConfig(parserConfig).build();
> Planner planner = Frameworks.getPlanner(frameworkConfig);
> String pg = "select * from generate_series(1, 5)";
> planner.parse(pg);
> }
> {code}
>  
> *Thrown exception*
> {noformat}
> Exception in thread "main" org.apache.calcite.sql.parser.SqlParseException: 
> Encountered "( 1" at line 1, column 30.
> Was expecting one of:
>     
>     "ORDER" ...
>     "LIMIT" ...
>     "OFFSET" ...
>     "FETCH" ...
>     "NATURAL" ...
>     "JOIN" ...
>     "INNER" ...
>     "LEFT" ...
>     "RIGHT" ...
>     "FULL" ...
>     "CROSS" ...
>     "," ...
>     "OUTER" ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "MATCH_RECOGNIZE" ...
>     "." ...
>     "(" ...
>      ...
>      ...
>      ...
>      ...
>      ...
>     "TABLESAMPLE" ...
>     "WHERE" ...
>     "GROUP" ...
>     "HAVING" ...
>     "WINDOW" ...
>     "UNION" ...
>     "INTERSECT" ...
>     "EXCEPT" ...
>     "MINUS" ...
>     
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.convertException(SqlBabelParserImpl.java:354)
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.normalizeException(SqlBabelParserImpl.java:142)
>     at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:156)
>     at org.apache.calcite.sql.parser.SqlParser.parseStmt(SqlParser.java:181)
>     at org.apache.calcite.prepare.PlannerImpl.parse(PlannerImpl.java:174)
>     at org.apache.calcite.tools.Planner.parse(Planner.java:50)
>     at com.lab.calcite.App2.main(App2.java:24)
> Caused by: org.apache.calcite.sql.parser.babel.ParseException: Encountered "( 
> 1" at line 1, column 30.
> Was expecting one of:
>     
>     "ORDER" ...
>     "LIMIT" ...
>     "OFFSET" ...
>     "FETCH" ...
>     "NATURAL" ...
>     "JOIN" ...
>     "INNER" ...
>     "LEFT" ...
>     "RIGHT" ...
>     "FULL" ...
>     "CROSS" ...
>     "," ...
>     "OUTER" ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "MATCH_RECOGNIZE" ...
>     "." ...
>     "(" ...
>      ...
>      ...
>      ...
>      ...
>      ...
>     "TABLESAMPLE" ...
>     "WHERE" ...
>     "GROUP" ...
>     "HAVING" ...
>     "WINDOW" ...
>     "UNION" ...
>     "INTERSECT" ...
>     "EXCEPT" ...
>     "MINUS" ...
>     
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.generateParseException(SqlBabelParserImpl.java:31191)
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.jj_consume_token(SqlBabelParserImpl.java:31008)
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.SqlStmtEof(SqlBabelParserImpl.java:877)
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.parseSqlStmtEof(SqlBabelParserImpl.java:198)
>     at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:148)
>     ... 4 more
> {noformat}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-2844) Babel parser should parse PostgreSQL table functions

2019-04-02 Thread Hongze Zhang (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2844?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16807878#comment-16807878
 ] 

Hongze Zhang commented on CALCITE-2844:
---

I've run the two tests and reproduced the failures.

The first one {{testOuterApplyFunctionFails}} fails because the table function 
"ramp(deptno)" is now get successfully parsed, as it was previously not a legal 
syntax. 

Besides, the SQL used in the case is wired since it ends with two right 
brackets "{{))}}":

{code:sql}
select * from dept outer apply ramp(deptno^)^)
{code}

In general it should be 

{code:sql}
select * from dept outer apply ramp(deptno^)^
{code}

The second bracket looks like a typo. I think you can just remove the bracket 
and error anchors (the "^"). Then let the test case pass.

The case {{testTableExtend}} fails because of bad lookahead.

I see your LOOKAHEAD hint is set as 

{code}
LOOKAHEAD({ (getToken(1).kind == IDENTIFIER && getToken(2).kind == LPAREN) || 
(getToken(1).kind == SPECIFIC && getToken(2).kind == IDENTIFIER && 
getToken(3).kind == LPAREN) })
{code}

The hint is conflict with "extend clause" (see CALCITE-493). There should be 
multiple solutions to solve the conflict (using syntactic lookahead, or 
changing the expansion match order, etc. Maybe the later is better?)


> Babel parser should parse PostgreSQL table functions
> 
>
> Key: CALCITE-2844
> URL: https://issues.apache.org/jira/browse/CALCITE-2844
> Project: Calcite
>  Issue Type: Bug
>  Components: babel
>Affects Versions: 1.18.0
>Reporter: Muhammad Gelbana
>Priority: Major
>
> *Code to reproduce the problem*
> {code:java}
> public static void main(String[] args) throws Exception {
> Config parserConfig = 
> configBuilder().setConformance(SqlConformanceEnum.BABEL).setParserFactory(SqlBabelParserImpl.FACTORY).build();
> FrameworkConfig frameworkConfig = 
> Frameworks.newConfigBuilder().parserConfig(parserConfig).build();
> Planner planner = Frameworks.getPlanner(frameworkConfig);
> String pg = "select * from generate_series(1, 5)";
> planner.parse(pg);
> }
> {code}
>  
> *Thrown exception*
> {noformat}
> Exception in thread "main" org.apache.calcite.sql.parser.SqlParseException: 
> Encountered "( 1" at line 1, column 30.
> Was expecting one of:
>     
>     "ORDER" ...
>     "LIMIT" ...
>     "OFFSET" ...
>     "FETCH" ...
>     "NATURAL" ...
>     "JOIN" ...
>     "INNER" ...
>     "LEFT" ...
>     "RIGHT" ...
>     "FULL" ...
>     "CROSS" ...
>     "," ...
>     "OUTER" ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "MATCH_RECOGNIZE" ...
>     "." ...
>     "(" ...
>      ...
>      ...
>      ...
>      ...
>      ...
>     "TABLESAMPLE" ...
>     "WHERE" ...
>     "GROUP" ...
>     "HAVING" ...
>     "WINDOW" ...
>     "UNION" ...
>     "INTERSECT" ...
>     "EXCEPT" ...
>     "MINUS" ...
>     
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.convertException(SqlBabelParserImpl.java:354)
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.normalizeException(SqlBabelParserImpl.java:142)
>     at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:156)
>     at org.apache.calcite.sql.parser.SqlParser.parseStmt(SqlParser.java:181)
>     at org.apache.calcite.prepare.PlannerImpl.parse(PlannerImpl.java:174)
>     at org.apache.calcite.tools.Planner.parse(Planner.java:50)
>     at com.lab.calcite.App2.main(App2.java:24)
> Caused by: org.apache.calcite.sql.parser.babel.ParseException: Encountered "( 
> 1" at line 1, column 30.
> Was expecting one of:
>     
>     "ORDER" ...
>     "LIMIT" ...
>     "OFFSET" ...
>     "FETCH" ...
>     "NATURAL" ...
>     "JOIN" ...
>     "INNER" ...
>     "LEFT" ...
>     "RIGHT" ...
>     "FULL" ...
>     "CROSS" ...
>     "," ...
>     "OUTER" ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "MATCH_RECOGNIZE" ...
>     "." ...
>     "(" ...
>      ...
>      ...
>      ...
>      ...
>      ...
>     "TABLESAMPLE" ...
>     "WHERE" ...
>     "GROUP" ...
>     "HAVING" ...
>     "WINDOW" ...
>     "UNION" ...
>     "INTERSECT" ...
>     "EXCEPT" ...
>     "MINUS" ...
>     
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.generateParseException(SqlBabelParserImpl.java:31191)
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.jj_consume_token(SqlBabelParserImpl.java:31008)
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.SqlStmtEof(SqlBabelParserImpl.java:877)
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.parseSqlStmtEof(SqlBabelParserImpl.java:198)
>     at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:148)
>     ... 4 more
> {noformat}



--
This message was sent by 

[jira] [Commented] (CALCITE-2844) Babel parser should parse PostgreSQL table functions

2019-04-01 Thread Muhammad Gelbana (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2844?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16807294#comment-16807294
 ] 

Muhammad Gelbana commented on CALCITE-2844:
---

I made some progress but I have two failing test cases for reason I don't 
understand. I ignored them and then all other tests are passing.

You can find the tests 
[here|https://github.com/MGelbana/calcite/blob/CALCITE-2844/babel/src/test/java/org/apache/calcite/test/BabelParserTest.java#L50]
 and 
[here|https://github.com/MGelbana/calcite/blob/CALCITE-2844/babel/src/test/java/org/apache/calcite/test/BabelParserTest.java#L53].

I appreciate if someoen could give it a look and tell me what am I missing ?

> Babel parser should parse PostgreSQL table functions
> 
>
> Key: CALCITE-2844
> URL: https://issues.apache.org/jira/browse/CALCITE-2844
> Project: Calcite
>  Issue Type: Bug
>  Components: babel
>Affects Versions: 1.18.0
>Reporter: Muhammad Gelbana
>Priority: Major
>
> *Code to reproduce the problem*
> {code:java}
> public static void main(String[] args) throws Exception {
> Config parserConfig = 
> configBuilder().setConformance(SqlConformanceEnum.BABEL).setParserFactory(SqlBabelParserImpl.FACTORY).build();
> FrameworkConfig frameworkConfig = 
> Frameworks.newConfigBuilder().parserConfig(parserConfig).build();
> Planner planner = Frameworks.getPlanner(frameworkConfig);
> String pg = "select * from generate_series(1, 5)";
> planner.parse(pg);
> }
> {code}
>  
> *Thrown exception*
> {noformat}
> Exception in thread "main" org.apache.calcite.sql.parser.SqlParseException: 
> Encountered "( 1" at line 1, column 30.
> Was expecting one of:
>     
>     "ORDER" ...
>     "LIMIT" ...
>     "OFFSET" ...
>     "FETCH" ...
>     "NATURAL" ...
>     "JOIN" ...
>     "INNER" ...
>     "LEFT" ...
>     "RIGHT" ...
>     "FULL" ...
>     "CROSS" ...
>     "," ...
>     "OUTER" ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "MATCH_RECOGNIZE" ...
>     "." ...
>     "(" ...
>      ...
>      ...
>      ...
>      ...
>      ...
>     "TABLESAMPLE" ...
>     "WHERE" ...
>     "GROUP" ...
>     "HAVING" ...
>     "WINDOW" ...
>     "UNION" ...
>     "INTERSECT" ...
>     "EXCEPT" ...
>     "MINUS" ...
>     
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.convertException(SqlBabelParserImpl.java:354)
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.normalizeException(SqlBabelParserImpl.java:142)
>     at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:156)
>     at org.apache.calcite.sql.parser.SqlParser.parseStmt(SqlParser.java:181)
>     at org.apache.calcite.prepare.PlannerImpl.parse(PlannerImpl.java:174)
>     at org.apache.calcite.tools.Planner.parse(Planner.java:50)
>     at com.lab.calcite.App2.main(App2.java:24)
> Caused by: org.apache.calcite.sql.parser.babel.ParseException: Encountered "( 
> 1" at line 1, column 30.
> Was expecting one of:
>     
>     "ORDER" ...
>     "LIMIT" ...
>     "OFFSET" ...
>     "FETCH" ...
>     "NATURAL" ...
>     "JOIN" ...
>     "INNER" ...
>     "LEFT" ...
>     "RIGHT" ...
>     "FULL" ...
>     "CROSS" ...
>     "," ...
>     "OUTER" ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "MATCH_RECOGNIZE" ...
>     "." ...
>     "(" ...
>      ...
>      ...
>      ...
>      ...
>      ...
>     "TABLESAMPLE" ...
>     "WHERE" ...
>     "GROUP" ...
>     "HAVING" ...
>     "WINDOW" ...
>     "UNION" ...
>     "INTERSECT" ...
>     "EXCEPT" ...
>     "MINUS" ...
>     
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.generateParseException(SqlBabelParserImpl.java:31191)
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.jj_consume_token(SqlBabelParserImpl.java:31008)
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.SqlStmtEof(SqlBabelParserImpl.java:877)
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.parseSqlStmtEof(SqlBabelParserImpl.java:198)
>     at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:148)
>     ... 4 more
> {noformat}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-2844) Babel parser should parse PostgreSQL table functions

2019-02-14 Thread Muhammad Gelbana (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2844?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16768132#comment-16768132
 ] 

Muhammad Gelbana commented on CALCITE-2844:
---

[~zabetak], done.

> Babel parser should parse PostgreSQL table functions
> 
>
> Key: CALCITE-2844
> URL: https://issues.apache.org/jira/browse/CALCITE-2844
> Project: Calcite
>  Issue Type: Bug
>  Components: babel
>Affects Versions: 1.18.0
>Reporter: Muhammad Gelbana
>Assignee: Julian Hyde
>Priority: Major
>
> *Code to reproduce the problem*
> {code:java}
> public static void main(String[] args) throws Exception {
> Config parserConfig = 
> configBuilder().setConformance(SqlConformanceEnum.BABEL).setParserFactory(SqlBabelParserImpl.FACTORY).build();
> FrameworkConfig frameworkConfig = 
> Frameworks.newConfigBuilder().parserConfig(parserConfig).build();
> Planner planner = Frameworks.getPlanner(frameworkConfig);
> String pg = "select * from generate_series(1, 5)";
> planner.parse(pg);
> }
> {code}
>  
> *Thrown exception*
> {noformat}
> Exception in thread "main" org.apache.calcite.sql.parser.SqlParseException: 
> Encountered "( 1" at line 1, column 30.
> Was expecting one of:
>     
>     "ORDER" ...
>     "LIMIT" ...
>     "OFFSET" ...
>     "FETCH" ...
>     "NATURAL" ...
>     "JOIN" ...
>     "INNER" ...
>     "LEFT" ...
>     "RIGHT" ...
>     "FULL" ...
>     "CROSS" ...
>     "," ...
>     "OUTER" ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "MATCH_RECOGNIZE" ...
>     "." ...
>     "(" ...
>      ...
>      ...
>      ...
>      ...
>      ...
>     "TABLESAMPLE" ...
>     "WHERE" ...
>     "GROUP" ...
>     "HAVING" ...
>     "WINDOW" ...
>     "UNION" ...
>     "INTERSECT" ...
>     "EXCEPT" ...
>     "MINUS" ...
>     
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.convertException(SqlBabelParserImpl.java:354)
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.normalizeException(SqlBabelParserImpl.java:142)
>     at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:156)
>     at org.apache.calcite.sql.parser.SqlParser.parseStmt(SqlParser.java:181)
>     at org.apache.calcite.prepare.PlannerImpl.parse(PlannerImpl.java:174)
>     at org.apache.calcite.tools.Planner.parse(Planner.java:50)
>     at com.lab.calcite.App2.main(App2.java:24)
> Caused by: org.apache.calcite.sql.parser.babel.ParseException: Encountered "( 
> 1" at line 1, column 30.
> Was expecting one of:
>     
>     "ORDER" ...
>     "LIMIT" ...
>     "OFFSET" ...
>     "FETCH" ...
>     "NATURAL" ...
>     "JOIN" ...
>     "INNER" ...
>     "LEFT" ...
>     "RIGHT" ...
>     "FULL" ...
>     "CROSS" ...
>     "," ...
>     "OUTER" ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "("  ...
>     "MATCH_RECOGNIZE" ...
>     "." ...
>     "(" ...
>      ...
>      ...
>      ...
>      ...
>      ...
>     "TABLESAMPLE" ...
>     "WHERE" ...
>     "GROUP" ...
>     "HAVING" ...
>     "WINDOW" ...
>     "UNION" ...
>     "INTERSECT" ...
>     "EXCEPT" ...
>     "MINUS" ...
>     
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.generateParseException(SqlBabelParserImpl.java:31191)
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.jj_consume_token(SqlBabelParserImpl.java:31008)
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.SqlStmtEof(SqlBabelParserImpl.java:877)
>     at 
> org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.parseSqlStmtEof(SqlBabelParserImpl.java:198)
>     at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:148)
>     ... 4 more
> {noformat}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)