@@ -6,12 +6,13 @@ import org.jetbrains.kotlinx.dataframe.plugin.impl.Arguments
6
6
import org.jetbrains.kotlinx.dataframe.plugin.impl.PluginDataFrameSchema
7
7
import org.jetbrains.kotlinx.dataframe.plugin.impl.Present
8
8
import org.jetbrains.kotlinx.dataframe.plugin.impl.SimpleCol
9
- import org.jetbrains.kotlinx.dataframe.plugin.impl.SimpleDataColumn
10
9
import org.jetbrains.kotlinx.dataframe.plugin.impl.SimpleColumnGroup
10
+ import org.jetbrains.kotlinx.dataframe.plugin.impl.SimpleDataColumn
11
11
import org.jetbrains.kotlinx.dataframe.plugin.impl.SimpleFrameColumn
12
12
import org.jetbrains.kotlinx.dataframe.plugin.impl.data.ColumnPathApproximation
13
13
import org.jetbrains.kotlinx.dataframe.plugin.impl.data.ColumnWithPathApproximation
14
14
import org.jetbrains.kotlinx.dataframe.plugin.impl.dataFrame
15
+ import org.jetbrains.kotlinx.dataframe.plugin.impl.simpleColumnOf
15
16
16
17
internal class Explode0 : AbstractInterpreter <PluginDataFrameSchema >() {
17
18
val Arguments .dropEmpty: Boolean by arg(defaultValue = Present (true ))
@@ -20,14 +21,21 @@ internal class Explode0 : AbstractInterpreter<PluginDataFrameSchema>() {
20
21
override val Arguments .startingSchema get() = receiver
21
22
22
23
override fun Arguments.interpret (): PluginDataFrameSchema {
23
- val columns = selector ? : TODO ()
24
+ val columns = selector ? : object : ColumnsResolver {
25
+ override fun resolve (df : PluginDataFrameSchema ): List <ColumnWithPathApproximation > {
26
+ return df.flatten(includeFrames = false ).filter {
27
+ val column = it.column
28
+ column is SimpleFrameColumn || column is SimpleDataColumn && column.type.isList()
29
+ }
30
+ }
31
+ }
24
32
return receiver.explodeImpl(dropEmpty, columns.resolve(receiver).map { ColumnPathApproximation (it.path.path) })
25
33
}
26
34
}
27
35
28
- val KotlinTypeFacade .explodeImpl: PluginDataFrameSchema .(dropEmpty: Boolean , selector: List <ColumnPathApproximation >? ) -> PluginDataFrameSchema
36
+ val KotlinTypeFacade .explodeImpl: PluginDataFrameSchema .(dropEmpty: Boolean , selector: List <ColumnPathApproximation >) -> PluginDataFrameSchema
29
37
get() = { dropEmpty, selector ->
30
- val columns = selector ? : TODO ()
38
+ val columns = selector
31
39
32
40
val selected: Set <List <String >> = columns.map { it.path }.toSet()
33
41
@@ -36,9 +44,7 @@ val KotlinTypeFacade.explodeImpl: PluginDataFrameSchema.(dropEmpty: Boolean, sel
36
44
is SimpleColumnGroup -> SimpleColumnGroup (column.name, column.columns().map { makeNullable(it) })
37
45
is SimpleFrameColumn -> column
38
46
is SimpleDataColumn -> {
39
- // val nullable = if (dropEmpty) (column.type as TypeApproximationImpl).nullable else true
40
-
41
- column.changeType(type = column.type.changeNullability { nullable -> if (dropEmpty) nullable else true })
47
+ column.changeType(type = column.type.changeNullability { nullable -> selector.size > 1 || ! dropEmpty || nullable })
42
48
}
43
49
}
44
50
}
@@ -61,7 +67,7 @@ val KotlinTypeFacade.explodeImpl: PluginDataFrameSchema.(dropEmpty: Boolean, sel
61
67
column.type.isList() -> column.type.typeArgument()
62
68
else -> column.type
63
69
}
64
- SimpleDataColumn ( column.name, newType)
70
+ makeNullable(simpleColumnOf( column.name, newType.type) )
65
71
} else {
66
72
column
67
73
}
0 commit comments