Skip to content

[Compiler plugin] Support SingleColumn.select #1145

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
merged 1 commit into from
Apr 23, 2025
Merged
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 @@ -178,6 +178,7 @@ public interface SelectColumnsSelectionDsl {
*
* `df.`[select][DataFrame.select]` { myColGroup `[`{`][SingleColumn.select]` colA `[and][ColumnsSelectionDsl.and]` colB `[`}`][SingleColumn.select]` }`
*/
@Interpretable("NestedSelect")
public fun <C, R> SingleColumn<DataRow<C>>.select(selector: ColumnsSelector<C, R>): ColumnSet<R> =
selectInternal(selector)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,6 @@ internal class ValueCols2 : AbstractInterpreter<ColumnsResolver>() {
}
}


internal class Named0 : AbstractInterpreter<ColumnsResolver>() {
val Arguments.receiver: SingleColumnApproximation by arg()
val Arguments.newName: String by arg()
Expand All @@ -702,3 +701,12 @@ internal class Named0 : AbstractInterpreter<ColumnsResolver>() {
return columnsResolver { receiver named newName }
}
}

internal class NestedSelect : AbstractInterpreter<ColumnsResolver>() {
val Arguments.receiver: SingleColumnApproximation by arg()
val Arguments.selector: ColumnsResolver by arg()

override fun Arguments.interpret(): ColumnsResolver {
return columnsResolver { receiver.asColumnGroup().select { selector } }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ import org.jetbrains.kotlinx.dataframe.plugin.impl.api.NameStartsWith0
import org.jetbrains.kotlinx.dataframe.plugin.impl.api.NameStartsWith1
import org.jetbrains.kotlinx.dataframe.plugin.impl.api.NameStartsWith2
import org.jetbrains.kotlinx.dataframe.plugin.impl.api.Named0
import org.jetbrains.kotlinx.dataframe.plugin.impl.api.NestedSelect
import org.jetbrains.kotlinx.dataframe.plugin.impl.api.PairConstructor
import org.jetbrains.kotlinx.dataframe.plugin.impl.api.PairToConstructor
import org.jetbrains.kotlinx.dataframe.plugin.impl.api.PerRowCol
Expand Down Expand Up @@ -316,6 +317,7 @@ internal inline fun <reified T> String.load(): T {
"RenameMapping" -> RenameMapping()
"Select0" -> Select0()
"Distinct0" -> Select0()
"NestedSelect" -> NestedSelect()
"Expr0" -> Expr0()
"And0" -> And0()
"Remove0" -> Remove0()
Expand Down
15 changes: 15 additions & 0 deletions plugins/kotlin-dataframe/testData/box/csDsl/select.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import org.jetbrains.kotlinx.dataframe.*
import org.jetbrains.kotlinx.dataframe.annotations.*
import org.jetbrains.kotlinx.dataframe.api.*
import org.jetbrains.kotlinx.dataframe.io.*

fun box(): String {
val df = dataFrameOf(
"a" to listOf(1),
"b" to listOf(1),
).group { a and b }.into("gr")
val res = df.select { gr.select { a and b } }
res.a
res.b
return "OK"
}
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,12 @@ public void testRename() {
runTest("testData/box/csDsl/rename.kt");
}

@Test
@TestMetadata("select.kt")
public void testSelect() {
runTest("testData/box/csDsl/select.kt");
}

@Test
@TestMetadata("single.kt")
public void testSingle() {
Expand Down