Skip to content

Commit

Permalink
Fix performance problem in rename implementation. Use column path i…
Browse files Browse the repository at this point in the history
…nstead of column content as a key for `associateBy`.
  • Loading branch information
nikitinas committed Dec 12, 2023
1 parent 348e9ab commit 046cd0c
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ internal fun <T, C> RenameClause<T, C>.renameImpl(newNames: Array<out String>):
internal fun <T, C> RenameClause<T, C>.renameImpl(transform: (ColumnWithPath<C>) -> String): DataFrame<T> {
// get all selected columns and their paths
val selectedColumnsWithPath = df.getColumnsWithPaths(columns)
.associateBy { it.data }
.associateBy { it.path }
// gather a tree of all columns where the nodes will be renamed
val tree = df.getColumnsWithPaths { all().rec() }.collectTree()

// perform rename in nodes
tree.allChildrenNotNull().forEach { node ->
tree.allChildrenNotNull().map { it to it.pathFromRoot() }.forEach { (node, originalPath) ->
// Check if the current node/column is a selected column and, if so, get its ColumnWithPath
val column = selectedColumnsWithPath[node.data] ?: return@forEach
val column = selectedColumnsWithPath[originalPath] ?: return@forEach
// Use the found selected ColumnWithPath to query for the new name
val newColumnName = transform(column)
node.name = newColumnName
Expand Down

0 comments on commit 046cd0c

Please sign in to comment.