[ 
https://issues.apache.org/jira/browse/CALCITE-110?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16348105#comment-16348105
 ] 

Ye Ding commented on CALCITE-110:
---------------------------------

I have ran into same trouble, after exploring the source code I found a 
suspicious code that may cause the problem.

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

{code:java}
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(
        nlsString.getValue(),
        type.getCharset().name(),
        type.getCollation());
  }
{code}

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 name.

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

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

> utf-16 is wrong in  SqlUtil.translateCharacterSetName()
> -------------------------------------------------------
>
>                 Key: CALCITE-110
>                 URL: https://issues.apache.org/jira/browse/CALCITE-110
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: GitHub Import
>            Priority: Major
>              Labels: github-import
>
> SqlUtil.translateCharacterSetName() should compare "UTF-16" instaed of 
> "UTF16".
> Now it will trigger the exception if I change the "saffron.default.charset" 
> system property to "UTF-16".
> java.nio.charset.UnsupportedCharsetException: UTF-16
>       at org.eigenbase.util.NlsString.<init>(NlsString.java:77)
>       at org.eigenbase.rex.RexBuilder.makeLiteral(RexBuilder.java:824)
>       at org.eigenbase.rex.RexBuilder.<init>(RexBuilder.java:84)
>       at 
> net.hydromatic.optiq.prepare.OptiqPrepareImpl$OptiqPreparingStmt.<init>(OptiqPrepareImpl.java:519)
>       at 
> net.hydromatic.optiq.prepare.OptiqPrepareImpl.prepare2_(OptiqPrepareImpl.java:275)
>       at 
> net.hydromatic.optiq.prepare.OptiqPrepareImpl.prepare_(OptiqPrepareImpl.java:223)
>       at 
> net.hydromatic.optiq.prepare.OptiqPrepareImpl.prepareSql(OptiqPrepareImpl.java:193)
>       at 
> net.hydromatic.optiq.jdbc.OptiqConnectionImpl.parseQuery(OptiqConnectionImpl.java:155)
>       at net.hydromatic.optiq.jdbc.MetaImpl.prepare(MetaImpl.java:696)
>       at 
> net.hydromatic.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:68)
> ---------------- Imported from GitHub ----------------
> Url: https://github.com/julianhyde/optiq/issues/110
> Created by: [jiangxuchina|https://github.com/jiangxuchina]
> Labels: 
> Created at: Wed Jan 08 04:59:19 CET 2014
> State: closed



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to