Re: Cannot parse query that contains colons for casting in postgres sql

2020-01-08 Thread XING JIN
Hi, Rick ~
Babel parser supports casting by double colon [1]

[1] https://issues.apache.org/jira/browse/CALCITE-2843

-Jin

Rick Liao  于2020年1月9日周四 上午6:05写道:

> Hello all,
>
> I'm trying to parse a postgres sql query that contains :: for casting. The
> parser fails when it reaches the colon. I'm using version 1.21.0. This is
> what I'm running (with a simple query to showcase the error):
>
> SqlParser.Config parserConfig =
>
> SqlParser.configBuilder().setConformance(SqlConformanceEnum.LENIENT).build();
> SqlParser parser1 = SqlParser.create("SELECT 'test'::text t from
> countries", parserConfig);
> SqlNode parsedQuery1 = parser1.parseQuery();
>
> The error:
>
> org.apache.calcite.sql.parser.SqlParseException: Encountered ":" at line 1,
> column 14.
>
> Was expecting one of:
>
> 
>
> "AS" ...
>
> "EXCEPT" ...
>
> "FETCH" ...
>
> "FROM" ...
>
> "INTERSECT" ...
>
> "LIMIT" ...
>
> "OFFSET" ...
>
> "ORDER" ...
>
> "MINUS" ...
>
> "UESCAPE" ...
>
> "UNION" ...
>
>  ...
>
> "," ...
>
>  ...
>
>  ...
>
>  ...
>
>  ...
>
>  ...
>
> "." ...
>
> "NOT" ...
>
> "IN" ...
>
> "<" ...
>
> "<=" ...
>
> ">" ...
>
> ">=" ...
>
> "=" ...
>
> "<>" ...
>
> "!=" ...
>
> "BETWEEN" ...
>
> "LIKE" ...
>
> "SIMILAR" ...
>
> "+" ...
>
> "-" ...
>
> "*" ...
>
> "/" ...
>
> "%" ...
>
> "||" ...
>
> "AND" ...
>
> "OR" ...
>
> "IS" ...
>
> "MEMBER" ...
>
> "SUBMULTISET" ...
>
> "CONTAINS" ...
>
> "OVERLAPS" ...
>
> "EQUALS" ...
>
> "PRECEDES" ...
>
> "SUCCEEDS" ...
>
> "MULTISET" ...
>
> "[" ...
>
>
>
> at
>
> org.apache.calcite.sql.parser.impl.SqlParserImpl.convertException(SqlParserImpl.java:343)
>
> at
>
> org.apache.calcite.sql.parser.impl.SqlParserImpl.normalizeException(SqlParserImpl.java:142)
>
> at
> org.apache.calcite.sql.parser.SqlParser.handleException(SqlParser.java:147)
>
> at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:162)
>
> Perhaps, I have just not found the right conformance for postgres sql.
>
> Thanks for your help!
>
> Rick
>


Cannot parse query that contains colons for casting in postgres sql

2020-01-08 Thread Rick Liao
Hello all,

I'm trying to parse a postgres sql query that contains :: for casting. The
parser fails when it reaches the colon. I'm using version 1.21.0. This is
what I'm running (with a simple query to showcase the error):

SqlParser.Config parserConfig =
SqlParser.configBuilder().setConformance(SqlConformanceEnum.LENIENT).build();
SqlParser parser1 = SqlParser.create("SELECT 'test'::text t from
countries", parserConfig);
SqlNode parsedQuery1 = parser1.parseQuery();

The error:

org.apache.calcite.sql.parser.SqlParseException: Encountered ":" at line 1,
column 14.

Was expecting one of:



"AS" ...

"EXCEPT" ...

"FETCH" ...

"FROM" ...

"INTERSECT" ...

"LIMIT" ...

"OFFSET" ...

"ORDER" ...

"MINUS" ...

"UESCAPE" ...

"UNION" ...

 ...

"," ...

 ...

 ...

 ...

 ...

 ...

"." ...

"NOT" ...

"IN" ...

"<" ...

"<=" ...

">" ...

">=" ...

"=" ...

"<>" ...

"!=" ...

"BETWEEN" ...

"LIKE" ...

"SIMILAR" ...

"+" ...

"-" ...

"*" ...

"/" ...

"%" ...

"||" ...

"AND" ...

"OR" ...

"IS" ...

"MEMBER" ...

"SUBMULTISET" ...

"CONTAINS" ...

"OVERLAPS" ...

"EQUALS" ...

"PRECEDES" ...

"SUCCEEDS" ...

"MULTISET" ...

"[" ...



at
org.apache.calcite.sql.parser.impl.SqlParserImpl.convertException(SqlParserImpl.java:343)

at
org.apache.calcite.sql.parser.impl.SqlParserImpl.normalizeException(SqlParserImpl.java:142)

at
org.apache.calcite.sql.parser.SqlParser.handleException(SqlParser.java:147)

at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:162)

Perhaps, I have just not found the right conformance for postgres sql.

Thanks for your help!

Rick