【发布时间】:2020-03-06 16:19:10
【问题描述】:
我正在使用 v2.1 中的 Spark SQL 自学 JSON,并使用链接中的数据
我的问题是当我使用时:
val lines = spark.read
.option("multiLine", true).option("mode", "PERMISSIVE")
.json("E:/VW/meta_plus_sample_Data.json")`
我让 Spark SQL 将所有数据作为一行返回。
+--------------------+--------------------+
| data| meta|
+--------------------+--------------------+
|[[row-8eh8_xxkx-u...|[[[[1439474950, t...|
+--------------------+--------------------+`
当我删除时:
.option("multiLine", true).option("mode", "PERMISSIVE")
我得到一个错误
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
Exception in thread "main" org.apache.spark.sql.AnalysisException: Since Spark 2.3, the queries from raw JSON/CSV files are disallowed when the
referenced columns only include the internal corrupt record column
(named _corrupt_record by default). For example:
spark.read.schema(schema).json(file).filter($"_corrupt_record".isNotNull).count()
and spark.read.schema(schema).json(file).select("_corrupt_record").show().
Instead, you can cache or save the parsed results and then send the same query.
For example, val df = spark.read.schema(schema).json(file).cache() and then
df.filter($"_corrupt_record".isNotNull).count().;
是否有一个选项可以在 Spark SQL 中将文件中的每条记录作为表中的一行来实现?
【问题讨论】:
标签: scala apache-spark apache-spark-sql