[GitHub] [spark] WeichenXu123 commented on a change in pull request #34021: [SPARK-36642][SQL] Add df.withMetadata pyspark API

2021-09-18 Thread GitBox


WeichenXu123 commented on a change in pull request #34021:
URL: https://github.com/apache/spark/pull/34021#discussion_r711587577



##
File path: python/pyspark/sql/dataframe.py
##
@@ -2536,6 +2536,28 @@ def withColumnRenamed(self, existing, new):
 """
 return DataFrame(self._jdf.withColumnRenamed(existing, new), 
self.sql_ctx)
 
+def withMetadata(self, columnName, metadata):
+"""Returns a new :class:`DataFrame` by updating an existing column 
with metadata.
+
+.. versionadded:: 3.3.0
+
+Parameters
+--
+columnName : str
+string, name of the existing column to update the metadata.
+metadata : dict
+dict, new metadata to be assigned to df.schema[columnName].metadata
+
+Examples
+
+>>> df_meta = df.withMetadata('age', {'foo': 'bar'})
+>>> df_meta.schema['age'].metadata
+{'foo': 'bar'}
+"""
+if not isinstance(metadata, dict):

Review comment:
   @HyukjinKwon 
   
   > 
https://github.com/apache/spark/blob/master/python/pyspark/sql/column.py#L712 
The existing API that takes the metadata also specified that the metadata 
should be a dict in the docstring. However, I'm also fine with not checking the 
dict type.
   
   But in code here 
https://github.com/apache/spark/blob/cabc36b54d7f6633d8b128e511e7049c475b919d/python/pyspark/sql/column.py#L747
 it doesn't require metadata to be dict , so is it a doc error or code error 
there ?




-- 
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-unsubscr...@spark.apache.org

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



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



[GitHub] [spark] WeichenXu123 commented on a change in pull request #34021: [SPARK-36642][SQL] Add df.withMetadata pyspark API

2021-09-16 Thread GitBox


WeichenXu123 commented on a change in pull request #34021:
URL: https://github.com/apache/spark/pull/34021#discussion_r710137451



##
File path: python/pyspark/sql/dataframe.py
##
@@ -2536,6 +2536,28 @@ def withColumnRenamed(self, existing, new):
 """
 return DataFrame(self._jdf.withColumnRenamed(existing, new), 
self.sql_ctx)
 
+def withMetadata(self, columnName, metadata):
+"""Returns a new :class:`DataFrame` by updating an existing column 
with metadata.
+
+.. versionadded:: 3.3.0
+
+Parameters
+--
+columnName : str
+string, name of the existing column to update the metadata.
+metadata : dict
+dict, new metadata to be assigned to df.schema[columnName].metadata
+
+Examples
+
+>>> df_meta = df.withMetadata('age', {'foo': 'bar'})
+>>> df_meta.schema['age'].metadata
+{'foo': 'bar'}
+"""
+if not isinstance(metadata, dict):

Review comment:
   why restrict the type to be dict ? we should allow any types which can 
be converted to JSON.




-- 
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-unsubscr...@spark.apache.org

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



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



[GitHub] [spark] WeichenXu123 commented on a change in pull request #34021: [SPARK-36642][SQL] Add df.withMetadata pyspark API

2021-09-16 Thread GitBox


WeichenXu123 commented on a change in pull request #34021:
URL: https://github.com/apache/spark/pull/34021#discussion_r710134006



##
File path: python/pyspark/sql/dataframe.py
##
@@ -2536,6 +2536,28 @@ def withColumnRenamed(self, existing, new):
 """
 return DataFrame(self._jdf.withColumnRenamed(existing, new), 
self.sql_ctx)
 
+def withMetadata(self, columnName, metadata):
+"""Returns a new :class:`DataFrame` by updating an existing column 
with metadata.
+
+.. versionadded:: 3.3.0
+
+Parameters
+--
+columnName : str
+string, name of the existing column to update the metadata.
+metadata : dict
+dict, new metadata to be assigned to df.schema[columnName].metadata
+
+Examples
+
+>>> df_meta = df.withMetadata('age', {'foo': 'bar'})
+>>> df_meta.schema['age'].metadata
+{'foo': 'bar'}
+"""
+if not isinstance(metadata, dict):
+raise TypeError("metadata should be a dict")
+return DataFrame(self._jdf.withMetadata(columnName, metadata), 
self.sql_ctx)

Review comment:
   The metadata argument type is a dict , how does it pass to the java 
method `def withMetadata(columnName: String, metadata: Metadata)` and the 
metadata become a `Metadata` class type ?




-- 
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-unsubscr...@spark.apache.org

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



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