Skip to content

Commit 88f202d

Browse files
committed
HADOOP-18830. Reviews and test completion
Change-Id: I72fda6324d04856c2f2016320f507f12e7efba0c
1 parent 1ddc2c2 commit 88f202d

11 files changed

Lines changed: 59 additions & 484 deletions

File tree

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/ChangeTracker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public void processResponse(final CopyObjectResponse copyObjectResponse)
223223
* cause.
224224
* @param e the exception
225225
* @param operation the operation performed when the exception was
226-
* generated (e.g. "copy", "read", "select").
226+
* generated (e.g. "copy", "read").
227227
* @throws RemoteFileChangedException if the remote file has changed.
228228
*/
229229
public void processException(SdkException e, String operation) throws

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/OpenFileSupport.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.apache.hadoop.fs.s3a.S3ALocatedFileStatus;
3737
import org.apache.hadoop.fs.s3a.S3AReadOpContext;
3838
import org.apache.hadoop.fs.s3a.select.SelectConstants;
39+
import org.apache.hadoop.fs.store.LogExactlyOnce;
3940

4041
import static org.apache.hadoop.fs.Options.OpenFileOptions.FS_OPTION_OPENFILE_BUFFER_SIZE;
4142
import static org.apache.hadoop.fs.Options.OpenFileOptions.FS_OPTION_OPENFILE_LENGTH;
@@ -67,6 +68,7 @@ public class OpenFileSupport {
6768
private static final Logger LOG =
6869
LoggerFactory.getLogger(OpenFileSupport.class);
6970

71+
public static final LogExactlyOnce LOG_NO_SQL_SELECT = new LogExactlyOnce(LOG);
7072
/**
7173
* For use when a value of an split/file length is unknown.
7274
*/
@@ -152,6 +154,7 @@ public S3AReadOpContext applyDefaultOptions(S3AReadOpContext roc) {
152154

153155
/**
154156
* Prepare to open a file from the openFile parameters.
157+
* S3Select SQL is rejected if a mandatory opt, ignored if optional.
155158
* @param path path to the file
156159
* @param parameters open file parameters from the builder.
157160
* @param blockSize for fileStatus
@@ -167,10 +170,15 @@ public OpenFileInformation prepareToOpenFile(
167170
final long blockSize) throws IOException {
168171
Configuration options = parameters.getOptions();
169172
Set<String> mandatoryKeys = parameters.getMandatoryKeys();
170-
// S3 Select is not supported in this release; fail wit
171-
// a specific message.
173+
// S3 Select is not supported in this release
172174
if (options.get(SelectConstants.SELECT_SQL, null) != null) {
173-
throw new UnsupportedOperationException(SelectConstants.SELECT_UNSUPPORTED);
175+
if (mandatoryKeys.contains(SelectConstants.SELECT_SQL)) {
176+
// mandatory option: fail with a specific message.
177+
throw new UnsupportedOperationException(SelectConstants.SELECT_UNSUPPORTED);
178+
} else {
179+
// optional; log once and continue
180+
LOG_NO_SQL_SELECT.warn(SelectConstants.SELECT_UNSUPPORTED);
181+
}
174182
}
175183
// choice of keys depends on open type
176184
rejectUnknownMandatoryKeys(

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/select/BlockingEnumeration.java

Lines changed: 0 additions & 156 deletions
This file was deleted.

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/select/package-info.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818

1919
/**
2020
* Was the location for support for S3 Select.
21-
* Now removed apart from some constants and a
22-
* class {@link org.apache.hadoop.fs.s3a.select.BlockingEnumeration}
23-
* which may be useful in future.
21+
* Now removed apart from some constants.f
22+
* There was a class {@code BlockingEnumeration} which
23+
* mapped SdkPublisher to an Enumeration.
24+
* This may be of use elsewhere; it can be retrieved from
25+
* hadoop commit 8bf72346a59c.
2426
*/
2527
@InterfaceAudience.Private
2628
@InterfaceStability.Unstable

hadoop-tools/hadoop-aws/src/site/markdown/tools/hadoop-aws/s3_select.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414

1515
# S3 Select
1616

17-
<!-- MACRO{toc|fromDepth=0|toDepth=5} -->
18-
1917
S3 Select is a feature for Amazon S3 introduced in April 2018. It allows for
2018
SQL-like SELECT expressions to be applied to files in some structured
2119
formats, including CSV and JSON.
2220

2321
It is no longer supported in Hadoop releases.
2422

2523
Any Hadoop release built on the [AWS V2 SDK](./aws_sdk_upgrade.html)
26-
will reject calls to open files using the select APIs.
24+
will reject calls to open files using the select APIs.
25+
26+
If a build of Hadoop with S3 Select is desired, the relevant
27+
classes can be found in hadoop trunk commit `8bf72346a59c`.

hadoop-tools/hadoop-aws/src/site/markdown/tools/hadoop-aws/testing.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,10 +572,6 @@ on third party stores.
572572
<name>test.fs.s3a.create.storage.class.enabled</name>
573573
<value>false</value>
574574
</property>
575-
<property>
576-
<name>fs.s3a.select.enabled</name>
577-
<value>false</value>
578-
</property>
579575
<property>
580576
<name>test.fs.s3a.sts.enabled</name>
581577
<value>false</value>

hadoop-tools/hadoop-aws/src/site/markdown/tools/hadoop-aws/third_party_stores.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -419,11 +419,6 @@ this makes renaming and deleting significantly slower.
419419
<value>false</value>
420420
</property>
421421

422-
<property>
423-
<name>fs.s3a.bucket.gcs-container.select.enabled</name>
424-
<value>false</value>
425-
</property>
426-
427422
<property>
428423
<name>fs.s3a.bucket.gcs-container.path.style.access</name>
429424
<value>true</value>

hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/select/ITestSelectUnsupported.java

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,45 +21,63 @@
2121
import org.assertj.core.api.Assertions;
2222
import org.junit.Test;
2323

24+
import org.apache.hadoop.fs.Path;
25+
import org.apache.hadoop.fs.contract.ContractTestUtils;
2426
import org.apache.hadoop.fs.s3a.AbstractS3ATestBase;
27+
import org.apache.hadoop.fs.s3a.S3AFileSystem;
2528
import org.apache.hadoop.fs.s3a.s3guard.S3GuardTool;
2629
import org.apache.hadoop.util.ExitUtil;
2730

2831
import static org.apache.hadoop.fs.s3a.select.SelectConstants.SELECT_SQL;
2932
import static org.apache.hadoop.fs.s3a.select.SelectConstants.SELECT_UNSUPPORTED;
3033
import static org.apache.hadoop.service.launcher.LauncherExitCodes.EXIT_UNSUPPORTED_VERSION;
3134
import static org.apache.hadoop.test.LambdaTestUtils.intercept;
35+
import static org.apache.hadoop.util.ExitUtil.disableSystemExit;
3236

3337
/**
3438
* Verify that s3 select is unsupported.
3539
*/
3640
public class ITestSelectUnsupported extends AbstractS3ATestBase {
3741

42+
/**
43+
* S3 Select SQL statement.
44+
*/
45+
private static final String STATEMENT = "SELECT *" +
46+
" FROM S3Object s" +
47+
" WHERE s._1 = 'foo'";
48+
49+
/**
50+
* A {@code .must(SELECT_SQL, _)} option MSUT not fail the build.
51+
*/
3852
@Test
39-
public void testS3GuardOpenFileMust() throws Throwable {
53+
public void testSelectOpenFileMust() throws Throwable {
4054

41-
// TODO: intercept
42-
getFileSystem().openFile(methodPath())
43-
.must(SELECT_SQL, "SELECT *" +
44-
" FROM S3Object s" +
45-
" WHERE s._1 = 'foo'")
46-
.build().get();
55+
intercept(UnsupportedOperationException.class, SELECT_UNSUPPORTED, () ->
56+
getFileSystem().openFile(methodPath())
57+
.must(SELECT_SQL, STATEMENT)
58+
.build()
59+
/**/.get());
4760
}
4861

62+
/**
63+
* A {@code .opt(SELECT_SQL, _)} option does not fail the build.
64+
*/
4965
@Test
50-
public void testS3GuardOpenFileMay() throws Throwable {
51-
52-
// TODO: intercept
66+
public void testSelectOpenFileMay() throws Throwable {
5367

54-
getFileSystem().openFile(methodPath())
55-
.opt(SELECT_SQL, "SELECT *" +
56-
" FROM S3Object s" +
57-
" WHERE s._1 = 'foo'")
58-
.build().get();
68+
final Path path = methodPath();
69+
final S3AFileSystem fs = getFileSystem();
70+
ContractTestUtils.touch(fs, path);
71+
fs.openFile(path)
72+
.opt(SELECT_SQL, STATEMENT)
73+
.build()
74+
.get()
75+
.close();
5976
}
6077

6178
@Test
62-
public void testFSLacksSupport() throws Throwable {
79+
public void testPathCapabilityNotAvailable() throws Throwable {
80+
describe("verify that the FS lacks the path capability");
6381
Assertions.assertThat(getFileSystem().hasPathCapability(methodPath(), SELECT_SQL))
6482
.describedAs("S3 Select reported as present")
6583
.isFalse();
@@ -68,15 +86,15 @@ public void testFSLacksSupport() throws Throwable {
6886
@Test
6987
public void testS3GuardToolFails() throws Throwable {
7088

89+
// ensure that the command doesn't actually exit the VM.
90+
disableSystemExit();
7191
final ExitUtil.ExitException ex =
7292
intercept(ExitUtil.ExitException.class, SELECT_UNSUPPORTED,
7393
() -> S3GuardTool.main(new String[]{
74-
"select",
75-
"-sql", "SELECT * FROM S3Object s WHERE s._1 = 'foo'"
94+
"select", "-sql", STATEMENT
7695
}));
7796
Assertions.assertThat(ex.getExitCode())
7897
.describedAs("exit code of exception")
7998
.isEqualTo(EXIT_UNSUPPORTED_VERSION);
80-
8199
}
82100
}

0 commit comments

Comments
 (0)