Skip to content

Commit

Permalink
auto-linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolanrensen committed Jan 27, 2025
1 parent dcb3403 commit 45d60d4
Showing 1 changed file with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jetbrains.kotlinx.dataframe.plugin.impl.api

import org.jetbrains.kotlinx.dataframe.api.rename
import org.jetbrains.kotlinx.dataframe.api.renameToCamelCase
import org.jetbrains.kotlinx.dataframe.plugin.impl.AbstractInterpreter
import org.jetbrains.kotlinx.dataframe.plugin.impl.AbstractSchemaModificationInterpreter
Expand All @@ -18,9 +17,8 @@ import org.jetbrains.kotlinx.dataframe.plugin.impl.toPluginDataFrameSchema
class Rename : AbstractInterpreter<RenameClauseApproximation>() {
private val Arguments.receiver by dataFrame()
private val Arguments.columns: ColumnsResolver by arg()
override fun Arguments.interpret(): RenameClauseApproximation {
return RenameClauseApproximation(receiver, columns)
}

override fun Arguments.interpret(): RenameClauseApproximation = RenameClauseApproximation(receiver, columns)
}

class RenameClauseApproximation(val schema: PluginDataFrameSchema, val columns: ColumnsResolver)
Expand All @@ -33,58 +31,72 @@ class RenameInto : AbstractSchemaModificationInterpreter() {
val columns = receiver.columns.resolve(receiver.schema)
require(columns.size == newNames.size)
var i = 0
return receiver.schema.map(columns.mapTo(mutableSetOf()) { it.path.path }, nextName = { newNames[i].also { i += 1 } })
return receiver.schema.map(
selected = columns.mapTo(mutableSetOf()) { it.path.path },
nextName = { newNames[i].also { i += 1 } },
)
}
}

internal fun PluginDataFrameSchema.map(selected: ColumnsSet, nextName: () -> String): PluginDataFrameSchema {
return PluginDataFrameSchema(
f(columns(), nextName, selected, emptyList())
internal fun PluginDataFrameSchema.map(selected: ColumnsSet, nextName: () -> String): PluginDataFrameSchema =
PluginDataFrameSchema(
f(columns(), nextName, selected, emptyList()),
)
}

internal fun f(columns: List<SimpleCol>, nextName: () -> String, selected: ColumnsSet, path: List<String>): List<SimpleCol> {
return columns.map {
internal fun f(
columns: List<SimpleCol>,
nextName: () -> String,
selected: ColumnsSet,
path: List<String>,
): List<SimpleCol> =
columns.map {
val fullPath = path + listOf(it.name)
when (it) {
is SimpleColumnGroup -> {
val group = if (fullPath in selected) {
it.rename(nextName())
} else {
} else {
it
}
group.map(selected, fullPath, nextName)
}

is SimpleFrameColumn -> {
val frame = if (fullPath in selected) {
it.rename(nextName())
} else {
} else {
it
}
frame.map(selected, fullPath, nextName)
}

is SimpleDataColumn -> if (fullPath in selected) {
it.rename(nextName())
} else {
it
}
}
}
}

internal fun SimpleColumnGroup.map(selected: ColumnsSet, path: List<String>, nextName: () -> String): SimpleColumnGroup {
return SimpleColumnGroup(
name,
f(columns(), nextName, selected, path)
internal fun SimpleColumnGroup.map(
selected: ColumnsSet,
path: List<String>,
nextName: () -> String,
): SimpleColumnGroup =
SimpleColumnGroup(
name = name,
columns = f(columns(), nextName, selected, path),
)
}

internal fun SimpleFrameColumn.map(selected: ColumnsSet, path: List<String>, nextName: () -> String): SimpleFrameColumn {
return SimpleFrameColumn(
name,
f(columns(), nextName, selected, path)
internal fun SimpleFrameColumn.map(
selected: ColumnsSet,
path: List<String>,
nextName: () -> String,
): SimpleFrameColumn =
SimpleFrameColumn(
name = name,
columns = f(columns(), nextName, selected, path),
)
}

class RenameToCamelCase : AbstractSchemaModificationInterpreter() {
val Arguments.receiver by dataFrame()
Expand Down

0 comments on commit 45d60d4

Please sign in to comment.