cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Compiling Flattened Dataframe back to Struct Columns

etsyal1e2r3
Honored Contributor

I have a dataframe with this format of columns:

[`first.second.third` , `alpha.bravo.test1` , `alpha.bravo.test2`]

I'd like to get an output dataframe of this:

[               `first`                  |              `alpha`             ]
-------------------------------------------
[{'second':                        |    [{'bravo':
        [{'third': value}]        |         [{'test1': value}     
                                          |         {'test2': value} ]
 }]                                      |    }]

I tried doing something like this but have some errors with using *select_list

AnalysisException: [UNRESOLVED_COLUMN.WITH_SUGGESTION] A column or function parameter with name `F`.`col("_timestamp"),` cannot be resolved.

But manually putting in generated list of select cols with structs works but not exactly what I want.

imageIn the above example the columns were...

[`cloud-provider` , `cloud-region` , `cloud-service-name`]

So the desired result is supposed to be...

[`cloud`]
-------
[{'provider': value},
{'region': value},
{'service': {
        'name': value}}]

Thank you for your help!!!

1 ACCEPTED SOLUTION

Accepted Solutions

etsyal1e2r3
Honored Contributor

I have figured out the solution.

View solution in original post

1 REPLY 1

etsyal1e2r3
Honored Contributor

I have figured out the solution.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group