You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "amaliujia (via GitHub)" <gi...@apache.org> on 2023/05/10 16:31:33 UTC

[GitHub] [spark] amaliujia opened a new pull request, #41123: [SPARK-43428][FOLLOW-UP] Utils and JSON Utils refactoring

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

   <!--
   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.
   -->
   1. We can use define trait for the `SparkClassUtils` and let Spark Utils to extend that to avoid duplicate code.
   2. We can also define trait for the `JsonUtil` and JsonProtocol can also extend that to re-use code.
   
   ### 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.
     3. If you fix a bug, you can clarify why it is a bug.
   -->
   Share more between common/utils module and Spark core.
   
   ### 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'.
   -->
   No
   
   ### How was this patch tested?
   <!--
   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.
   -->
   Existing UT


-- 
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] hvanhovell commented on a diff in pull request #41123: [SPARK-43428][FOLLOW-UP] Utils and JSON Utils refactoring

Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #41123:
URL: https://github.com/apache/spark/pull/41123#discussion_r1190212060


##########
common/utils/src/main/scala/org/apache/spark/util/JsonUtils.scala:
##########
@@ -25,9 +25,9 @@ import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
 import com.fasterxml.jackson.module.scala.DefaultScalaModule
 
 
-private[spark] object JsonUtils {
+private[spark] trait JsonUtils {
 
-  private val mapper = new ObjectMapper().registerModule(DefaultScalaModule)
+  protected val mapper = new ObjectMapper().registerModule(DefaultScalaModule)

Review Comment:
   It needs to be protected because of the JsonProtocol class.



-- 
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] amaliujia commented on a diff in pull request #41123: [SPARK-43428][FOLLOW-UP] Utils and JSON Utils refactoring

Posted by "amaliujia (via GitHub)" <gi...@apache.org>.
amaliujia commented on code in PR #41123:
URL: https://github.com/apache/spark/pull/41123#discussion_r1190436250


##########
common/utils/src/main/scala/org/apache/spark/util/JsonUtils.scala:
##########
@@ -25,9 +25,9 @@ import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
 import com.fasterxml.jackson.module.scala.DefaultScalaModule
 
 
-private[spark] object JsonUtils {
+private[spark] trait JsonUtils {
 
-  private val mapper = new ObjectMapper().registerModule(DefaultScalaModule)
+  protected val mapper = new ObjectMapper().registerModule(DefaultScalaModule)

Review Comment:
   @LuciferYang which type annotation you are referring to? Can you share an example?



-- 
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] LuciferYang commented on a diff in pull request #41123: [SPARK-43428][FOLLOW-UP] Utils and JSON Utils refactoring

Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #41123:
URL: https://github.com/apache/spark/pull/41123#discussion_r1190178101


##########
common/utils/src/main/scala/org/apache/spark/util/JsonUtils.scala:
##########
@@ -25,9 +25,9 @@ import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
 import com.fasterxml.jackson.module.scala.DefaultScalaModule
 
 
-private[spark] object JsonUtils {
+private[spark] trait JsonUtils {
 
-  private val mapper = new ObjectMapper().registerModule(DefaultScalaModule)
+  protected val mapper = new ObjectMapper().registerModule(DefaultScalaModule)

Review Comment:
   And I want to know within what scope this `mapper` will be used in design?
   
   



-- 
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] amaliujia commented on pull request #41123: [SPARK-43428][FOLLOW-UP] Utils and JSON Utils refactoring

Posted by "amaliujia (via GitHub)" <gi...@apache.org>.
amaliujia commented on PR #41123:
URL: https://github.com/apache/spark/pull/41123#issuecomment-1542499515

   @hvanhovell @cloud-fan 


-- 
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] hvanhovell commented on a diff in pull request #41123: [SPARK-43428][FOLLOW-UP] Utils and JSON Utils refactoring

Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #41123:
URL: https://github.com/apache/spark/pull/41123#discussion_r1190183443


##########
common/utils/src/main/scala/org/apache/spark/util/JsonUtils.scala:
##########
@@ -39,3 +39,5 @@ private[spark] object JsonUtils {
     new String(baos.toByteArray, StandardCharsets.UTF_8)
   }
 }
+

Review Comment:
   `ByteArrayOutputStream` does not really need to be closed. 



-- 
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] LuciferYang commented on a diff in pull request #41123: [SPARK-43428][FOLLOW-UP] Utils and JSON Utils refactoring

Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #41123:
URL: https://github.com/apache/spark/pull/41123#discussion_r1190161190


##########
common/utils/src/main/scala/org/apache/spark/util/JsonUtils.scala:
##########
@@ -25,9 +25,9 @@ import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
 import com.fasterxml.jackson.module.scala.DefaultScalaModule
 
 
-private[spark] object JsonUtils {
+private[spark] trait JsonUtils {
 
-  private val mapper = new ObjectMapper().registerModule(DefaultScalaModule)
+  protected val mapper = new ObjectMapper().registerModule(DefaultScalaModule)

Review Comment:
   We should add type annotation to `protected` member



##########
common/utils/src/main/scala/org/apache/spark/util/JsonUtils.scala:
##########
@@ -39,3 +39,5 @@ private[spark] object JsonUtils {
     new String(baos.toByteArray, StandardCharsets.UTF_8)
   }
 }
+

Review Comment:
   hmm... should we always close `generator` and `baos` in `finally` block(line 37&38)? If so, we can refactor it in this pr
   
   



-- 
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] LuciferYang commented on a diff in pull request #41123: [SPARK-43428][FOLLOW-UP] Utils and JSON Utils refactoring

Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #41123:
URL: https://github.com/apache/spark/pull/41123#discussion_r1190177641


##########
common/utils/src/main/scala/org/apache/spark/util/JsonUtils.scala:
##########
@@ -39,3 +39,5 @@ private[spark] object JsonUtils {
     new String(baos.toByteArray, StandardCharsets.UTF_8)
   }
 }
+

Review Comment:
   And I want to know within what scope this `mapper` will be used in design?
   
   



-- 
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 #41123: [SPARK-43428][CORE][FOLLOWUP] Utils and JSON Utils refactoring

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon closed pull request #41123: [SPARK-43428][CORE][FOLLOWUP] Utils and JSON Utils refactoring
URL: https://github.com/apache/spark/pull/41123


-- 
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] LuciferYang commented on a diff in pull request #41123: [SPARK-43428][FOLLOW-UP] Utils and JSON Utils refactoring

Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #41123:
URL: https://github.com/apache/spark/pull/41123#discussion_r1190566500


##########
common/utils/src/main/scala/org/apache/spark/util/JsonUtils.scala:
##########
@@ -25,9 +25,9 @@ import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
 import com.fasterxml.jackson.module.scala.DefaultScalaModule
 
 
-private[spark] object JsonUtils {
+private[spark] trait JsonUtils {
 
-  private val mapper = new ObjectMapper().registerModule(DefaultScalaModule)
+  protected val mapper = new ObjectMapper().registerModule(DefaultScalaModule)

Review Comment:
   ```suggestion
     protected val mapper: ObjectMapper =  new ObjectMapper().registerModule(DefaultScalaModule)
   ```



-- 
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 #41123: [SPARK-43428][CORE][FOLLOWUP] Utils and JSON Utils refactoring

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #41123:
URL: https://github.com/apache/spark/pull/41123#issuecomment-1547146047

   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] LuciferYang commented on a diff in pull request #41123: [SPARK-43428][FOLLOW-UP] Utils and JSON Utils refactoring

Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #41123:
URL: https://github.com/apache/spark/pull/41123#discussion_r1190185598


##########
common/utils/src/main/scala/org/apache/spark/util/JsonUtils.scala:
##########
@@ -39,3 +39,5 @@ private[spark] object JsonUtils {
     new String(baos.toByteArray, StandardCharsets.UTF_8)
   }
 }
+

Review Comment:
   Yeah, it's not important, but it's a habit ... I may be a bit OCD :)
   
   
    



-- 
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] hvanhovell commented on a diff in pull request #41123: [SPARK-43428][FOLLOW-UP] Utils and JSON Utils refactoring

Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #41123:
URL: https://github.com/apache/spark/pull/41123#discussion_r1190210933


##########
common/utils/src/main/scala/org/apache/spark/util/JsonUtils.scala:
##########
@@ -39,3 +39,5 @@ private[spark] object JsonUtils {
     new String(baos.toByteArray, StandardCharsets.UTF_8)
   }
 }
+

Review Comment:
   Some OCD is fine :). In this particular case you have the concrete implementation of the InputStream, it is a stable implementation, and its semantics are very well understood. I am fine with omitting the close because of this.



-- 
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] amaliujia commented on a diff in pull request #41123: [SPARK-43428][FOLLOW-UP] Utils and JSON Utils refactoring

Posted by "amaliujia (via GitHub)" <gi...@apache.org>.
amaliujia commented on code in PR #41123:
URL: https://github.com/apache/spark/pull/41123#discussion_r1190436826


##########
common/utils/src/main/scala/org/apache/spark/util/JsonUtils.scala:
##########
@@ -39,3 +39,5 @@ private[spark] object JsonUtils {
     new String(baos.toByteArray, StandardCharsets.UTF_8)
   }
 }
+

Review Comment:
   ```
       /**
        * Closing a {@code ByteArrayOutputStream} has no effect. The methods in
        * this class can be called after the stream has been closed without
        * generating an {@code IOException}.
        */
       public void close() throws IOException {
       }
   ```
   
   I guess probably we do not need to close (and this is existing code but just refactor anyway)
   



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