Issue 1:
[ERROR] 2021-12-11 18:18:37.516 [ShardingSphere-Command-0] o.a.s.p.f.c.CommandExecutorTask - Exception occur:

java.sql.SQLException: exception while executing query: java.math.BigInteger cannot be cast to java.lang.Long

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.AvaticaConnection.executeQueryInternal(AvaticaConnection.java:577)

at org.apache.calcite.avatica.AvaticaPreparedStatement.executeQuery(AvaticaPreparedStatement.java:137)

at org.apache.shardingsphere.infra.executor.sql.federate.original.OriginalFilterableExecutor.execute(OriginalFilterableExecutor.java:87)

at org.apache.shardingsphere.infra.executor.sql.federate.original.OriginalFilterableExecutor.executeQuery(OriginalFilterableExecutor.java:77)

at org.apache.shardingsphere.proxy.backend.communication.ProxySQLExecutor.federateExecute(ProxySQLExecutor.java:164)

at org.apache.shardingsphere.proxy.backend.communication.ProxySQLExecutor.execute(ProxySQLExecutor.java:136)

at org.apache.shardingsphere.proxy.backend.communication.ProxySQLExecutor.execute(ProxySQLExecutor.java:127)

at org.apache.shardingsphere.proxy.backend.communication.ProxyLockEngine.doExecute(ProxyLockEngine.java:103)

at org.apache.shardingsphere.proxy.backend.communication.ProxyLockEngine.execute(ProxyLockEngine.java:81)

at org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine.execute(DatabaseCommunicationEngine.java:126)

at org.apache.shardingsphere.proxy.backend.text.data.impl.SchemaAssignedDatabaseBackendHandler.execute(SchemaAssignedDatabaseBackendHandler.java:55)

at org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor.execute(MySQLComQueryPacketExecutor.java:61)

at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:99)

at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:72)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

at java.lang.Thread.run(Thread.java:748)

Caused by: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long

at Baz$2.apply(Unknown Source)

at Baz$2.apply(Unknown Source)

at org.apache.calcite.linq4j.EnumerableDefaults.toLookup_(EnumerableDefaults.java:3604)

at org.apache.calcite.linq4j.EnumerableDefaults.toLookup(EnumerableDefaults.java:3594)

at org.apache.calcite.linq4j.EnumerableDefaults.toLookup(EnumerableDefaults.java:3570)

at org.apache.calcite.linq4j.DefaultEnumerable.toLookup(DefaultEnumerable.java:748)

at org.apache.calcite.linq4j.EnumerableDefaults$6.enumerator(EnumerableDefaults.java:1316)

at org.apache.calcite.linq4j.AbstractEnumerable.iterator(AbstractEnumerable.java:33)

at org.apache.calcite.avatica.MetaImpl.createCursor(MetaImpl.java:90)

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)

... 16 common frames omitted

Issue 2:
Bug Report

For English only, other languages will not accept.

Before report a bug, make sure you have:

Searched open and closed GitHub issues.

Read documentation: ShardingSphere Doc.

Please pay attention on issues you submitted, because we maybe need more details.

If no response more than 7 days and we cannot reproduce it on current information, we will close it.

Please answer these questions before submitting your issue. Thanks!

Which version of ShardingSphere did you use?

3.1.0

Which project did you use? Sharding-JDBC or Sharding-Proxy?

Sharding-JDBC

Expected behavior

subquery can work as expect

Actual behavior

Reason analyze (If you can)

bug.txt

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

Example codes for reproduce this issue (such as a github link).