Skip to content

List<T>.toDataFrame() sorts lexicographically when primary constructor has @ColumnName annotations #1002

Closed
@hantsy

Description

@hantsy

When upgrading to v0.15, the exporting csv is broken.

We defined the DataSchema as the following:

@DataSchema
data class CsvExampleDataModel(
    @ColumnName("Amount")
    val amount: BigDecimal? = null,
    @ColumnName("Last 4")
    val last4: String? = null,
    @ColumnName("ACH Type")
    val type: ACHType? = null
)

In the exported CSV, the column names are ordered by letters, not using the nature order in the CsvExampleDataModel.

Give the following example codes.

  val exportedCsv = listOf(
      CsvExampleDataModel(BigDecimal("10.2"), "1234", ACHType.SAME_DAY),
      CsvExampleDataModel(BigDecimal("11.20"), "4567", ACHType.NEXT_DAY)
  ).toDataFrame().toCsv()
  println("expected csv: $exportedCsv")

And print result in console like this:

expected csv: ACH Type,Amount,Last 4
SAME_DAY,10.2,1234
NEXT_DAY,11.20,4567

Check the examples: https://github.com/hantsy/dataframe-sandbox/blob/master/src/main/kotlin/com/example/CsvExample.kt#L37-L41

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions