You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2023/01/06 22:53:02 UTC

[GitHub] [iceberg] dennishuo opened a new pull request, #6538: Add InMemoryFileIO as a test helper class

dennishuo opened a new pull request, #6538:
URL: https://github.com/apache/iceberg/pull/6538

   Add InMemoryFileIO alongside existing InMemoryOutputFile and InMemoryInputFile as a test helper class stitching the two together and maintaining an in-memory listing of files. Add a dedicated unittest for the new test helper.


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] dennishuo commented on pull request #6538: Add InMemoryFileIO as a test helper class

Posted by GitBox <gi...@apache.org>.
dennishuo commented on PR #6538:
URL: https://github.com/apache/iceberg/pull/6538#issuecomment-1374231766

   As suggested in https://github.com/apache/iceberg/pull/6428#discussion_r1056132787 this PR breaks out the addition of the InMemoryFileIO as a separate addition that can be generally useful in iceberg-core for unittesting purposes.
   
   @nastra @danielcweeks @rdblue 


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] dennishuo commented on a diff in pull request #6538: Add InMemoryFileIO as a test helper class

Posted by GitBox <gi...@apache.org>.
dennishuo commented on code in PR #6538:
URL: https://github.com/apache/iceberg/pull/6538#discussion_r1065016314


##########
core/src/test/java/org/apache/iceberg/io/InMemoryFileIO.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.io;
+
+import java.util.Map;
+import org.apache.iceberg.exceptions.NotFoundException;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+
+public class InMemoryFileIO implements FileIO {
+
+  private Map<String, byte[]> inMemoryFiles = Maps.newHashMap();
+  private boolean closed = false;
+
+  public void addFile(String path, byte[] contents) {

Review Comment:
   Done



##########
core/src/test/java/org/apache/iceberg/io/InMemoryFileIO.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.io;
+
+import java.util.Map;
+import org.apache.iceberg.exceptions.NotFoundException;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+
+public class InMemoryFileIO implements FileIO {
+
+  private Map<String, byte[]> inMemoryFiles = Maps.newHashMap();
+  private boolean closed = false;
+
+  public void addFile(String path, byte[] contents) {
+    Preconditions.checkState(!closed, "Cannot call addFile after calling close()");
+    inMemoryFiles.put(path, contents);
+  }
+
+  public boolean fileExists(String path) {
+    return inMemoryFiles.containsKey(path);
+  }
+
+  @Override
+  public InputFile newInputFile(String path) {
+    Preconditions.checkState(!closed, "Cannot call newInputFile after calling close()");
+    if (!inMemoryFiles.containsKey(path)) {
+      throw new NotFoundException("No in-memory file found for path: %s", path);
+    }
+    return new InMemoryInputFile(path, inMemoryFiles.get(path));
+  }
+
+  @Override
+  public OutputFile newOutputFile(String path) {
+    Preconditions.checkState(!closed, "Cannot call newOutputFile after calling close()");
+    return new InMemoryOutputFile(path, this);
+  }
+
+  @Override
+  public void deleteFile(String path) {
+    Preconditions.checkState(!closed, "Cannot call deleteFile after calling close()");
+    if (!inMemoryFiles.containsKey(path)) {
+      throw new NotFoundException("No in-memory file found for path: %s", path);

Review Comment:
   Done



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] nastra commented on a diff in pull request #6538: Add InMemoryFileIO as a test helper class

Posted by GitBox <gi...@apache.org>.
nastra commented on code in PR #6538:
URL: https://github.com/apache/iceberg/pull/6538#discussion_r1064538826


##########
core/src/test/java/org/apache/iceberg/io/InMemoryFileIO.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.io;
+
+import java.util.Map;
+import org.apache.iceberg.exceptions.NotFoundException;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+
+public class InMemoryFileIO implements FileIO {
+
+  private Map<String, byte[]> inMemoryFiles = Maps.newHashMap();

Review Comment:
   nit: maybe worth using `Maps.newConcurrentMap()` here?



##########
core/src/test/java/org/apache/iceberg/io/InMemoryFileIO.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.io;
+
+import java.util.Map;
+import org.apache.iceberg.exceptions.NotFoundException;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+
+public class InMemoryFileIO implements FileIO {
+
+  private Map<String, byte[]> inMemoryFiles = Maps.newHashMap();
+  private boolean closed = false;
+
+  public void addFile(String path, byte[] contents) {

Review Comment:
   nit: in other FileIO implementations we use `location` rather than `path`



##########
core/src/test/java/org/apache/iceberg/io/InMemoryFileIO.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.io;
+
+import java.util.Map;
+import org.apache.iceberg.exceptions.NotFoundException;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+
+public class InMemoryFileIO implements FileIO {
+
+  private Map<String, byte[]> inMemoryFiles = Maps.newHashMap();
+  private boolean closed = false;
+
+  public void addFile(String path, byte[] contents) {
+    Preconditions.checkState(!closed, "Cannot call addFile after calling close()");
+    inMemoryFiles.put(path, contents);
+  }
+
+  public boolean fileExists(String path) {
+    return inMemoryFiles.containsKey(path);
+  }
+
+  @Override
+  public InputFile newInputFile(String path) {
+    Preconditions.checkState(!closed, "Cannot call newInputFile after calling close()");
+    if (!inMemoryFiles.containsKey(path)) {
+      throw new NotFoundException("No in-memory file found for path: %s", path);
+    }
+    return new InMemoryInputFile(path, inMemoryFiles.get(path));
+  }
+
+  @Override
+  public OutputFile newOutputFile(String path) {
+    Preconditions.checkState(!closed, "Cannot call newOutputFile after calling close()");
+    return new InMemoryOutputFile(path, this);
+  }
+
+  @Override
+  public void deleteFile(String path) {
+    Preconditions.checkState(!closed, "Cannot call deleteFile after calling close()");
+    if (!inMemoryFiles.containsKey(path)) {
+      throw new NotFoundException("No in-memory file found for path: %s", path);

Review Comment:
   nit: in other FileIO implementations we use `location` rather than `path`



##########
core/src/test/java/org/apache/iceberg/io/InMemoryFileIO.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.io;
+
+import java.util.Map;
+import org.apache.iceberg.exceptions.NotFoundException;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+
+public class InMemoryFileIO implements FileIO {
+
+  private Map<String, byte[]> inMemoryFiles = Maps.newHashMap();
+  private boolean closed = false;
+
+  public void addFile(String path, byte[] contents) {
+    Preconditions.checkState(!closed, "Cannot call addFile after calling close()");
+    inMemoryFiles.put(path, contents);
+  }
+
+  public boolean fileExists(String path) {
+    return inMemoryFiles.containsKey(path);
+  }
+
+  @Override
+  public InputFile newInputFile(String path) {
+    Preconditions.checkState(!closed, "Cannot call newInputFile after calling close()");
+    if (!inMemoryFiles.containsKey(path)) {
+      throw new NotFoundException("No in-memory file found for path: %s", path);
+    }
+    return new InMemoryInputFile(path, inMemoryFiles.get(path));
+  }
+
+  @Override
+  public OutputFile newOutputFile(String path) {
+    Preconditions.checkState(!closed, "Cannot call newOutputFile after calling close()");
+    return new InMemoryOutputFile(path, this);
+  }
+
+  @Override
+  public void deleteFile(String path) {
+    Preconditions.checkState(!closed, "Cannot call deleteFile after calling close()");
+    if (!inMemoryFiles.containsKey(path)) {

Review Comment:
   nit: what about using the result of the `remove` call here? `if (!inMemoryFiles.remove(path)) { ... }`



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] dennishuo commented on pull request #6538: Add InMemoryFileIO as a test helper class

Posted by GitBox <gi...@apache.org>.
dennishuo commented on PR #6538:
URL: https://github.com/apache/iceberg/pull/6538#issuecomment-1376199470

   Thanks! Suggestions applied.


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] dennishuo commented on a diff in pull request #6538: Add InMemoryFileIO as a test helper class

Posted by GitBox <gi...@apache.org>.
dennishuo commented on code in PR #6538:
URL: https://github.com/apache/iceberg/pull/6538#discussion_r1065041310


##########
core/src/test/java/org/apache/iceberg/io/InMemoryFileIO.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.io;
+
+import java.util.Map;
+import org.apache.iceberg.exceptions.NotFoundException;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+
+public class InMemoryFileIO implements FileIO {
+
+  private Map<String, byte[]> inMemoryFiles = Maps.newHashMap();
+  private boolean closed = false;
+
+  public void addFile(String path, byte[] contents) {
+    Preconditions.checkState(!closed, "Cannot call addFile after calling close()");
+    inMemoryFiles.put(path, contents);
+  }
+
+  public boolean fileExists(String path) {
+    return inMemoryFiles.containsKey(path);
+  }
+
+  @Override
+  public InputFile newInputFile(String path) {
+    Preconditions.checkState(!closed, "Cannot call newInputFile after calling close()");
+    if (!inMemoryFiles.containsKey(path)) {
+      throw new NotFoundException("No in-memory file found for path: %s", path);
+    }
+    return new InMemoryInputFile(path, inMemoryFiles.get(path));
+  }
+
+  @Override
+  public OutputFile newOutputFile(String path) {
+    Preconditions.checkState(!closed, "Cannot call newOutputFile after calling close()");
+    return new InMemoryOutputFile(path, this);
+  }
+
+  @Override
+  public void deleteFile(String path) {
+    Preconditions.checkState(!closed, "Cannot call deleteFile after calling close()");
+    if (!inMemoryFiles.containsKey(path)) {

Review Comment:
   Done, also updated the `get` in `newInputFile` to follow the same pattern.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] danielcweeks commented on pull request #6538: Add InMemoryFileIO as a test helper class

Posted by GitBox <gi...@apache.org>.
danielcweeks commented on PR #6538:
URL: https://github.com/apache/iceberg/pull/6538#issuecomment-1376342937

   Thanks @dennishuo !!


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] danielcweeks merged pull request #6538: Add InMemoryFileIO as a test helper class

Posted by GitBox <gi...@apache.org>.
danielcweeks merged PR #6538:
URL: https://github.com/apache/iceberg/pull/6538


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] dennishuo commented on a diff in pull request #6538: Add InMemoryFileIO as a test helper class

Posted by GitBox <gi...@apache.org>.
dennishuo commented on code in PR #6538:
URL: https://github.com/apache/iceberg/pull/6538#discussion_r1065047914


##########
core/src/test/java/org/apache/iceberg/io/InMemoryFileIO.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.io;
+
+import java.util.Map;
+import org.apache.iceberg.exceptions.NotFoundException;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+
+public class InMemoryFileIO implements FileIO {
+
+  private Map<String, byte[]> inMemoryFiles = Maps.newHashMap();

Review Comment:
   Done



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org