You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Rick Liao <ri...@data.world> on 2020/01/08 22:05:01 UTC

Cannot parse query that contains colons for casting in postgres sql

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:

    <EOF>

    "AS" ...

    "EXCEPT" ...

    "FETCH" ...

    "FROM" ...

    "INTERSECT" ...

    "LIMIT" ...

    "OFFSET" ...

    "ORDER" ...

    "MINUS" ...

    "UESCAPE" ...

    "UNION" ...

    <QUOTED_STRING> ...

    "," ...

    <BRACKET_QUOTED_IDENTIFIER> ...

    <QUOTED_IDENTIFIER> ...

    <BACK_QUOTED_IDENTIFIER> ...

    <IDENTIFIER> ...

    <UNICODE_QUOTED_IDENTIFIER> ...

    "." ...

    "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

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

Posted by XING JIN <ji...@gmail.com>.
Hi, Rick ~
Babel parser supports casting by double colon [1]

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

-Jin

Rick Liao <ri...@data.world> 于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:
>
>     <EOF>
>
>     "AS" ...
>
>     "EXCEPT" ...
>
>     "FETCH" ...
>
>     "FROM" ...
>
>     "INTERSECT" ...
>
>     "LIMIT" ...
>
>     "OFFSET" ...
>
>     "ORDER" ...
>
>     "MINUS" ...
>
>     "UESCAPE" ...
>
>     "UNION" ...
>
>     <QUOTED_STRING> ...
>
>     "," ...
>
>     <BRACKET_QUOTED_IDENTIFIER> ...
>
>     <QUOTED_IDENTIFIER> ...
>
>     <BACK_QUOTED_IDENTIFIER> ...
>
>     <IDENTIFIER> ...
>
>     <UNICODE_QUOTED_IDENTIFIER> ...
>
>     "." ...
>
>     "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
>