0

I have a Spark DS with the below structure, I want to flatten each and extract all the columns. I tried get_json_object like below but it isn't working.

root
  |-- data: struct (nullable = true)
  |    |-- Level: long (nullable = true)
  |    |-- activityName: string (nullable = true)
  |    |-- activityRunId: string (nullable = true)
  |    |-- activityType: string (nullable = true)
  |    |-- category: string (nullable = true) 
  |    |-- correlationId: string (nullable = true)
  |    |-- effectiveIntegrationRuntime: string (nullable = true)
  |    |-- end: string (nullable = true)
  |    |-- level: string (nullable = true)
  |    |-- location: string (nullable = true)
  |    |-- operationName: string (nullable = true)
  |    |-- pipelineName: string (nullable = true)
  |    |-- pipelineRunId: string (nullable = true)
  |    |-- properties: struct (nullable = true)
  |    |    |-- Annotations: array (nullable = true)
  |    |    |    |-- element: string (containsNull = true)
  |    |    |-- Error: struct (nullable = true)
  |    |    |    |-- errorCode: string (nullable = true)


val DS = logDS.select(get_json_object($"data", "$.Level").alias("level"))

Requirement is I want to extract as separate columns

Ramesh Maharjan
  • 41,071
  • 6
  • 69
  • 97
prady
  • 563
  • 4
  • 9
  • 24

0 Answers0