Aviral Kumar
Aviral Kumar

Reputation: 824

Building select clause for Dataframe in spark

I have a list of columns and I need to build a Column object which contains all the column names so that I can query that as select.

For eg something like this.. this is for AND case though

for(int i =1;i<tablecols.size();i++){
    col = col.and(new org.apache.spark.sql.Column(tablecols.get(i).getTclName()));
  }
  initialDataFrame.select(col);

Upvotes: 0

Views: 358

Answers (1)

Paweł Jurczenko
Paweł Jurczenko

Reputation: 4471

You should try something like this:

List<String> tablecols = Arrays.asList("first_col", "second_col");
List<Column> columns = new ArrayList<Column>();

for (String tablecol : tablecols) {
    columns.add(new Column(tablecol));
}

initialDataFrame.select(columns.toArray(new Column[columns.size()]));

Upvotes: 1

Related Questions