D
D
denislysenko2022-02-10 22:41:02
SQL
denislysenko, 2022-02-10 22:41:02

How to split a column into two columns, provided that this column is a dictionary?

there is such a table

+----+--------------------------------+-----+----+
|id  |topping                         |type |name|
+----+--------------------------------+-----+----+
|0001|{5001, None}                    |donut|Cake|
|0001|{5002, Glazed}                  |donut|Cake|
|0001|{5005, Sugar}                   |donut|Cake|
|0001|{5007, Powdered Sugar}          |donut|Cake|
|0001|{5006, Chocolate with Sprinkles}|donut|Cake|
|0001|{5003, Chocolate}               |donut|Cake|
|0001|{5004, Maple}                   |donut|Cake|
+----+--------------------------------+-----+----+


how can a topping column be split into two columns key and value using spark.sql or spark.dataframe ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aricus, 2022-02-11
@Aricus

1. Create a new column.
2. In PHP or another server-side language, loop through all the lines and assign the correct values.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question