Skip to content

Commit 6041d95

Browse files
committed
K2 compatibility: Fixed test from PivotTests by making ConfiguredAggregateColumn implement both SingleColumn<C>, ColumnSet<C>. Changed the factory functions to explicitly accept either of those only.
1 parent 50f7ca5 commit 6041d95

File tree

4 files changed

+68
-28
lines changed

4 files changed

+68
-28
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@ public interface ColumnsForAggregateSelectionDsl<out T> : ColumnsSelectionDsl<T>
1313
ConfiguredAggregateColumn.withDefault(this, defaultValue)
1414

1515
public infix fun <C> SingleColumn<C>.default(defaultValue: C): SingleColumn<C> =
16-
ConfiguredAggregateColumn.withDefault(this, defaultValue).single()
16+
ConfiguredAggregateColumn.withDefault(this, defaultValue)
1717

1818
public fun path(vararg names: String): ColumnPath = ColumnPath(names.asList())
1919

20-
public infix fun <C> ColumnSet<C>.into(name: String): ColumnSet<C> = ConfiguredAggregateColumn.withPath(this, pathOf(name))
20+
public infix fun <C> ColumnSet<C>.into(name: String): ColumnSet<C> =
21+
ConfiguredAggregateColumn.withPath(this, pathOf(name))
2122

2223
public infix fun <C> SingleColumn<C>.into(name: String): SingleColumn<C> =
23-
ConfiguredAggregateColumn.withPath(this, pathOf(name)).single()
24+
ConfiguredAggregateColumn.withPath(this, pathOf(name))
2425

25-
public infix fun <C> ColumnSet<C>.into(path: ColumnPath): ColumnSet<C> = ConfiguredAggregateColumn.withPath(this, path)
26+
public infix fun <C> ColumnSet<C>.into(path: ColumnPath): ColumnSet<C> =
27+
ConfiguredAggregateColumn.withPath(this, path)
2628

2729
public infix fun <C> SingleColumn<C>.into(path: ColumnPath): SingleColumn<C> =
28-
ConfiguredAggregateColumn.withPath(this, path).single()
30+
ConfiguredAggregateColumn.withPath(this, path)
2931
}

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

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnResolutionContext
55
import org.jetbrains.kotlinx.dataframe.columns.ColumnSet
66
import org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath
77
import org.jetbrains.kotlinx.dataframe.columns.ColumnsResolver
8+
import org.jetbrains.kotlinx.dataframe.columns.SingleColumn
89
import org.jetbrains.kotlinx.dataframe.columns.shortPath
910

1011
internal class ConfiguredAggregateColumn<C> private constructor(
1112
val columns: ColumnsResolver<C>,
1213
private val default: C? = null,
1314
private val newPath: ColumnPath? = null,
14-
) : ColumnSet<C> {
15+
) : SingleColumn<C>, ColumnSet<C> {
1516

1617
private fun ColumnWithPath<C>.toDescriptor(keepName: Boolean): AggregateColumnDescriptor<C> =
1718
when (val col = this) {
@@ -38,16 +39,33 @@ internal class ConfiguredAggregateColumn<C> private constructor(
3839
override fun resolve(context: ColumnResolutionContext): List<ColumnWithPath<C>> =
3940
resolve(context, columns)
4041

42+
override fun resolveSingle(context: ColumnResolutionContext): ColumnWithPath<C>? =
43+
resolve(context, columns).singleOrNull()
44+
4145
companion object {
4246

43-
fun <C> withDefault(src: ColumnsResolver<C>, default: C?): ColumnSet<C> = when (src) {
44-
is ConfiguredAggregateColumn<C> -> ConfiguredAggregateColumn(src.columns, default, src.newPath)
45-
else -> ConfiguredAggregateColumn(src, default, null)
46-
}
47+
fun <C> withPath(src: SingleColumn<C>, newPath: ColumnPath): SingleColumn<C> =
48+
when (src) {
49+
is ConfiguredAggregateColumn<C> -> ConfiguredAggregateColumn(src.columns, src.default, newPath)
50+
else -> ConfiguredAggregateColumn(src, null, newPath)
51+
}
4752

48-
fun <C> withPath(src: ColumnsResolver<C>, newPath: ColumnPath): ColumnSet<C> = when (src) {
49-
is ConfiguredAggregateColumn<C> -> ConfiguredAggregateColumn(src.columns, src.default, newPath)
50-
else -> ConfiguredAggregateColumn(src, null, newPath)
51-
}
53+
fun <C> withDefault(src: SingleColumn<C>, default: C?): SingleColumn<C> =
54+
when (src) {
55+
is ConfiguredAggregateColumn<C> -> ConfiguredAggregateColumn(src.columns, default, src.newPath)
56+
else -> ConfiguredAggregateColumn(src, default, null)
57+
}
58+
59+
fun <C> withPath(src: ColumnSet<C>, newPath: ColumnPath): ColumnSet<C> =
60+
when (src) {
61+
is ConfiguredAggregateColumn<C> -> ConfiguredAggregateColumn(src.columns, src.default, newPath)
62+
else -> ConfiguredAggregateColumn(src, null, newPath)
63+
}
64+
65+
fun <C> withDefault(src: ColumnSet<C>, default: C?): ColumnSet<C> =
66+
when (src) {
67+
is ConfiguredAggregateColumn<C> -> ConfiguredAggregateColumn(src.columns, default, src.newPath)
68+
else -> ConfiguredAggregateColumn(src, default, null)
69+
}
5270
}
5371
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@ public interface ColumnsForAggregateSelectionDsl<out T> : ColumnsSelectionDsl<T>
1313
ConfiguredAggregateColumn.withDefault(this, defaultValue)
1414

1515
public infix fun <C> SingleColumn<C>.default(defaultValue: C): SingleColumn<C> =
16-
ConfiguredAggregateColumn.withDefault(this, defaultValue).single()
16+
ConfiguredAggregateColumn.withDefault(this, defaultValue)
1717

1818
public fun path(vararg names: String): ColumnPath = ColumnPath(names.asList())
1919

20-
public infix fun <C> ColumnSet<C>.into(name: String): ColumnSet<C> = ConfiguredAggregateColumn.withPath(this, pathOf(name))
20+
public infix fun <C> ColumnSet<C>.into(name: String): ColumnSet<C> =
21+
ConfiguredAggregateColumn.withPath(this, pathOf(name))
2122

2223
public infix fun <C> SingleColumn<C>.into(name: String): SingleColumn<C> =
23-
ConfiguredAggregateColumn.withPath(this, pathOf(name)).single()
24+
ConfiguredAggregateColumn.withPath(this, pathOf(name))
2425

25-
public infix fun <C> ColumnSet<C>.into(path: ColumnPath): ColumnSet<C> = ConfiguredAggregateColumn.withPath(this, path)
26+
public infix fun <C> ColumnSet<C>.into(path: ColumnPath): ColumnSet<C> =
27+
ConfiguredAggregateColumn.withPath(this, path)
2628

2729
public infix fun <C> SingleColumn<C>.into(path: ColumnPath): SingleColumn<C> =
28-
ConfiguredAggregateColumn.withPath(this, path).single()
30+
ConfiguredAggregateColumn.withPath(this, path)
2931
}

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

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnResolutionContext
55
import org.jetbrains.kotlinx.dataframe.columns.ColumnSet
66
import org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath
77
import org.jetbrains.kotlinx.dataframe.columns.ColumnsResolver
8+
import org.jetbrains.kotlinx.dataframe.columns.SingleColumn
89
import org.jetbrains.kotlinx.dataframe.columns.shortPath
910

1011
internal class ConfiguredAggregateColumn<C> private constructor(
1112
val columns: ColumnsResolver<C>,
1213
private val default: C? = null,
1314
private val newPath: ColumnPath? = null,
14-
) : ColumnSet<C> {
15+
) : SingleColumn<C>, ColumnSet<C> {
1516

1617
private fun ColumnWithPath<C>.toDescriptor(keepName: Boolean): AggregateColumnDescriptor<C> =
1718
when (val col = this) {
@@ -38,16 +39,33 @@ internal class ConfiguredAggregateColumn<C> private constructor(
3839
override fun resolve(context: ColumnResolutionContext): List<ColumnWithPath<C>> =
3940
resolve(context, columns)
4041

42+
override fun resolveSingle(context: ColumnResolutionContext): ColumnWithPath<C>? =
43+
resolve(context, columns).singleOrNull()
44+
4145
companion object {
4246

43-
fun <C> withDefault(src: ColumnsResolver<C>, default: C?): ColumnSet<C> = when (src) {
44-
is ConfiguredAggregateColumn<C> -> ConfiguredAggregateColumn(src.columns, default, src.newPath)
45-
else -> ConfiguredAggregateColumn(src, default, null)
46-
}
47+
fun <C> withPath(src: SingleColumn<C>, newPath: ColumnPath): SingleColumn<C> =
48+
when (src) {
49+
is ConfiguredAggregateColumn<C> -> ConfiguredAggregateColumn(src.columns, src.default, newPath)
50+
else -> ConfiguredAggregateColumn(src, null, newPath)
51+
}
4752

48-
fun <C> withPath(src: ColumnsResolver<C>, newPath: ColumnPath): ColumnSet<C> = when (src) {
49-
is ConfiguredAggregateColumn<C> -> ConfiguredAggregateColumn(src.columns, src.default, newPath)
50-
else -> ConfiguredAggregateColumn(src, null, newPath)
51-
}
53+
fun <C> withDefault(src: SingleColumn<C>, default: C?): SingleColumn<C> =
54+
when (src) {
55+
is ConfiguredAggregateColumn<C> -> ConfiguredAggregateColumn(src.columns, default, src.newPath)
56+
else -> ConfiguredAggregateColumn(src, default, null)
57+
}
58+
59+
fun <C> withPath(src: ColumnSet<C>, newPath: ColumnPath): ColumnSet<C> =
60+
when (src) {
61+
is ConfiguredAggregateColumn<C> -> ConfiguredAggregateColumn(src.columns, src.default, newPath)
62+
else -> ConfiguredAggregateColumn(src, null, newPath)
63+
}
64+
65+
fun <C> withDefault(src: ColumnSet<C>, default: C?): ColumnSet<C> =
66+
when (src) {
67+
is ConfiguredAggregateColumn<C> -> ConfiguredAggregateColumn(src.columns, default, src.newPath)
68+
else -> ConfiguredAggregateColumn(src, default, null)
69+
}
5270
}
5371
}

0 commit comments

Comments
 (0)