Kotlin / Kotlin/dataframe

Join operations that can introduce nulls (leftJoin, rightJoin, etc) lead to null values FrameColumn and NPE on basic operations

Open
#2,039 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Kotlin
Stars
1.1k
Forks
83
Avg merge
4d 12h
Merged PRs (30d)
30

Description

Repro:

val l = (0..10).toDataFrame {
    "id" from { it }
}
val r = (0..5).toDataFrame {
    "id" from { it }
    "frame" from {
        (0..10).toDataFrame {
            "col" from { it }
        }
    }
}
val res = l.leftJoin(r)
res.print()

Actual:
Throws exception at print.

Exception in thread "main" java.lang.NullPointerException: Parameter specified as non-null is null: method org.jetbrains.kotlinx.dataframe.DataFrameKt.getNrow, parameter <this>
	at org.jetbrains.kotlinx.dataframe.DataFrameKt.getNrow(DataFrame.kt)

Culprit is this unchecked cast that sneaks AnyFrame? values into FrameColumn (we expect no nulls there):
https://github.com/Kotlin/dataframe/blob/1232fd13637af2192023c1f2a1b19e1bf03f0d99/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/join.kt#L235

Expected:
At this point i'd expected frame column to have 5 DataFrames from r, and remaining 5 rows filled with empty dataframes with same schema: col: Int, but 0 rows
In that ColumnKind.Frame branch we should replace all nulls with "null object" dataframe: https://github.com/Kotlin/dataframe/blob/06990d03a0b5f24aa3bfd2754ee54c64e62eb4ce/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/DataFrame.kt#L61

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 in core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/join.kt at the unchecked cast near line 235, then read the null-object DataFrame definition in core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/DataFrame.kt around line 61. Reproduce the issue with the supplied leftJoin example and print call. Done means FrameColumn values contain empty DataFrames with the existing schema instead of nulls, and the example prints without an NPE.

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
Active
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.