From 079e8608c828d8b7dec9a6e853b73465b03374b3 Mon Sep 17 00:00:00 2001 From: Nikita Klimenko Date: Thu, 4 Sep 2025 14:45:27 +0300 Subject: [PATCH] Prepare utility to assert compile time column order --- .../kotlin/org/jetbrains/kotlinx/dataframe/api/schema.kt | 8 ++++++-- .../org/jetbrains/kotlinx/dataframe/impl/api/schema.kt | 5 ++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/schema.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/schema.kt index 88f93ffa17..d8b665bd82 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/schema.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/schema.kt @@ -26,5 +26,9 @@ public fun GroupBy<*, *>.schema(): DataFrameSchema = toDataFrame().schema() // endregion -public inline fun DataFrame.compileTimeSchema(): DataFrameSchema = - compileTimeSchemaImpl(schema(), T::class) +/** + * [ordered] - if true, columns are ordered the same as in runtime schema for easier diff between the two. + * if false, columns are ordered as they are represented in the compiler plugin + */ +public inline fun DataFrame.compileTimeSchema(ordered: Boolean = true): DataFrameSchema = + compileTimeSchemaImpl(if (ordered) schema() else null, T::class) diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/schema.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/schema.kt index dd0d952ed0..288ac17c4a 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/schema.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/schema.kt @@ -8,8 +8,9 @@ import org.jetbrains.kotlinx.dataframe.schema.DataFrameSchema import kotlin.reflect.KClass @PublishedApi -internal fun compileTimeSchemaImpl(runtimeSchema: DataFrameSchema, klass: KClass<*>): DataFrameSchema { +internal fun compileTimeSchemaImpl(runtimeSchema: DataFrameSchema?, klass: KClass<*>): DataFrameSchema { val compileSchema = getSchema(klass) + if (runtimeSchema == null) return compileSchema val root = ColumnPath(emptyList()) val order = buildMap { putColumnsOrder(runtimeSchema, path = root) @@ -41,8 +42,6 @@ internal fun DataFrameSchema.sortedBy(order: Map, path: ColumnP is ColumnSchema.Group -> ColumnSchema.Group(column.schema.sortedBy(order, path + name), column.contentType) is ColumnSchema.Value -> column - - else -> TODO("unexpected ColumnSchema class ${column::class}") } }.sortedBy { (name, _) -> order[path + name]