You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/07/21 11:11:13 UTC
[GitHub] [shardingsphere] Superainbower opened a new issue #11437: The result isn't right in Row to Column scenario
Superainbower opened a new issue #11437:
URL: https://github.com/apache/shardingsphere/issues/11437
## Question
**For English only**, other languages will not accept.
Hi, i find the result isn't right in Row to Column scenario (shardingsphere jdbc 5.0.0-beta)
Here is my data in mysql ( table sharding by time)

SQL like this:
select car_no,
ifnull(sum( CASE WHEN type = '1' THEN cnt END ),0) AS type1,
ifnull(sum( CASE WHEN type = '2' THEN cnt END ),0) AS type2
from (
select car_no,type,count( * ) AS cnt from tb_warning_info where
begin_time >= #{start} and begin_time <= #{end}
group by car_no,type
) a group by car_no
When #{start} >= 2021-01-01 00:00:00 and #{end} <= 2021-12-31 23:59:59, the result is right
[{"type2":0,"car_no":"云EXXXXX","type1":1}]
When #{start} >= 2020-01-01 00:00:00 and #{end} <= 2020-12-31 23:59:59, the result is right
[{"type2":1,"car_no":"云EXXXXX","type1":0}]
But when #{start} >= 2020-01-01 00:00:00 and #{end} <= 2021-12-31 23:59:59
the result must be [{"type2":1,"car_no":"云EXXXXX","type1":1}], but got [{"type2":0,"car_no":"云EXXXXX","type1":1}]
i really think it should return [{"type2":0,"car_no":"云EXXXXX","type1":1},{"type2":1,"car_no":"云EXXXXX","type1":0}]
i can calculate by myself
so what should i do in this scenario?
Before asking a question, make sure you have:
- Googled your question.
- Searched open and closed [GitHub issues](https://github.com/apache/shardingsphere/issues).
- Read documentation: [ShardingSphere Doc](https://shardingsphere.apache.org/document/current/en/overview).
Please pay attention on issues you submitted, because we maybe need more details.
If no response anymore and we cannot reproduce it on current information, we will **close it**.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] Superainbower commented on issue #11437: The result isn't right in Row to Column scenario
Posted by GitBox <gi...@apache.org>.
Superainbower commented on issue #11437:
URL: https://github.com/apache/shardingsphere/issues/11437#issuecomment-884124909
@strongduanmu demo link
https://github.com/Superainbower/demo
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] Superainbower edited a comment on issue #11437: The result isn't right in Row to Column scenario
Posted by GitBox <gi...@apache.org>.
Superainbower edited a comment on issue #11437:
URL: https://github.com/apache/shardingsphere/issues/11437#issuecomment-895075521
The error log is Function '{fn ifnull}' is not defined
I refer to your suggestion, but you said ss will do it, it make me confused
We need to rewrite the SQL to the following format:
SELECT order_id, {fn IFNULL(SUM(cnt), 0)} AS totoal FROM (
SELECT order_id, user_id, COUNT(1) AS cnt FROM t_order GROUP BY order_id, user_id
) a GROUP BY order_id;
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] strongduanmu commented on issue #11437: The result isn't right in Row to Column scenario
Posted by GitBox <gi...@apache.org>.
strongduanmu commented on issue #11437:
URL: https://github.com/apache/shardingsphere/issues/11437#issuecomment-893961488
> i got error log when use {fn IFNULL(SUM(cnt), 0)}
>
> * Function '{fn ifnull}' is not defined
@Superainbower What is your error log? BTW, you doesn't need to rewrite sql by yourself, ss will do it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] Superainbower commented on issue #11437: The result isn't right in Row to Column scenario
Posted by GitBox <gi...@apache.org>.
Superainbower commented on issue #11437:
URL: https://github.com/apache/shardingsphere/issues/11437#issuecomment-893960673
i got error log when use {fn IFNULL(SUM(cnt), 0)}
- Function '{fn ifnull}' is not defined
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] strongduanmu commented on issue #11437: The result isn't right in Row to Column scenario
Posted by GitBox <gi...@apache.org>.
strongduanmu commented on issue #11437:
URL: https://github.com/apache/shardingsphere/issues/11437#issuecomment-893563982
According to the [calcite official documentation](https://calcite.apache.org/docs/reference.html), the JDBC function needs to be escaped before it can be executed. We need to rewrite the SQL to the following format:
```sql
SELECT order_id, {fn IFNULL(SUM(cnt), 0)} AS totoal FROM (
SELECT order_id, user_id, COUNT(1) AS cnt FROM t_order GROUP BY order_id, user_id
) a GROUP BY order_id;
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] strongduanmu commented on issue #11437: The result isn't right in Row to Column scenario
Posted by GitBox <gi...@apache.org>.
strongduanmu commented on issue #11437:
URL: https://github.com/apache/shardingsphere/issues/11437#issuecomment-893525182
Using the master branch to execute, the following error will appear:
```
[INFO ] 2021-08-05 22:54:20.318 [ShardingSphere-Command-1] ShardingSphere-SQL - Logic SQL: SELECT order_id, IFNULL(SUM(cnt), 0) AS totoal FROM ( SELECT order_id, user_id, COUNT(1) AS cnt FROM t_order GROUP BY order_id, user_id ) a GROUP BY order_id
[INFO ] 2021-08-05 22:54:20.318 [ShardingSphere-Command-1] ShardingSphere-SQL - SQLStatement: MySQLSelectStatement(limit=Optional.empty, lock=Optional.empty, window=Optional.empty)
[INFO ] 2021-08-05 22:54:20.318 [ShardingSphere-Command-1] ShardingSphere-SQL - Actual SQL: ds_0 ::: SELECT order_id, IFNULL(SUM(cnt), 0) AS totoal FROM ( SELECT order_id, user_id, COUNT(1) AS cnt FROM t_order GROUP BY order_id, user_id ) a GROUP BY order_id
[INFO ] 2021-08-05 22:54:20.318 [ShardingSphere-Command-1] ShardingSphere-SQL - Actual SQL: ds_1 ::: SELECT order_id, IFNULL(SUM(cnt), 0) AS totoal FROM ( SELECT order_id, user_id, COUNT(1) AS cnt FROM t_order GROUP BY order_id, user_id ) a GROUP BY order_id
[ERROR] 2021-08-05 22:54:20.326 [ShardingSphere-Command-1] o.a.s.p.f.c.CommandExecutorTask - Exception occur:
java.sql.SQLException: Error while preparing statement [SELECT order_id, IFNULL(SUM(cnt), 0) AS totoal FROM ( SELECT order_id, user_id, COUNT(1) AS cnt FROM t_order GROUP BY order_id, user_id ) a GROUP BY order_id]
at org.apache.calcite.avatica.Helper.createException(Helper.java:56)
at org.apache.calcite.avatica.Helper.createException(Helper.java:41)
at org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement_(CalciteConnectionImpl.java:220)
at org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement(CalciteConnectionImpl.java:202)
at org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement(CalciteConnectionImpl.java:93)
at org.apache.calcite.avatica.AvaticaConnection.prepareStatement(AvaticaConnection.java:175)
at org.apache.shardingsphere.infra.executor.sql.federate.execute.FederateJDBCExecutor.execute(FederateJDBCExecutor.java:105)
at org.apache.shardingsphere.infra.executor.sql.federate.execute.FederateJDBCExecutor.executeQuery(FederateJDBCExecutor.java:84)
at org.apache.shardingsphere.proxy.backend.communication.ProxySQLExecutor.federateExecute(ProxySQLExecutor.java:163)
at org.apache.shardingsphere.proxy.backend.communication.ProxySQLExecutor.execute(ProxySQLExecutor.java:135)
at org.apache.shardingsphere.proxy.backend.communication.ProxySQLExecutor.execute(ProxySQLExecutor.java:126)
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:125)
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:57)
at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:98)
at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:72)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.calcite.runtime.CalciteContextException: From line 1, column 18 to line 1, column 36: No match found for function signature IFNULL(<NUMERIC>, <NUMERIC>)
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:467)
at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:883)
at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:868)
at org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(SqlValidatorImpl.java:5043)
at org.apache.calcite.sql.validate.SqlValidatorImpl.handleUnresolvedFunction(SqlValidatorImpl.java:1838)
at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:321)
at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:226)
at org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5882)
at org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5869)
at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:139)
at org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1756)
at org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1741)
at org.apache.calcite.sql.SqlAsOperator.deriveType(SqlAsOperator.java:133)
at org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5882)
at org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5869)
at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:139)
at org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1756)
at org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1741)
at org.apache.calcite.sql.validate.SqlValidatorImpl.expandSelectItem(SqlValidatorImpl.java:440)
at org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelectList(SqlValidatorImpl.java:4205)
at org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3474)
at org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:60)
at org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84)
at org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:1067)
at org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:1041)
at org.apache.calcite.sql.SqlSelect.validate(SqlSelect.java:232)
at org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:1016)
at org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:724)
at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:567)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:242)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:208)
at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:642)
at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:508)
at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:478)
at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:231)
at org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement_(CalciteConnectionImpl.java:213)
... 18 common frames omitted
Caused by: org.apache.calcite.sql.validate.SqlValidatorException: No match found for function signature IFNULL(<NUMERIC>, <NUMERIC>)
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:467)
at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:560)
... 53 common frames omitted
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] Superainbower commented on issue #11437: The result isn't right in Row to Column scenario
Posted by GitBox <gi...@apache.org>.
Superainbower commented on issue #11437:
URL: https://github.com/apache/shardingsphere/issues/11437#issuecomment-895075521
The error log is Function '{fn ifnull}' is not defined
I refer to your suggestion, and you said ss will do it, it make me confused
We need to rewrite the SQL to the following format:
SELECT order_id, {fn IFNULL(SUM(cnt), 0)} AS totoal FROM (
SELECT order_id, user_id, COUNT(1) AS cnt FROM t_order GROUP BY order_id, user_id
) a GROUP BY order_id;
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org