kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpe...@apache.org
Subject [1/2] kudu git commit: [Java] Add private API to get a table range partitions
Date Sat, 09 Jun 2018 01:04:11 GMT
Repository: kudu
Updated Branches:
  refs/heads/master 220cd66f2 -> a9a54ec94


[Java] Add private API to get a table range partitions

Adds a private API to KuduTable to get the range
partitions. This is similar to getFormattedRangePartitions
but a bit more generic because it returns Partiton and
PartialRow objects instead of a specially formatted string.

Change-Id: I612b93fbebc6f2f1c449bb3c7f2e561f1485a720
Reviewed-on: http://gerrit.cloudera.org:8080/10547
Tested-by: Kudu Jenkins
Reviewed-by: Adar Dembo <adar@cloudera.com>
Reviewed-by: Dan Burkert <danburkert@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/dd71ddc3
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/dd71ddc3
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/dd71ddc3

Branch: refs/heads/master
Commit: dd71ddc3ef5e201378bd151d884c377c085a94fa
Parents: 220cd66
Author: Grant Henke <granthenke@apache.org>
Authored: Wed May 30 13:05:44 2018 -0500
Committer: Grant Henke <granthenke@apache.org>
Committed: Thu Jun 7 23:55:46 2018 +0000

----------------------------------------------------------------------
 .../java/org/apache/kudu/client/KuduTable.java  | 31 +++++++++--
 .../org/apache/kudu/client/LocatedTablet.java   |  1 +
 .../java/org/apache/kudu/client/Partition.java  | 28 ++++++++++
 .../org/apache/kudu/client/TestKuduTable.java   | 58 ++++++++++++++++++++
 4 files changed, 113 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/dd71ddc3/java/kudu-client/src/main/java/org/apache/kudu/client/KuduTable.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/KuduTable.java b/java/kudu-client/src/main/java/org/apache/kudu/client/KuduTable.java
index 83186d9..4c50094 100644
--- a/java/kudu-client/src/main/java/org/apache/kudu/client/KuduTable.java
+++ b/java/kudu-client/src/main/java/org/apache/kudu/client/KuduTable.java
@@ -227,15 +227,36 @@ public class KuduTable {
    * range partitions will be returned in sorted order by value, and will
    * contain no duplicates.
    *
-   * @param deadline the deadline of the operation
+   * @param timeout the timeout of the operation
    * @return a list of the formatted range partitions
    */
   @InterfaceAudience.LimitedPrivate("Impala")
   @InterfaceStability.Unstable
-  public List<String> getFormattedRangePartitions(long deadline) throws Exception {
-    List<String> rangePartitions = new ArrayList<>();
+  public List<String> getFormattedRangePartitions(long timeout) throws Exception {
+    List<Partition> rangePartitions = getRangePartitions(timeout);
+    List<String> formattedPartitions = new ArrayList<>();
+    for (Partition partition : rangePartitions) {
+      formattedPartitions.add(partition.formatRangePartition(this));
+    }
+    return formattedPartitions;
+  }
+
+  /**
+   * Retrieves this table's range partitions. The range partitions will be returned
+   * in sorted order by value, and will contain no duplicates.
+   *
+   * @param timeout the timeout of the operation
+   * @return a list of the formatted range partitions
+   */
+  @InterfaceAudience.Private
+  @InterfaceStability.Unstable
+  public List<Partition> getRangePartitions(long timeout) throws Exception {
+    // TODO: This could be moved into the RangeSchemaPB returned from server
+    // to avoid an extra call to get the range partitions.
+    List<Partition> rangePartitions = new ArrayList<>();
     List<KuduScanToken> scanTokens = new KuduScanToken.KuduScanTokenBuilder(client,
this)
-        .setTimeout(deadline).build();
+      .setTimeout(timeout)
+      .build();
     for (KuduScanToken token : scanTokens) {
       Partition partition = token.getTablet().getPartition();
       // Filter duplicate range partitions by taking only the tablets whose hash
@@ -243,7 +264,7 @@ public class KuduTable {
       if (!Iterators.all(partition.getHashBuckets().iterator(), Predicates.equalTo(0))) {
         continue;
       }
-      rangePartitions.add(partition.formatRangePartition(this));
+      rangePartitions.add(partition);
     }
     return rangePartitions;
   }

http://git-wip-us.apache.org/repos/asf/kudu/blob/dd71ddc3/java/kudu-client/src/main/java/org/apache/kudu/client/LocatedTablet.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/LocatedTablet.java b/java/kudu-client/src/main/java/org/apache/kudu/client/LocatedTablet.java
index af2546e..7539d8a 100644
--- a/java/kudu-client/src/main/java/org/apache/kudu/client/LocatedTablet.java
+++ b/java/kudu-client/src/main/java/org/apache/kudu/client/LocatedTablet.java
@@ -51,6 +51,7 @@ public class LocatedTablet {
     return replicas;
   }
 
+  @InterfaceAudience.LimitedPrivate("Impala")
   public Partition getPartition() {
     return partition;
   }

http://git-wip-us.apache.org/repos/asf/kudu/blob/dd71ddc3/java/kudu-client/src/main/java/org/apache/kudu/client/Partition.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/Partition.java b/java/kudu-client/src/main/java/org/apache/kudu/client/Partition.java
index 46a7a6c..410f6eb 100644
--- a/java/kudu-client/src/main/java/org/apache/kudu/client/Partition.java
+++ b/java/kudu-client/src/main/java/org/apache/kudu/client/Partition.java
@@ -98,6 +98,20 @@ public class Partition implements Comparable<Partition> {
   }
 
   /**
+   * Gets the decoded start range key.
+   * @return the decoded start range key
+   */
+  public PartialRow getDecodedRangeKeyStart(KuduTable table) {
+    Schema schema = table.getSchema();
+    if (rangeKeyStart.length == 0) {
+      return schema.newPartialRow();
+    } else {
+      PartitionSchema partitionSchema = table.getPartitionSchema();
+      return KeyEncoder.decodeRangePartitionKey(schema, partitionSchema, rangeKeyStart);
+    }
+  }
+
+  /**
    * Gets the end range key.
    * @return the end range key
    */
@@ -106,6 +120,20 @@ public class Partition implements Comparable<Partition> {
   }
 
   /**
+   * Gets the decoded end range key.
+   * @return the decoded end range key
+   */
+  public PartialRow getDecodedRangeKeyEnd(KuduTable table) {
+    Schema schema = table.getSchema();
+    if (rangeKeyEnd.length == 0) {
+      return schema.newPartialRow();
+    } else {
+      PartitionSchema partitionSchema = table.getPartitionSchema();
+      return KeyEncoder.decodeRangePartitionKey(schema, partitionSchema, rangeKeyEnd);
+    }
+  }
+
+  /**
    * Gets the partition hash buckets.
    * @return the partition hash buckets
    */

http://git-wip-us.apache.org/repos/asf/kudu/blob/dd71ddc3/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduTable.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduTable.java b/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduTable.java
index 7f19e43..dd99b83 100644
--- a/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduTable.java
+++ b/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduTable.java
@@ -576,6 +576,64 @@ public class TestKuduTable extends BaseKuduTest {
   }
 
   @Test(timeout = 100000)
+  public void testGetRangePartitions() throws Exception {
+    String tableName = name.getMethodName() + System.currentTimeMillis();
+
+    ArrayList<ColumnSchema> columns = new ArrayList<>();
+    columns.add(new ColumnSchema.ColumnSchemaBuilder("a", Type.STRING).key(true).build());
+    columns.add(new ColumnSchema.ColumnSchemaBuilder("b", Type.INT8).key(true).build());
+    Schema schema = new Schema(columns);
+
+    CreateTableOptions builder = new CreateTableOptions();
+    builder.addHashPartitions(ImmutableList.of("a"), 2);
+    builder.addHashPartitions(ImmutableList.of("b"), 2);
+    builder.setRangePartitionColumns(ImmutableList.of("a", "b"));
+
+    PartialRow bottom = schema.newPartialRow();
+    PartialRow middle = schema.newPartialRow();
+    middle.addString("a", "");
+    middle.addByte("b", (byte) -100);
+    PartialRow upper = schema.newPartialRow();
+
+    builder.addRangePartition(bottom, middle);
+    builder.addRangePartition(middle, upper);
+
+    KuduTable table = createTable(tableName, schema, builder);
+
+    List<Partition> rangePartitions =
+        table.getRangePartitions(client.getDefaultOperationTimeoutMs());
+    assertEquals(rangePartitions.size(), 2);
+
+    Partition lowerPartition = rangePartitions.get(0);
+    assertEquals(0, lowerPartition.getRangeKeyStart().length);
+    assertTrue(lowerPartition.getRangeKeyEnd().length > 0);
+    PartialRow decodedLower = lowerPartition.getDecodedRangeKeyEnd(table);
+    assertEquals("", decodedLower.getString("a"));
+    assertEquals((byte) -100, decodedLower.getByte("b"));
+
+    Partition upperPartition = rangePartitions.get(1);
+    assertTrue(upperPartition.getRangeKeyStart().length > 0);
+    assertEquals(0, upperPartition.getRangeKeyEnd().length);
+    PartialRow decodedUpper = upperPartition.getDecodedRangeKeyStart(table);
+    assertEquals("", decodedUpper.getString("a"));
+    assertEquals((byte) -100, decodedUpper.getByte("b"));
+  }
+
+  @Test(timeout = 100000)
+  public void testGetRangePartitionsUnbounded() throws Exception {
+    String tableName = name.getMethodName() + System.currentTimeMillis();
+    CreateTableOptions builder = getBasicCreateTableOptions();
+    KuduTable table = createTable(tableName, schema, builder);
+
+    List<Partition> rangePartitions =
+        table.getRangePartitions(client.getDefaultOperationTimeoutMs());
+    assertEquals(rangePartitions.size(), 1);
+    Partition partition = rangePartitions.get(0);
+    assertEquals(0, partition.getRangeKeyStart().length);
+    assertEquals(0, partition.getRangeKeyEnd().length);
+  }
+
+  @Test(timeout = 100000)
   public void testAlterNoWait() throws Exception {
     String tableName = name.getMethodName() + System.currentTimeMillis();
     createTable(tableName, basicSchema, getBasicCreateTableOptions());


Mime
View raw message