Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion python/pyspark/sql/connect/functions/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
DataType,
StructType,
ArrayType,
MapType,
StringType,
)
from pyspark.sql.utils import enum_to_value as _enum_to_value
Expand Down Expand Up @@ -1974,7 +1975,7 @@ def from_csv(

def from_json(
col: "ColumnOrName",
schema: Union[ArrayType, StructType, Column, str],
schema: Union[ArrayType, StructType, MapType, Column, str],
options: Optional[Mapping[str, str]] = None,
) -> Column:
if isinstance(schema, (str, Column)):
Expand Down
7 changes: 4 additions & 3 deletions python/pyspark/sql/functions/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
DataType,
StringType,
StructType,
MapType,
NumericType,
_from_numpy_type,
)
Expand Down Expand Up @@ -21044,7 +21045,7 @@ def json_tuple(col: "ColumnOrName", *fields: str) -> Column:
@_try_remote_functions
def from_json(
col: "ColumnOrName",
schema: Union[ArrayType, StructType, Column, str],
schema: Union[ArrayType, StructType, MapType, Column, str],
options: Optional[Mapping[str, str]] = None,
) -> Column:
"""
Expand All @@ -21061,8 +21062,8 @@ def from_json(
----------
col : :class:`~pyspark.sql.Column` or str
a column or column name in JSON format
schema : :class:`DataType` or str
a StructType, ArrayType of StructType or Python string literal with a DDL-formatted string
schema : :class:`StructType`, :class:`ArrayType`, :class:`MapType`, or str
a StructType, ArrayType of StructType, MapType, or Python string literal with a DDL-formatted string
to use when parsing the json column
options : dict, optional
options to control parsing. accepts the same options as the json datasource.
Expand Down
2 changes: 2 additions & 0 deletions python/pyspark/sql/tests/connect/test_connect_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
StructField,
ArrayType,
IntegerType,
MapType,
)
from pyspark.testing import assertDataFrameEqual
from pyspark.testing.pandasutils import PandasOnSparkTestUtils
Expand Down Expand Up @@ -1825,6 +1826,7 @@ def test_json_functions(self):
"MAP<STRING,INT>",
StructType([StructField("a", IntegerType())]),
ArrayType(StructType([StructField("a", IntegerType())])),
MapType(StringType(), IntegerType()),
]:
self.compare_by_show(
cdf.select(CF.from_json(cdf.a, schema)),
Expand Down
1 change: 1 addition & 0 deletions python/pyspark/sql/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def test_wildcard_import(self):
"ByteType", # should be imported from pyspark.sql.types
"Column", # should be imported from pyspark.sql
"DataType", # should be imported from pyspark.sql.types
"MapType", # should be imported from pyspark.sql.types
"NumericType", # should be imported from pyspark.sql.types
"PySparkTypeError", # should be imported from pyspark.errors
"PySparkValueError", # should be imported from pyspark.errors
Expand Down