You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2023/01/11 13:11:36 UTC

[GitHub] [spark] beliefer opened a new pull request, #39514: [SPARK-41987][CONNECT][PYTHON] createDataFrame supports column with map type

beliefer opened a new pull request, #39514:
URL: https://github.com/apache/spark/pull/39514

   ### What changes were proposed in this pull request?
   Currently, Connect API createDataFrame does not support create dataframe with map type.
   For example, 
   ```
       >>> df = spark.createDataFrame(
       ...     [(1, ["foo", "bar"], {"x": 1.0}), (2, [], {}), (3, None, None)],
       ...     ("id", "an_array", "a_map")
       ... )
   ```
   
   The above code want create a dataframe with column 'a_map' which is map type.
   But pyarrow recognize {"x": 1.0} as a struct not map.
   pyarrow supports map with format [('x', 1.0)]
   
   Because the data frame's schema is not correct, so the other sequence operator will be impacted.
   For example:
   `df.select("id", "a_map", posexplode_outer("an_array")).show()`
   
   Expected:
   ```
       +---+----------+----+----+
       | id|     a_map| pos| col|
       +---+----------+----+----+
       |  1|{x -> 1.0}|   0| foo|
       |  1|{x -> 1.0}|   1| bar|
       |  2|        {}|null|null|
       |  3|      null|null|null|
       +---+----------+----+----+
   ```
   
   But got:
   ```
       +---+------+----+----+
       | id| a_map| pos| col|
       +---+------+----+----+
       |  1| {1.0}|   0| foo|
       |  1| {1.0}|   1| bar|
       |  2|{null}|null|null|
       |  3|  null|null|null|
       +---+------+----+----+
       <BLANKLINE>
   ```
   
   ### Why are the changes needed?
   Let createDataFrame supports column with map type and fix some bugs.
   
   
   ### Does this PR introduce _any_ user-facing change?
   'No'.
   New feature.
   
   
   ### How was this patch tested?
   Manual test and doc test.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] beliefer closed pull request #39514: [SPARK-41987][CONNECT][PYTHON] Connect API: createDataFrame should supports column with map type

Posted by GitBox <gi...@apache.org>.
beliefer closed pull request #39514: [SPARK-41987][CONNECT][PYTHON] Connect API: createDataFrame should supports column with map type
URL: https://github.com/apache/spark/pull/39514


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] beliefer commented on pull request #39514: [SPARK-41987][CONNECT][PYTHON] Connect API: createDataFrame should supports column with map type

Posted by GitBox <gi...@apache.org>.
beliefer commented on PR #39514:
URL: https://github.com/apache/spark/pull/39514#issuecomment-1381306222

   > @beliefer Thanks for working on this, but I prefer to supporting all the complex types together [in one batch](https://github.com/apache/spark/pull/39535). Would you mind taking a look at it?
   
   OK. Let your PR go on.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] beliefer commented on a diff in pull request #39514: [SPARK-41987][CONNECT][PYTHON] createDataFrame supports column with map type

Posted by GitBox <gi...@apache.org>.
beliefer commented on code in PR #39514:
URL: https://github.com/apache/spark/pull/39514#discussion_r1066989161


##########
python/pyspark/sql/functions.py:
##########
@@ -4608,9 +4608,11 @@ def hour(col: "ColumnOrName") -> Column:
     Examples
     --------
     >>> import datetime
-    >>> df = spark.createDataFrame([(datetime.datetime(2015, 4, 8, 13, 8, 15),)], ['ts'])
+    >>> df = spark.createDataFrame(
+    ...     [(datetime.datetime(2015, 4, 8, 13, 8, 15, tzinfo=datetime.timezone.utc),)], ['ts']
+    ... )
     >>> df.select(hour('ts').alias('hour')).collect()
-    [Row(hour=13)]
+    [Row(hour=21)]

Review Comment:
   Because https://github.com/apache/spark/blob/7ec5af4c052229dbe94628951df2f67b3036609f/python/pyspark/sql/pandas/types.py#L83 give the timezone=utc for timestamp.
   So I explicitly update test cases with timezone utc.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] zhengruifeng commented on pull request #39514: [SPARK-41987][CONNECT][PYTHON] Connect API: createDataFrame should supports column with map type

Posted by GitBox <gi...@apache.org>.
zhengruifeng commented on PR #39514:
URL: https://github.com/apache/spark/pull/39514#issuecomment-1381312106

   Thank you @beliefer 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] zhengruifeng commented on pull request #39514: [SPARK-41987][CONNECT][PYTHON] Connect API: createDataFrame should supports column with map type

Posted by GitBox <gi...@apache.org>.
zhengruifeng commented on PR #39514:
URL: https://github.com/apache/spark/pull/39514#issuecomment-1381181758

   @beliefer Thanks for working on this, but I prefer to supporting all the complex types together [in one batch](https://github.com/apache/spark/pull/39535). Would you mind taking a look at it?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on pull request #39514: [WIP][SPARK-41987][CONNECT][PYTHON] createDataFrame supports column with map type

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on PR #39514:
URL: https://github.com/apache/spark/pull/39514#issuecomment-1380158350

   cc @zhengruifeng 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org