Terminal pivot operations return incorrect `T` schema, should be Any? instead
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 1.1k
- Forks
- 83
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 30
Description
result of pivot is always new set of columns created based on data in columns. Current return type is a guaranteed runtime exception:
Operations like public fun <T> Pivot<T>.count(): DataRow<T> = delegate { count() } should become
public fun <T> Pivot<T>.count(): DataRow<*> = delegate { count() }
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.annotations.*
import org.jetbrains.kotlinx.dataframe.api.*
import org.jetbrains.kotlinx.dataframe.io.*
@DataSchema
data class Students(
val age: Int,
val name: Name,
val scores: List<Scores>
) {
@DataSchema
data class Name(
val firstName: String,
val lastName: String?
)
@DataSchema
data class Scores(
val subject: String,
@ColumnName("value")
val `value`: Int
)
}
fun main() {
val students = DataFrame.readJson("/home/nikita/IdeaProjects/dataframe-examples/students.json")
.cast<Students>()
students.explode { scores }.pivot { scores.subject }.count().schema().print()
}
=>
math: Int
biology: Int
music: Int
nothing: Int
russian: Int
art: Int
There's some connection to original data if "with" is used, but even so it's still misleading. As a side note,
students.explode { scores }.pivot { scores.subject }.with { it }.schema().print()
math: *
name:
firstName: String
lastName: String
age: Int
scores:
subject: String
value: Int
biology: *
name:
firstName: String
lastName: String
age: Int
scores:
subject: String
value: Int
music:
name:
firstName: String
lastName: String
age: Int
scores:
subject: String
value: Int
nothing:
name:
firstName: String
lastName: String?
age: Int
scores:
subject: String
value: Int
russian:
name:
firstName: String
lastName: String
age: Int
scores:
subject: String
value: Int
art:
name:
firstName: String
lastName: String
age: Int
scores:
subject: String
value: Int
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the terminal Pivot operations, including Pivot.count(), and reproduce the schema output with the Students example and students.json. Check the generated return types against the runtime pivot columns, then verify that terminal pivot results expose an unknown schema type such as DataRow<*> rather than a misleading T.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100