14

I saved an Array[String] to a Parquet file from Spark.

To read it I use:

row.getAs[Array[String]]("result")

But get:

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

Here is the result of printSchema():

root                                                                            
 |-- result: array (nullable = true)
 |    |-- element: string (containsNull = true)

How should the getAs() be modified?

6
  • 5
    Does row.getAs[Seq[String]]("result") work? Commented Oct 18, 2015 at 23:13
  • Or row.getAs[scala.collection.mutable.WrappedArray[String]]("result") . @Reactormonk I think you should make it an answer. Commented Oct 18, 2015 at 23:24
  • @zero323 Seq and WrappedArray work. Do you see any reason to use one over the other? More interested about performance than usage. Commented Oct 20, 2015 at 21:47
  • There is no difference. In both cases you have the same type of object (WrappedArray). Commented Oct 20, 2015 at 21:55
  • @zero323 I didn't know Seq allows for mutable data types. Good to know. Commented Oct 20, 2015 at 21:57

1 Answer 1

29

Does row.getAs[Seq[String]]("result") work?

Sign up to request clarification or add additional context in comments.

2 Comments

Seems like Spark could use an implicit for this case. If I get a chance will check it out and submit PR.
@BAR did you end up submitting a PR or filing a ticket? I didn't see one off the bat and I just got bit by this with 1.6.1

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.