Skip to content

Commit c88b200

Browse files
committed
K2 compatibility: Fixed test from PivotTests thanks to smart-casting behavior changes. Also improved readability with ?:-hell in that function.
1 parent 6041d95 commit c88b200

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/ConfiguredAggregateColumn.kt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,29 @@ internal class ConfiguredAggregateColumn<C> private constructor(
1717
private fun ColumnWithPath<C>.toDescriptor(keepName: Boolean): AggregateColumnDescriptor<C> =
1818
when (val col = this) {
1919
is AggregateColumnDescriptor<C> -> {
20-
val path = if (keepName) newPath?.plus(col.newPath ?: col.column.shortPath()) ?: col.newPath
21-
else newPath ?: col.newPath
22-
AggregateColumnDescriptor(col.column, default ?: col.default, path)
20+
21+
// Fix for K2 smart-casting changes
22+
val currentDefault = this@ConfiguredAggregateColumn.default
23+
val currentNewPath = this@ConfiguredAggregateColumn.newPath
24+
25+
val newPath = when {
26+
currentNewPath == null -> col.newPath
27+
keepName -> currentNewPath + (col.newPath ?: col.column.shortPath())
28+
else -> currentNewPath
29+
}
30+
AggregateColumnDescriptor(
31+
column = col.column,
32+
default = currentDefault ?: col.default,
33+
newPath = newPath,
34+
)
2335
}
2436

25-
else -> AggregateColumnDescriptor(col, default, if (keepName) newPath?.plus(col.name) else newPath)
37+
else ->
38+
AggregateColumnDescriptor(
39+
column = col,
40+
default = default,
41+
newPath = if (keepName) newPath?.plus(col.name) else newPath,
42+
)
2643
}
2744

2845
private fun resolve(context: ColumnResolutionContext, columns: ColumnsResolver<C>): List<ColumnWithPath<C>> {

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/ConfiguredAggregateColumn.kt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,29 @@ internal class ConfiguredAggregateColumn<C> private constructor(
1717
private fun ColumnWithPath<C>.toDescriptor(keepName: Boolean): AggregateColumnDescriptor<C> =
1818
when (val col = this) {
1919
is AggregateColumnDescriptor<C> -> {
20-
val path = if (keepName) newPath?.plus(col.newPath ?: col.column.shortPath()) ?: col.newPath
21-
else newPath ?: col.newPath
22-
AggregateColumnDescriptor(col.column, default ?: col.default, path)
20+
21+
// Fix for K2 smart-casting changes
22+
val currentDefault = this@ConfiguredAggregateColumn.default
23+
val currentNewPath = this@ConfiguredAggregateColumn.newPath
24+
25+
val newPath = when {
26+
currentNewPath == null -> col.newPath
27+
keepName -> currentNewPath + (col.newPath ?: col.column.shortPath())
28+
else -> currentNewPath
29+
}
30+
AggregateColumnDescriptor(
31+
column = col.column,
32+
default = currentDefault ?: col.default,
33+
newPath = newPath,
34+
)
2335
}
2436

25-
else -> AggregateColumnDescriptor(col, default, if (keepName) newPath?.plus(col.name) else newPath)
37+
else ->
38+
AggregateColumnDescriptor(
39+
column = col,
40+
default = default,
41+
newPath = if (keepName) newPath?.plus(col.name) else newPath,
42+
)
2643
}
2744

2845
private fun resolve(context: ColumnResolutionContext, columns: ColumnsResolver<C>): List<ColumnWithPath<C>> {

0 commit comments

Comments
 (0)