Мое требование - прочитать указанные данные столбца c из таблицы, которая хранится в сложном формате в одной плоской строке.
This is one of complex format I section of the table
|-- borr: map (nullable = true)
| |-- key: integer
| |-- value: array (valueContainsNull = true)
| | |-- element: struct (containsNull = true)
| | | |-- APPLNT_ID: integer (nullable = true)
| | | |-- APPLNT_TYPE_CD: string (nullable = true)
| | | |-- POSITN_NBR: integer (nullable = true)
| | | |-- ETHNC1_CD: integer (nullable = true)
| | | |-- ETHNC2_CD: integer (nullable = true)
| | | |-- ETHNC3_CD: integer (nullable = true)
| | | |-- ETHNC4_CD: integer (nullable = true)
| | | |-- ETHNC5_CD: integer (nullable = true)
| | | |-- ETHNC_CD: integer (nullable = true)
| | | |-- ETHNC_DESC: string (nullable = true)
| | | |-- RACE1_CD: integer (nullable = true)
| | | |-- RACE2_CD: integer (nullable = true)
| | | |-- RACE3_CD: integer (nullable = true)
| | | |-- RACE4_CD: integer (nullable = true)
| | | |-- RACE5_CD: integer (nullable = true)
| | | |-- RACE_BASIS_CD: integer (nullable = true)
| | | |-- RACE_OTHR_AMRCN_INDN_DESC: string (nullable = true)
| | | |-- RACE_OTHR_ASIAN_DESC: string (nullable = true)
| | | |-- RACE_OTHR_PCFC_ISL_DESC: string (nullable = true)
| | | |-- GNDR_CD: integer (nullable = true)
| | | |-- GNDR_BASIS_CD: integer (nullable = true)
I tried to explode as below
val df = spark.sql(""" select * from table """)
df.select($"appln_id",explode($"borr")).show(false)
+--------+------+----------------------------------------+
|appln_id|key |value |
+--------+------+----------------------------------------+
|10 |304|[[304, X, 1, 2,,,,,,, 5,,,,,,,,, 1,]]|
|10 |304|[[304, Y, 2, 2,,,,,,, 5,,,,,,,,, 2,]]|
|14 |305|[[305, X, 1, 2,,,,,,, 5,,,,,,,,, 1,]]|
|14 |305|[[305, Y, 2, 2,,,,,,, 5,,,,,,,,, 2,]]|
|27 |306|[[305, Y, 2, 2,,,,,,, 5,,,,,,,,, 2,]]|
Я пытаюсь получить ожидаемое, как показано ниже, в едином плоском потоке (APPLNT_ID - ключевой столбец)
APPLNT_ID APPLNT_TYPE_CD ETHNC1_CD ETHNC2_CD ETHNC3_CD RACE1_CD RACE2_CD RACE3_CD
Спасибо, Шивананд