This is an automated email from the ASF dual-hosted git repository.
achennaka 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 5cc5d42ca KUDU-1261 [Java] Add guard rails for Array type columns
5cc5d42ca is described below
commit 5cc5d42ca254c9f859575d86eb975c65a529f331
Author: Abhishek Chennaka <[email protected]>
AuthorDate: Thu Oct 23 13:46:56 2025 -0700
KUDU-1261 [Java] Add guard rails for Array type columns
This patch adds the needed checks to make sure the Array type columns
- Cannot have default values
- Cannot be a part of primary key columns
Once the functionality has been implemented, the guard rails can
be removed.
Change-Id: I4959369b19cf338b88508e032b3dd1878d666857
Reviewed-on: http://gerrit.cloudera.org:8080/23587
Reviewed-by: Alexey Serbin <[email protected]>
Tested-by: Abhishek Chennaka <[email protected]>
---
.../main/java/org/apache/kudu/ColumnSchema.java | 11 +++++++++
.../java/org/apache/kudu/TestColumnSchema.java | 27 ++++++++++++++++++++++
2 files changed, 38 insertions(+)
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 c8e5ca41c..ff8d6159d 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
@@ -678,6 +678,17 @@ public class ColumnSchema {
new ColumnSchema.ArrayTypeDescriptor(this.type);
nestedDesc = ColumnSchema.NestedTypeDescriptor.forArray(arrDesc);
finalType = Type.NESTED;
+ // Array type columns cannot have default values or be key columns yet
+ if (this.defaultValue != null) {
+ throw new IllegalArgumentException(
+ String.format("Array type column: %s cannot have a default
value",
+ this.name));
+ }
+ if (this.key) {
+ throw new IllegalArgumentException(
+ String.format("Array type column: %s cannot be a key column",
+ this.name));
+ }
} else {
nestedDesc = null;
finalType = this.type;
diff --git
a/java/kudu-client/src/test/java/org/apache/kudu/TestColumnSchema.java
b/java/kudu-client/src/test/java/org/apache/kudu/TestColumnSchema.java
index 0f7ea8cd7..6f8852b64 100644
--- a/java/kudu-client/src/test/java/org/apache/kudu/TestColumnSchema.java
+++ b/java/kudu-client/src/test/java/org/apache/kudu/TestColumnSchema.java
@@ -266,4 +266,31 @@ public class TestColumnSchema {
assertEquals(arrayCol.getTypeAttributes(), arrayCopy.getTypeAttributes());
}
+ @Test
+ public void testArrayColumnWithDefaultValue() {
+ Throwable thrown = assertThrows(IllegalArgumentException.class, new
ThrowingRunnable() {
+ @Override
+ public void run() throws Exception {
+ new ColumnSchema.ColumnSchemaBuilder("arr_col", Type.INT32)
+ .array(true)
+ .defaultValue(new int[]{1, 2, 3})
+ .build();
+ }
+ });
+ assertTrue(thrown.getMessage().contains("cannot have a default value"));
+ }
+
+ @Test
+ public void testArrayColumnBeingKeyColumn() {
+ Throwable thrown = assertThrows(IllegalArgumentException.class, new
ThrowingRunnable() {
+ @Override
+ public void run() throws Exception {
+ new ColumnSchema.ColumnSchemaBuilder("arr_col", Type.INT32)
+ .array(true)
+ .key(true)
+ .build();
+ }
+ });
+ assertTrue(thrown.getMessage().contains("cannot be a key column"));
+ }
}