eric-maynard commented on code in PR #402:
URL: https://github.com/apache/polaris/pull/402#discussion_r1819525596


##########
polaris-service/src/test/java/org/apache/polaris/service/catalog/io/TestFileIO.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.polaris.service.catalog.io;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Supplier;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.DeleteFile;
+import org.apache.iceberg.ManifestFile;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.InputFile;
+import org.apache.iceberg.io.OutputFile;
+
+/**
+ * File IO wrapper used for tests. It measures the number of bytes read, files 
written, and files
+ * deleted. It can inject exceptions during InputFile and OutputFile creation.
+ */
+public class TestFileIO implements FileIO {
+  private final FileIO io;
+
+  // When present, the following will be used to throw exceptions at various 
parts of the IO
+  private final Optional<Supplier<RuntimeException>> 
newInputFileExceptionSupplier;
+  private final Optional<Supplier<RuntimeException>> 
newOutputFileExceptionSupplier;

Review Comment:
   Yes, `Optional<A<B<..>>` can always accept the `A` being null, or the `B` 
being null, or `B.c.x.y.z` being null. But the point of optional types is to 
make it obvious to the caller exactly at what level the optionality lies. 
Without it, they are left to read the code to guess what exact reference needs 
to be null (if any) for things to work.
   
   Instead of pursuing 110% null-safety at every level of the object hierarchy 
across all APIs, it's better to be explicit and use Optional to clearly 
demarcate what objects are "optional". If the caller passes in a `null` for 
`A.B.c` even though `A` was optional, this is pretty clearly a bug and not an 
appropriate way to disable behavior. That's less clear if `A` is not optional 
and we are using nulls as flow control.
   
   Having said all of this, it's a test class. Because of that I think it's 
fair to expect folks using this to read the code, and so all of this doesn't 
matter very much. I am okay merging this either way.



-- 
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]

Reply via email to