Skip to content

Commit

Permalink
Merge pull request #6543 from grzesiek2010/COLLECT-6537_2
Browse files Browse the repository at this point in the history
Fixed the filtering of duplicate columns
  • Loading branch information
seadowg committed Dec 9, 2024
1 parent 264f3f1 commit 2ccb27f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ class DatabaseEntitiesRepository(context: Context, dbPath: String) : EntitiesRep
val missingColumns = entity.properties
.map { EntitiesTable.getPropertyColumn(it.first) }
.distinctBy { it.lowercase() }
.filterNot { columnNames.contains(it) }
.filterNot { columnName -> columnNames.any { it.equals(columnName, ignoreCase = true) } }

if (missingColumns.isNotEmpty()) {
databaseConnection.resetTransaction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ abstract class EntitiesRepositoryTest {
}

@Test
fun `#save ignores case-insensitive duplicate properties`() {
fun `#save ignores case-insensitive duplicate new properties`() {
val repository = buildSubject()
val entity = Entity.New(
"1",
Expand All @@ -745,15 +745,26 @@ abstract class EntitiesRepositoryTest {
)

repository.save("things", entity)
var savedEntities = repository.getEntities("things")
val savedEntities = repository.getEntities("things")
assertThat(savedEntities[0].properties.size, equalTo(1))
assertThat(savedEntities[0].properties[0].first, equalTo("prop"))
}

@Test
fun `#save ignores case-insensitive duplicate properties if one of them has already been saved`() {
val repository = buildSubject()
val entity = Entity.New(
"1",
"One",
properties = listOf(Pair("prop", "value"))
)

/**
* Attempt to save again to ensure that duplicate properties are correctly compared, not only
* within the current entity list, but also against properties already saved in the database.
*/
repository.save("things", entity)
var savedEntities = repository.getEntities("things")
assertThat(savedEntities[0].properties.size, equalTo(1))
assertThat(savedEntities[0].properties[0].first, equalTo("prop"))

repository.save("things", entity.copy(properties = listOf(Pair("Prop", "value"))))
savedEntities = repository.getEntities("things")
assertThat(savedEntities[0].properties.size, equalTo(1))
assertThat(savedEntities[0].properties[0].first, equalTo("prop"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,15 @@ class InMemEntitiesRepository : EntitiesRepository {

private fun updateLists(list: String, entity: Entity) {
lists.add(list)
listProperties.getOrPut(list) {
val properties = listProperties.getOrPut(list) {
mutableSetOf()
}.addAll(
}
properties.addAll(
entity
.properties
.distinctBy { it.first.lowercase() }
.map { it.first }
.distinctBy { it.lowercase() }
.filterNot { properties.any { property -> property.equals(it, ignoreCase = true) } }
)
}

Expand Down

0 comments on commit 2ccb27f

Please sign in to comment.