diff --git a/extensions-core/s3-extensions/src/main/java/org/apache/druid/storage/s3/S3TaskLogs.java b/extensions-core/s3-extensions/src/main/java/org/apache/druid/storage/s3/S3TaskLogs.java index 9319e8a5fc9..a28fd1651c3 100644 --- a/extensions-core/s3-extensions/src/main/java/org/apache/druid/storage/s3/S3TaskLogs.java +++ b/extensions-core/s3-extensions/src/main/java/org/apache/druid/storage/s3/S3TaskLogs.java @@ -95,7 +95,7 @@ public class S3TaskLogs implements TaskLogs } final GetObjectRequest request = new GetObjectRequest(config.getS3Bucket(), taskKey) - .withMatchingETagConstraint(objectMetadata.getETag()) + .withMatchingETagConstraint(ensureQuotated(objectMetadata.getETag())) .withRange(start, end); return Optional.of(service.getObject(request).getObjectContent()); @@ -115,6 +115,16 @@ public class S3TaskLogs implements TaskLogs } } + static String ensureQuotated(String eTag) + { + if (eTag != null) { + if (!eTag.startsWith("\"") && !eTag.endsWith("\"")) { + return "\"" + eTag + "\""; + } + } + return eTag; + } + @Override public void pushTaskLog(final String taskid, final File logFile) throws IOException { diff --git a/extensions-core/s3-extensions/src/test/java/org/apache/druid/storage/s3/S3TaskLogsTest.java b/extensions-core/s3-extensions/src/test/java/org/apache/druid/storage/s3/S3TaskLogsTest.java index 3b28ac07e6b..7b82ca102be 100644 --- a/extensions-core/s3-extensions/src/test/java/org/apache/druid/storage/s3/S3TaskLogsTest.java +++ b/extensions-core/s3-extensions/src/test/java/org/apache/druid/storage/s3/S3TaskLogsTest.java @@ -480,4 +480,23 @@ public class S3TaskLogsTest extends EasyMockSupport return aclExpected.getGrantsAsList(); } + + @Test + public void testEnsureQuotated() + { + Assert.assertEquals("\"etag\"", S3TaskLogs.ensureQuotated("etag")); + Assert.assertNull(S3TaskLogs.ensureQuotated(null)); + Assert.assertEquals("\"etag", S3TaskLogs.ensureQuotated("\"etag")); + Assert.assertEquals("etag\"", S3TaskLogs.ensureQuotated("etag\"")); + } + + @Test + public void testMatchingEtagConstraintWithEnsureQuotated() + { + String eTag = "etag"; + final GetObjectRequest request = new GetObjectRequest(null, null) + .withMatchingETagConstraint(S3TaskLogs.ensureQuotated(eTag)) + .withRange(0, 1); + Assert.assertEquals("\"" + eTag + "\"", request.getMatchingETagConstraints().get(0)); + } }