nastra commented on code in PR #7759:
URL: https://github.com/apache/iceberg/pull/7759#discussion_r1226670569


##########
core/src/test/java/org/apache/iceberg/view/TestViewMetadata.java:
##########
@@ -0,0 +1,280 @@
+/*
+ * 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.iceberg.view;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.types.Types;
+import org.junit.jupiter.api.Test;
+
+public class TestViewMetadata {
+
+  @Test
+  public void nullAndMissingFields() {
+    assertThatThrownBy(() -> ImmutableViewMetadata.builder().build())
+        .isInstanceOf(IllegalStateException.class)
+        .hasMessage(
+            "Cannot build ViewMetadata, some of required attributes are not 
set [formatVersion, location, currentSchemaId, currentVersionId]");

Review Comment:
   Collections are empty by default if not set and typically they are being 
checked in a `@Value.Check` method. See also 
https://github.com/immutables/immutables/issues/1429#issuecomment-1374013397 
for some historical reasons why Collections are being empty by default if not 
set.
   
   The other alternative would be to use the Java Bean Validation API, which 
would allow expressing validations on Collections via annotations, but I don't 
think we'd want to do that here.
   
   That's the main reason why I'd like to keep `currentVersion()` and 
`schema()`  being `@Value.Lazy` so that we don't have misleading error 
messaging.
   What I mean here is that for example, if `currentVersionId()` is set but 
`versions()` is empty, we would see `java.lang.NullPointerException: 
currentVersion` (because `currentVersion` cannot be derived from `versions()` 
and thus ends up being null) rather than `java.lang.IllegalArgumentException: 
Cannot find current version 23 in view versions: [1]`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to