-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-20009][SQL] Support DDL strings for defining schema in functions.from_json #17406
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 all commits
87abf7b
2afa6f3
fb61535
ec5452f
6e81235
e2d121f
842ca77
9ddd515
8448d7a
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 |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import scala.collection.JavaConverters._ | |
| import scala.language.implicitConversions | ||
| import scala.reflect.runtime.universe.{typeTag, TypeTag} | ||
| import scala.util.Try | ||
| import scala.util.control.NonFatal | ||
|
|
||
| import org.apache.spark.annotation.{Experimental, InterfaceStability} | ||
| import org.apache.spark.sql.catalyst.ScalaReflection | ||
|
|
@@ -3055,13 +3056,21 @@ object functions { | |
| * with the specified schema. Returns `null`, in the case of an unparseable string. | ||
| * | ||
| * @param e a string column containing JSON data. | ||
| * @param schema the schema to use when parsing the json string as a json string | ||
| * @param schema the schema to use when parsing the json string as a json string. In Spark 2.1, | ||
| * the user-provided schema has to be in JSON format. Since Spark 2.2, the DDL | ||
| * format is also supported for the schema. | ||
| * | ||
| * @group collection_funcs | ||
| * @since 2.1.0 | ||
| */ | ||
| def from_json(e: Column, schema: String, options: java.util.Map[String, String]): Column = | ||
| from_json(e, DataType.fromJson(schema), options) | ||
| def from_json(e: Column, schema: String, options: java.util.Map[String, String]): Column = { | ||
| val dataType = try { | ||
|
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. A little concern: Won't the error message from parsing json be shadowed?
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. That is fine, right? cc @cloud-fan
Contributor
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. yea I think it's fine |
||
| DataType.fromJson(schema) | ||
| } catch { | ||
| case NonFatal(_) => StructType.fromDDL(schema) | ||
| } | ||
|
Comment on lines
+3067
to
+3071
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. I am wondering why parsing schema from a string is implemented here but not inside of 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. I think you came to a wrong PR. The schema parsing was started in Scala side at maropu@fe33121#diff-b5e6d03d9c9afbfa925e039c48e31078608ea749c193e6af3087b79eb701bc7cR2877. I guess reason is that, the schema parameter was not intended to be used an expression before. Now we take it in SQL as well.
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. I think I just missed it, so making the code in common seems fine.
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. Thanks, @HyukjinKwon. Ah, I see, I totally forgot it...
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. I moved parsing to a common place. Please, take a look at #30201 |
||
| from_json(e, dataType, options) | ||
| } | ||
|
|
||
| /** | ||
| * (Scala-specific) Converts a column containing a `StructType` or `ArrayType` of `StructType`s | ||
|
|
||
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.
The same here