我有一个列列表,我需要构建一个包含所有列名称的 Column 对象,以便我可以将其作为选择进行查询。
例如像这样的东西..尽管这是 AND 情况
for(int i =1;i<tablecols.size();i++){
col = col.and(new org.apache.spark.sql.Column(tablecols.get(i).getTclName()));
}
initialDataFrame.select(col);
最佳答案
你应该尝试这样的事情:
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()]));
关于java - 在 Spark 中为 Dataframe 构建选择子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40823246/