Skip to content

Commit

Permalink
Resolved comments
Browse files Browse the repository at this point in the history
  • Loading branch information
itholic committed Jul 6, 2021
1 parent 048d222 commit d81b3d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions python/pyspark/sql/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,20 @@ def test_infer_nested_schema(self):
df = self.spark.createDataFrame(rdd)
self.assertEqual(Row(field1=1, field2=u'row1'), df.first())

def test_infer_nested_dict(self):
def test_infer_nested_dict_as_struct(self):
# SPARK-35929: Test inferring nested dict as a struct type.
NestedRow = Row("f1", "f2")

with self.sql_conf({"spark.sql.pyspark.inferNestedDictAsStruct.enabled": True}):
nestedRdd = self.sc.parallelize([NestedRow([{"payment": 200.5, "name": "A"}], [1, 2]),
NestedRow([{"payment": 100.5, "name": "B"}], [2, 3])])
df = self.spark.createDataFrame(nestedRdd)
self.assertEqual(Row(f1=[Row(payment=200.5, name='A')], f2=[1, 2]), df.collect()[0])
self.assertEqual(Row(f1=[Row(payment=200.5, name='A')], f2=[1, 2]), df.first())

data = [NestedRow([{"payment": 200.5, "name": "A"}], [1, 2]),
NestedRow([{"payment": 100.5, "name": "B"}], [2, 3])]
df = self.spark.createDataFrame(data)
self.assertEqual(Row(f1=[Row(payment=200.5, name='A')], f2=[1, 2]), df.first())

def test_create_dataframe_from_dict_respects_schema(self):
df = self.spark.createDataFrame([{'a': 1}], ["b"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3328,7 +3328,8 @@ object SQLConf {
.createWithDefault(0)

val INFER_NESTED_DICT_AS_STRUCT = buildConf("spark.sql.pyspark.inferNestedDictAsStruct.enabled")
.doc("When set to true, infers the nested dict as a struct. By default, it infers it as a map")
.doc("When set to true, infers the nested dict as a struct. By default, it infers it as a map " +
"when using SparkSession.createDataFrame.")
.version("3.3.0")
.booleanConf
.createWithDefault(false)
Expand Down

0 comments on commit d81b3d3

Please sign in to comment.