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: 

Flattening JSON while also keep embedded types

amanda3
Visitor

I'm attempting to create DLT tables from a source table that includes an "data" column that is a JSON string. I'm doing something like this: 

sales_schema = StructType([
  StructField("customer_id", IntegerType(), True),
  StructField("order_numbers", ArrayType(LongType()), True)
StructField("data", StructType([
StructField("value", IntegerType())
])
]
) @dlt.table( schema=sales_schema) def sales(): df = spark.readStream.table("table_name")
.withColumn("parsed_data", from_json(col("data"), sales_schema)
.select("parsed_data.*")
return df
this works to flatten, but for some reason the data column in the DLT sales table becomes a struct where "value" is no longer an Integer but a String. 
 
is there a way to keep the original value type?

 

0 REPLIES 0

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