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

ElasticSearch query with varchar literal projection fails with JsonParseException

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.26.0
    • 1.27.0
    • 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

              volodymyr Vova Vysotskyi
              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