kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From granthe...@apache.org
Subject [kudu] branch master updated: [java] Allow delete operations with extra columns set
Date Tue, 12 Mar 2019 20:00:09 GMT
This is an automated email from the ASF dual-hosted git repository.

granthenke pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/master by this push:
     new 17fb5a1  [java] Allow delete operations with extra columns set
17fb5a1 is described below

commit 17fb5a10319d2bc19e8e54aa9c088335b04926e9
Author: Grant Henke <granthenke@apache.org>
AuthorDate: Fri Mar 8 14:30:38 2019 -0600

    [java] Allow delete operations with extra columns set
    
    Before this patch, a delete operation required that the
    key columns and only the key columns are set. If any
    additional column was set, the operation would fail
    server side.
    
    With this patch, any non-key columns are stripped
    when encoding the row. This allows extra columns to
    be set in a delete operation client side without inflating the
    message on the wire.
    
    Change-Id: Id302f349a35b9faf7382c74f9a3823f8e76f000c
    Reviewed-on: http://gerrit.cloudera.org:8080/12705
    Tested-by: Kudu Jenkins
    Reviewed-by: Alexey Serbin <aserbin@cloudera.com>
    Reviewed-by: Adar Dembo <adar@cloudera.com>
---
 .../java/org/apache/kudu/client/Operation.java     | 23 ++++++++++++++----
 .../org/apache/kudu/client/TestKuduSession.java    | 27 ++++++++++++++++++++++
 2 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/Operation.java b/java/kudu-client/src/main/java/org/apache/kudu/client/Operation.java
index d1d9748..726a2dc 100644
--- a/java/kudu-client/src/main/java/org/apache/kudu/client/Operation.java
+++ b/java/kudu-client/src/main/java/org/apache/kudu/client/Operation.java
@@ -20,6 +20,7 @@ package org.apache.kudu.client;
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 import java.util.ArrayList;
+import java.util.BitSet;
 import java.util.List;
 
 import com.google.common.base.Preconditions;
@@ -345,15 +346,28 @@ public abstract class Operation extends KuduRpc<OperationResponse>
{
     }
 
     private void encodeRow(PartialRow row, ChangeType type) {
+      int columnCount = row.getSchema().getColumnCount();
+      BitSet columnsBitSet = row.getColumnsBitSet();
+      BitSet nullsBitSet = row.getNullsBitSet();
+
+      // If this is a DELETE operation only the key columns should to be set.
+      if (type == ChangeType.DELETE) {
+        columnCount = row.getSchema().getPrimaryKeyColumnCount();
+        // Clear the bits indicating any non-key fields are set.
+        columnsBitSet.clear(schema.getPrimaryKeyColumnCount(), columnsBitSet.size() - 1);
+        nullsBitSet.clear(schema.getPrimaryKeyColumnCount(), nullsBitSet.size() - 1);
+      }
+
       rows.put(type.toEncodedByte());
-      rows.put(Bytes.fromBitSet(row.getColumnsBitSet(), schema.getColumnCount()));
+      rows.put(Bytes.fromBitSet(columnsBitSet, schema.getColumnCount()));
       if (schema.hasNullableColumns()) {
-        rows.put(Bytes.fromBitSet(row.getNullsBitSet(), schema.getColumnCount()));
+        rows.put(Bytes.fromBitSet(nullsBitSet, schema.getColumnCount()));
       }
-      int colIdx = 0;
+
       byte[] rowData = row.getRowAlloc();
       int currentRowOffset = 0;
-      for (ColumnSchema col : row.getSchema().getColumns()) {
+      for (int colIdx = 0; colIdx < columnCount; colIdx++) {
+        ColumnSchema col = schema.getColumnByIndex(colIdx);
         // Keys should always be specified, maybe check?
         if (row.isSet(colIdx) && !row.isSetToNull(colIdx)) {
           if (col.getType() == Type.STRING || col.getType() == Type.BINARY) {
@@ -370,7 +384,6 @@ public abstract class Operation extends KuduRpc<OperationResponse>
{
           }
         }
         currentRowOffset += col.getTypeSize();
-        colIdx++;
       }
     }
 
diff --git a/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduSession.java b/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduSession.java
index 09bacb1..1df4490 100644
--- a/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduSession.java
+++ b/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduSession.java
@@ -28,6 +28,7 @@ import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import com.google.common.collect.ImmutableList;
@@ -139,6 +140,32 @@ public class TestKuduSession {
     assertEquals(0, countRowsInScan(client.newScannerBuilder(table).build()));
   }
 
+  @Test(timeout = 100000)
+  public void testDeleteWithFullRow() throws Exception {
+    KuduTable table = client.createTable(tableName, basicSchema, getBasicCreateTableOptions());
+
+    KuduSession session = client.newSession();
+    session.setFlushMode(SessionConfiguration.FlushMode.MANUAL_FLUSH);
+
+    List<PartialRow> rows = new ArrayList<>();
+    for (int i = 0; i < 25; i++) {
+      Insert insert = createInsert(table, i);
+      rows.add(insert.getRow());
+      session.apply(insert);
+    }
+    session.flush();
+
+    for (PartialRow row : rows) {
+      Delete del = table.newDelete();
+      del.setRow(row);
+      session.apply(del);
+    }
+    session.flush();
+
+    assertEquals(0, session.countPendingErrors());
+    assertEquals(0, countRowsInScan(client.newScannerBuilder(table).build()));
+  }
+
   /**
    * Regression test for KUDU-1402. Calls to session.flush() should return an empty list
    * instead of null.


Mime
View raw message