This is an automated email from the ASF dual-hosted git repository.
jmclean pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new 45759ad112 [#8196]Improvement(TableDto): validation in TableDTO
Builder (#8247)
45759ad112 is described below
commit 45759ad112f8403196c05e2db882e882042b008a
Author: Sambhavi Pandey <[email protected]>
AuthorDate: Mon Aug 25 15:25:10 2025 +0530
[#8196]Improvement(TableDto): validation in TableDTO Builder (#8247)
### What changes were proposed in this pull request?
Added missing validation to TableDTO.Builder.build() to make sure the
table has a non-null, non-empty column list before construction,
### Why are the changes needed?
Improvement to make sure the table has a non-null, non-empty column list
before construction,
Fix: #8196
### Does this PR introduce _any_ user-facing change?
no
### How was this patch tested?
unit testing
---------
Co-authored-by: Justin Mclean <[email protected]>
---
.../org/apache/gravitino/dto/rel/TableDTO.java | 2 +
.../org/apache/gravitino/dto/rel/TestTableDTO.java | 57 ++++++++++++++++++++++
2 files changed, 59 insertions(+)
diff --git a/common/src/main/java/org/apache/gravitino/dto/rel/TableDTO.java
b/common/src/main/java/org/apache/gravitino/dto/rel/TableDTO.java
index 9a6843a3fd..d029c609b9 100644
--- a/common/src/main/java/org/apache/gravitino/dto/rel/TableDTO.java
+++ b/common/src/main/java/org/apache/gravitino/dto/rel/TableDTO.java
@@ -296,6 +296,8 @@ public class TableDTO implements Table {
public TableDTO build() {
Preconditions.checkArgument(name != null && !name.isEmpty(), "name
cannot be null or empty");
Preconditions.checkArgument(audit != null, "audit cannot be null");
+ Preconditions.checkArgument(
+ columns != null && columns.length > 0, "columns cannot be null or
empty");
return new TableDTO(
name,
diff --git
a/common/src/test/java/org/apache/gravitino/dto/rel/TestTableDTO.java
b/common/src/test/java/org/apache/gravitino/dto/rel/TestTableDTO.java
new file mode 100644
index 0000000000..5f0733c5ea
--- /dev/null
+++ b/common/src/test/java/org/apache/gravitino/dto/rel/TestTableDTO.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.dto.rel;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.time.Instant;
+import org.apache.gravitino.dto.AuditDTO;
+import org.apache.gravitino.rel.types.Types;
+import org.junit.jupiter.api.Test;
+
+public class TestTableDTO {
+ @Test
+ public void testBuildWithoutColumns() {
+ AuditDTO audit =
+
AuditDTO.builder().withCreator("creator").withCreateTime(Instant.now()).build();
+ TableDTO.Builder<?> builder =
TableDTO.builder().withName("t1").withAudit(audit);
+ assertThrows(IllegalArgumentException.class, builder::build);
+ }
+
+ @Test
+ public void testBuildWithEmptyColumns() {
+ AuditDTO audit =
+
AuditDTO.builder().withCreator("creator").withCreateTime(Instant.now()).build();
+ TableDTO.Builder<?> builder =
+ TableDTO.builder().withName("t1").withAudit(audit).withColumns(new
ColumnDTO[0]);
+ assertThrows(IllegalArgumentException.class, builder::build);
+ }
+
+ @Test
+ public void testBuildWithColumns() {
+ AuditDTO audit =
+
AuditDTO.builder().withCreator("creator").withCreateTime(Instant.now()).build();
+ ColumnDTO column =
+
ColumnDTO.builder().withName("c1").withDataType(Types.IntegerType.get()).build();
+ TableDTO.Builder<?> builder =
+ TableDTO.builder().withName("t1").withAudit(audit).withColumns(new
ColumnDTO[] {column});
+ assertDoesNotThrow(builder::build);
+ }
+}