Copilot commented on code in PR #12163:
URL: https://github.com/apache/gluten/pull/12163#discussion_r3518085612


##########
cpp/velox/substrait/SubstraitToVeloxPlan.cc:
##########
@@ -458,26 +458,8 @@ core::PlanNodePtr 
SubstraitToVeloxPlanConverter::toVeloxPlan(const ::substrait::
   } else if (
       sJoin.has_advanced_extension() &&
       SubstraitParser::configSetInOptimization(sJoin.advanced_extension(), 
"isBHJ=")) {
-    std::string hashTableId = sJoin.hashtableid();
-
-    std::shared_ptr<core::OpaqueHashTable> opaqueSharedHashTable = nullptr;
-    bool joinHasNullKeys = false;
-
-    try {
-      auto hashTableBuilder = 
ObjectStore::retrieve<gluten::HashTableBuilder>(getJoin(hashTableId));
-      joinHasNullKeys = hashTableBuilder->joinHasNullKeys();
-      auto originalShared = hashTableBuilder->hashTable();
-      opaqueSharedHashTable = std::shared_ptr<core::OpaqueHashTable>(
-          originalShared, 
reinterpret_cast<core::OpaqueHashTable*>(originalShared.get()));
-
-      LOG(INFO) << "Successfully retrieved and aliased HashTable for reuse. 
ID: " << hashTableId;
-    } catch (const std::exception& e) {
-      LOG(WARNING)
-          << "Error retrieving HashTable from ObjectStore: " << e.what()
-          << ". Falling back to building new table. To ensure correct results, 
please verify that spark.gluten.velox.buildHashTableOncePerExecutor.enabled is 
set to false.";
-      opaqueSharedHashTable = nullptr;
-    }
-
+    const auto& hashTableId = sJoin.hashtableid();
+    const auto joinNodeId = hashTableId.empty() ? nextPlanNodeId() : 
hashTableId;
     // Create HashJoinNode node
     return std::make_shared<core::HashJoinNode>(
         nextPlanNodeId(),

Review Comment:
   `joinNodeId` is computed but never used; when `sJoin.hashtableid()` is empty 
this still calls `nextPlanNodeId()` once (advancing the internal counter) and 
then calls it again for the node ID. This both introduces an unused-variable 
warning (often treated as error) and changes plan node ID sequencing, and it 
also leaves the cache key argument as an empty string in the empty-ID case.



##########
gluten-substrait/src/main/scala/org/apache/gluten/execution/JoinExecTransformer.scala:
##########
@@ -394,7 +405,8 @@ abstract class BroadcastHashJoinExecTransformerBase(
   override def joinBuildSide: BuildSide = buildSide
   override def hashJoinType: JoinType = joinType
 
-  lazy val buildHashTableId: String = buildPlan.id.toString
+  // Unique ID for builded hash table
+  lazy val buildHashTableId: String = canonicalBuildHashTableId(buildPlan)
 
   override def genJoinParametersInternal(): (Int, Int, String) = {
     (1, if (isNullAwareAntiJoin) 1 else 0, buildHashTableId)

Review Comment:
   `buildHashTableId` is now canonicalized across `BroadcastQueryStageExec` / 
`ReusedExchangeExec`, which increases hash-table reuse across multiple BHJ 
operators. However, the cache key still only includes the (canonical) build 
plan ID, while the actual hash table build behavior changes with join semantics 
(e.g., semi/anti joins can drop duplicates when there is no filter). Reusing 
the same cache key across different join types / filter presence can cause the 
wrong hash table variant to be reused and lead to incorrect results.



##########
gluten-substrait/src/main/scala/org/apache/gluten/execution/JoinExecTransformer.scala:
##########
@@ -394,7 +405,8 @@ abstract class BroadcastHashJoinExecTransformerBase(
   override def joinBuildSide: BuildSide = buildSide
   override def hashJoinType: JoinType = joinType
 
-  lazy val buildHashTableId: String = buildPlan.id.toString
+  // Unique ID for builded hash table
+  lazy val buildHashTableId: String = canonicalBuildHashTableId(buildPlan)

Review Comment:
   Typo in comment: "builded" should be "built".



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