Struct 如何分解结构数组
我有一个这样的模式Struct 如何分解结构数组,struct,apache-spark-sql,azure-databricks,Struct,Apache Spark Sql,Azure Databricks,我有一个这样的模式 root |-- CaseNumber: string (nullable = true) |-- Interactions: struct (nullable = true) | |-- EmailInteractions: array (nullable = true) | | |-- element: string (containsNull = true) | |-- PhoneInteractions: array (nullabl
root
|-- CaseNumber: string (nullable = true)
|-- Interactions: struct (nullable = true)
| |-- EmailInteractions: array (nullable = true)
| | |-- element: string (containsNull = true)
| |-- PhoneInteractions: array (nullable = true)
| | |-- element: struct (containsNull = true)
| | | |-- Contact: struct (nullable = true)
| | | | |-- id: string (nullable = true)
| | | |-- CreatedOn: string (nullable = true)
| | | |-- Direction: string (nullable = true)
| |-- WebInteractions: array (nullable = true)
| | |-- element: string (containsNull = true)
我想分解这三个数组(EmailInteractions、PhoneInteractions、WebInteractions)并使用CaseNumber分组,创建三个表并执行此sql查询
Select casenumber,CreatedOn
from EmailInteration
where Direction = 'Outgoing'
union all
Select casenumber,CreatedOn
from PhoneInteraction
where Direction = 'Outgoing'
union all
Select casenumber,CreatedOn
from WebInteraction
where Direction = 'Outgoing'
用于检索架构的代码
val dl = spark.read.format("com.databricks.spark.avro").load("adl://power.azuredatalakestore.net/Se/eventhubspace/eventhub/0_2020_01_20_*_*_*.avro")
val dl1=dl.select($"body".cast("string")).map(_.toString())
val dl2=spark.read.json(dl1)
val dl3=dl2.select($"Content.*",$"RawProperties.UserProperties.*")
我是databricks的新手,任何帮助都将不胜感激。提前感谢。但这不是JSON模式;它不能转换为JSON模式。也许编辑你的问题以显示实际的模式。因为它是从Json读取的,所以我认为它是Json模式,我的错。以上是实际的模式。这就是我想要压扁的那个。