Skip to content

Instantly share code, notes, and snippets.

@1ambda
Created December 21, 2021 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1ambda/6355f96cecb10a6764ac0fbc190d18c5 to your computer and use it in GitHub Desktop.
Save 1ambda/6355f96cecb10a6764ac0fbc190d18c5 to your computer and use it in GitHub Desktop.
dfRecovered = dfCategory\
.withColumn("category_id", get_json_object(col("category"), "$.category_id").cast(LongType()))\
.withColumn("category_code", get_json_object(col("category"), "$.category_code"))
dfRecovered.printSchema()
root
|-- brand: string (nullable = true)
|-- product_id: integer (nullable = true)
|-- category: string (nullable = true)
|-- category_id: long (nullable = true)
|-- category_code: string (nullable = true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment