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

ElasticSearch query with varchar literal projection fails with JsonParseException

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.26.0
    • Fix Version/s: 1.27.0
    • Component/s: None

      Description

      A query that contains varchar literals in projection fails for ElasticSearch adapter. Simple test case to reproduce the issue:

      @Test void projectionStringLiteral() {
          CalciteAssert.that()
              .with(newConnectionFactory())
              .query(
                  String.format(Locale.ROOT, "select 'foo' as \"lit\"\n"
                      + "from \"elastic\".\"%s\"", NAME))
              .returns("lit=foo\n");
        }
      

      Error:

      Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('f' (code 102)): was expecting comma to separate Object entries
       at [Source: (String)"{"script_fields": {"lit":{"script": ""foo""}, "a":{"script": "params._source.a"}}}"; line: 1, column: 40]
      	at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1840)
      

      The problem is that RexToElasticsearchTranslator.visitLiteral method do not escape literal quotes, and forms the following string: "lit":""foo"" that cannot be handled by jackson.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                volodymyr Vova Vysotskyi
                Reporter:
                volodymyr Vova Vysotskyi
              • Votes:
                1 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 40m
                  40m