我正在读取一个 json 文件,其中的键是特殊字符。例如
[{
"ABB/aws:1.0/CustomerId:2.0": [{
"id": 20,
"namehash": "de8cfcde-95c5-47ac-a544-13db50557eaa"
}]
}]
我正在创建一个 scala 数据框,然后尝试使用 Spark.sql“ABB/aws:1.0/CustomerId:2.0”选择列。那就是抱怨特殊性格的时候。
使用反引号(`)选择列,如下所示。
scala> df.select("`ABB/aws:1.0/CustomerId:2.0`").show(false)
+--------------------------------------------+
|ABB/aws:1.0/CustomerId:2.0 |
+--------------------------------------------+
|[{20, de8cfcde-95c5-47ac-a544-13db50557eaa}]|
+--------------------------------------------+