clintropolis commented on a change in pull request #8823: Add InputSource and 
InputFormat interfaces
URL: https://github.com/apache/incubator-druid/pull/8823#discussion_r346499344
 
 

 ##########
 File path: core/src/main/java/org/apache/druid/data/input/InputEntity.java
 ##########
 @@ -0,0 +1,115 @@
+/*
+ * 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.druid.data.input;
+
+import com.google.common.base.Predicate;
+import org.apache.druid.guice.annotations.UnstableApi;
+import org.apache.druid.java.util.common.FileUtils;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.logger.Logger;
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * InputEntity abstracts an object and knows how to read bytes from the given 
object.
+ *
+ * @param <T> Type of input entity
+ */
+@UnstableApi
+public interface InputEntity<T>
+{
+  Logger LOG = new Logger(InputEntity.class);
+
+  int DEFAULT_FETCH_BUFFER_SIZE = 4 * 1024; // 4 KB
+  int DEFAULT_MAX_NUM_FETCH_TRIES = 3; // 3 tries including the initial try
+
+  /**
+   * CleanableFile is the result type of {@link #fetch}.
+   * It should clean up any temporary resource on {@link #close()}.
+   */
+  interface CleanableFile extends Closeable
+  {
+    File file();
+  }
+
+  T getObject();
+
+  /**
+   * Opens an {@link InputStream} on the object directly.
+   * This is the basic way to read the given object.
+   *
+   * @see #fetch as an alternative way to read data.
+   */
+  InputStream open() throws IOException;
+
+  /**
+   * Fetches the object into the local storage.
+   * This method might be preferred instead of {@link #open()}, for example
+   *
+   * - {@link InputFormat} requires expensive random access on remote storage.
+   * - Holding a connection until you consume the entire InputStream is 
expensive.
+   *
+   * @param temporaryDirectory to store temp data. This directory will be 
removed automatically once
+   *                           the task finishes.
+   * @param fetchBuffer        is used to fetch remote object into local 
storage.
+   *
+   * @see FileUtils#copyLarge
+   */
+  default CleanableFile fetch(File temporaryDirectory, byte[] fetchBuffer) 
throws IOException
+  {
+    final File tempFile = File.createTempFile("druid-object-source", ".tmp", 
temporaryDirectory);
 
 Review comment:
   should `druid-object-source` be `druid-input-entity` since this class had 
it's name changed? (same with the `LOG.debug` message just below this line, as 
well as some of the javadoc)

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org
For additional commands, e-mail: commits-h...@druid.apache.org

Reply via email to