1

This is what I am trying to do in Java but is not working as concat_ws requires Seq as the type of 2nd argument while collect_list return Column:

Dataset aggregatedDF = someDF
  .groupBy("colA")
  .agg(
      concat_ws(",", collect_list(col("colB"))).as("comma_sep_col_b")
  );

Same thing works in Scala:

val aggregatedDF = someDF
  .groupBy("colA")
  .agg(
      concat_ws(",", collect_list($"colB")) as "comma_sep_col_b"
  )
1
  • Works fine for me in java : Dataset aggregatedDF = df.groupBy("Age").agg(concat_ws(",", collect_list(col("Wage"))).as("comma_sep_col_b")); aggregatedDF.show(); Commented Nov 18, 2019 at 8:45

1 Answer 1

1

You probably want to use the array_join() function.

Background:

The signature of concat_ws in Scala includes variable arguments

def concat_ws(sep: String, exprs: Column*): Column

Variable arguments of type Column in Scala are handled as Seq[Column], with the Scala compiler providing the syntactic sugar management.

Note that the columns to be concatenated must be provided at transformation time, not execution time. collect_list() returns a single column, which is an ArrayType(...).

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.