Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-4893

JsonParseException happens when externalizing expressions with escape character from JSON

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • None
    • 1.31.0
    • None
    • None

    Description

      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.

      // 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)"{
      

      Attachments

        Issue Links

          Activity

            People

              Chunwei Lei Chunwei Lei
              Chunwei Lei Chunwei Lei
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: