Skip to content
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

fix: EXPOSED-646 count() voids distinctOn call on query #2311

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ open class Query(override var set: FieldSet, where: Op<Boolean>?) : AbstractQuer
* @sample org.jetbrains.exposed.sql.tests.shared.dml.InsertSelectTests.testInsertSelect02
*/
override fun count(): Long {
return if (distinct || groupedByColumns.isNotEmpty() || limit != null || offset > 0) {
return if (distinct || distinctOn != null || groupedByColumns.isNotEmpty() || limit != null || offset > 0) {
fun Column<*>.makeAlias() =
alias(transaction.db.identifierManager.quoteIfNecessary("${table.tableNameWithoutSchemeSanitized}_$name"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,22 @@ class DistinctOnTests : DatabaseTestsBase() {
assertEquals(1, value)
}
}

@Test
fun testDistinctOnWithCount() {
val tester = object : IntIdTable() {
val name = varchar("name", 50)
}

withTables(excludeSettings = TestDB.ALL - distinctOnSupportedDb, tester) {
tester.batchInsert(listOf("tester1", "tester1", "tester2", "tester3", "tester2")) {
this[tester.name] = it
}

val count = tester.selectAll()
.withDistinctOn(tester.name)
.count()
assertEquals(3, count)
}
}
}
Loading