Skip to content

Commit 3f20af5

Browse files
koperagenSpace Team
authored andcommitted
[KDF] Replace custom removeImpl with DataFrame.remove
1 parent 071c5d8 commit 3f20af5

File tree

1 file changed

+2
-27
lines changed
  • plugins/kotlin-dataframe/src/org/jetbrains/kotlinx/dataframe/plugin/impl/api

1 file changed

+2
-27
lines changed
Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,13 @@
11
package org.jetbrains.kotlinx.dataframe.plugin.impl.api
22

3-
import org.jetbrains.kotlinx.dataframe.plugin.extensions.KotlinTypeFacade
3+
import org.jetbrains.kotlinx.dataframe.api.remove
44
import org.jetbrains.kotlinx.dataframe.plugin.impl.*
55

66
class Remove0 : AbstractSchemaModificationInterpreter() {
77
val Arguments.receiver: PluginDataFrameSchema by dataFrame()
88
val Arguments.columns: ColumnsResolver by arg()
99

1010
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()
1312
}
1413
}
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

Comments
 (0)