2016-11-26 24 views
0

我有一個列的列表,我需要構建一個包含所有列名的列對象,以便我可以將其查詢爲select。構建火花的數據框的select子句

對於如這樣的事情。這是和案件雖然

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

他們只是字符串值。我必須從不同的序列創建另一個數據幀。所以我想做一個選擇表達 –

回答

1

你應該嘗試這樣的事:

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()])); 
+0

感謝帕維爾..它的工作 –