Разобрать json в столбцы DynamicFrame - PullRequest
0 голосов
/ 14 июля 2020

Здравствуйте, я пытаюсь разобрать json файл в следующей структуре на столбцы DynamicFrame.Мне нужен каждый столбец отдельно

changedFields|First Name|Last Name| ...... | id
             |          |         |        |  
             |          |         |        |
|-- employees: array
|    |-- element: struct
|    |    |-- changedFields: array
|    |    |    |-- element: choice
|    |    |    |    |-- int
|    |    |    |    |-- string
|    |    |-- fields: struct
|    |    |    |-- First Name: string
|    |    |    |-- Last Name: string
|    |    |    |-- Status: string
|    |    |    |-- Employee #: string
|    |    |    |-- Marital Status: string
|    |    |    |-- Address Line 1: string
|    |    |    |-- Mobile Phone: string
|    |    |    |-- Work Email: string
|    |    |    |-- Hire Date: string
|    |    |    |-- Original Hire Date: string
|    |    |    |-- Effective Date: string
|    |    |    |-- Location: string
|    |    |    |-- Division: string
|    |    |    |-- Department: string
|    |    |    |-- Job Title: string
|    |    |    |-- Reports To: string
|    |    |-- id: string

1 Ответ

0 голосов
/ 14 июля 2020
df=spark.read.format("json").option("inferSchema","true").load("test.json").select(F.explode("employees").alias('employees')).select('employees.*').select("element.*")

df2 = df.select(df.select(F.explode("fields").alias("fields").select("fields.*"), df.select("fields.*"), df.id.alias("id"))
df.show()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...