Repository navigation
Conversation
HEAD requests replaced the SELECT with count(*) but kept GROUP BY, so SELECT count(*) AS count FROM Vehicle GROUP BY vid,sdate returned one row per group instead of the number of groups. That made total in grouped pagination report the rows inside a group, as reported in issue 624. Wrap the grouped statement in an outer count(*) subquery, the same way the Oracle branch already does. MySQL and SQL Server require an alias on a FROM subquery, so the subquery is aliased with gainSQLAliasWithQuote(). Tests assert the outer count(*) plus subquery shape for MySQL, PostgreSQL, SQL Server and DB2, and keep the plain count(*) and plain GET paths unchanged. fix APIJSON#624
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
issue #624 反馈:
[]里带@group时,total拿到的是组内数量而不是分组后的总条数。复现请求(issue 里的原始 JSON):
{ "[]": { "VehicleList_count": { "vehicleid$": "鄂QD24S8_0%", "sumdate%": "2023-10-15,2023-10-17", "@group": "vehicleid,sumdate", "@column": "vehicleid;sumdate;max(cnt):maxcnt", "@order": "maxcnt-" }, "page": 0, "count": 5 }, "total@": "/[]/total" }原因
gainColumnString在 HEAD 请求下把 SELECT 换成count(*),但gainConditionString对 HEAD 仍然拼接GROUP BY,于是生成:这条 SQL 返回的是每一组的行数(多行),不是分组后的组数,所以
total语义错位。Oracle 分支(isOracle() || isDameng() || isKingBaseOracle())早就用外层count(*)包了一层子查询,其它库没有对应处理。修复
在
gainSelectSQL里对齐 Oracle 的写法:@group非空且是 HEAD 方法时,把原语句包成子查询再count(*):MySQL / SQL Server 要求 FROM 子查询有别名,用已有的
gainSQLAliasWithQuote()补上,各库引号风格自动适配。修复后:
测试
新增
AbstractSQLConfigGroupCountTest,覆盖:count(*)+ 子查询结构,且外层不再出现GROUP BY@group时保持原来的单层count(*),不包子查询GET+@group保持原样,不被改成count(*)双通道验证
修复前(
git checkout还原AbstractSQLConfig.java):修复后:
全量
mvn test44 个用例全绿(原有 38 + 新增 6),无回归。fix #624