Github user marmbrus commented on a diff in the pull request:
https://github.com/apache/spark/pull/999#discussion_r13520443
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/SQLContext.scala ---
@@ -98,6 +99,41 @@ class SQLContext(@transient val sparkContext:
SparkContext)
new SchemaRDD(this, parquet.ParquetRelation(path))
/**
+ * Loads a JSON file, returning the result as a [[SchemaRDD]].
+ * Right now, we only do eager schema resolution.
+ */
+ def jsonFile(
+ path: String,
+ mode: SchemaResolutionMode = EAGER_SCHEMA_RESOLUTION): SchemaRDD = {
+ logger.info(s"Loads a JSON file $path.")
+ val json = sparkContext.textFile(path)
+ jsonRDD(json, mode)
+ }
+
+ /**
+ * Loads a RDD[String] storing JSON objects (one object per record),
+ * returning the result as a [[SchemaRDD]].
+ * Right now, we only do eager schema resolution.
+ */
+ def jsonRDD(
+ json: RDD[String],
+ mode: SchemaResolutionMode = EAGER_SCHEMA_RESOLUTION): SchemaRDD = {
+ mode match {
+ case EAGER_SCHEMA_RESOLUTION =>
+ logger.info(s"Eagerly resolve the schema without sampling.")
+ val logicalPlan = JsonTable.inferSchema(json)
+ logicalPlanToSparkQuery(logicalPlan)
+ case EAGER_SCHEMA_RESOLUTION_WITH_SAMPLING(fraction) =>
+ logger.info(s"Eagerly resolve the schema with sampling " +
+ s"(sampling fraction: $fraction).")
+ val logicalPlan = JsonTable.inferSchema(json, Some(fraction))
+ logicalPlanToSparkQuery(logicalPlan)
+ case LAZY_SCHEMA_RESOLUTION =>
--- End diff --
Perhaps we should just leave this out so users will get compile errors
instead of runtime errors.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---