File tree Expand file tree Collapse file tree 5 files changed +38
-0
lines changed
core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api
src/org/jetbrains/kotlinx/dataframe/plugin
tests-gen/org/jetbrains/kotlin/fir/dataframe Expand file tree Collapse file tree 5 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -207,6 +207,7 @@ public class AddDsl<T>(
207
207
208
208
public infix fun <R > ColumnReference<R>.into (column : KProperty <R >): Boolean = into(column.name)
209
209
210
+ @Interpretable(" AddDslStringInvoke" )
210
211
public operator fun String.invoke (body : AddDsl <T >.() -> Unit ): Unit = group(this , body)
211
212
212
213
public infix fun AnyColumnGroupAccessor.from (body : AddDsl <T >.() -> Unit ): Unit = group(this , body)
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import org.jetbrains.kotlinx.dataframe.plugin.impl.Arguments
7
7
import org.jetbrains.kotlinx.dataframe.plugin.impl.Interpreter
8
8
import org.jetbrains.kotlinx.dataframe.plugin.impl.PluginDataFrameSchema
9
9
import org.jetbrains.kotlinx.dataframe.plugin.impl.SimpleCol
10
+ import org.jetbrains.kotlinx.dataframe.plugin.impl.SimpleColumnGroup
10
11
import org.jetbrains.kotlinx.dataframe.plugin.impl.dataFrame
11
12
import org.jetbrains.kotlinx.dataframe.plugin.impl.simpleColumnOf
12
13
import org.jetbrains.kotlinx.dataframe.plugin.impl.dsl
@@ -57,3 +58,15 @@ class AddWithDsl : AbstractSchemaModificationInterpreter() {
57
58
return PluginDataFrameSchema (addDsl.columns)
58
59
}
59
60
}
61
+
62
+ class AddDslStringInvoke : AbstractInterpreter <Unit >() {
63
+ val Arguments .dsl: AddDslApproximation by arg(lens = Interpreter .Value )
64
+ val Arguments .receiver: String by string()
65
+ val Arguments .body by dsl()
66
+
67
+ override fun Arguments.interpret () {
68
+ val addDsl = AddDslApproximation (mutableListOf ())
69
+ body(addDsl, emptyMap())
70
+ dsl.columns.add(SimpleColumnGroup (receiver, addDsl.columns))
71
+ }
72
+ }
Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ import org.jetbrains.kotlin.fir.types.classId
67
67
import org.jetbrains.kotlin.fir.types.coneType
68
68
import org.jetbrains.kotlin.name.ClassId
69
69
import org.jetbrains.kotlin.name.Name
70
+ import org.jetbrains.kotlinx.dataframe.plugin.impl.api.AddDslStringInvoke
70
71
import org.jetbrains.kotlinx.dataframe.plugin.impl.api.AddId
71
72
import org.jetbrains.kotlinx.dataframe.plugin.impl.api.All0
72
73
import org.jetbrains.kotlinx.dataframe.plugin.impl.api.ColsAtAnyDepth0
@@ -196,6 +197,7 @@ internal inline fun <reified T> String.load(): T {
196
197
" Flatten0" -> Flatten0 ()
197
198
" FlattenDefault" -> FlattenDefault ()
198
199
" AddId" -> AddId ()
200
+ " AddDslStringInvoke" -> AddDslStringInvoke ()
199
201
else -> error(" $this " )
200
202
} as T
201
203
}
Original file line number Diff line number Diff line change
1
+ import org.jetbrains.kotlinx.dataframe.*
2
+ import org.jetbrains.kotlinx.dataframe.annotations.*
3
+ import org.jetbrains.kotlinx.dataframe.api.*
4
+ import org.jetbrains.kotlinx.dataframe.io.*
5
+
6
+ fun box (): String {
7
+ val df = dataFrameOf(" a" )(1 ).add {
8
+ " id" from { it }
9
+ " group" {
10
+ " a" from { it }
11
+ }
12
+ }
13
+
14
+ df.group.a
15
+ return " OK"
16
+ }
Original file line number Diff line number Diff line change 17
17
@ TestMetadata ("testData/box" )
18
18
@ TestDataPath ("$PROJECT_ROOT" )
19
19
public class DataFrameBlackBoxCodegenTestGenerated extends AbstractDataFrameBlackBoxCodegenTest {
20
+ @ Test
21
+ @ TestMetadata ("addDsl.kt" )
22
+ public void testAddDsl () {
23
+ runTest ("testData/box/addDsl.kt" );
24
+ }
25
+
20
26
@ Test
21
27
@ TestMetadata ("addId.kt" )
22
28
public void testAddId () {
You can’t perform that action at this time.
0 commit comments