这里尝试将后续列添加到数据集行,出现的问题是最后一列仅可见。之前添加的列不会保留
private static void populate(Dataset<Row> res, String[] args)
{
String[] propArr = args[0].split(","); // Eg: [abc, def, ghi]
// Dataset<Row> addColToMergedData = null;
/** Here each element is the name of the column to be inserted */
for(int i = 0; i < propArr.length; i++){
// addColToMergedData = res.withColumn(propArr[i], lit(null));
}
}
答案 0 :(得分:0)
for 循环 中的逻辑存在缺陷,因此是问题所在。 您可以按如下方式修改程序:
private static void populate(Dataset<Row> res, String[] args)
{
String[] propArr = args[0].split(","); // Eg: [abc, def, ghi]
Dataset<Row> addColToMergedData = null;
/** Here each element is the name of the column to be inserted */
for(int i = 0; i < propArr.length; i++)
{
res = res.withColumn(propArr[i], lit(null));
}
addColToMergedData = res
}
答案 1 :(得分:0)
溶胶:
// addColToMergedData = res.withColumn(colMap.get(propArr[i]), lit(null));
应该写成: res = res.withColumn(colMap.get(propArr[i]), lit(null));