0

I have column with type Array of Arrays I need to get column array of string.

+--------------------------+
|field                     |
+--------------------------+
|[[1, 2, 3], [1, 2, 3], []]|
+--------------------------+

I need to get:

+--------------------------+
|field                     |
+--------------------------+
|["123", "123", ""]        |
+--------------------------+

Can I do this in Spark without using UDF?

0

1 Answer 1

2

You can use transform higher order function,

import spark.implicits._

val df = Seq(Seq(Seq(1,2,3), Seq(1,2,3), Seq())).toDF("field")

df.withColumn("field", expr("transform(field, v->concat_ws('',v))"))
    .show

+------------+
|       field|
+------------+
|[123, 123, ]|
+------------+
Sign up to request clarification or add additional context in comments.

2 Comments

That's great! I couldn't find this function. Do you know how I can return array without 1st element? I found how to get first element, but I can't find how to get from this [1, 2, 3] this [2,3]
You can use transform function in this way - transform(field, v->slice(v, 2, size(v)))

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.