siddharthteotia commented on code in PR #15350:
URL: https://github.com/apache/pinot/pull/15350#discussion_r2059659109


##########
pinot-core/src/main/java/org/apache/pinot/core/operator/combine/merger/SelectionOnlyResultsBlockMerger.java:
##########
@@ -46,15 +50,42 @@ public void mergeResultsBlocks(SelectionResultsBlock 
mergedBlock, SelectionResul
     DataSchema mergedDataSchema = mergedBlock.getDataSchema();
     DataSchema dataSchemaToMerge = blockToMerge.getDataSchema();
     assert mergedDataSchema != null && dataSchemaToMerge != null;
-    if (!mergedDataSchema.equals(dataSchemaToMerge)) {
-      String errorMessage =
-          String.format("Data schema mismatch between merged block: %s and 
block to merge: %s, drop block to merge",
+    QueryContext mergedQueryContext = mergedBlock.getQueryContext();
+    if (!mergedDataSchema.equals(dataSchemaToMerge) && mergedQueryContext != 
null
+            && mergedQueryContext.isSelectStarQuery()) {
+      Map<String, Integer> mergedBlockIndexMap = 
mergedDataSchema.getColumnNameToIndexMap();
+      Map<String, Integer> blockToMergeIndexMap = 
dataSchemaToMerge.getColumnNameToIndexMap();
+
+      List<String> commonColumns = 
mergedBlockIndexMap.keySet().stream().filter(blockToMergeIndexMap::containsKey)
+              .collect(Collectors.toList());
+
+      if (commonColumns.isEmpty()) {
+        String errorMessage = String.format("No common columns to merge 
between merged block:"
+                + " %s and block to merge: %s", mergedDataSchema, 
dataSchemaToMerge);
+        LOGGER.debug(errorMessage);
+        
mergedBlock.addErrorMessage(QueryErrorMessage.safeMsg(QueryErrorCode.MERGE_RESPONSE,
 errorMessage));
+        return;
+      }
+
+      List<Integer> mergedIndices = 
commonColumns.stream().map(mergedBlockIndexMap::get).collect(Collectors.toList());
+      List<Integer> toMergeIndices = 
commonColumns.stream().map(blockToMergeIndexMap::get).collect(Collectors.toList());
+
+      SelectionOperatorUtils.mergeMatchingColumns(mergedBlock, blockToMerge, 
_numRowsToKeep, mergedIndices,
+              toMergeIndices);
+      // Update the data schema of the merged block to only include common 
columns

Review Comment:
   You may want to add an example in comments to describe the logic in this if 
block 



-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to