Dynamicially Change Column Name Defined in Schema #622
-
Given the following data schema defined. @DataSchema
data class ExampleDataSchema(
@ColumnName("NAME")
val name: String? = null,
@ColumnName("CREATED AT")
val createdAt: LocalDateTime? = null
) We try to export CSV content like this: aList
.map {
ExampleDataSchema(
it.name,
it.createdAt?.toLocalZone(zoneId)// tolocalzone is an extension used to convert a UTC datetime to local datatime.
)
}
.toDataFrame().toCsv() We want to add the zone info to the column title, and change the Column Name |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
If I understand you correctly, this requires just two DataFrame calls. Given some list of data, we first create a DataFrame with your import java.time.ZoneId
val data = listOf(
ExampleDataSchema("John", java.time.LocalDateTime.now()),
ExampleDataSchema("Jane", java.time.LocalDateTime.now())
)
val df = data.toDataFrame()
df
Then, we get the val zoneId = ZoneId.systemDefault() You just want to rename the column right? Not update the values? Then it's as simple as: val df2 = df
.rename { `CREATED AT` }.into { "CREATED DATE($zoneId)" }
df2
and then you can Is that what you were looking for? |
Beta Was this translation helpful? Give feedback.
If I understand you correctly, this requires just two DataFrame calls.
Given some list of data, we first create a DataFrame with your
@DataSchema
class:Then, we get the
zoneId
we want to convert to, likeYou just want to rename the column right? Not update the values? Then it's as simple as: