|
1 | 1 | package org.jetbrains.kotlinx.dataframe.plugin.impl.api |
2 | 2 |
|
3 | | -import org.jetbrains.kotlinx.dataframe.plugin.extensions.KotlinTypeFacade |
| 3 | +import org.jetbrains.kotlinx.dataframe.api.remove |
4 | 4 | import org.jetbrains.kotlinx.dataframe.plugin.impl.* |
5 | 5 |
|
6 | 6 | class Remove0 : AbstractSchemaModificationInterpreter() { |
7 | 7 | val Arguments.receiver: PluginDataFrameSchema by dataFrame() |
8 | 8 | val Arguments.columns: ColumnsResolver by arg() |
9 | 9 |
|
10 | 10 | override fun Arguments.interpret(): PluginDataFrameSchema { |
11 | | - val removeResult = removeImpl(receiver.columns(), columns.resolve(receiver).mapTo(mutableSetOf()) { it.path.path }) |
12 | | - return PluginDataFrameSchema(removeResult.updatedColumns) |
| 11 | + return receiver.asDataFrame().remove { columns }.toPluginDataFrameSchema() |
13 | 12 | } |
14 | 13 | } |
15 | | - |
16 | | -class RemoveResult(val updatedColumns: List<SimpleCol>, val removedColumns: List<SimpleCol>) |
17 | | - |
18 | | -fun KotlinTypeFacade.removeImpl(schema: List<SimpleCol>, paths: Set<List<String>>): RemoveResult { |
19 | | - val removed = mutableListOf<SimpleCol>() |
20 | | - fun remove(schema: List<SimpleCol>, p: List<String>): List<SimpleCol> { |
21 | | - return schema.flatMap { |
22 | | - if (p + it.name() in paths) { |
23 | | - removed.add(it) |
24 | | - emptyList() |
25 | | - } else { |
26 | | - if (it is SimpleColumnGroup) { |
27 | | - val columns = remove(it.columns(), p + it.name()) |
28 | | - if (columns.isEmpty()) emptyList() else listOf(SimpleColumnGroup(it.name(), columns)) |
29 | | - } else { |
30 | | - listOf(it) |
31 | | - } |
32 | | - } |
33 | | - } |
34 | | - } |
35 | | - |
36 | | - val updatedColumns = remove(schema, emptyList()) |
37 | | - return RemoveResult(updatedColumns, removed) |
38 | | -} |
0 commit comments