tkhurana commented on code in PR #1967:
URL: https://github.com/apache/phoenix/pull/1967#discussion_r1750816331
##########
phoenix-core-server/src/main/java/org/apache/phoenix/hbase/index/IndexRegionObserver.java:
##########
@@ -1586,29 +1661,61 @@ public Void visit(KeyValueColumnExpression expression) {
* Otherwise, we will generate one Put mutation and optionally one Delete
mutation (with
* DeleteColumn type cells for all columns set to null).
*/
- private List<Mutation> generateOnDupMutations(BatchMutateContext context,
Put atomicPut) throws IOException {
+ private List<Mutation> generateOnDupMutations(BatchMutateContext context,
+ Put atomicPut,
+
MiniBatchOperationInProgress<Mutation> miniBatchOp)
+ throws IOException {
List<Mutation> mutations = Lists.newArrayListWithExpectedSize(2);
byte[] opBytes = atomicPut.getAttribute(ATOMIC_OP_ATTRIB);
- if (opBytes == null) { // Unexpected
- return null;
- }
+ byte[] returnResult = atomicPut.getAttribute(RETURN_RESULT);
+ if ((opBytes == null && returnResult == null) ||
+ (opBytes == null && miniBatchOp.size() != 1)) {
+ // Unexpected
+ // Either mutation should be atomic by providing non-null ON
DUPLICATE KEY, or
+ // if the result needs to be returned, only single row must be
updated as part of
+ // the batch mutation.
+ return null;
+ }
Put put = null;
Delete delete = null;
// mutations returned by this function will have the LATEST timestamp
// later these timestamps will be updated by the
IndexRegionObserver#setTimestamps() function
long ts = HConstants.LATEST_TIMESTAMP;
- byte[] rowKey = atomicPut.getRow();
+ // store current cells into a map where the key is ColumnReference of
the column family and
+ // column qualifier, and value is a pair of cell and a boolean. The
value of the boolean
+ // will be true if the expression is CaseExpression and Else-clause is
evaluated to be
+ // true, will be null if there is no expression on this column,
otherwise false
+ Map<ColumnReference, Pair<Cell, Boolean>> currColumnCellExprMap = new
HashMap<>();
+
+ byte[] rowKey = atomicPut.getRow();
ImmutableBytesPtr rowKeyPtr = new ImmutableBytesPtr(rowKey);
// Get the latest data row state
Pair<Put, Put> dataRowState = context.dataRowStates.get(rowKeyPtr);
Put currentDataRowState = dataRowState != null ? dataRowState.getFirst()
: null;
+ // if result needs to be returned but the DML does not have ON
DUPLICATE KEY present,
+ // perform the mutation and return the result.
+ if (opBytes == null) {
+ mutations.add(atomicPut);
+ updateCurrColumnCellExpr(atomicPut, currColumnCellExprMap);
Review Comment:
atomicPut will only contain columns which are being updated. So in case of
partial update we will be returning only those columns instead of the full row.
--
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]