-
Notifications
You must be signed in to change notification settings - Fork 33
Adding COUNT and COUNT(DISTINCT) aggregation support #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
Implements comprehensive COUNT operations for ScalaSQL addressing issue com-lihaoyi#95: Core Implementation: - Add AggAnyOps.scala with count/countDistinct methods for Expr[T] - Add countBy/countDistinctBy methods to AggOps for grouped queries - Add implicit conversion in Dialect for AggAnyOps integration API Features: - count/countDistinct: COUNT(expr) and COUNT(DISTINCT expr) - countBy/countDistinctBy: COUNT(column) and COUNT(DISTINCT column) - Full cross-dialect support (PostgreSQL, MySQL, SQLite, H2, MS SQL) - Proper NULL handling (COUNT ignores NULL values) - Window function support with OVER clauses - Integration with existing aggregation patterns Test Coverage: - Basic COUNT operations and edge cases - Option type handling with NULL database values - Complex type support (UUID, BigDecimal, DateTime, Boolean) - GROUP BY with COUNT aggregations - Window functions, filters, joins, and complex expressions - Cross-platform compatibility testing Documentation: - Updated tutorial.md with COUNT examples and patterns - Added comprehensive reference.md API documentation - Updated cheatsheet.md with COUNT operations - Added window function documentation for COUNT
Adding COUNT and COUNT(DISTINCT) aggregation support
Contributor
Author
|
Working & Debugging the issues. |
Fixed all SQL formatting issues. Used the correct multi-dialect sqls pattern from existing tests. Applied proper PostgreSQL/SQLite (||), MySQL (CONCAT), and MS SQL Server (+) string concatenation formats. Properly handled whitespace normalization in TestChecker
Formatting and fixing MSSQL Dialect issues
Updated documentation
Reverted reference.md
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 functions
Implement COUNT and COUNT(DISTINCT) aggregation operations
Contributor
Author
|
Ready for review. Addressing issue #95 |
Member
|
Looks fine to me, seems some docs nee to be updated |
Contributor
Author
Thanks, updated the documentation. We are good now :-) |
Member
|
tagged 0.2.2 with this PR |
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.
Summary
Can we add
COUNTandCOUNT(DISTINCT)aggregations? #95Changes Made
Core Operations
.countBy(_.column)- GeneratesCOUNT(column)SQL, ignores NULL values.countDistinctBy(_.column)- GeneratesCOUNT(DISTINCT column)SQL for unique non-NULL counts.counton mapped expressions -query.map(_.expr).count.countDistincton mapped expressions -query.map(_.expr).countDistinctAdvanced Usage
Files Added/Modified
Database compatibility
Test Coverage
Documentation
.sizedocumentationTest Plan
#95