Skip to content

Instantly share code, notes, and snippets.

View ThiagoPositeli's full-sized avatar
🏠
Working from home

Thiago Positeli ThiagoPositeli

🏠
Working from home
View GitHub Profile
from pyspark.sql.types import *
from pyspark.sql.functions import *
#Flatten array of structs and structs
def flatten(df):
# compute Complex Fields (Lists and Structs) in Schema
complex_fields = dict([(field.name, field.dataType)
for field in df.schema.fields
if type(field.dataType) == ArrayType or type(field.dataType) == StructType])
while len(complex_fields)!=0: