繁華開滿天機(jī)
2022-07-20 15:59:05
就我而言,我在 JavaSparkSQL 中使用數(shù)據(jù)集(數(shù)據(jù)框)。此數(shù)據(jù)集來(lái)自 JSON 文件。json 文件由鍵值組成。當(dāng)我午餐查詢時(shí),查看我寫的值,例如: SELECT key1.name from table示例 JSON 文件 { "key1": { "name": ".....",....} "key2": { "name":"....",....} }我的問(wèn)題是,當(dāng)我想加入所有關(guān)鍵時(shí),我相信我應(yīng)該使用像select key*.name from table但我不知道正則表達(dá)式!請(qǐng)幫忙
1 回答

森林海
TA貢獻(xiàn)2011條經(jīng)驗(yàn) 獲得超2個(gè)贊
恐怕(火花)SQL 中沒有這樣的語(yǔ)法。
不過(guò),您可能希望以編程方式構(gòu)建查詢。
就像是 :
String sql = Stream.of(ds.schema().fieldNames()).filter(name -> name.startsWith("key")).collect(Collectors.joining(", ", "select ", " from table"));
System.out.println(sql);
甚至
Dataset<Row> result = spark.table("table").select(Stream.of(ds.schema().fieldNames()).filter(name -> name.startsWith("key")).map(name -> ds.col(name))
.toArray(Column[]::new));
result.show();
!
添加回答
舉報(bào)
0/150
提交
取消