Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read Multilple json schema with spark

Software Configuration:

Hadoop distribution:Amazon 2.8.3
Applications:Hive 2.3.2, Pig 0.17.0, Hue 4.1.0, Spark 2.3.0

Tried to read with multiple json schema,

val df = spark.read.option("mergeSchema", "true").json("s3a://s3bucket/2018/01/01/*")

Throws an error,

org.apache.spark.sql.AnalysisException: Unable to infer schema for JSON. It must be specified manually.;
  at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$9.apply(DataSource.scala:207)
  at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$9.apply(DataSource.scala:207)
  at scala.Option.getOrElse(Option.scala:121)
  at org.apache.spark.sql.execution.datasources.DataSource.getOrInferFileFormatSchema(DataSource.scala:206)
  at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:392)
  at org.apache.spark.sql.DataFrameReader.loadV1Source(DataFrameReader.scala:239)
  at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:227)
  at org.apache.spark.sql.DataFrameReader.json(DataFrameReader.scala:397)
  at org.apache.spark.sql.DataFrameReader.json(DataFrameReader.scala:340)

How to read json with multipl schema's with spark?

like image 700
Kannaiyan Avatar asked Jul 09 '26 17:07

Kannaiyan


1 Answers

This sometimes happens when you are pointing to wrong path (when data does not exist).

like image 149
DejanS Avatar answered Jul 12 '26 10:07

DejanS