1

When writing in Spark Java I'm meeting this error while accessing a column of row of a Dataframe. I don't get why WrappedArray is retrieved from the Row instead of a normal Array.

java.lang.ClassCastException: class scala.collection.mutable.WrappedArray$ofRef cannot be cast to class [Ljava.lang.String

Example code : String[] myarray = my_df_row.getAs("col_name");

I need Java code, not scala or python. How to solve this issue ?

1 Answer 1

1

The WrappedArray needs to be converted to a Java list and then an Array. Code example :

import scala.collection.JavaConversions;

String[] myarray;
myarray = JavaConversions.seqAsJavaList(my_df_row.getAs("col_name")).toArray(myarray);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.