calcite-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ye Ding (JIRA)" <>
Subject [jira] [Created] (CALCITE-2163) Using "UTF16" as default charset failed
Date Sun, 04 Feb 2018 05:38:00 GMT
Ye Ding created CALCITE-2163:

             Summary: Using "UTF16" as default charset failed
                 Key: CALCITE-2163
             Project: Calcite
          Issue Type: Bug
            Reporter: Ye Ding
            Assignee: Julian Hyde

I have a project that need to handle non-ASCII character, so I have set default charset to
"UTF16" by setting "saffron.default.charset" to "UTF16", but failed with below error stack

Caused by: java.nio.charset.UnsupportedCharsetException: UTF-16
	at org.apache.calcite.util.NlsString.<init>(
	at org.apache.calcite.rex.RexBuilder.makeLiteral(
	at org.apache.calcite.rex.RexBuilder.<init>(
	at org.apache.calcite.prepare.CalcitePrepareImpl.perform(
	... 29 more

Having explored related source code I found a suspicious code that may cause the problem.

Here is a code block from RexBuilder, between L869 and L883.

case CHAR:
  // Character literals must have a charset and collation. Populate
  // from the type if necessary.
  assert o instanceof NlsString;
  NlsString nlsString = (NlsString) o;
  if ((nlsString.getCollation() == null)
      || (nlsString.getCharset() == null)) {
    assert type.getSqlTypeName() == SqlTypeName.CHAR;
    assert type.getCharset().name() != null;
    assert type.getCollation() != null;
    o = new NlsString(

At the last line, a *Java* charset name is used to construct NlsString.

But from the code of NlsString's constructor, the charsetName is supposed to be *SQL* charset

  public NlsString(
      String value,
      String charsetName,
      SqlCollation collation) {
    assert value != null;
    if (null != charsetName) {
      charsetName = charsetName.toUpperCase(Locale.ROOT);
      this.charsetName = charsetName;
      String javaCharsetName =
      if (javaCharsetName == null) {
        throw new UnsupportedCharsetException(charsetName);
      this.charset = Charset.forName(javaCharsetName);
      CharsetEncoder encoder = charset.newEncoder();

I have not read and fully understood codes, so I'm not sure if it's the root cause of the
problem. Currently I've managed to work around it by setting "saffron.default.charset" to

This message was sent by Atlassian JIRA

View raw message