1 回答

TA貢獻(xiàn)1943條經(jīng)驗 獲得超7個贊
首先使類標(biāo)題成為java bean類,即編寫獲取器和設(shè)置器。
public class Title implements Serializable {
String txn_date;
Timestamp timestamp;
String txn_type;
String txn_rcvd_time;
String txn_ref;
String txn_status;
public Title(String data){... //set values for fields with the data}
// add all getters and setters for fields
}
Dataset<Title> resultdf = df.selectExpr("CAST(value AS STRING)").map(value -> new Title(value), Encoders.bean(Title.class))
resultdf.filter(title -> // apply any predicate on title)
如果要先篩選數(shù)據(jù),然后應(yīng)用編碼,
df.selectExpr("CAST(value AS STRING)")
.filter(get_json_object(col("value"), "$.sample_title").isNotNull)
// for simple filter use, .filter(t-> t.contains("sample_title"))
.map(value -> new Title(value), Encoders.bean(Title.class))
添加回答
舉報