GitHub user chenghao-intel opened a pull request:
https://github.com/apache/spark/pull/4492
[SPARK-5706] [SQL] Add json schema inferring method
We need to provide json infer schema API instead of manually provide the
json schema.
```
val completeJsonRecord = """{"struct":{"field1": true, "field2":
92233720368547758070},
"structWithArrayFields":{"field1":[4, 5, 6], "field2":["str1",
"str2"]},
"arrayOfString":["str1", "str2"],
"arrayOfInteger":[1, 2147483647, -2147483648],
@@ -90,7 +111,10 @@ object TestJsonData {
"arrayOfStruct":[{"field1": true, "field2": "str1"}, {"field1":
false}, {"field3": null}],
"arrayOfArray1":[[1, 2, 3], ["str1", "str2"]],
"arrayOfArray2":[[1, 2, 3], [1.1, 2.1, 3.1]]
}"""
val schema = sqlContext.inferJsonSchema(completeJsonRecord)
val jsonDF = sqlContext.jsonFile("/user/myjson", schema)
```
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/chenghao-intel/spark json_inferschema
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/4492.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #4492
----
commit 0768b04c8f549f678a8654305c0e9db9059d7041
Author: Cheng Hao <[email protected]>
Date: 2015-02-10T01:44:54Z
Add json schema inferring method
----
---
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.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]