diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/codeGen/SchemaProcessorImpl.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/codeGen/SchemaProcessorImpl.kt index 9517fbe078..31e25fb384 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/codeGen/SchemaProcessorImpl.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/codeGen/SchemaProcessorImpl.kt @@ -58,6 +58,7 @@ internal class SchemaProcessorImpl( private fun generateFields( schema: DataFrameSchema, visibility: MarkerVisibility, + openNestedDataSchemas: Boolean, requiredSuperMarkers: List = emptyList(), ): List { val usedFieldNames = @@ -66,18 +67,26 @@ internal class SchemaProcessorImpl( fun getFieldType(columnSchema: ColumnSchema): FieldType = when (columnSchema) { is ColumnSchema.Value -> - FieldType.ValueFieldType(columnSchema.type.toString()) + FieldType.ValueFieldType(typeFqName = columnSchema.type.toString()) is ColumnSchema.Group -> FieldType.GroupFieldType( - process(columnSchema.schema, false, visibility).name, + markerName = process( + schema = columnSchema.schema, + isOpen = openNestedDataSchemas, + visibility = visibility, + ).name, renderAsObject = true, ) is ColumnSchema.Frame -> FieldType.FrameFieldType( - process(columnSchema.schema, false, visibility).name, - columnSchema.nullable, + markerName = process( + schema = columnSchema.schema, + isOpen = openNestedDataSchemas, + visibility = visibility, + ).name, + nullable = columnSchema.nullable, renderAsList = true, ) @@ -145,11 +154,24 @@ internal class SchemaProcessorImpl( } } } - generateFields(scheme, visibility, baseMarkers) + generateFields( + schema = scheme, + visibility = visibility, + openNestedDataSchemas = isOpen, + requiredSuperMarkers = baseMarkers, + ) } else { - generateFields(scheme, visibility) + generateFields(schema = scheme, visibility = visibility, openNestedDataSchemas = isOpen) } - return Marker(name, isOpen, fields, baseMarkers.onlyLeafs(), visibility, emptyList(), emptyList()) + return Marker( + name = name, + isOpen = isOpen, + fields = fields, + superMarkers = baseMarkers.onlyLeafs(), + visibility = visibility, + typeParameters = emptyList(), + typeArguments = emptyList(), + ) } private fun DataFrameSchema.getRequiredMarkers() = registeredMarkers.filterRequiredForSchema(this) diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/CodeGenerationTests.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/CodeGenerationTests.kt index 1cfe07482d..3596948041 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/CodeGenerationTests.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/CodeGenerationTests.kt @@ -158,7 +158,7 @@ class CodeGenerationTests : BaseTest() { val type2 = ReplCodeGeneratorImpl.markerInterfacePrefix val declaration1 = """ - @DataSchema(isOpen = false) + @DataSchema interface $type1 { val city: String? val name: String diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/ReplCodeGenTests.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/ReplCodeGenTests.kt index 48f0c2e101..e762ee268e 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/ReplCodeGenTests.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/ReplCodeGenTests.kt @@ -277,7 +277,7 @@ class ReplCodeGenTests : BaseTest() { val c = repl.process(Test5.df, Test5::df) c.declarations shouldBe """ - @DataSchema(isOpen = false) + @DataSchema interface _DataFrameType3 { val a: Int val c: Int diff --git a/dataframe-jupyter/src/test/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/CodeGenerationTests.kt b/dataframe-jupyter/src/test/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/CodeGenerationTests.kt index cdd2c1e318..1ad40fe1af 100644 --- a/dataframe-jupyter/src/test/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/CodeGenerationTests.kt +++ b/dataframe-jupyter/src/test/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/CodeGenerationTests.kt @@ -70,4 +70,27 @@ class CodeGenerationTests : DataFrameJupyterTest() { df1.leaf.c """.checkCompilation() } + + // https://github.com/Kotlin/dataframe/issues/1222 + @Test + fun `reusing marker with nullable column`() { + @Language("kt") + val _1 = """ + val df1 = dataFrameOf("group" to columnOf("a" to columnOf(1, null, 3))) + val df2 = dataFrameOf("group" to columnOf("a" to columnOf(1, 2, 3))) + df1.group.a + df2.group.a + """.checkCompilation() + } + + @Test + fun `not reusing marker with non-nullable column`() { + @Language("kt") + val _1 = """ + val df1 = dataFrameOf("group" to columnOf("a" to columnOf(1, 2, 3))) + val df2 = dataFrameOf("group" to columnOf("a" to columnOf(1, null, 3))) + df1.group.a + df2.group.a + """.checkCompilation() + } }