apache-spark - 如何处理列名中的空格以在 expr 方法中使用 spark 合并函数
问题描述
我正在coalesce
我的项目中研究火花功能。代码在没有空格的列上工作正常,但在间隔列上失败。
e1.csv
id,code,type,no root
1,,A,1
2,,,0
3,123,I,1
e2.csv
id,code,type,no root
1,456,A,1
2,789,A1,0
3,,C,0
逻辑代码
Dataset<Row> df1 = spark.read().format("csv").option("header", "true").load("/home/user/Videos/<folder>/e1.csv");
Dataset<Row> df2 = spark.read().format("csv").option("header", "true").load("/home/user/Videos/<folder>/e2.csv");
Dataset<Row> newDS = df1.as("a").join(df2.as("b")).where("a.id== b.id").selectExpr("coalesce(`a.no root`,`b.no root`) AS `a.no root`");
newDS.show();
我试过的
Dataset<Row> newDS = df1.as("a").join(df2.as("b")).where("a.id== b.id").selectExpr("""coalesce(`a.no root`,`b.no root`) AS `a.no root`""");
espexted 的结果就像
no root
1
0
1
解决方案
使用以下标准
val newDS = df1.as("a").join(df2.as("b")).where("a.id==b.id").selectExpr("coalesce(a.`no root`,b.`no root`) AS `a.no root`")
将产生预期的输出
+---------+
|a.no root|
+---------+
| 1|
| 0|
| 1|
+---------+
推荐阅读
- java - 持久列表
处于休眠状态 - xamarin.forms - 错误 XF003:Xamarin.Forms 需要 msbuild。不再支持 xbuild
- c# - 缓存 wcf 服务的问题 - “AspNetCacheProfileAttribute 只能用于 GET 操作”
- javascript - 在 php 中使用 javascript var 获取 wordpress 附件
- proxy - 具有公司代理身份验证的 Chrome 无头浏览器无法正常工作
- android - 片段中的轮播错误
- vidyo - Vidyo - 如何设置 logFileName 写入本地文件
- java - 在Java Stream中的多个数组内循环
- mysql - MySQL连接行值作为列名
- vue.js - 在类星体框架数据表中获取选定的行 ID