You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "LuciferYang (via GitHub)" <gi...@apache.org> on 2024/03/01 09:35:48 UTC

[PR] [SPARK-47246][SQL] Replace 'InternalRow.fromSeq' with 'new GenericInternalRow' to save collection conversion [spark]

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

   ### What changes were proposed in this pull request?
   This PR changes the use of `InternalRow.fromSeq` in the following scenarios to directly construct `GenericInternalRow` to save a collection conversion:
   
   1. The input is a locally constructed `Array`, such as:
   
   https://github.com/apache/spark/blob/a5a282234295467a2bf4a13eb25f51a971bd1a05/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala#L204-L206
   
   https://github.com/apache/spark/blob/a5a282234295467a2bf4a13eb25f51a971bd1a05/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala#L1517
   
   https://github.com/apache/spark/blob/a5a282234295467a2bf4a13eb25f51a971bd1a05/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/StaxXmlParser.scala#L332
   
   https://github.com/apache/spark/blob/a5a282234295467a2bf4a13eb25f51a971bd1a05/sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/InMemoryRelation.scala#L114-L115
   
   and so on.
   
   2. The input is a manually constructed `Seq`, which can be changed to manually construct an `Array`, such as:
   
   https://github.com/apache/spark/blob/a5a282234295467a2bf4a13eb25f51a971bd1a05/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/state/metadata/StateMetadataSource.scala#L61-L69
   
   https://github.com/apache/spark/blob/a5a282234295467a2bf4a13eb25f51a971bd1a05/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/StaxXmlParser.scala#L330
   
   3. The input can be directly converted to an `Array`, without the need to first convert to `Seq` and then call `InternalRow.fromSeq` to convert to `Array`, such as:
   
   https://github.com/apache/spark/blob/a5a282234295467a2bf4a13eb25f51a971bd1a05/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveInspectors.scala#L747
   
   https://github.com/apache/spark/blob/a5a282234295467a2bf4a13eb25f51a971bd1a05/sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/HiveTableScanExec.scala#L162
   
   This PR only modifies parts under `src`, and does not modify cases in the test.
   
   ### Why are the changes needed?
   Avoid some unnecessary collection conversions
   
   
   ### 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?
   <!--
   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.
   -->
   
   
   ### Was this patch authored or co-authored using generative AI tooling?
   <!--
   If generative AI tooling has been used in the process of authoring this patch, please include the
   phrase: 'Generated-by: ' followed by the name of the tool and its version.
   If no, write 'No'.
   Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
   -->
   


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


Re: [PR] [SPARK-47246][SQL] Replace 'InternalRow.fromSeq' with 'new GenericInternalRow' to save collection conversion [spark]

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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/StaxXmlParser.scala:
##########
@@ -327,9 +327,9 @@ class StaxXmlParser(
 
     if (valuesMap.isEmpty) {
       // Return an empty row with all nested elements by the schema set to null.
-      InternalRow.fromSeq(Seq.fill(schema.fieldNames.length)(null))
+      new GenericInternalRow(Array.fill[Any](schema.length)(null))

Review Comment:
   `schema.fieldNames.length` => `schema.fields.map(_.name).length`
   
   `schema.length` => `fields.length`
   
   `schema.length` and `schema.fieldNames.length` should be equal, and `schema.length` can save a map conversion, so here it is casually changed to `schema.length`



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


Re: [PR] [SPARK-47246][SQL] Replace `InternalRow.fromSeq` with `new GenericInternalRow` to save a collection conversion [spark]

Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang closed pull request #45356: [SPARK-47246][SQL] Replace `InternalRow.fromSeq` with `new GenericInternalRow` to save a collection conversion
URL: https://github.com/apache/spark/pull/45356


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


Re: [PR] [SPARK-47246][SQL] Replace `InternalRow.fromSeq` with `new GenericInternalRow` to save a collection conversion [spark]

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

   Merged into master for Spark 4.0. Thanks @HyukjinKwon 


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