在 运行 时间动态过滤火花列
Filter spark columns dynamically at run-time
我需要创建一个 spark 过滤器语句来过滤在 运行 时动态传递给它的列列表。
我有一个 SQL 数据库 table,其中有一列存储大数据 table 的列名列表。大数据 table 已分配给 spark 数据集,我需要使用此列列表来检查列表中找到的任何数据集列是否存在数据问题,例如空值或空字符串和 return受影响的行数的计数。列列表将在 运行 时间决定。列表的大小会有所不同。
public int returnRowCount (List<String> columnsAffected, Dataset<Row> dataset) {
return dataset.filter(dataset.col(columnsAffected.get(0)).isNotNull()
|| dataset.col(columnsAffected.get(0)).notEqual("")
|| dataset.col(columnsAffected.get(1)).isNotNull()
|| dataset.col(columnsAffected.get(1)).notEqual("")
|| etc ).count();
}
我需要获取任何列列表和任何数据集的方法。我希望受空字符串或空字符串影响的列表中的任何列是否只计算一次
您可以创建字符串过滤器表达式并在 DataSets
中使用该过滤器
public long returnRowCount (List<String> columnsAffected, Dataset<Row> dataset) {
String str = "";
for (String col : columnsAffected){
if (str != "")
str = str + String.format("or %1$s is null or %1$s == '' ", col);
else
str = String.format(" %1$s is null or %1$s == '' ", col);
}
return dataset.filter(str).count();
}
我需要创建一个 spark 过滤器语句来过滤在 运行 时动态传递给它的列列表。
我有一个 SQL 数据库 table,其中有一列存储大数据 table 的列名列表。大数据 table 已分配给 spark 数据集,我需要使用此列列表来检查列表中找到的任何数据集列是否存在数据问题,例如空值或空字符串和 return受影响的行数的计数。列列表将在 运行 时间决定。列表的大小会有所不同。
public int returnRowCount (List<String> columnsAffected, Dataset<Row> dataset) {
return dataset.filter(dataset.col(columnsAffected.get(0)).isNotNull()
|| dataset.col(columnsAffected.get(0)).notEqual("")
|| dataset.col(columnsAffected.get(1)).isNotNull()
|| dataset.col(columnsAffected.get(1)).notEqual("")
|| etc ).count();
}
我需要获取任何列列表和任何数据集的方法。我希望受空字符串或空字符串影响的列表中的任何列是否只计算一次
您可以创建字符串过滤器表达式并在 DataSets
public long returnRowCount (List<String> columnsAffected, Dataset<Row> dataset) {
String str = "";
for (String col : columnsAffected){
if (str != "")
str = str + String.format("or %1$s is null or %1$s == '' ", col);
else
str = String.format(" %1$s is null or %1$s == '' ", col);
}
return dataset.filter(str).count();
}