You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Manjay Kumar (Jira)" <ji...@apache.org> on 2020/08/18 10:53:00 UTC

[jira] [Comment Edited] (SPARK-32619) converting dataframe to dataset for the json schema

    [ https://issues.apache.org/jira/browse/SPARK-32619?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17179541#comment-17179541 ] 

Manjay Kumar edited comment on SPARK-32619 at 8/18/20, 10:52 AM:
-----------------------------------------------------------------

Please find the code snippet.

val sparkSession:SparkSession = SparkSession.builder().master("local[*]").getOrCreate()
 val dataframe = sparkSession.read.json("test.json")

import sparkSession.implicits._
 val dealList:Dataset[FinancingDealUnpaid] = dataframe.as[FinancingDealUnpaid]

 

input 1:
 { "backDealUID": "xyxyyx", "sourceApplicationCode": "asdsad", "facilityUnpaids": [{ "facilityId": "asdjadj", "sourceApplicationCode": "asddsa", "facilityFeeUnpaids": [{ "feeId": "asddsaasd", "unpaids": [

{ "unpaidId": "asddsa", "unpaidDate": "asdas", "unpaidSrc": "asd", "amount": 9999999, "currency": "asdasd", "scheduledFlowDate": "asddsa", "technicalUnpaidReasonCode": "asddsadasdsad" }

] }] }] }

 

Input 2:

{{ "backDealUID": "uaygdia", "sourceApplicationCode": "dvsd", "dealFeeUnpaids": [{ "feeId": "sdfsdf", "unpaids": [{ "unpaidId": "sdfsdf", "unpaidDate": "sdfsdf", "unpaidSrc": "sfdsd", "amount": 234324, "currency": "dzcsdf", "scheduledFlowDate": "erexdz", "technicalUnpaidReasonCode": "zdc", "repayments": [

{ "amount": 23423, "currency": "eaas", "paymentDate": "saff" }

] }] }] }

 

input 2 has unpaid and input doesnt have unpaid

 

while casting for one dataset it should be null for unpaid

 

Exception log:: 

but it is failing with Exception in thread "main" org.apache.spark.sql.AnalysisException: No such struct field repayments in amt , .......

 

what should be the fix ?? Ideally , it should mark repayment object as null incase of no data input fields in input data.

 

 


was (Author: manjay7869):
Please find the code snippet.

val sparkSession:SparkSession = SparkSession.builder().master("local[*]").getOrCreate()
val dataframe = sparkSession.read.json("test.json")



import sparkSession.implicits._
val dealList:Dataset[FinancingDealUnpaid] = dataframe.as[FinancingDealUnpaid]

 

input 1:
{ "backDealUID": "xyxyyx", "sourceApplicationCode": "asdsad", "facilityUnpaids": [\{ "facilityId": "asdjadj", "sourceApplicationCode": "asddsa", "facilityFeeUnpaids": [{ "feeId": "asddsaasd", "unpaids": [{ "unpaidId": "asddsa", "unpaidDate": "asdas", "unpaidSrc": "asd", "amount": 9999999, "currency": "asdasd", "scheduledFlowDate": "asddsa", "technicalUnpaidReasonCode": "asddsadasdsad" }] }] }] }

 

Input 2:

{\{ "backDealUID": "uaygdia", "sourceApplicationCode": "dvsd", "dealFeeUnpaids": [{ "feeId": "sdfsdf", "unpaids": [{ "unpaidId": "sdfsdf", "unpaidDate": "sdfsdf", "unpaidSrc": "sfdsd", "amount": 234324, "currency": "dzcsdf", "scheduledFlowDate": "erexdz", "technicalUnpaidReasonCode": "zdc", "repayments": [{ "amount": 23423, "currency": "eaas", "paymentDate": "saff" }] }] }] }

 

input 2 has unpaid and input doesnt have unpaid

 

while casting for one dataset it should be null for unpaid

 

but it is failing with Exception in thread "main" org.apache.spark.sql.AnalysisException: No such struct field repayments in amt , .......

 

what should be the fix ??

 

 

> converting dataframe to dataset for the json schema
> ---------------------------------------------------
>
>                 Key: SPARK-32619
>                 URL: https://issues.apache.org/jira/browse/SPARK-32619
>             Project: Spark
>          Issue Type: Bug
>          Components: Spark Core
>    Affects Versions: 2.4.3
>            Reporter: Manjay Kumar
>            Priority: Minor
>
> have a schema 
>  
> {
> Details :[{
> phone : "98977999"
> contacts: [{
> name:"manjay"
> ---------- has missing street block in json
> ]}
> ]}
>  
> }
>  
> Case class , based on schema
> case class Details (
>  phone : String,
> contacts : Array[Adress]
> )
>  
> case class Adress(
> name : String
> street : String
>  
> )
>  
>  
> this throws : No such struct field street - Analysis exception.
>  
> dataframe.as[Details]
>  
> Is this a bug ?? or there is a resolution for this.
>  
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org