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 f39a422db KUDU-1261 apply ARRAY_1D_COLUMN_TYPE in Java client
f39a422db is described below

commit f39a422db9eb4b9687bc9b7bec1b7046e3b0e410
Author: Alexey Serbin <[email protected]>
AuthorDate: Wed Oct 22 14:31:21 2025 -0700

    KUDU-1261 apply ARRAY_1D_COLUMN_TYPE in Java client
    
    This changelist updates Kudu Java client to require a Kudu cluster
    (in particular, Kudu master) to support ARRAY_1D_COLUMN_TYPE feature
    when creating a new table with array type columns or altering an already
    existing table by adding a new array type column.  New test scenarios
    to cover the newly added functionality are present as well.
    
    This is a follow-up to 9e39015095f5a8a3f33bc87fe19617c7d3caf410.
    
    Change-Id: I63e9b2c508f581c47f538d85ed83e879d9673d28
    Reviewed-on: http://gerrit.cloudera.org:8080/23573
    Reviewed-by: Abhishek Chennaka <[email protected]>
    Tested-by: Alexey Serbin <[email protected]>
---
 .../main/java/org/apache/kudu/ColumnSchema.java    |  7 ++++
 .../src/main/java/org/apache/kudu/Schema.java      | 12 ++++++-
 .../org/apache/kudu/client/AlterTableOptions.java  |  6 ++++
 .../org/apache/kudu/client/CreateTableOptions.java |  4 +++
 .../org/apache/kudu/client/TestKuduClient.java     | 42 ++++++++++++++++++++++
 5 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/java/kudu-client/src/main/java/org/apache/kudu/ColumnSchema.java 
b/java/kudu-client/src/main/java/org/apache/kudu/ColumnSchema.java
index 3be19a028..e5706e156 100644
--- a/java/kudu-client/src/main/java/org/apache/kudu/ColumnSchema.java
+++ b/java/kudu-client/src/main/java/org/apache/kudu/ColumnSchema.java
@@ -188,6 +188,13 @@ public class ColumnSchema {
     return autoIncrementing;
   }
 
+  /**
+   * @return true if the column is of a nested (i.e. non-scalar) type
+   */
+  public boolean isNestedType() {
+    return nestedTypeDescriptor != null;
+  }
+
   /**
    * The Java object representation of the default value that's read
    * @return the default read value
diff --git a/java/kudu-client/src/main/java/org/apache/kudu/Schema.java 
b/java/kudu-client/src/main/java/org/apache/kudu/Schema.java
index 335bd512b..7c60a41f7 100644
--- a/java/kudu-client/src/main/java/org/apache/kudu/Schema.java
+++ b/java/kudu-client/src/main/java/org/apache/kudu/Schema.java
@@ -83,7 +83,7 @@ public class Schema {
   private final boolean hasNullableColumns;
   private final boolean hasImmutableColumns;
   private final boolean hasAutoIncrementingColumn;
-
+  private final boolean hasNestedTypeColumns;
   private final int isDeletedIndex;
   private static final int NO_IS_DELETED_INDEX = -1;
 
@@ -173,6 +173,7 @@ public class Schema {
     int offset = 0;
     boolean hasNulls = false;
     boolean hasImmutables = false;
+    boolean hasNestedTypeColumns = false;
     int isDeletedIndex = NO_IS_DELETED_INDEX;
     // pre-compute a few counts and offsets
     for (int index = 0; index < columns.size(); index++) {
@@ -183,6 +184,7 @@ public class Schema {
 
       hasNulls |= column.isNullable();
       hasImmutables |= column.isImmutable();
+      hasNestedTypeColumns |= column.isNestedType();
       columnOffsets[index] = offset;
       offset += column.getTypeSize();
       if (this.columnsByName.put(column.getName(), index) != null) {
@@ -216,6 +218,7 @@ public class Schema {
     this.hasNullableColumns = hasNulls;
     this.hasImmutableColumns = hasImmutables;
     this.hasAutoIncrementingColumn = hasAutoIncrementing;
+    this.hasNestedTypeColumns = hasNestedTypeColumns;
     this.isDeletedIndex = isDeletedIndex;
   }
 
@@ -370,6 +373,13 @@ public class Schema {
     return this.hasAutoIncrementingColumn;
   }
 
+  /**
+   * @return true if the schema has at least one column of a nested type, 
false otherwise
+   */
+  public boolean hasNestedTypeColumns() {
+    return hasNestedTypeColumns;
+  }
+
   /**
    * Get the name of the auto-incrementing column
    * @return column name of the auto-incrementing column.
diff --git 
a/java/kudu-client/src/main/java/org/apache/kudu/client/AlterTableOptions.java 
b/java/kudu-client/src/main/java/org/apache/kudu/client/AlterTableOptions.java
index f3d7e4637..7ee79a672 100644
--- 
a/java/kudu-client/src/main/java/org/apache/kudu/client/AlterTableOptions.java
+++ 
b/java/kudu-client/src/main/java/org/apache/kudu/client/AlterTableOptions.java
@@ -48,6 +48,7 @@ public class AlterTableOptions {
   private final AlterTableRequestPB.Builder pb = 
AlterTableRequestPB.newBuilder();
   private boolean wait = true;
   private boolean isAddingRangeWithCustomHashSchema = false;
+  private boolean isAddingNestedTypeColumn = false;
 
   /**
    * Change a table's name.
@@ -95,6 +96,7 @@ public class AlterTableOptions {
     if (colSchema.isKey()) {
       throw new IllegalArgumentException("Key columns cannot be added");
     }
+    this.isAddingNestedTypeColumn |= colSchema.isNestedType();
     AlterTableRequestPB.Step.Builder step = pb.addAlterSchemaStepsBuilder();
     step.setType(AlterTableRequestPB.StepType.ADD_COLUMN);
     step.setAddColumn(AlterTableRequestPB.AddColumn.newBuilder()
@@ -600,6 +602,10 @@ public class AlterTableOptions {
                 
Integer.valueOf(Master.MasterFeatures.RANGE_SPECIFIC_HASH_SCHEMA_VALUE));
       }
     }
+    if (isAddingNestedTypeColumn) {
+      requiredFeatureFlags.add(
+          Integer.valueOf(Master.MasterFeatures.ARRAY_1D_COLUMN_TYPE_VALUE));
+    }
     return requiredFeatureFlags;
   }
 }
diff --git 
a/java/kudu-client/src/main/java/org/apache/kudu/client/CreateTableOptions.java 
b/java/kudu-client/src/main/java/org/apache/kudu/client/CreateTableOptions.java
index d577a590f..7b0b644b8 100644
--- 
a/java/kudu-client/src/main/java/org/apache/kudu/client/CreateTableOptions.java
+++ 
b/java/kudu-client/src/main/java/org/apache/kudu/client/CreateTableOptions.java
@@ -352,6 +352,10 @@ public class CreateTableOptions {
       requiredFeatureFlags.add(
               
Integer.valueOf(Master.MasterFeatures.RANGE_SPECIFIC_HASH_SCHEMA_VALUE));
     }
+    if (schema.hasNestedTypeColumns()) {
+      requiredFeatureFlags.add(
+          Integer.valueOf(Master.MasterFeatures.ARRAY_1D_COLUMN_TYPE_VALUE));
+    }
 
     return requiredFeatureFlags;
   }
diff --git 
a/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduClient.java 
b/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduClient.java
index be42de4ec..c2640fe3d 100644
--- a/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduClient.java
+++ b/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduClient.java
@@ -1242,6 +1242,48 @@ public class TestKuduClient {
     client.deleteTable(TABLE_NAME);
   }
 
+  /**
+   * Test an attempt to create a new table with array type column
+   * when the cluster doesn't support tables with 1D array columns.
+   */
+  @MasterServerConfig(flags = {
+      "--master_support_1d_array_columns=false",
+  })
+  @Test(timeout = 100000)
+  public void testCreateTableWithArrayColumnUnsupportedFeatureFlags() throws 
Exception {
+    try {
+      Schema schema = createSchemaWithArrayColumns();
+      client.createTable(TABLE_NAME, schema, getBasicCreateTableOptions());
+      fail("should have failed with 'unsupported feature flags' server-side 
error");
+    } catch (RpcRemoteException e) {
+      assertTrue(e.getMessage().contains("server sent error unsupported 
feature flags"));
+    }
+  }
+
+  /**
+   * Test an attempt to add a new array column into an existing table
+   * when the cluster doesn't support tables with 1D array columns.
+   */
+  @MasterServerConfig(flags = {
+      "--master_support_1d_array_columns=false",
+  })
+  @Test(timeout = 100000)
+  public void testAddArrayColumnUnsupportedFeatureFlags() throws Exception {
+    try {
+      AlterTableOptions alter = new AlterTableOptions();
+      ColumnSchema col =
+          new ColumnSchema.ColumnSchemaBuilder("int32_arr", Type.INT32)
+              .array(true)
+              .nullable(true)
+              .build();
+      alter.addColumn(col);
+      client.alterTable(TABLE_NAME, alter);
+      fail("should have failed with 'unsupported feature flags' server-side 
error");
+    } catch (RpcRemoteException e) {
+      assertTrue(e.getMessage().contains("server sent error unsupported 
feature flags"));
+    }
+  }
+
   /**
    * Test inserting and retrieving rows from a table that has a range partition
    * with custom hash schema.

Reply via email to