-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Iceberg]Support specifying S3 path as warehouse dir for Hadoop catalog #24221
Draft
hantangwangd
wants to merge
1
commit into
prestodb:master
Choose a base branch
from
hantangwangd:support_s3_as_warehouse_dir
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
presto-iceberg/src/main/java/com/facebook/presto/iceberg/s3/IcebergS3Module.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Licensed 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 com.facebook.presto.iceberg.s3; | ||
|
||
import com.facebook.presto.hive.HiveClientConfig; | ||
import com.facebook.presto.hive.s3.HiveS3Config; | ||
import com.facebook.presto.hive.s3.HiveS3Module; | ||
import com.facebook.presto.hive.s3.PrestoS3FileSystem; | ||
import com.facebook.presto.hive.s3.PrestoS3FileSystemStats; | ||
import com.facebook.presto.hive.s3.S3ConfigurationUpdater; | ||
import com.facebook.presto.hive.s3.S3FileSystemType; | ||
import com.google.inject.Binder; | ||
import com.google.inject.Scopes; | ||
|
||
import static com.facebook.airlift.configuration.ConfigBinder.configBinder; | ||
import static org.weakref.jmx.ObjectNames.generatedNameOf; | ||
import static org.weakref.jmx.guice.ExportBinder.newExporter; | ||
|
||
public class IcebergS3Module | ||
extends HiveS3Module | ||
{ | ||
public IcebergS3Module(String connectorId) | ||
{ | ||
super(connectorId); | ||
} | ||
|
||
@Override | ||
protected void setup(Binder binder) | ||
{ | ||
S3FileSystemType type = buildConfigObject(HiveClientConfig.class).getS3FileSystemType(); | ||
if (type == S3FileSystemType.PRESTO) { | ||
bindSecurityMapping(binder); | ||
|
||
binder.bind(S3ConfigurationUpdater.class).to(PrestoIcebergS3ConfigurationUpdater.class).in(Scopes.SINGLETON); | ||
configBinder(binder).bindConfig(HiveS3Config.class); | ||
|
||
binder.bind(PrestoS3FileSystemStats.class).toInstance(PrestoS3FileSystem.getFileSystemStats()); | ||
newExporter(binder).export(PrestoS3FileSystemStats.class).as(generatedNameOf(PrestoS3FileSystem.class, connectorId)); | ||
} | ||
else if (type == S3FileSystemType.EMRFS) { | ||
validateEmrFsClass(); | ||
binder.bind(S3ConfigurationUpdater.class).to(EmrFsS3ConfigurationUpdater.class).in(Scopes.SINGLETON); | ||
} | ||
else if (type == S3FileSystemType.HADOOP_DEFAULT) { | ||
// configuration is done using Hadoop configuration files | ||
binder.bind(S3ConfigurationUpdater.class).to(HadoopDefaultConfigurationUpdater.class).in(Scopes.SINGLETON); | ||
} | ||
else { | ||
throw new RuntimeException("Unknown file system type: " + type); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...iceberg/src/main/java/com/facebook/presto/iceberg/s3/PrestoIcebergNativeS3FileSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Licensed 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 com.facebook.presto.iceberg.s3; | ||
|
||
import com.amazonaws.AmazonClientException; | ||
import com.facebook.presto.hive.s3.PrestoS3FileSystem; | ||
import org.apache.hadoop.fs.Path; | ||
import org.apache.hadoop.fs.permission.FsPermission; | ||
|
||
public class PrestoIcebergNativeS3FileSystem | ||
extends PrestoS3FileSystem | ||
{ | ||
@Override | ||
public boolean mkdirs(Path f, FsPermission permission) | ||
{ | ||
try { | ||
s3.putObject(getBucketName(uri), keyFromPath(f) + PATH_SEPARATOR, ""); | ||
return true; | ||
} | ||
catch (AmazonClientException e) { | ||
return false; | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...erg/src/main/java/com/facebook/presto/iceberg/s3/PrestoIcebergS3ConfigurationUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Licensed 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 com.facebook.presto.iceberg.s3; | ||
|
||
import com.facebook.presto.hive.s3.HiveS3Config; | ||
import com.facebook.presto.hive.s3.PrestoS3ConfigurationUpdater; | ||
import com.facebook.presto.iceberg.IcebergConfig; | ||
import org.apache.hadoop.conf.Configuration; | ||
|
||
import javax.inject.Inject; | ||
|
||
import static com.facebook.presto.iceberg.CatalogType.HADOOP; | ||
|
||
public class PrestoIcebergS3ConfigurationUpdater | ||
extends PrestoS3ConfigurationUpdater | ||
{ | ||
private final IcebergConfig icebergConfig; | ||
|
||
@Inject | ||
public PrestoIcebergS3ConfigurationUpdater(HiveS3Config config, IcebergConfig icebergConfig) | ||
{ | ||
super(config); | ||
this.icebergConfig = icebergConfig; | ||
} | ||
|
||
@Override | ||
public void updateConfiguration(Configuration config) | ||
{ | ||
super.updateConfiguration(config); | ||
|
||
if (this.icebergConfig.getCatalogType().equals(HADOOP)) { | ||
// re-map filesystem schemes to match customized presto s3 filesystem for `HADOOP` catalog | ||
config.set("fs.s3.impl", PrestoIcebergNativeS3FileSystem.class.getName()); | ||
config.set("fs.s3a.impl", PrestoIcebergNativeS3FileSystem.class.getName()); | ||
config.set("fs.s3n.impl", PrestoIcebergNativeS3FileSystem.class.getName()); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this condition removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Object Storage System do not necessarily return content type
application/octet-stream
, for example, Ozone return a content typebinary/octet-stream
, see: https://github.com/apache/ozone/blob/master/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java#L645-L647. Besides, the response examples in amazon s3 api document also usedbinary/octet-stream
as it's content type, see the examples ofSample Response for general purpose buckets
in https://docs.aws.amazon.com/AmazonS3/latest/API/API_HeadObject.html.Moreover, I believe the remaining two conditions can already confirm that this is a directory. So I removed this condition in order to support as many Object Storage Systems as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense, but I'm not sure if there are additional implications. If our tests pass then I am ok with it. Though I will defer to @imjalpreet for any additional thoughts. He is the one that implemented this check previously
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hantangwangd Could we please verify if it is possible to create an external table on an empty directory in MinIO after removing the current condition?
I added this condition because we noticed that some systems, such as MinIO, were creating empty directories with a content type of
application/octet-stream
instead ofapplication/x-directory
.For your reference: #20603
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@imjalpreet Thanks for providing the relevant note and issue link. I have verified that we can create an external table on an empty directory in Minio after removing condition
'mediaType.is(OCTET_STREAM_MEDIA_TYPE)'
, the remaining conditions'metadata.isKeyNeedsPathSeparator() && objectMetadata.getContentLength() == 0'
is capable of handling the directory identification problem described in issue #20310.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meanwhile, if we do not remove condition
'mediaType.is(OCTET_STREAM_MEDIA_TYPE)'
, we will get an exceptionExternal location must be a directory
when trying to create an external table on an empty directory in some other Object Storage Systems like Ozone.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the empty directory table covered by any test cases that run in CI? If not we should add it. Aside from that I think this PR is good to go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'll check it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ZacBlanco @imjalpreet I have added test method
testCreateExternalTableOnEmptyS3Directory()
inBaseTestHiveInsertOverwrite
, it verifies the behavior of creating an external hive table on an empty S3 directory. Please take a look when convenient, thanks.