You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by gr...@apache.org on 2019/02/13 17:59:08 UTC

[kudu] 03/03: [Java] Add setRow to Operation

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

commit 9b698e98e87024e64f8fd515fd8241c21ba130bb
Author: Grant Henke <gr...@apache.org>
AuthorDate: Fri Feb 8 09:39:22 2019 -0600

    [Java] Add setRow to Operation
    
    Adds a setRow method to Operation to allow for existing
    rows to be added to an operation vs being manually built.
    
    Change-Id: I7adee20166e90249209e80700db315172669edb5
    Reviewed-on: http://gerrit.cloudera.org:8080/12409
    Reviewed-by: Adar Dembo <ad...@cloudera.com>
    Tested-by: Kudu Jenkins
---
 .../java/org/apache/kudu/client/Operation.java     | 25 +++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

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 3d04450..c0a83af 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
@@ -22,6 +22,7 @@ import java.nio.ByteOrder;
 import java.util.ArrayList;
 import java.util.List;
 
+import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.protobuf.ByteString;
 import com.google.protobuf.Message;
@@ -82,7 +83,7 @@ public abstract class Operation extends KuduRpc<OperationResponse> {
 
   static final String METHOD = "Write";
 
-  private final PartialRow row;
+  private PartialRow row;
 
   /** See {@link SessionConfiguration#setIgnoreAllDuplicateRows(boolean)} */
   boolean ignoreAllDuplicateRows = false;
@@ -180,6 +181,28 @@ public abstract class Operation extends KuduRpc<OperationResponse> {
     return this.row;
   }
 
+  /**
+   * Set the underlying row.
+   *
+   * Note: The schema of the underlying row and the table must be equal by reference.
+   * To ensure they are equal, create the partial row from the table's schema.
+   *
+   * <pre>{@code
+   *   KuduTable table = client.openTable("my-table");
+   *   PartialRow row = table.getSchema().newPartialRow();
+   *   ...
+   *   Operation op = table.newInsert();
+   *   op.setRow(row);
+   * }</pre>
+   *
+   * @param row the row to set
+   */
+  public void setRow(PartialRow row) {
+    Preconditions.checkArgument(row.getSchema() == table.getSchema(),
+        "The row's schema must be equal by reference to the table schema");
+    this.row = row;
+  }
+
   @Override
   void updateStatistics(Statistics statistics, OperationResponse response) {
     String tabletId = this.getTablet().getTabletId();