Commit fdcd7ba
committed
Implement COUNT and COUNT(DISTINCT) aggregation operations
Add comprehensive COUNT aggregation support addressing issue com-lihaoyi#95:
- Add AggAnyOps.scala with count/countDistinct for Expr[T] types
- Add countBy/countDistinctBy methods to AggOps.scala
- Full cross-database compatibility (PostgreSQL, MySQL, SQLite, H2, MS SQL)
- Proper NULL handling (COUNT ignores NULL values, COUNT(*) counts all)
- Support for expressions: map(...).count, map(...).countDistinct
- Multi-dialect SQL generation with proper operator precedence
- Comprehensive test coverage including edge cases and complex expressions
Features:
- .countBy(_.column) generates COUNT(column) SQL
- .countDistinctBy(_.column) generates COUNT(DISTINCT column) SQL
- .count/.countDistinct on mapped expressions for advanced scenarios
- Works with arithmetic expressions, filters, group by, and joins
- Consistent API design matching existing aggregation functions1 parent d780f92 commit fdcd7ba
File tree
2 files changed
+99
-252
lines changed- scalasql/test/src
- operations
2 files changed
+99
-252
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
| 89 | + | |
88 | 90 | | |
89 | 91 | | |
90 | 92 | | |
| |||
136 | 138 | | |
137 | 139 | | |
138 | 140 | | |
| 141 | + | |
139 | 142 | | |
140 | 143 | | |
141 | 144 | | |
| |||
185 | 188 | | |
186 | 189 | | |
187 | 190 | | |
| 191 | + | |
188 | 192 | | |
189 | 193 | | |
190 | 194 | | |
| |||
235 | 239 | | |
236 | 240 | | |
237 | 241 | | |
| 242 | + | |
238 | 243 | | |
239 | 244 | | |
240 | 245 | | |
| |||
290 | 295 | | |
291 | 296 | | |
292 | 297 | | |
| 298 | + | |
293 | 299 | | |
294 | 300 | | |
295 | 301 | | |
| |||
341 | 347 | | |
342 | 348 | | |
343 | 349 | | |
| 350 | + | |
344 | 351 | | |
345 | 352 | | |
346 | 353 | | |
| |||
0 commit comments