Kotlin / Kotlin/dataframe

Terminal pivot operations return incorrect `T` schema, should be Any? instead

Open
#1,787 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

API bug Compiler plugin
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:

Image

Operations like public fun <T> Pivot<T>.count(): DataRow<T> = delegate { count() } should become

public fun <T> Pivot<T>.count(): DataRow<*> = delegate { count() }

students.json

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.