如何选择其中包含特殊字符的scala数据框列?

问题描述 投票:0回答:1

我正在读取一个 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 apache-spark pyspark
1个回答
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}]|
+--------------------------------------------+
© www.soinside.com 2019 - 2024. All rights reserved.