Эй, ребята, я новичок в Spark / Scala, и я хотел переименовать несколько вложенных полей JSON, потому что, когда я выполняю боковое представление, это не удается, потому что есть несколько полей JSON с одинаковым именем.
Я хочу переименовать столбцы EffDate и ExpDate в EmployeeAddr и EmployeePhone.
Я пробовал с функциями ColumnRenamed и withColumn, но оба почему-то у меня не работают.
Code to load into dataframe:
val Employee= spark.read.format(Employeefile_type).option("header", "true").option("inferSchema","true").load(file_loction)
root
|-- BirthDate: string (nullable = true)
|-- EmployeeId: string (nullable = true)
|-- EmployeeAddr: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- AddrTypeName: string (nullable = true)
| | |-- City: string (nullable = true)
| | |-- CtryCode: string (nullable = true)
| | |-- EffDate: string (nullable = true)
| | |-- ExpDate: string (nullable = true)
| | |-- PostalCode: string (nullable = true)
| | |-- Province: string (nullable = true)
| | |-- Street1: string (nullable = true)
| | |-- Street2: string (nullable = true)
|-- EmployeeEmail: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- CrewEmailAddr: string (nullable = true)
| | |-- EmailType: string (nullable = true)
|-- EmployeeEmerContact: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- Addr: string (nullable = true)
| | |-- FirstName: string (nullable = true)
| | |-- LastName: string (nullable = true)
| | |-- PrimaryPhone: string (nullable = true)
| | |-- Relatnshp: string (nullable = true)
| | |-- Title: string (nullable = true)
|-- EmployeeEmplymntStatus: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- EmplymntStatusCode: string (nullable = true)
| | |-- EmplymntStatusReason: string (nullable = true)
| | |-- EndDate: string (nullable = true)
| | |-- StartDate: string (nullable = true)
|-- EmployeePhone: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- EmployeePhoneNumber: string (nullable = true)
| | |-- EffDate: string (nullable = true)
| | |-- ExpDate: string (nullable = true)
| | |-- PhoneType: string (nullable = true)