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

Generated model should escape backslashes

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.28.0
    • 1.31.0
    • core
    • None

    Description

      When a model is generated (because one is not provided in the JDBC URL), the generated JSON does not properly escape backslashes.

      Example in pseudo-code:

      Properties info = new Properties();
      info.setProperty("schema.jdbcUrl", "jdbc:mssql://host\\THEDB:1443");
      DriverManager.getConnection("jdbc:calcite:", info); 
      

      Expected result:

      The connection is opened successfully.

      Actual result:

      com.fasterxml.jackson.core.JsonParseException: Unrecognized character escape 'T' (code 84)
      at [Source: (String)"{
      ...
      "jdbcUrl": "jdbc:mssql://host\THEDB:1443"
      ...
      at org.apache.calcite.model.ModelHandler.<init>(ModelHandler.java:101)
      at org.apache.calcite.jdbc.Driver$1.onConnectionInit(Driver.java:101)
      

      Possible fix:

      Add the following to org.apache.calcite.util.JsonBuilder.append(JsonBuilder.java:95). This will fix backslashes but there may be other characters that need to be escaped too.

      .replace("\\", "\\\\")
      

      https://github.com/apache/calcite/blob/calcite-1.28.0/core/src/main/java/org/apache/calcite/util/JsonBuilder.java#L95

      It looks like it's being called by org.apache.calcite.jdbc.Driver$1.model(Driver.java:153).

      Attachments

        Issue Links

          Activity

            People

              julianhyde Julian Hyde
              freastro Gregory Hart
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: