This is an automated email from the ASF dual-hosted git repository.
dweeks pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git
The following commit(s) were added to refs/heads/master by this push:
new c27c1fb1f2 GCP: fix single byte read in GCSInputStream (#8071)
c27c1fb1f2 is described below
commit c27c1fb1f279c8be96847fc41ce637b3eff19661
Author: Bryan Keller <[email protected]>
AuthorDate: Sat Jul 15 05:52:17 2023 -0700
GCP: fix single byte read in GCSInputStream (#8071)
* GCP: fix byte read in GCSInputStream
* add test
---
.../java/org/apache/iceberg/gcp/gcs/GCSInputStream.java | 2 +-
.../org/apache/iceberg/gcp/gcs/GCSInputStreamTest.java | 16 ++++++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/gcp/src/main/java/org/apache/iceberg/gcp/gcs/GCSInputStream.java
b/gcp/src/main/java/org/apache/iceberg/gcp/gcs/GCSInputStream.java
index d8b092e4e7..fc09bafadb 100644
--- a/gcp/src/main/java/org/apache/iceberg/gcp/gcs/GCSInputStream.java
+++ b/gcp/src/main/java/org/apache/iceberg/gcp/gcs/GCSInputStream.java
@@ -117,7 +117,7 @@ class GCSInputStream extends SeekableInputStream {
readBytes.increment();
readOperations.increment();
- return singleByteBuffer.array()[0];
+ return singleByteBuffer.array()[0] & 0xFF;
}
@Override
diff --git
a/gcp/src/test/java/org/apache/iceberg/gcp/gcs/GCSInputStreamTest.java
b/gcp/src/test/java/org/apache/iceberg/gcp/gcs/GCSInputStreamTest.java
index 1a5200345b..733d910186 100644
--- a/gcp/src/test/java/org/apache/iceberg/gcp/gcs/GCSInputStreamTest.java
+++ b/gcp/src/test/java/org/apache/iceberg/gcp/gcs/GCSInputStreamTest.java
@@ -78,6 +78,22 @@ public class GCSInputStreamTest {
}
}
+ @Test
+ public void testReadSingle() throws Exception {
+ BlobId uri = BlobId.fromGsUtilUri("gs://bucket/path/to/read.dat");
+ int i0 = 1;
+ int i1 = 255;
+ byte[] data = {(byte) i0, (byte) i1};
+
+ writeGCSData(uri, data);
+
+ try (SeekableInputStream in =
+ new GCSInputStream(storage, uri, gcpProperties,
MetricsContext.nullMetrics())) {
+ assertThat(in.read()).isEqualTo(i0);
+ assertThat(in.read()).isEqualTo(i1);
+ }
+ }
+
private void readAndCheck(
SeekableInputStream in, long rangeStart, int size, byte[] original,
boolean buffered)
throws IOException {