virajjasani commented on code in PR #2209:
URL: https://github.com/apache/phoenix/pull/2209#discussion_r2188069520


##########
phoenix-core-server/src/main/java/org/apache/phoenix/coprocessor/CDCGlobalIndexRegionScanner.java:
##########
@@ -259,4 +310,44 @@ private Object getColumnValue(byte[] cellValue, int 
offset, int length, PDataTyp
         }
         return CDCUtil.getColumnEncodedValue(value, dataType);
     }
+
+    /**
+     * Handles CDC events that already contain pre-image data, avoiding data 
table scan.
+     * Supports both the new CDC_IMAGE_CQ column and traditional CDC JSON 
column.
+     *
+     * @param indexRow    The CDC index row cells
+     * @param indexRowKey The CDC index row key
+     * @param indexCell   The primary index cell
+     * @param result      The result list to populate
+     * @return true if event was processed successfully
+     */
+    private boolean handlePreImageCDCEvent(List<Cell> indexRow, byte[] 
indexRowKey,
+                                           Cell indexCell, List<Cell> result) {
+        Cell cdcDataCell = null;
+        for (Cell cell : indexRow) {
+            if (Bytes.equals(cell.getQualifierArray(), 
cell.getQualifierOffset(),
+                    cell.getQualifierLength(),
+                    QueryConstants.CDC_IMAGE_CQ_BYTES, 0,
+                    QueryConstants.CDC_IMAGE_CQ_BYTES.length)) {
+                cdcDataCell = cell;
+                break;
+            }
+        }
+        if (cdcDataCell == null) {
+            return false;
+        }
+        byte[] cdcEventBytes = CellUtil.cloneValue(cdcDataCell);

Review Comment:
   To retrieve value bytes directly from Cell object, we use 
`CellUtil.cloneValue()` almost every place possible.
   On the other hand `copyBytesIfNecessary()` is also doing copy similar to 
`CellUtil.cloneValue()`:
   ```
       public static byte[] copyBytesIfNecessary(byte[] bytes, int offset, int 
length) {
           if (offset == 0 && length == bytes.length) {
               return bytes;
           }
           return Arrays.copyOfRange(bytes, offset, offset + 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: issues-unsubscr...@phoenix.apache.org

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

Reply via email to