Column data to nested json object in Spark structured streaming

前端 未结 1 916
醉梦人生
醉梦人生 2021-01-21 16:17

In our application we obtain the field values as columns using Spark sql. Im\' trying to figure out how to put the columns values to nested json object and push to Elasticsearch

相关标签:
1条回答
  • 2021-01-21 16:56

    Adding all columns to a top level struct should give the expected output. In Scala:

    import org.apache.spark.sql.functions._
    
    data.select(struct(data.columns:_*).as("txn_summary"))
    

    In Java I would suspect it it would be:

    import org.apache.spark.sql.functions.struct;
    
    data.select(struct(data.columns()).as("txn_summary"));
    
    0 讨论(0)
提交回复
热议问题