Skip to content

Conversation

@Amraneze
Copy link
Contributor

@Amraneze Amraneze commented Oct 7, 2022

What changes were proposed in this pull request?

I encountered an issue using Spark while reading JSON files based on a schema it throws every time an exception related to conversion of types.

Note: This issue can be reproduced only with Scala 2.13, I'm not having this issue with 2.12

Failed to convert value ArraySeq(1, 2, 3) (class of class scala.collection.mutable.ArraySeq$ofRef}) with the type of ArrayType(StringType,true) to JSON.
java.lang.IllegalArgumentException: Failed to convert value ArraySeq(1, 2, 3) (class of class scala.collection.mutable.ArraySeq$ofRef}) with the type of ArrayType(StringType,true) to JSON.

If I add ArraySeq to the matching cases, the test that I added passed successfully
image

With the current code source, the test fails and we have this following error
image

Why are the changes needed?

If the person is using Scala 2.13, they can't parse an array. Which means they need to fallback to 2.12 to keep the project functioning

How was this patch tested?

I added a sample unit test for the case, but I can add more if you want to.

@AmplabJenkins
Copy link

Can one of the admins verify this patch?

@Amraneze Amraneze changed the title [SPARK-40705] Handle case of using mutable array when converting Row to JSON for Scala 2.13 [SPARK-40705][SQL] Handle case of using mutable array when converting Row to JSON for Scala 2.13 Oct 8, 2022
StructField("col1", StringType) ::
StructField("col2", StringType) ::
StructField("col3", IntegerType) :: Nil)
StructField("col2", StringType) ::
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scalafmt formatted the file, should I revert the changes related to formatting the code ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah revert all the formatting only changes please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a new commit with the revert of those changes

Copy link
Member

@srowen srowen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK otherwise

@srowen srowen closed this in 9a97f8c Oct 10, 2022
srowen pushed a commit that referenced this pull request Oct 10, 2022
… Row to JSON for Scala 2.13

### What changes were proposed in this pull request?
I encountered an issue using Spark while reading JSON files based on a schema it throws every time an exception related to conversion of types.

>Note: This issue can be reproduced only with Scala `2.13`, I'm not having this issue with `2.12`

````
Failed to convert value ArraySeq(1, 2, 3) (class of class scala.collection.mutable.ArraySeq$ofRef}) with the type of ArrayType(StringType,true) to JSON.
java.lang.IllegalArgumentException: Failed to convert value ArraySeq(1, 2, 3) (class of class scala.collection.mutable.ArraySeq$ofRef}) with the type of ArrayType(StringType,true) to JSON.
````

If I add ArraySeq to the matching cases, the test that I added passed successfully
![image](https://user-images.githubusercontent.com/28459763/194669557-2f13032f-126f-4c2e-bc6d-1a4cfd0a009d.png)

With the current code source, the test fails and we have this following error
![image](https://user-images.githubusercontent.com/28459763/194669654-19cefb13-180c-48ac-9206-69d8f672f64c.png)

### Why are the changes needed?
If the person is using Scala 2.13, they can't parse an array. Which means they need to fallback to 2.12 to keep the project functioning

### How was this patch tested?
I added a sample unit test for the case, but I can add more if you want to.

Closes #38154 from Amraneze/fix/spark_40705.

Authored-by: Ait Zeouay Amrane <[email protected]>
Signed-off-by: Sean Owen <[email protected]>
(cherry picked from commit 9a97f8c)
Signed-off-by: Sean Owen <[email protected]>
@srowen
Copy link
Member

srowen commented Oct 10, 2022

Merged to master/3.3

@Amraneze Amraneze deleted the fix/spark_40705 branch October 10, 2022 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants