# NOT RUN {
df <- createDataFrame(iris)
schema <- paste(
c(
'{"type": "record", "namespace": "example.avro", "name": "Iris", "fields": [',
'{"type": ["double", "null"], "name": "Sepal_Length"},',
'{"type": ["double", "null"], "name": "Sepal_Width"},',
'{"type": ["double", "null"], "name": "Petal_Length"},',
'{"type": ["double", "null"], "name": "Petal_Width"},',
'{"type": ["string", "null"], "name": "Species"}]}'
),
collapse="\\n"
)
df_serialized <- select(
df,
alias(to_avro(alias(struct(column("*")), "fields")), "payload")
)
df_deserialized <- select(
df_serialized,
from_avro(df_serialized$payload, schema)
)
head(df_deserialized)
# }
Run the code above in your browser using DataLab