-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Forbid scheme://authority locations (without trailing slash) #17923
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
99f6300
Test Location.parentDirectory for root paths
findepi 2f86859
Test Location.parentDirectory for folder-like locations
findepi 71a09c8
Consistently not quote location in exceptions
findepi de013ec
Fix exception message assertions in TestLocation
findepi 568c311
Add more location parsing tests
findepi 2677ae2
Test Hive behavior when table location `s3://bucket`
findepi c1cd116
Forbid scheme://authority locations (without trailing slash)
findepi 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
148 changes: 114 additions & 34 deletions
148
lib/trino-filesystem/src/test/java/io/trino/filesystem/TestLocation.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
124 changes: 124 additions & 0 deletions
124
plugin/trino-hive/src/test/java/io/trino/plugin/hive/s3/TestHiveS3MinioQueries.java
This file contains hidden or 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,124 @@ | ||
| /* | ||
| * 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 io.trino.plugin.hive.s3; | ||
|
|
||
| import com.google.common.collect.ImmutableMap; | ||
| import io.trino.plugin.hive.HiveQueryRunner; | ||
| import io.trino.plugin.hive.NodeVersion; | ||
| import io.trino.plugin.hive.metastore.HiveMetastoreConfig; | ||
| import io.trino.plugin.hive.metastore.file.FileHiveMetastore; | ||
| import io.trino.plugin.hive.metastore.file.FileHiveMetastoreConfig; | ||
| import io.trino.testing.AbstractTestQueryFramework; | ||
| import io.trino.testing.DataProviders; | ||
| import io.trino.testing.QueryRunner; | ||
| import io.trino.testing.containers.Minio; | ||
| import org.testng.annotations.AfterClass; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import java.io.File; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| import static com.google.common.base.Verify.verify; | ||
| import static io.trino.plugin.hive.HiveTestUtils.HDFS_ENVIRONMENT; | ||
| import static io.trino.testing.TestingNames.randomNameSuffix; | ||
| import static io.trino.testing.containers.Minio.MINIO_ACCESS_KEY; | ||
| import static io.trino.testing.containers.Minio.MINIO_SECRET_KEY; | ||
| import static java.nio.charset.StandardCharsets.UTF_8; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| public class TestHiveS3MinioQueries | ||
| extends AbstractTestQueryFramework | ||
| { | ||
| private Minio minio; | ||
|
|
||
| @Override | ||
| protected QueryRunner createQueryRunner() | ||
| throws Exception | ||
| { | ||
| minio = closeAfterClass(Minio.builder().build()); | ||
| minio.start(); | ||
|
|
||
| return HiveQueryRunner.builder() | ||
| .setMetastore(queryRunner -> { | ||
| File baseDir = queryRunner.getCoordinator().getBaseDataDir().resolve("hive_data").toFile(); | ||
| return new FileHiveMetastore( | ||
| new NodeVersion("testversion"), | ||
| HDFS_ENVIRONMENT, | ||
| new HiveMetastoreConfig().isHideDeltaLakeTables(), | ||
| new FileHiveMetastoreConfig() | ||
| .setCatalogDirectory(baseDir.toURI().toString()) | ||
| .setDisableLocationChecks(true) // matches Glue behavior | ||
|
hashhar marked this conversation as resolved.
|
||
| .setMetastoreUser("test")); | ||
| }) | ||
| .setHiveProperties(ImmutableMap.<String, String>builder() | ||
| .put("hive.s3.aws-access-key", MINIO_ACCESS_KEY) | ||
| .put("hive.s3.aws-secret-key", MINIO_SECRET_KEY) | ||
| .put("hive.s3.endpoint", minio.getMinioAddress()) | ||
| .put("hive.s3.path-style-access", "true") | ||
| .put("hive.non-managed-table-writes-enabled", "true") | ||
| .buildOrThrow()) | ||
| .build(); | ||
| } | ||
|
|
||
| @AfterClass(alwaysRun = true) | ||
| public void cleanUp() | ||
| { | ||
| minio = null; // closed by closeAfterClass | ||
| } | ||
|
|
||
| @Test(dataProviderClass = DataProviders.class, dataProvider = "trueFalse") | ||
| public void testTableLocationTopOfTheBucket(boolean locationWithTrailingSlash) | ||
|
findepi marked this conversation as resolved.
|
||
| { | ||
| String bucketName = "test-bucket-" + randomNameSuffix(); | ||
| minio.createBucket(bucketName); | ||
| minio.writeFile("We are\nawesome at\nmultiple slashes.".getBytes(UTF_8), bucketName, "a_file"); | ||
|
|
||
| String location = "s3://%s%s".formatted(bucketName, locationWithTrailingSlash ? "/" : ""); | ||
| String tableName = "test_table_top_of_bucket_%s_%s".formatted(locationWithTrailingSlash, randomNameSuffix()); | ||
| String create = "CREATE TABLE %s (a varchar) WITH (format='TEXTFILE', external_location='%s')".formatted(tableName, location); | ||
| if (!locationWithTrailingSlash) { | ||
| assertQueryFails(create, "External location is not a valid file system URI: " + location); | ||
| return; | ||
| } | ||
| assertUpdate(create); | ||
|
|
||
| // Verify location was not normalized along the way. Glue would not do that. | ||
| assertThat(getDeclaredTableLocation(tableName)) | ||
| .isEqualTo(location); | ||
|
|
||
| assertThat(query("TABLE " + tableName)) | ||
| .matches("VALUES VARCHAR 'We are', 'awesome at', 'multiple slashes.'"); | ||
|
|
||
| assertUpdate("INSERT INTO " + tableName + " VALUES 'Aren''t we?'", 1); | ||
|
|
||
| assertThat(query("TABLE " + tableName)) | ||
| .matches("VALUES VARCHAR 'We are', 'awesome at', 'multiple slashes.', 'Aren''t we?'"); | ||
|
|
||
| assertUpdate("DROP TABLE " + tableName); | ||
| } | ||
|
|
||
| private String getDeclaredTableLocation(String tableName) | ||
| { | ||
| Pattern locationPattern = Pattern.compile(".*external_location = '(.*?)'.*", Pattern.DOTALL); | ||
| Object result = computeScalar("SHOW CREATE TABLE " + tableName); | ||
| Matcher matcher = locationPattern.matcher((String) result); | ||
| if (matcher.find()) { | ||
| String location = matcher.group(1); | ||
| verify(!matcher.find(), "Unexpected second match"); | ||
| return location; | ||
| } | ||
| throw new IllegalStateException("Location not found in: " + result); | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.