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 2022/05/31 13:35:03 UTC

[GitHub] [iceberg] snazy commented on a diff in pull request #4918: Core: Add InMemoryFileIO implementation

snazy commented on code in PR #4918:
URL: https://github.com/apache/iceberg/pull/4918#discussion_r885645044


##########
core/src/main/java/org/apache/iceberg/io/inmemory/InMemoryFileStore.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.inmemory;
+
+import java.nio.ByteBuffer;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentMap;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.util.ByteBuffers;
+
+/** An in-memory collection based storage for file contents keyed by a string location. */
+class InMemoryFileStore {
+
+  private final ConcurrentMap<String, byte[]> store;
+
+  InMemoryFileStore() {
+    this.store = Maps.newConcurrentMap();
+  }
+
+  /** Put the file contents at the given location, overwrite if it already exists. */
+  public void put(String location, ByteBuffer data) {
+    // Copy the contents and store it.
+    store.put(location, ByteBuffers.toByteArray(data));
+  }
+
+  /** Get the file contents for the given location. */
+  public Optional<ByteBuffer> get(String location) {
+    return Optional.ofNullable(store.get(location))
+        .map(
+            bytes -> {

Review Comment:
   You can store the `ByteBuffer` in `put()` using `ByteBuffer.asReadOnlyBuffer()` and then return just return `ByteBuffer.duplicate()` here instead of the byte[] copy + wrapping.



##########
core/src/main/java/org/apache/iceberg/io/inmemory/InMemoryFileStore.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.inmemory;
+
+import java.nio.ByteBuffer;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentMap;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.util.ByteBuffers;
+
+/** An in-memory collection based storage for file contents keyed by a string location. */
+class InMemoryFileStore {

Review Comment:
   Maybe move the code from this class into `InMemoryFileIO` and make `InMemoryFileIO`'s inner classes top-level classes?



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