-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-23772][SQL] Provide an option to ignore column of all null values or empty array during JSON schema inference #20929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
085e9a3
8c75781
53b686d
7870f30
6c4592d
907cf38
58054ef
22e0d9f
4544433
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2408,4 +2408,24 @@ class JsonSuite extends QueryTest with SharedSQLContext with TestJsonData { | |
| spark.read.option("mode", "PERMISSIVE").option("encoding", "UTF-8").json(Seq(badJson).toDS()), | ||
| Row(badJson)) | ||
| } | ||
|
|
||
| test("SPARK-23772 ignore column of all null values or empty array during schema inference") { | ||
| withTempPath { tempDir => | ||
| val path = tempDir.getAbsolutePath | ||
| Seq( | ||
| """{"a":null, "b":[null, null], "c":null, "d":[[], [null]], "e":{}}""", | ||
| """{"a":null, "b":[null], "c":[], "d": [null, []], "e":{}}""", | ||
| """{"a":null, "b":[], "c":[], "d": null, "e":null}""") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a test when
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
| .toDS().write.mode("overwrite").text(path) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
| val df = spark.read.format("json") | ||
| .option("dropFieldIfAllNull", true) | ||
| .load(path) | ||
| val expectedSchema = new StructType() | ||
| .add("a", NullType).add("b", NullType).add("c", NullType).add("d", NullType) | ||
| .add("e", NullType) | ||
| assert(df.schema === expectedSchema) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, there's no explicit preference between them since the preferences are diverted even in committers. It's fine to use one of them. |
||
| val nullRow = Row(null, null, null, null, null) | ||
| checkAnswer(df, nullRow :: nullRow :: nullRow :: Nil) | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about DataStreamReader? I guess the description should be added to it too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok