Title: fix(sql): skip TSQL paging for aggregates without @group by lnuxe · Pull Request #885 · APIJSON/APIJSON · GitHub
Open Graph Title: fix(sql): skip TSQL paging for aggregates without @group by lnuxe · Pull Request #885 · APIJSON/APIJSON
X Title: fix(sql): skip TSQL paging for aggregates without @group by lnuxe · Pull Request #885 · APIJSON/APIJSON
Description: 背景 issue #648 反馈:SQL Server 下 @column 用聚合函数会报错。 复现请求: { "Moment": { "@column": "max(date):date" } } 报错: order by 子句列 id 无效,因为该列没有包含在聚合函数或 group by 子句中 原因 SQL Server / DB2 / Kingbase SQL Server 模式下,OFFSET ... FETCH ... 必须带 ORDER BY,所以 gainOrderString 在 getCount() > 0 时自动补上 ORDER BY "id": if (getCount() > 0 && (isSQLServer() || isKingBaseSQLServer() || isDb2())) { ... order = idKey; // 没传 @order 时默认用 id } 但 max(date) 这种不带 GROUP BY 的单聚合永远只返回一行,它没有 id 列可以排序,于是生成非法 SQL: SELECT max("date") AS "date" FROM "sys"."Moment" ORDER BY "id" OFFSET 0 ROWS FETCH FIRST 10 ROWS ONLY MySQL / PostgreSQL 走 LIMIT,不强制 ORDER BY,所以一直是好的——这解释了为什么只有 SQL Server 报。 修复 新增 isAggregateWithoutGroup():@group 为空、@column 只有一项、且该项是 SQL_AGGREGATE_FUNCTION_MAP 里的聚合函数(max/min/avg/count/sum)时返回 true。 两处使用: gainOrderString:这种查询不再补 ORDER BY。 gainLimitString:直接返回空字符串——结果本来就只有一行,OFFSET/FETCH 没有意义。 修复后: SELECT max("date") AS "date" FROM "sys"."Moment" 不受影响的场景 普通字段分页:仍保留 ORDER BY "id" OFFSET 0 ROWS FETCH FIRST 10 ROWS ONLY 带 @group 的聚合:仍保留 ORDER BY(可以按分组字段排序) MySQL / PostgreSQL:LIMIT 分支未改动 测试 新增 AbstractSQLConfigAggregatePagingTest(6 个用例): SQL Server / DB2 / Kingbase SQL Server 的聚合查询断言无 ORDER BY、无 OFFSET SQL Server 普通字段分页断言仍带 ORDER BY + OFFSET SQL Server 带 @group 的聚合断言仍带 ORDER BY 双通道验证 修复前(git checkout origin/main -- src/main/java/apijson/orm/AbstractSQLConfig.java): aggregate paging: SELECT max("date") AS "date" FROM "sys"."Moment" ORDER BY "id" OFFSET 0 ROWS FETCH FIRST 10 ROWS ONLY [ERROR] AbstractSQLConfigAggregatePagingTest.skipsOrderByForSQLServerAggregate:127 聚合函数不带 GROUP BY 时不应补 ORDER BY,否则列不在聚合函数内会报错 [ERROR] Tests run: 6, Failures: 4, Errors: 0, Skipped: 0 修复后: [INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0 -- in apijson.orm.AbstractSQLConfigAggregatePagingTest [INFO] Tests run: 44, Failures: 0, Errors: 0, Skipped: 0 [INFO] BUILD SUCCESS 全量 mvn test 44 个用例全绿(原有 38 + 新增 6),无回归。 fix #648
Open Graph Description: 背景 issue #648 反馈:SQL Server 下 @column 用聚合函数会报错。 复现请求: { "Moment": { "@column": "max(date):date" } } 报错: order by 子句列 id 无效,因为该列没有包含在聚合函数或 group by 子句中 原因 SQL ...
X Description: 背景 issue #648 反馈:SQL Server 下 @column 用聚合函数会报错。 复现请求: { "Moment": { "@column": "max(date):date" } } 报错: order by 子句列 id 无效,因为该列没有包含在聚合函...
Opengraph URL: https://github.com/APIJSON/APIJSON/pull/885
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:0926d03b-ffab-72f6-8942-caa67accda13 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9780:32D5F:FA0BCE:1671586:6AFCB1BA |
| html-safe-nonce | bd572ffd9c9b482a073ac8a34ae0461cbead836dfff17cd2cae4bb11321e0fe1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NzgwOjMyRDVGOkZBMEJDRToxNjcxNTg2OjZBRkNCMUJBIiwidmlzaXRvcl9pZCI6IjM0MzA1NTcxMzc1MTAzNzk5NjIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0199a5a32dc07d2d2c1c63ef7242eb90d48ba08f205cf783f1df97bdd837f8f7 |
| hovercard-subject-tag | pull_request:5259197757 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/APIJSON/APIJSON/pull/885/files |
| twitter:image | https://avatars.githubusercontent.com/u/144079529?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/144079529?s=400&v=4 |
| og:image:alt | 背景 issue #648 反馈:SQL Server 下 @column 用聚合函数会报错。 复现请求: { "Moment": { "@column": "max(date):date" } } 报错: order by 子句列 id 无效,因为该列没有包含在聚合函数或 group by 子句中 原因 SQL ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | e3084aead77cbcb4f4904fba53851fa1a0546b0dec3619bd250815e72588dc6d |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/APIJSON/APIJSON git https://github.com/APIJSON/APIJSON.git |
| octolytics-dimension-user_id | 41146037 |
| octolytics-dimension-user_login | APIJSON |
| octolytics-dimension-repository_id | 74359442 |
| octolytics-dimension-repository_nwo | APIJSON/APIJSON |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 74359442 |
| octolytics-dimension-repository_network_root_nwo | APIJSON/APIJSON |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5410e4bebd3e45b138c853ecef3992279d86d5af |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width