You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "JIasen Sheng (Jira)" <ji...@apache.org> on 2020/08/11 10:16:00 UTC

[jira] [Commented] (CALCITE-3351) calcite mysql utf8 throws exception in Chinese

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

JIasen Sheng commented on CALCITE-3351:
---------------------------------------

I also get this exception

my env is

mysql 5.7.22

macos High Sierra 10.13.6 (17G14019)

set calcite.default.charset = UTF8

sqlGenerate convert Chinese Word to u&'/xxxx/xxxx', mysql can not recognize u&, causes this exception

 
{code:java}
Caused by: java.lang.RuntimeException: While executing SQL [SELECT `id`Caused by: java.lang.RuntimeException: While executing SQL [SELECT `id`FROM `ad_group`WHERE `pin` = u&'\4f60\597d'] on JDBC sub-schema at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:463) at org.apache.calcite.runtime.ResultSetEnumerable.enumeratorBasedOnStatement(ResultSetEnumerable.java:276) at org.apache.calcite.runtime.ResultSetEnumerable.enumerator(ResultSetEnumerable.java:251) at org.apache.calcite.linq4j.AbstractEnumerable.iterator(AbstractEnumerable.java:33) at org.apache.calcite.avatica.MetaImpl.createCursor(MetaImpl.java:82) at org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:184) at org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:64) at org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:43) at org.apache.calcite.avatica.AvaticaConnection.executeQueryInternal(AvaticaConnection.java:573) ... 34 moreCaused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'u' in 'where clause' at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) at com.mysql.jdbc.Util.getInstance(Util.java:408) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3933) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3869) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2675) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2465) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2439) at com.mysql.jdbc.StatementImpl.executeInternal(StatementImpl.java:829) at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:729) at org.apache.commons.dbcp2.DelegatingStatement.execute(DelegatingStatement.java:175) at org.apache.commons.dbcp2.DelegatingStatement.execute(DelegatingStatement.java:175) at org.apache.calcite.runtime.ResultSetEnumerable.enumeratorBasedOnStatement(ResultSetEnumerable.java:265) ... 41 more
{code}
 

 

I override MysqlSqlDialect quoteStringLiteral function to fix it , but i think it's not a good solution
{code:java}
@Override
public void quoteStringLiteral(StringBuilder buf, String charsetName, String val) {
  if (charsetName != null) {
    buf.append("_");
    buf.append(charsetName);
  }
  buf.append(literalQuoteString);
  buf.append(val.replace(literalEndQuoteString, literalEscapedQuote));
  buf.append(literalEndQuoteString);
}
{code}

> calcite mysql utf8 throws exception in Chinese
> ----------------------------------------------
>
>                 Key: CALCITE-3351
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3351
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.19.0
>         Environment: Happened on both Windows and MacOS.
>            Reporter: cui
>            Priority: Major
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> Exception was thrown when connecting with mySQL to query Chinese. The following SQL was executed: 
> select * from \"test\".\"score_new\" where \"name\"= \'催\' limit 1
> ,if change "getDefaultCharset" in  "RelDataTypeFactoryImpl" to 
> return Charset.forName("UTF8");
> there will be also exception thrown as the following:
> java.sql.SQLException: Error while executing SQL "select * from "test"."score_new" where "name"= '催' limit 1": While executing SQL [SELECT *java.sql.SQLException: Error while executing SQL "select * from "test"."score_new" where "name"= '催' limit 1": While executing SQL [SELECT *FROM `score_new`WHERE `name` = u&'\50ac'LIMIT 1] on JDBC sub-schema at org.apache.calcite.avatica.Helper.createException(Helper.java:56) at org.apache.calcite.avatica.Helper.createException(Helper.java:41) at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:163) at org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:227) at QueryMysql.main(QueryMysql.java:42)Caused by: java.lang.RuntimeException: While executing SQL [SELECT *FROM `score_new`WHERE `name` = u&'\50ac'



--
This message was sent by Atlassian Jira
(v8.3.4#803005)