williamhyun commented on code in PR #17457:
URL: https://github.com/apache/iceberg/pull/17457#discussion_r3724416272


##########
core/src/main/java/org/apache/iceberg/io/http/HTTPInputFile.java:
##########
@@ -0,0 +1,190 @@
+/*
+ * 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.http;
+
+import java.io.IOException;
+import java.util.Locale;
+import org.apache.hc.client5.http.classic.methods.HttpGet;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.hc.core5.http.HttpStatus;
+import org.apache.iceberg.exceptions.NotFoundException;
+import org.apache.iceberg.exceptions.RuntimeIOException;
+import org.apache.iceberg.io.InputFile;
+import org.apache.iceberg.io.SeekableInputStream;
+import org.apache.iceberg.metrics.MetricsContext;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+
+/**
+ * An {@link InputFile} backed by an HTTP URL, typically a pre-signed 
object-store URL that encodes
+ * auth in its query parameters.
+ *
+ * <p>A known content length is returned directly; otherwise it is fetched 
lazily via a {@code GET
+ * Range: bytes=0-0} request, which (unlike HEAD) works with pre-signed GET 
URLs.
+ */
+class HTTPInputFile implements InputFile {
+  private static final long UNKNOWN_LENGTH = -1L;
+
+  private final CloseableHttpClient client;
+  private final String location;
+  private final String url;
+  private final MetricsContext metrics;
+
+  private long length;
+
+  HTTPInputFile(CloseableHttpClient client, String location, String url, 
MetricsContext metrics) {
+    this(client, location, url, UNKNOWN_LENGTH, metrics);
+  }
+
+  HTTPInputFile(
+      CloseableHttpClient client,
+      String location,
+      String url,
+      long length,
+      MetricsContext metrics) {
+    Preconditions.checkNotNull(client, "Invalid HTTP client: null");
+    Preconditions.checkNotNull(location, "Invalid location: null");
+    Preconditions.checkNotNull(url, "Invalid url: null");
+    Preconditions.checkNotNull(metrics, "Invalid metrics context: null");
+    this.client = client;
+    this.location = location;
+    this.url = url;
+    this.length = length;
+    this.metrics = metrics;
+  }
+
+  @Override
+  public long getLength() {
+    if (length == UNKNOWN_LENGTH) {
+      this.length = fetchContentLength();
+    }
+
+    return length;
+  }
+
+  @Override
+  public SeekableInputStream newStream() {
+    return new HTTPInputStream(client, location, url, metrics);
+  }
+
+  @Override
+  public String location() {
+    return location;
+  }
+
+  @Override
+  public boolean exists() {
+    try {
+      HttpGet request = new HttpGet(url);
+      request.setHeader(HttpHeaders.RANGE, "bytes=0-0");

Review Comment:
   Thanks Steve. As far as I'm aware I don't expect a material performance 
penalty against S3 for this. Since GET and HEAD requests are categorized under 
the same per-request pricing. A partial GET that returns only one byte should 
be limited in extra cost. [pricing](https://aws.amazon.com/s3/pricing/)
   
   One thing to note is that GET _can_ incur data-retrieval charges for storage 
classes such as Standard-IA, One Zone-IA, and Glacier Instant Retrieval, and 
bytes=0-0 is not satisfiable for a zero-byte object. For normal S3 Standard 
objects, though, I don’t expect a meaningful performance or cost difference. 
[S3 storage 
classes](https://docs.aws.amazon.com/AmazonS3/latest/userguide/storage-class-intro.html)



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