GROUP_CONCAT returns an empty string instead of NULL when all merged values are NULL
GROUP_CONCAT returns an empty string instead of NULL when all merged values are NULL
Bug Report
Which version of ShardingSphere did you use?
master @ 101c3d56ccd
Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
Both
Expected behavior
GROUP_CONCAT over a group whose values are NULL on every shard returns NULL, as MySQL documents: "It returns NULL if there are no non-NULL values."
Actual behavior
On a multi-shard route the merged GROUP_CONCAT and GROUP_CONCAT(DISTINCT ...) value is "" with wasNull() == false; a single-shard route returns NULL.
Reason analyze (If you can)
GroupConcatAggregationUnit.getResult() and DistinctGroupConcatAggregationUnit.getResult() (features/sharding/core/.../merge/dql/groupby/aggregation/) always return String.join(separator, values); merge() skips NULL, so an all-NULL group yields "".
The six sibling units return null when nothing was merged, and GroupByStreamMergedResult.getValue() already maps null to wasNull. Introduced with #33808.
Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
- Shard
t_useracross two data sources. - Insert rows for one
user_idinto both shards withnickname = NULL. SELECT user_id, GROUP_CONCAT(nickname) FROM t_user GROUP BY user_idreturns""instead of NULL.
Example codes for reproduce this issue (such as a github link).
N/A
Source: apache/shardingsphere