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 2022/11/10 19:56:50 UTC

[GitHub] [spark] SandishKumarHN opened a new pull request, #38603: [SPARK-41101][PYTHON][PROTOBUF] Message classname support for PYSPARK-PROTOBUF

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

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'core/src/main/resources/error/README.md'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   - Adding message classname support for pyspark-protobuf 
   - functions from_protobuf and to_protobuf
   
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   ### How was this patch tested?
   
   - Python Doctests.
   - To avoid adding an extra jar, I used the existing spark-protobuf jar because it has a shadded google-protobuf and used a Timestamp message as an example protobuf messageClassName in Doctests
   
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   


-- 
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] SandishKumarHN commented on a diff in pull request #38603: [SPARK-41101][PYTHON][PROTOBUF] Message classname support for PYSPARK-PROTOBUF

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


##########
python/pyspark/sql/protobuf/functions.py:
##########
@@ -49,7 +49,10 @@ def from_protobuf(
     data : :class:`~pyspark.sql.Column` or str
         the binary column.
     messageName: str
-        the protobuf message name to look for in descriptor file.
+        the protobuf message name to look for in descriptor file. Or
+        The Protobuf class name. E.g. <code>org.spark.examples.protobuf.ExampleEvent</code>,

Review Comment:
   @HyukjinKwon thanks for the quick review made changes. 



-- 
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] SandishKumarHN commented on a diff in pull request #38603: [SPARK-41101][PYTHON][PROTOBUF] Message classname support for PYSPARK-PROTOBUF

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


##########
python/pyspark/sql/protobuf/functions.py:
##########
@@ -48,8 +48,11 @@ def from_protobuf(
     ----------
     data : :class:`~pyspark.sql.Column` or str
         the binary column.
-    messageName: str
-        the protobuf message name to look for in descriptor file.
+    messageName: str, optional
+        the protobuf message name to look for in descriptor file. Or
+        The Protobuf class name. E.g. ``org.spark.examples.protobuf.ExampleEvent``,

Review Comment:
   fixed



-- 
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] AmplabJenkins commented on pull request #38603: [SPARK-41101][PYTHON][PROTOBUF] Message classname support for PYSPARK-PROTOBUF

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

   Can one of the admins verify this patch?


-- 
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 a diff in pull request #38603: [SPARK-41101][PYTHON][PROTOBUF] Message classname support for PYSPARK-PROTOBUF

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


##########
python/pyspark/sql/protobuf/functions.py:
##########
@@ -32,7 +32,7 @@
 def from_protobuf(
     data: "ColumnOrName",
     messageName: str,
-    descFilePath: str,
+    descFilePath = None,

Review Comment:
   ```suggestion
       descFilePath: Optional[str] = None,
   ```



-- 
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] rangadi commented on a diff in pull request #38603: [SPARK-41101][PYTHON][PROTOBUF] Message classname support for PYSPARK-PROTOBUF

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


##########
python/pyspark/sql/protobuf/functions.py:
##########
@@ -32,7 +32,7 @@
 def from_protobuf(
     data: "ColumnOrName",
     messageName: str,
-    descFilePath: str,
+    descFilePath: Optional[str] = None,

Review Comment:
   Update documentation to reflect change in contract.
   @HyukjinKwon is it common to use Optional[] for optional arguments in PySpark?



-- 
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 #38603: [SPARK-41101][PYTHON][PROTOBUF] Message classname support for PYSPARK-PROTOBUF

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

   Merged to master.


-- 
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 a diff in pull request #38603: [SPARK-41101][PYTHON][PROTOBUF] Message classname support for PYSPARK-PROTOBUF

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


##########
python/pyspark/sql/protobuf/functions.py:
##########
@@ -95,22 +98,40 @@ def from_protobuf(
     +------------------+
     |{2, Alice, 109200}|
     +------------------+
+    >>> data = [([(1668035962, 2020)])]
+    >>> ddl_schema = "value struct<seconds: LONG, nanos: INT>"
+    >>> df = spark.createDataFrame(data, ddl_schema)
+    >>> message_class_name = "org.sparkproject.spark-protobuf.protobuf.Timestamp"
+    >>> to_proto_df = df.select(to_protobuf(df.value, message_class_name).alias("value"))
+    >>> from_proto_df = to_proto_df.select(
+    ...     from_protobuf(to_proto_df.value, message_class_name).alias("value"))
+    >>> from_proto_df.show(truncate=False)
+    +------------------+
+    |value             |
+    +------------------+
+    |{1668035962, 2020}|
+    +------------------+
     """
 
     sc = SparkContext._active_spark_context
     assert sc is not None and sc._jvm is not None
     try:
-        jc = sc._jvm.org.apache.spark.sql.protobuf.functions.from_protobuf(
-            _to_java_column(data), messageName, descFilePath, options or {}
-        )
+        if descFilePath is not None:
+            jc = sc._jvm.org.apache.spark.sql.protobuf.functions.from_protobuf(
+                _to_java_column(data), messageName, descFilePath, options or {}
+            )
+        else:
+            jc = sc._jvm.org.apache.spark.sql.protobuf.functions.from_protobuf(
+                _to_java_column(data), messageName
+            )
     except TypeError as e:
         if str(e) == "'JavaPackage' object is not callable":
             _print_missing_jar("Protobuf", "protobuf", "protobuf", sc.version)
         raise
     return Column(jc)
 
 
-def to_protobuf(data: "ColumnOrName", messageName: str, descFilePath: str) -> Column:
+def to_protobuf(data: "ColumnOrName", messageName: str, descFilePath = None) -> Column:

Review Comment:
   ```suggestion
   def to_protobuf(data: "ColumnOrName", messageName: str, descFilePath: Optional[str] = None) -> Column:
   ```



##########
python/pyspark/sql/protobuf/functions.py:
##########
@@ -121,7 +142,10 @@ def to_protobuf(data: "ColumnOrName", messageName: str, descFilePath: str) -> Co
     data : :class:`~pyspark.sql.Column` or str
         the data column.
     messageName: str

Review Comment:
   ```suggestion
       messageName: str, optional
   ```



-- 
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 a diff in pull request #38603: [SPARK-41101][PYTHON][PROTOBUF] Message classname support for PYSPARK-PROTOBUF

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


##########
python/pyspark/sql/protobuf/functions.py:
##########
@@ -49,7 +49,10 @@ def from_protobuf(
     data : :class:`~pyspark.sql.Column` or str
         the binary column.
     messageName: str

Review Comment:
   ```suggestion
       messageName: str, optional
   ```



-- 
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 a diff in pull request #38603: [SPARK-41101][PYTHON][PROTOBUF] Message classname support for PYSPARK-PROTOBUF

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


##########
python/pyspark/sql/protobuf/functions.py:
##########
@@ -32,7 +32,7 @@
 def from_protobuf(
     data: "ColumnOrName",
     messageName: str,
-    descFilePath: str,
+    descFilePath: Optional[str] = None,

Review Comment:
   Yes, it should be fine.



-- 
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 a diff in pull request #38603: [SPARK-41101][PYTHON][PROTOBUF] Message classname support for PYSPARK-PROTOBUF

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


##########
python/pyspark/sql/protobuf/functions.py:
##########
@@ -121,7 +142,10 @@ def to_protobuf(data: "ColumnOrName", messageName: str, descFilePath: str) -> Co
     data : :class:`~pyspark.sql.Column` or str
         the data column.
     messageName: str
-        the protobuf message name to look for in descriptor file.
+        the protobuf message name to look for in descriptor file. Or
+        The Protobuf class name. E.g. <code>org.spark.examples.protobuf.ExampleEvent</code>,

Review Comment:
   ```suggestion
           The Protobuf class name. E.g. ``org.spark.examples.protobuf.ExampleEvent``,
   ```



-- 
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] rangadi commented on a diff in pull request #38603: [SPARK-41101][PYTHON][PROTOBUF] Message classname support for PYSPARK-PROTOBUF

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


##########
python/pyspark/sql/protobuf/functions.py:
##########
@@ -48,8 +48,11 @@ def from_protobuf(
     ----------
     data : :class:`~pyspark.sql.Column` or str
         the binary column.
-    messageName: str
-        the protobuf message name to look for in descriptor file.
+    messageName: str, optional
+        the protobuf message name to look for in descriptor file. Or
+        The Protobuf class name. E.g. ``org.spark.examples.protobuf.ExampleEvent``,

Review Comment:
   We need to add a comment about shading requirement. In scala, we are changing this name to `shadedMessageClassName`. See scaladoc update in open PR here: https://github.com/apache/spark/pull/38384/files#diff-93adb6d1143432aff776baed60d056133658635a2d8f9d29d925018fada64ff7R76-R83
   
   
   



-- 
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 a diff in pull request #38603: [SPARK-41101][PYTHON][PROTOBUF] Message classname support for PYSPARK-PROTOBUF

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


##########
python/pyspark/sql/protobuf/functions.py:
##########
@@ -49,7 +49,10 @@ def from_protobuf(
     data : :class:`~pyspark.sql.Column` or str
         the binary column.
     messageName: str
-        the protobuf message name to look for in descriptor file.
+        the protobuf message name to look for in descriptor file. Or
+        The Protobuf class name. E.g. <code>org.spark.examples.protobuf.ExampleEvent</code>,

Review Comment:
   ```suggestion
           The Protobuf class name. E.g. ``org.spark.examples.protobuf.ExampleEvent``,
   ```



-- 
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] rangadi commented on a diff in pull request #38603: [SPARK-41101][PYTHON][PROTOBUF] Message classname support for PYSPARK-PROTOBUF

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


##########
python/pyspark/sql/protobuf/functions.py:
##########
@@ -48,8 +48,11 @@ def from_protobuf(
     ----------
     data : :class:`~pyspark.sql.Column` or str
         the binary column.
-    messageName: str
-        the protobuf message name to look for in descriptor file.
+    messageName: str, optional
+        the protobuf message name to look for in descriptor file. Or
+        The Protobuf class name. E.g. ``org.spark.examples.protobuf.ExampleEvent``,

Review Comment:
   We need to add a comment about shading requirement. In scala, I am changing this name to `shadedMessageClassName`. See scaladoc update in open PR here: https://github.com/apache/spark/pull/38384/files#diff-93adb6d1143432aff776baed60d056133658635a2d8f9d29d925018fada64ff7R76-R83
   
   
   



-- 
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 closed pull request #38603: [SPARK-41101][PYTHON][PROTOBUF] Message classname support for PYSPARK-PROTOBUF

Posted by GitBox <gi...@apache.org>.
HyukjinKwon closed pull request #38603: [SPARK-41101][PYTHON][PROTOBUF] Message classname support for PYSPARK-PROTOBUF
URL: https://github.com/apache/spark/pull/38603


-- 
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