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

SqlNode#toSqlString() does not honor dialect's supportsCharSet() flag on nested types

    XMLWordPrintableJSON

Details

    Description

      Say we generate a RelNode corresponding to

      SELECT CAST(c AS VARCHAR) FROM t
      

      and we were to "unparse" that rel node back into the Postgres SQL dialect using

      var converter = new RelToSqlConverter(PostgresqlSqlDialect.DEFAULT);
      SqlImplementor.Result result = converter.visitRoot(rel);
      SqlNode sqlNode = result.asStatement();
      var sql = sqlNode.toSqlString(PostgresqlSqlDialect.DEFAULT).getSql();
      

      it would generate something like:

      SELECT CAST("c" AS VARCHAR) AS "c"
      FROM "t"
      

      Note that there is no charset information included in the cast, since the PostgresSqlDialect specifies that it does not support char sets:

        @Override public boolean supportsCharSet() {
          return false;
        }
      

      Given that, we would expect that unparsing

      SELECT CAST(c AS VARCHAR ARRAY) FROM t
      

      back into SQL would also generate a type with no charset specified, but it in fact generates

      SELECT CAST("c" AS VARCHAR CHARACTER SET "ISO-8859-1" ARRAY) AS "c"
      FROM "t"
      

      This seems to come from the way `SqlTypeUtil.convertTypeToSpec()` handles collection types.

      Attachments

        1. CharsetTest.java
          3 kB
          Chris Rice

        Issue Links

          Activity

            People

              jiajunbernoulli Jiajun Xie
              chrisrice Chris Rice
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: