1

I have a dataset ds1 with following schema

root
 |-- binary_col1: binary (nullable = true)

which i transform as needed using

val ds2 = ds1.map(row => row.getAs[Array[Byte]]("binary_col1"))

But how do I transform the dataset when it has two columns of binary type ?

root
 |-- binary_col1: binary (nullable = true)
  -- binary_col2: binary (nullable = false)

I want to create new dataset with 2 columns
( binary_col1.toByteArray , binary_col2.toByteArray)

1 Answer 1

1

You can use as on the dataframe/dataset, and provide a tuple2 type:

val ds2 = ds1.as[(Array[Byte], Array[Byte])]

This is better than using map because it preserves column names.

Of course, you can also use map, e.g.

val ds2 = ds1.map(row => (row.getAs[Array[Byte]]("binary_col1"), row.getAs[Array[Byte]]("binary_col2")))
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.