You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (Jira)" <ji...@apache.org> on 2022/04/09 14:53:00 UTC

[jira] [Commented] (CALCITE-4893) JsonParseException happens when externalizing expressions with escape character from JSON

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

Julian Hyde commented on CALCITE-4893:
--------------------------------------

This case has the same cause as CALCITE-5088: JsonBuilder is not escaping characters such as doublequote and backslash in strings correctly for JSON syntax.

> JsonParseException happens when externalizing expressions with escape character from JSON
> -----------------------------------------------------------------------------------------
>
>                 Key: CALCITE-4893
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4893
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Chunwei Lei
>            Assignee: Chunwei Lei
>            Priority: Major
>
> When the expression has escape characters, such as "\r", "\t" and so on, it cannot be externalized correctly. The following test can reproduce the error.
> {code:java}
> // RelWriterTest.java
> @Test void testEscapeCharacter() {
>   final FrameworkConfig config = RelBuilderTest.config().build();
>   final RelBuilder builder = RelBuilder.create(config);
>   final RelNode rel = builder
>       .scan("EMP")
>       .project(
>           builder.call(new MockSqlOperatorTable.SplitFunction(),
>               builder.field("ENAME"), builder.literal("\r")))
>       .build();
>   final String relJson = RelOptUtil.dumpPlan("", rel,
>       SqlExplainFormat.JSON, SqlExplainLevel.EXPPLAN_ATTRIBUTES);
>   final String s = deserializeAndDumpToTextFormat(getSchema(rel), relJson);
>   final String expected = ""
>       + "LogicalProject($f0=[SPLIT($1, '\r')])\n"
>       + "  LogicalTableScan(table=[[scott, EMP]])\n";
>   assertThat(s, isLinux(expected));
> } 
> FAILURE   3.3sec, org.apache.calcite.plan.RelWriterTest > testEscapeCharacter()
>     java.lang.RuntimeException: com.fasterxml.jackson.core.JsonParseException: Illegal unquoted character ((CTRL-CHAR, code 13)): has to be escaped using backslash to be included in string value
>      at [Source: (String)"{
>       "rels": [
>         {
>           "id": "0",
>           "relOp": "LogicalTableScan",
>           "table": [
>             "scott",
>             "EMP"
>           ],
>           "inputs": []
>         },
>         {
>           "id": "1",
>           "relOp": "LogicalProject",
>           "fields": [
>             "$f0"
>           ],
>           "exprs": [
>             {
>               "op": {
>                 "name": "SPLIT",
>                 "kind": "OTHER_FUNCTION",
>                 "syntax": "FUNCTION"
>               },
>               "operands": [
>                 {
>                   "input": 1,
>                   "name": "$1""[truncated 625 chars]; line: 31, column: 28]
>         at org.apache.calcite.tools.Frameworks.withPrepare(Frameworks.java:193)
>         at org.apache.calcite.tools.Frameworks.withPlanner(Frameworks.java:135)
>         at org.apache.calcite.tools.Frameworks.withPlanner(Frameworks.java:153)
>         at org.apache.calcite.plan.RelWriterTest.deserializeAndDump(RelWriterTest.java:1006)
>         at org.apache.calcite.plan.RelWriterTest.deserializeAndDumpToTextFormat(RelWriterTest.java:1026)
>         at org.apache.calcite.plan.RelWriterTest.testEscapeCharacter(RelWriterTest.java:978)
>         Caused by: com.fasterxml.jackson.core.JsonParseException: Illegal unquoted character ((CTRL-CHAR, code 13)): has to be escaped using backslash to be included in string value
>          at [Source: (String)"{
> {code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)