-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
add google as external storage for msq export #16051
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
73277e3
add google as external storage for msq export
pjain1 ffb02ab
for test coverage
pjain1 033a4d1
review comments
pjain1 a869e73
static checks
pjain1 7633021
spelling
pjain1 435acb8
Update docs/multi-stage-query/reference.md
pjain1 5c30d95
Update docs/multi-stage-query/reference.md
pjain1 389a406
Update docs/multi-stage-query/reference.md
pjain1 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
72 changes: 72 additions & 0 deletions
72
...e-extensions/src/main/java/org/apache/druid/storage/google/output/GoogleExportConfig.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,72 @@ | ||
/* | ||
* 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.druid.storage.google.output; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import org.apache.druid.java.util.common.HumanReadableBytes; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.List; | ||
|
||
public class GoogleExportConfig | ||
{ | ||
@JsonProperty("tempLocalDir") | ||
private final String tempLocalDir; | ||
@JsonProperty("chunkSize") | ||
private final HumanReadableBytes chunkSize; | ||
@JsonProperty("maxRetry") | ||
private final Integer maxRetry; | ||
@JsonProperty("allowedExportPaths") | ||
private final List<String> allowedExportPaths; | ||
|
||
@JsonCreator | ||
public GoogleExportConfig( | ||
@JsonProperty("tempLocalDir") final String tempLocalDir, | ||
@JsonProperty("chunkSize") @Nullable final HumanReadableBytes chunkSize, | ||
@JsonProperty("maxRetry") @Nullable final Integer maxRetry, | ||
@JsonProperty("allowedExportPaths") final List<String> allowedExportPaths) | ||
{ | ||
this.tempLocalDir = tempLocalDir; | ||
this.chunkSize = chunkSize; | ||
this.maxRetry = maxRetry; | ||
this.allowedExportPaths = allowedExportPaths; | ||
} | ||
|
||
public String getTempLocalDir() | ||
{ | ||
return tempLocalDir; | ||
} | ||
|
||
public HumanReadableBytes getChunkSize() | ||
{ | ||
return chunkSize; | ||
} | ||
|
||
public Integer getMaxRetry() | ||
{ | ||
return maxRetry; | ||
} | ||
|
||
public List<String> getAllowedExportPaths() | ||
{ | ||
return allowedExportPaths; | ||
} | ||
} |
149 changes: 149 additions & 0 deletions
149
...ons/src/main/java/org/apache/druid/storage/google/output/GoogleExportStorageProvider.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,149 @@ | ||
/* | ||
* 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.druid.storage.google.output; | ||
|
||
import com.fasterxml.jackson.annotation.JacksonInject; | ||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import com.google.common.annotations.VisibleForTesting; | ||
import org.apache.druid.data.input.google.GoogleCloudStorageInputSource; | ||
import org.apache.druid.data.input.impl.CloudObjectLocation; | ||
import org.apache.druid.error.DruidException; | ||
import org.apache.druid.java.util.common.StringUtils; | ||
import org.apache.druid.storage.ExportStorageProvider; | ||
import org.apache.druid.storage.StorageConnector; | ||
import org.apache.druid.storage.google.GoogleInputDataConfig; | ||
import org.apache.druid.storage.google.GoogleStorage; | ||
import org.apache.druid.storage.google.GoogleStorageDruidModule; | ||
|
||
import javax.validation.constraints.NotNull; | ||
import java.io.File; | ||
import java.net.URI; | ||
import java.util.List; | ||
|
||
@JsonTypeName(GoogleExportStorageProvider.TYPE_NAME) | ||
public class GoogleExportStorageProvider implements ExportStorageProvider | ||
{ | ||
public static final String TYPE_NAME = GoogleCloudStorageInputSource.TYPE_KEY; | ||
@JsonProperty | ||
private final String bucket; | ||
@JsonProperty | ||
private final String prefix; | ||
|
||
@JacksonInject | ||
GoogleExportConfig googleExportConfig; | ||
@JacksonInject | ||
GoogleStorage googleStorage; | ||
@JacksonInject | ||
GoogleInputDataConfig googleInputDataConfig; | ||
|
||
@JsonCreator | ||
public GoogleExportStorageProvider( | ||
@JsonProperty(value = "bucket", required = true) String bucket, | ||
@JsonProperty(value = "prefix", required = true) String prefix | ||
) | ||
{ | ||
this.bucket = bucket; | ||
this.prefix = prefix; | ||
} | ||
|
||
@Override | ||
public StorageConnector get() | ||
{ | ||
final String tempDir = googleExportConfig.getTempLocalDir(); | ||
if (tempDir == null) { | ||
throw DruidException.forPersona(DruidException.Persona.OPERATOR) | ||
.ofCategory(DruidException.Category.NOT_FOUND) | ||
.build("The runtime property `druid.export.storage.google.tempLocalDir` must be configured for GCS export."); | ||
} | ||
final List<String> allowedExportPaths = googleExportConfig.getAllowedExportPaths(); | ||
if (allowedExportPaths == null) { | ||
throw DruidException.forPersona(DruidException.Persona.OPERATOR) | ||
.ofCategory(DruidException.Category.NOT_FOUND) | ||
.build( | ||
"The runtime property `druid.export.storage.google.allowedExportPaths` must be configured for GCS export."); | ||
} | ||
validatePrefix(allowedExportPaths, bucket, prefix); | ||
final GoogleOutputConfig googleOutputConfig = new GoogleOutputConfig( | ||
bucket, | ||
prefix, | ||
new File(tempDir), | ||
googleExportConfig.getChunkSize(), | ||
googleExportConfig.getMaxRetry() | ||
); | ||
return new GoogleStorageConnector(googleOutputConfig, googleStorage, googleInputDataConfig); | ||
} | ||
|
||
@VisibleForTesting | ||
static void validatePrefix(@NotNull final List<String> allowedExportPaths, final String bucket, final String prefix) | ||
{ | ||
final URI providedUri = new CloudObjectLocation(bucket, prefix).toUri(GoogleStorageDruidModule.SCHEME_GS); | ||
for (final String path : allowedExportPaths) { | ||
final URI allowedUri = URI.create(path); | ||
if (validateUri(allowedUri, providedUri)) { | ||
return; | ||
} | ||
} | ||
throw DruidException.forPersona(DruidException.Persona.USER) | ||
.ofCategory(DruidException.Category.INVALID_INPUT) | ||
.build("None of the allowed prefixes matched the input path [%s]. " | ||
+ "Please reach out to the cluster admin for the whitelisted paths for export. " | ||
+ "The paths are controlled via the property `druid.export.storage.google.allowedExportPaths`.", | ||
providedUri); | ||
} | ||
|
||
private static boolean validateUri(final URI allowedUri, final URI providedUri) | ||
{ | ||
if (!allowedUri.getHost().equals(providedUri.getHost())) { | ||
return false; | ||
} | ||
final String allowedPath = StringUtils.maybeAppendTrailingSlash(allowedUri.getPath()); | ||
final String providedPath = StringUtils.maybeAppendTrailingSlash(providedUri.getPath()); | ||
return providedPath.startsWith(allowedPath); | ||
} | ||
|
||
@JsonProperty("bucket") | ||
public String getBucket() | ||
{ | ||
return bucket; | ||
} | ||
|
||
@JsonProperty("prefix") | ||
public String getPrefix() | ||
{ | ||
return prefix; | ||
} | ||
|
||
@Override | ||
@JsonIgnore | ||
public String getResourceType() | ||
{ | ||
return TYPE_NAME; | ||
} | ||
|
||
@Override | ||
@JsonIgnore | ||
public String getBasePath() | ||
{ | ||
return new CloudObjectLocation(bucket, prefix).toUri(GoogleStorageDruidModule.SCHEME_GS).toString(); | ||
} | ||
} |
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
73 changes: 73 additions & 0 deletions
73
...src/test/java/org/apache/druid/storage/google/output/GoogleExportStorageProviderTest.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,73 @@ | ||
/* | ||
* 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.druid.storage.google.output; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import org.apache.druid.error.DruidException; | ||
import org.apache.druid.storage.StorageConnector; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
|
||
public class GoogleExportStorageProviderTest | ||
{ | ||
private final List<String> validPrefixes = ImmutableList.of( | ||
"gs://bucket-name/validPath1", | ||
"gs://bucket-name/validPath2" | ||
); | ||
|
||
@Test | ||
public void testGoogleExportStorageProvider() | ||
{ | ||
GoogleExportStorageProvider googleExportStorageProvider = new GoogleExportStorageProvider("bucket-name", "validPath1"); | ||
googleExportStorageProvider.googleExportConfig = new GoogleExportConfig("tempLocalDir", null, null, validPrefixes); | ||
StorageConnector storageConnector = googleExportStorageProvider.get(); | ||
Assert.assertNotNull(storageConnector); | ||
Assert.assertTrue(storageConnector instanceof GoogleStorageConnector); | ||
|
||
Assert.assertEquals("gs://bucket-name/validPath1", googleExportStorageProvider.getBasePath()); | ||
} | ||
|
||
@Test | ||
public void testValidatePaths() | ||
{ | ||
GoogleExportStorageProvider.validatePrefix(validPrefixes, "bucket-name", "validPath1/"); | ||
GoogleExportStorageProvider.validatePrefix(validPrefixes, "bucket-name", "validPath1"); | ||
GoogleExportStorageProvider.validatePrefix(validPrefixes, "bucket-name", "validPath1/validSubPath/"); | ||
|
||
GoogleExportStorageProvider.validatePrefix(ImmutableList.of("gs://bucket-name"), "bucket-name", ""); | ||
GoogleExportStorageProvider.validatePrefix(ImmutableList.of("gs://bucket-name"), "bucket-name", "validPath"); | ||
GoogleExportStorageProvider.validatePrefix(validPrefixes, "bucket-name", "validPath1/../validPath2/"); | ||
|
||
Assert.assertThrows( | ||
DruidException.class, | ||
() -> GoogleExportStorageProvider.validatePrefix(validPrefixes, "incorrect-bucket", "validPath1/") | ||
); | ||
Assert.assertThrows( | ||
DruidException.class, | ||
() -> GoogleExportStorageProvider.validatePrefix(validPrefixes, "bucket-name", "invalidPath1") | ||
); | ||
Assert.assertThrows( | ||
DruidException.class, | ||
() -> GoogleExportStorageProvider.validatePrefix(validPrefixes, "bucket-name", "validPath123") | ||
); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
1M | ||
100MiB | ||
32-bit | ||
4MiB | ||
500MiB | ||
64-bit | ||
ACL | ||
|
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.
what is the need to have this class than having these properties directly passed into GoogleExportStorageConnector? It would be nice to have uniformity in various cloud provider implementations.
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.
Just followed what
S3ExportStorageProvider
does. I think the reason for separate config is that these configs needs to be injected while creatingExportStorageProvider
instance in the sql planning phase.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.
Ah right. I see it now.