【发布时间】:2018-10-30 11:42:21
【问题描述】:
我有一个包含 json 对象的 json 文件,每个对象逐行。 我有这些对象的以下架构:
root
|-- endtime: long (nullable = true)
|-- result: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- hop: long (nullable = true)
| | |-- result: array (nullable = true)
| | | |-- element: struct (containsNull = true)
| | | | |-- from: string (nullable = true)
| | | | |-- rtt: double (nullable = true)
| | | | |-- size: long (nullable = true)
| | | | |-- ttl: long (nullable = true)
| | | | |-- x: string (nullable = true)
问题:如何从 Dataframe 创建一个新的 DataFrame,其中包含作为输入提供的 json 文件中的数据,并将数据删除为 ttl 和 x?
| | | | |-- ttl: long (nullable = true)
| | | | |-- x: string (nullable = true)
鉴于我是 Spark (Scala) 的新手,我不知道有哪些可能的方法!
删除结束时间很简单:
val pathToTraceroutesExamples = getClass.getResource("/test/sample_1.json")
val df = spark.read.json(pathToTraceroutesExamples.getPath)
// Displays the content of the DataFrame to stdout
df.show()
df.printSchema()
var newDf = df.drop("endtime")
【问题讨论】:
标签: json scala apache-spark