maigar
maigar

Reputation: 197

How to select columns from a Dataset using Seq<String> in Java?

I have a Seq and need to use it to select columns in Java

I know about the function .select(String col, Seq<String> cols) but I don't have the first column name.

Upvotes: 1

Views: 444

Answers (1)

vinsce
vinsce

Reputation: 1348

If you want to select using a Seq<String> you can split the Seq extracting the first element separately:

Seq<String> columns = /* ... */;

Dataframe<Row> newDf = df.select(
    columns.apply(0), // first element
    columns.slice(1, columns.size()) // from the second to the end
);

maybe check the length of columns first, to avoid IndexOutOfBoundsException

Upvotes: 1

Related Questions