1

In my project I got a column after applying collect_list aggregate function, which is of format wrappedArray , I wanted to know is there anyway to convert that wrappedArray to normal array or list So that I can iterate over that column and extract values row by row in that column?

Language:- JAVA Using Apache spark library

By this I am getting that column which is of wrappedArray type

dataset.groupBy( "department","salary","tag")
.agg(collect_list(col("id")));
dataset.foreach(row ->
      row.getAs("id)")

);

I am confused how should I proceed further to iterate in that column.

2 Answers 2

1

If you have a WrappedArray there are several ways to convert it to a Java collection. You can leverage scala.collection.JavaConverters helper methods:

WrappedArray<Long> wrappedArray = row.getAs("ids");
List<Long> list = scala.collection.JavaConverters.seqAsJavaList(wrappedArray.seq());

Alternatively, you can use the Row.getList method to obtain directly a Java List:

List<Long> list = row.getList(row.fieldIndex("ids"));
Sign up to request clarification or add additional context in comments.

Comments

0

To convert scala wrappedArray column to Java list in java spark. here line is of type Row.

List<Long> list = scala.collection.JavaConverters.seqAsJavaList(line.getAs("fieldName")));

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.