did anyone face issue while using TRY_CAST ? in my...
# troubleshooting
n
did anyone face issue while using TRY_CAST ? in my query cast is working but TRY_CAST giving me error: rg.apache.calcite.sql.parser.impl.ParseException: Encountered "as" at line 1, column 28. Was expecting one of: "EXCEPT" ... "FETCH" ... "INTERSECT" ... "LIMIT" ... "OFFSET" ... "ORDER" ... "MINUS" ... "UNION" ... ")" ... "," ... "=>" ... "." ... "NOT" ... "IN" ... "<" ... "<=" ... ">" ... ">=" ... "=" ... "<>" ... "!=" ... "BETWEEN" ... "LIKE" ... "SIMILAR" ... "+" ... "-" ... "*" ... "/" ... "%" ... "||" ... "AND" ... "OR" ... "IS" ... "MEMBER" ... "SUBMULTISET" ... "CONTAINS" ... "OVERLAPS" ... "EQUALS" ... "PRECEDES" ... "SUCCEEDS" ... "IMMEDIATELY" ... "MULTISET" ... "[" ... "FORMAT" ... "(" ... at org.apache.calcite.sql.parser.impl.SqlParserImpl.generateParseException(SqlParserImpl.java:35588) at org.apache.calcite.sql.parser.impl.SqlParserImpl.jj_consume_token(SqlParserImpl.java:35402) sql -> select TRY_CAST(myField as INT) from myStreamTable
Copy code
public static SqlNodeList parse(String sql) throws Exception {
    // Keep the SQL syntax consistent with Flink
    try (StringReader in = new StringReader(sql)) {
        SqlParserImpl impl = new SqlParserImpl(in);

        // back tick as the quote
        SqlAbstractParserImpl.LexicalState state = SqlAbstractParserImpl.LexicalState.BTID;
        impl.switchTo(state);
        impl.setTabSize(1);
        impl.setQuotedCasing(Lex.JAVA.quotedCasing);
        impl.setUnquotedCasing(Lex.JAVA.unquotedCasing);
        impl.setIdentifierMaxLength(DEFAULT_IDENTIFIER_MAX_LENGTH);
        return impl.parseSqlStmtList();
    }
}
Full Stack Trace: org.apache.calcite.sql.parser.impl.ParseException: Encountered "as" at line 1, column 26. Was expecting one of: "EXCEPT" ... "FETCH" ... "INTERSECT" ... "LIMIT" ... "OFFSET" ... "ORDER" ... "MINUS" ... "UNION" ... ")" ... "," ... "=>" ... "." ... "NOT" ... "IN" ... "<" ... "<=" ... ">" ... ">=" ... "=" ... "<>" ... "!=" ... "BETWEEN" ... "LIKE" ... "SIMILAR" ... "+" ... "-" ... "*" ... "/" ... "%" ... "||" ... "AND" ... "OR" ... "IS" ... "MEMBER" ... "SUBMULTISET" ... "CONTAINS" ... "OVERLAPS" ... "EQUALS" ... "PRECEDES" ... "SUCCEEDS" ... "IMMEDIATELY" ... "MULTISET" ... "[" ... "FORMAT" ... "(" ... at org.apache.calcite.sql.parser.impl.SqlParserImpl.generateParseException(SqlParserImpl.java:35588) at org.apache.calcite.sql.parser.impl.SqlParserImpl.jj_consume_token(SqlParserImpl.java:35402) at org.apache.calcite.sql.parser.impl.SqlParserImpl.FunctionParameterList(SqlParserImpl.java:1752) at org.apache.calcite.sql.parser.impl.SqlParserImpl.NamedFunctionCall(SqlParserImpl.java:25053) at org.apache.calcite.sql.parser.impl.SqlParserImpl.AtomicRowExpression(SqlParserImpl.java:16296) at org.apache.calcite.sql.parser.impl.SqlParserImpl.Expression3(SqlParserImpl.java:16031) at org.apache.calcite.sql.parser.impl.SqlParserImpl.Expression2b(SqlParserImpl.java:15701) at org.apache.calcite.sql.parser.impl.SqlParserImpl.Expression2(SqlParserImpl.java:15742) at org.apache.calcite.sql.parser.impl.SqlParserImpl.Expression(SqlParserImpl.java:15673) at org.apache.calcite.sql.parser.impl.SqlParserImpl.SelectExpression(SqlParserImpl.java:8786) at org.apache.calcite.sql.parser.impl.SqlParserImpl.SelectItem(SqlParserImpl.java:7662) at org.apache.calcite.sql.parser.impl.SqlParserImpl.SelectList(SqlParserImpl.java:7636) at org.apache.calcite.sql.parser.impl.SqlParserImpl.SqlSelect(SqlParserImpl.java:4325) at org.apache.calcite.sql.parser.impl.SqlParserImpl.LeafQuery(SqlParserImpl.java:630) at org.apache.calcite.sql.parser.impl.SqlParserImpl.LeafQueryOrExpr(SqlParserImpl.java:15656) at org.apache.calcite.sql.parser.impl.SqlParserImpl.QueryOrExpr(SqlParserImpl.java:15118) at org.apache.calcite.sql.parser.impl.SqlParserImpl.OrderedQueryOrExpr(SqlParserImpl.java:504) at org.apache.calcite.sql.parser.impl.SqlParserImpl.SqlStmt(SqlParserImpl.java:3700) at org.apache.calcite.sql.parser.impl.SqlParserImpl.SqlStmtList(SqlParserImpl.java:2751) at org.apache.calcite.sql.parser.impl.SqlParserImpl.parseSqlStmtList(SqlParserImpl.java:203)
s
is Calcite version same as used in Flink? I'm asking since recently there was introduced
TRY_CAST
in Calcite which is different from Flink's implementation
n
yes it is calcite-core-1.26.0
s
what is the Flink version, 1.15, 1.16?
btw why in the code snippet above there is
SqlParserImpl
and not
FlinkSqlParserImpl
like at
org.apache.flink.sql.parser.TableApiIdentifierParsingTest#createFlinkParser
n
It is 1.16.1
k
Can you help me with SQL? and check that your original table is with the same data type
n
sql -> select TRY_CAST(myField as INT) from myStreamTable
Hi @Keyur Makwana, the sql in present in the original question and i have also added ^
k
TRY_CAST(field AS BIGINT)
Can you try this?
n
same error
k
Can you try with latest version of flink?