score:0
Interesting idea. The way I would do it:
- Ingest your data in a dataframe.
- Write a utility method that takes the dataframe and class name (here SampleRecord).
- Use introspection to read the annotations (you could eventually add some if you need to define specific properties).
- Rename the columns with withColumnRenamed() on the dataframe.
- Return the modified dataframe.
hih
score:1
public class SampleRecord implements Serializable {
private Long sampleId;
private String name;
private String description;
@JsonProperty("sample_id")
public void setSampleId(Long sampleId) {
this.sampleId = sampleId;
}
@JsonProperty("sample_name")
public void setName(String name) {
this.name = name;
}
@JsonProperty("sample_desc")
public void setDescription(String description) {
this.description = description;
}
}
Source: stackoverflow.com
Related Query
- Rename columns in spark using @JsonProperty while creating Datasets
- Using a Map to rename and select columns on an Apache Spark Dataframe (Scala)
- Spark dataframe missing columns when data are not available while using pivot function
- Using a case class to rename split columns with Spark Dataframe
- Error while creating Wordcount project using Spark & Java on Eclipse in Cloudera through Vmware
- "null" columns while creating derived column using withColumns
- Concatenating datasets of different RDDs in Apache spark using scala
- Using Spark ML's OneHotEncoder on multiple columns
- Count instances of combination of columns in spark dataframe using scala
- Rename nested struct columns in a Spark DataFrame
- How to get Histogram of all columns in a large CSV / RDD[Array[double]] using Apache Spark Scala?
- SPARK dataframe error: cannot be cast to scala.Function2 while using a UDF to split strings in column
- Multiple constructors with the same number of parameters exception while transforming data in spark using scala
- NoClassDefFoundError while using scopt OptionParser with Spark
- Creating Spark application using wrong Scala version
- Adding new Columns based on aggregation on existing column in Spark DataFrame using scala
- Spark Dataframes join with 2 columns using or operator
- How to add multiple columns in a spark dataframe using SCALA
- Dynamically select multiple columns while joining different Dataframe in Scala Spark
- Discarding first few values while calculating moving average using Spark window function
- using spark to read specific columns data from hbase
- Convert multiple columns into a column of map on Spark Dataframe using Scala
- pom.xml dependencies for spark while using scala 2.12.10
- Why does the `is not a member of` error come while creating a list in scala using the :: operator
- Spark SQL - select all columns while updating one
- Spark Scala Datasets using Java Classes
- Reflection error while creating spark session through Livy
- Task not serializable while using custom dataframe class in Spark Scala
- Getting connection error while reading data from ElasticSearch using apache Spark & Scala
- Using Multiple Languages while developing a Spark application
More Query from same tag
- Import code packaged as jar into another sbt project
- Scala "primitive" optimisation
- Is eq always called in scala ==?
- Spark Dataframes UPSERT to Postgres Table
- How do I control order of execution of exec statements in Gatling scenario?
- Put Data in mutlple branch of Array : Json Transformer ,Scala Play
- Scala futures not outputting to screen despite using awaitAll?
- What's the Scala syntax for a function taking any subtype of Ordered[A]?
- Graphx Scala: Applying filter on Vertex with Property Inheritance
- Ordering can't take parameter type for context bound
- Scala - error "value map is not a member of"
- scala user define function not working in sparksql
- Executing update using Anorm returns PSQLException: The column index is out of range: 2, number of columns: 1
- Spark forcing usage of java.lang.Long instead of scala.Long
- How to fix my Fibonacci stream in Scala
- Why I'm getting type mismatch when filtering rows for a specific aggregate with spark sql?
- Catching SQL error on future failure in Slick
- Handle errors with union
- Play 2.0 pass route value to action
- Scala Play List[Any] to JsArray
- What is the fastest way to convert a boolean array to bytes in Scala?
- Write/store dataframe in text file
- Add an external Project dependency to my Play application
- EMR Spark cluster mode Hive issue
- How write two main function in neighbouring actors?
- DataFrame.registerTempTable sql failed
- Converting blocking code to using scala futures
- oauth2 implementation in the Play scala web-socket
- Creating a column of array using another column of array in a Spark Dataframe (Scala)
- Why does Kotlin compile faster than Scala?