This is an automated email from the ASF dual-hosted git repository.

alexey 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 2696d5d04 KUDU-2671 show custom hash schema in formatRangePartition
2696d5d04 is described below

commit 2696d5d044a44f35abf906ac371eebd627c98d08
Author: Kurt Deschler <kdesc...@cloudera.com>
AuthorDate: Fri Jul 1 21:33:58 2022 -0500

    KUDU-2671 show custom hash schema in formatRangePartition
    
    This patch introduces a new method targeted for Impala for formatted
    output of table's range partitions along with hash their schemas.
    Hash schema information is appended to each range partition.
    
    Several test scenarios in TestKuduTable are updated to provide coverage
    for the functionality of the newly introduced method
    KuduTable.getFormattedRangePartitionsWithHashSchema().
    
    Change-Id: Ia1a014ad820b2d73ea09fe3f67baefe9d0acb7aa
    Reviewed-on: http://gerrit.cloudera.org:8080/18693
    Tested-by: Alexey Serbin <ale...@apache.org>
    Reviewed-by: Kurt Deschler <kdesc...@cloudera.com>
    Reviewed-by: Alexey Serbin <ale...@apache.org>
---
 .../java/org/apache/kudu/client/KuduTable.java     | 22 ++++++++++-
 .../java/org/apache/kudu/client/Partition.java     | 27 ++++++++++++-
 .../java/org/apache/kudu/client/TestKuduTable.java | 46 ++++++++++++++--------
 3 files changed, 76 insertions(+), 19 deletions(-)

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 b6fee17cf..c5a7c2636 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
@@ -303,7 +303,27 @@ public class KuduTable {
     List<Partition> rangePartitions = getRangePartitions(timeout);
     List<String> formattedPartitions = new ArrayList<>();
     for (Partition partition : rangePartitions) {
-      formattedPartitions.add(partition.formatRangePartition(this));
+      formattedPartitions.add(partition.formatRangePartition(this, false));
+    }
+    return formattedPartitions;
+  }
+
+  /**
+   * Retrieves a formatted representation of this table's range partitions 
along
+   * with hash schema output for each range. The range partitions are returned
+   * in sorted order by value and contain no duplicates.
+   *
+   * @param timeout the timeout of the operation
+   * @return a list of the formatted range partitions with hash schema for each
+   */
+  @InterfaceAudience.LimitedPrivate("Impala")
+  @InterfaceStability.Unstable
+  public List<String> getFormattedRangePartitionsWithHashSchema(long timeout)
+      throws Exception {
+    List<Partition> rangePartitions = getRangePartitions(timeout);
+    List<String> formattedPartitions = new ArrayList<>();
+    for (Partition partition : rangePartitions) {
+      formattedPartitions.add(partition.formatRangePartition(this, true));
     }
     return formattedPartitions;
   }
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 7f9a80f57..1fce1e2b5 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
@@ -220,9 +220,10 @@ public class Partition implements Comparable<Partition> {
    * Formats the range partition into a string suitable for debug printing.
    *
    * @param table that this partition belongs to
+   * @param showHashInfo whether to output hash schema info per range
    * @return a string containing a formatted representation of the range 
partition
    */
-  String formatRangePartition(KuduTable table) {
+  String formatRangePartition(KuduTable table, boolean showHashInfo) {
     Schema schema = table.getSchema();
     PartitionSchema partitionSchema = table.getPartitionSchema();
     PartitionSchema.RangeSchema rangeSchema = partitionSchema.getRangeSchema();
@@ -296,6 +297,30 @@ public class Partition implements Comparable<Partition> {
       }
     }
 
+    if (showHashInfo) {
+      List<PartitionSchema.HashBucketSchema> hashSchema =
+          partitionSchema.getHashSchemaForRange(rangeKeyStart);
+      boolean firstHashDimension = true;
+      for (PartitionSchema.HashBucketSchema hashDimension : hashSchema) {
+        if (firstHashDimension) {
+          firstHashDimension = false;
+        } else {
+          sb.append(',');
+        }
+        sb.append(" HASH(");
+        boolean firstId = true;
+        for (Integer id : hashDimension.getColumnIds()) {
+          if (firstId) {
+            firstId = false;
+          } else {
+            sb.append(',');
+          }
+          
sb.append(schema.getColumnByIndex(schema.getColumnIndex(id)).getName());
+        }
+        sb.append(") PARTITIONS ");
+        sb.append(hashDimension.getNumBuckets());
+      }
+    }
     return sb.toString();
   }
 }
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 4385a5df0..40a94c52f 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
@@ -538,11 +538,12 @@ public class TestKuduTable {
       assertEquals(100, rangeKeyEndDecoded.getInt(0));
     }
 
-    List<String> expected = Lists.newArrayList();
-    expected.add("-100 <= VALUES < 100");
     assertEquals(
-        expected,
+        ImmutableList.of("-100 <= VALUES < 100"),
         client.openTable(tableName).getFormattedRangePartitions(10000));
+    assertEquals(
+        ImmutableList.of("-100 <= VALUES < 100"),
+        
client.openTable(tableName).getFormattedRangePartitionsWithHashSchema(10000));
   }
 
   @Test(timeout = 100000)
@@ -574,11 +575,12 @@ public class TestKuduTable {
 
     KuduTable table = client.createTable(tableName, basicSchema, builder);
 
-    List<String> expected = Lists.newArrayList();
-    expected.add("-100 <= VALUES < 200");
     assertEquals(
-        expected,
+        ImmutableList.of("-100 <= VALUES < 200"),
         client.openTable(tableName).getFormattedRangePartitions(10000));
+    assertEquals(
+        ImmutableList.of("-100 <= VALUES < 200 HASH(key) PARTITIONS 2"),
+        
client.openTable(tableName).getFormattedRangePartitionsWithHashSchema(10000));
 
     // Check the result: retrieve the information on tablets from master
     // and check if each partition has expected parameters.
@@ -751,12 +753,14 @@ public class TestKuduTable {
     // There should be 5 tablets: 2 for [0, 100) range and 3 for [100, 200).
     assertEquals(5, tablets.size());
 
-    List<String> expected = Lists.newArrayList();
-    expected.add("0 <= VALUES < 100");
-    expected.add("100 <= VALUES < 200");
     assertEquals(
-        expected,
+        ImmutableList.of("0 <= VALUES < 100", "100 <= VALUES < 200"),
         client.openTable(tableName).getFormattedRangePartitions(10000));
+    assertEquals(
+        ImmutableList.of(
+            "0 <= VALUES < 100 HASH(key) PARTITIONS 2",
+            "100 <= VALUES < 200 HASH(key) PARTITIONS 3"),
+        
client.openTable(tableName).getFormattedRangePartitionsWithHashSchema(10000));
 
     // Insert data into the newly created table and read it back.
     KuduSession session = client.newSession();
@@ -938,12 +942,14 @@ public class TestKuduTable {
     // There should be 7 tablets: 2 for the [0, 100) range and 5 for [100, 
200).
     assertEquals(7, tablets.size());
 
-    List<String> expected = Lists.newArrayList();
-    expected.add("0 <= VALUES < 100");
-    expected.add("100 <= VALUES < 200");
     assertEquals(
-        expected,
+        ImmutableList.of("0 <= VALUES < 100", "100 <= VALUES < 200"),
         client.openTable(tableName).getFormattedRangePartitions(10000));
+    assertEquals(
+        ImmutableList.of(
+            "0 <= VALUES < 100 HASH(key) PARTITIONS 2",
+            "100 <= VALUES < 200 HASH(key) PARTITIONS 5"),
+        
client.openTable(tableName).getFormattedRangePartitionsWithHashSchema(10000));
 
     // Insert data into the newly created table and read it back.
     KuduSession session = client.newSession();
@@ -1787,6 +1793,9 @@ public class TestKuduTable {
     assertEquals(
         ImmutableList.of("-100 <= VALUES < 100"),
         client.openTable(tableName).getFormattedRangePartitions(10000));
+    assertEquals(
+        ImmutableList.of("-100 <= VALUES < 100 HASH(key) PARTITIONS 2"),
+        
client.openTable(tableName).getFormattedRangePartitionsWithHashSchema(10000));
 
     {
       PartialRow lower = schema.newPartialRow();
@@ -1808,11 +1817,14 @@ public class TestKuduTable {
 
     final KuduTable table = client.openTable(tableName);
 
-    List<String> expected = ImmutableList.of(
-        "-100 <= VALUES < 100", "100 <= VALUES < 200");
     assertEquals(
-        expected,
+        ImmutableList.of("-100 <= VALUES < 100", "100 <= VALUES < 200"),
         client.openTable(tableName).getFormattedRangePartitions(10000));
+    assertEquals(
+        ImmutableList.of(
+            "-100 <= VALUES < 100 HASH(key) PARTITIONS 2",
+            "100 <= VALUES < 200 HASH(key) PARTITIONS 7"),
+        
client.openTable(tableName).getFormattedRangePartitionsWithHashSchema(10000));
 
     final PartitionSchema ps = 
client.openTable(tableName).getPartitionSchema();
     assertTrue(ps.hasCustomHashSchemas());

Reply via email to