Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/9977#discussion_r45921244
--- Diff: python/pyspark/sql/functions.py ---
@@ -1475,15 +1487,29 @@ def get_json_object(col, path):
@since(1.6)
-def json_tuple(col, fields):
+def json_tuple(col, *fields):
"""Creates a new row for a json column according to the given field
names.
:param col: string column in json format
:param fields: list of fields to extract
- """
- sc = SparkContext._active_spark_context
- jc = sc._jvm.functions.json_tuple(_to_java_column(col), fields)
+ >>> data = [("1", '''{"f1": "value1", "f2": "value2", "f3": 3, "f5":
5.23}'''), \
+ ("2", '''{"f1": "value12", "f3": "value3", "f2": 2, "f4":
4.01}'''), \
+ ("3", '''{"f1": "value13", "f4": "value44", "f3": "value33",
"f2": 2, "f5": 5.01}'''), \
+ ("4", None), \
+ ("5", '''{"f1": "", "f5": null}'''), \
+ ("6", '''[invalid JSON string]''')]
+ >>> df = sqlContext.createDataFrame(data, ("key", "jstring"))
+ >>> df.select(df.key, json_tuple(df.jstring, 'f1', 'f2', 'f3', 'f4',
'f5')).collect()
--- End diff --
sure, will do.
---
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]