srowen commented on code in PR #37843:
URL: https://github.com/apache/spark/pull/37843#discussion_r967700615


##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/expressions/Expression.java:
##########
@@ -44,7 +44,16 @@ public interface Expression {
    * List of fields or columns that are referenced by this expression.
    */
   default NamedReference[] references() {
-    return Arrays.stream(children()).map(e -> e.references())
-      .flatMap(Arrays::stream).distinct().toArray(NamedReference[]::new);
+    List<NamedReference> list = new ArrayList<>();
+    Set<NamedReference> uniqueValues = new HashSet<>();
+    for (Expression e : children()) {
+      NamedReference[] references = e.references();
+      for (NamedReference reference : references) {
+        if (uniqueValues.add(reference)) {
+          list.add(reference);
+        }
+      }
+    }
+    return list.toArray(new NamedReference[0]);

Review Comment:
   Do you need to build the List too? why not just .toArray on the Set, because 
ordering is important? LinkedHashSet could help there



##########
common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/OneForOneBlockFetcher.java:
##########
@@ -113,10 +113,28 @@ public OneForOneBlockFetcher(
    * @return whether the array contains only shuffle block IDs
    */
   private boolean areShuffleBlocksOrChunks(String[] blockIds) {
-    if (Arrays.stream(blockIds).anyMatch(blockId -> 
!blockId.startsWith(SHUFFLE_BLOCK_PREFIX))) {
+    if (isAnyBlockNotStartWithShuffleBlockPrefix(blockIds)) {
       // It comes here because there is a blockId which doesn't have 
"shuffle_" prefix so we
       // check if all the block ids are shuffle chunk Ids.
-      return Arrays.stream(blockIds).allMatch(blockId -> 
blockId.startsWith(SHUFFLE_CHUNK_PREFIX));
+      return isAllBlocksStartWithShuffleChunkPrefix(blockIds);
+    }
+    return true;
+  }
+
+  private boolean isAnyBlockNotStartWithShuffleBlockPrefix(String[] blockIds) {

Review Comment:
   Can these be static methods?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to