Skip to content

Commit

Permalink
Add test for S3 and Glue metastore
Browse files Browse the repository at this point in the history
Change AWS credential to use the same S3 bucket as other tests.

Co-Authored-By: Slawomir Pajak <[email protected]>
  • Loading branch information
ebyhr and pajaks committed Jun 18, 2023
1 parent 5804fb1 commit b9cd773
Show file tree
Hide file tree
Showing 9 changed files with 989 additions and 2 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,10 @@ jobs:
ABFS_CONTAINER: ${{ secrets.AZURE_ABFS_CONTAINER }}
ABFS_ACCOUNT: ${{ secrets.AZURE_ABFS_ACCOUNT }}
ABFS_ACCESSKEY: ${{ secrets.AZURE_ABFS_ACCESSKEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESSKEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRETKEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.TRINO_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.TRINO_AWS_SECRET_ACCESS_KEY }}
AWS_REGION: us-east-2
S3_BUCKET: trino-ci-test
GCP_CREDENTIALS_KEY: ${{ secrets.GCP_CREDENTIALS_KEY }}
# Run tests if any of the secrets is present. Do not skip tests when one secret renamed, or secret name has a typo.
if: >-
Expand Down
2 changes: 2 additions & 0 deletions plugin/trino-delta-lake/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@
<exclude>**/TestDeltaLakeAdlsStorage.java</exclude>
<exclude>**/TestDeltaLakeAdlsConnectorSmokeTest.java</exclude>
<exclude>**/TestDeltaLakeGlueMetastore.java</exclude>
<exclude>**/TestDeltaS3AndGlueMetastoreTest.java</exclude>
<exclude>**/TestDeltaLakeCleanUpGlueMetastore.java</exclude>
<exclude>**/TestDeltaLakeSharedGlueMetastoreViews.java</exclude>
<exclude>**/TestDeltaLakeSharedGlueMetastoreWithTableRedirections.java</exclude>
Expand Down Expand Up @@ -508,6 +509,7 @@
<include>**/TestDeltaLakeAdlsStorage.java</include>
<include>**/TestDeltaLakeAdlsConnectorSmokeTest.java</include>
<include>**/TestDeltaLakeGlueMetastore.java</include>
<include>**/TestDeltaS3AndGlueMetastoreTest.java</include>
<include>**/TestDeltaLakeCleanUpGlueMetastore.java</include>
<include>**/TestDeltaLakeSharedGlueMetastoreViews.java</include>
<include>**/TestDeltaLakeSharedGlueMetastoreWithTableRedirections.java</include>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* 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.deltalake.metastore.glue;

import com.google.common.collect.ImmutableMap;
import io.trino.hdfs.TrinoFileSystemCache;
import io.trino.plugin.deltalake.DeltaLakeQueryRunner;
import io.trino.plugin.hive.BaseS3AndGlueMetastoreTest;
import io.trino.testing.DistributedQueryRunner;
import io.trino.testing.QueryRunner;

import java.nio.file.Path;
import java.util.Set;
import java.util.stream.Collectors;

import static com.google.common.collect.Iterables.getOnlyElement;
import static io.trino.plugin.deltalake.DeltaLakeQueryRunner.DELTA_CATALOG;
import static io.trino.plugin.hive.metastore.glue.GlueHiveMetastore.createTestingGlueHiveMetastore;
import static java.util.Objects.requireNonNull;
import static org.assertj.core.api.Assertions.assertThat;

public class TestDeltaS3AndGlueMetastoreTest
extends BaseS3AndGlueMetastoreTest
{
public TestDeltaS3AndGlueMetastoreTest()
{
super("partitioned_by", "location", requireNonNull(System.getenv("S3_BUCKET"), "Environment variable not set: S3_BUCKET"));
}

@Override
protected QueryRunner createQueryRunner()
throws Exception
{
closeAfterClass(TrinoFileSystemCache.INSTANCE::closeAll);

metastore = createTestingGlueHiveMetastore(Path.of(schemaPath()));
DistributedQueryRunner queryRunner = DeltaLakeQueryRunner.builder()
.setCatalogName(DELTA_CATALOG)
.setDeltaProperties(ImmutableMap.<String, String>builder()
.put("hive.metastore", "glue")
.put("hive.metastore.glue.default-warehouse-dir", schemaPath())
.put("delta.enable-non-concurrent-writes", "true")
.buildOrThrow())
.build();
queryRunner.execute("CREATE SCHEMA " + schemaName + " WITH (location = '" + schemaPath() + "')");
return queryRunner;
}

@Override
protected void validateDataFiles(String partitionColumn, String tableName, String location)
{
getActiveFiles(tableName).forEach(dataFile ->
{
String locationDirectory = location.endsWith("/") ? location : location + "/";
String partitionPart = partitionColumn.isEmpty() ? "" : partitionColumn + "=[a-z0-9]+/";
assertThat(dataFile).matches("^" + locationDirectory + partitionPart + "[a-zA-Z0-9_-]+$");
verifyPathExist(dataFile);
});
}

@Override
protected void validateMetadataFiles(String location)
{
String locationDirectory = location.endsWith("/") ? location : location + "/";
getAllMetadataDataFilesFromTableDirectory(location).forEach(metadataFile ->
{
assertThat(metadataFile).matches("^" + locationDirectory + "_delta_log/[0-9]+.json$");
verifyPathExist(metadataFile);
});

assertThat(getExtendedStatisticsFileFromTableDirectory(location)).matches("^" + locationDirectory + "_delta_log/_trino_meta/extended_stats.json$");
}

@Override
protected void validateFilesAfterDrop(String location)
{
// In Delta table created with location in treated as external, so files are not removed
assertThat(getTableFiles(location)).isNotEmpty();
}

@Override
protected Set<String> getAllDataFilesFromTableDirectory(String tableLocation)
{
return getTableFiles(tableLocation).stream()
.filter(path -> !path.contains("_delta_log"))
.collect(Collectors.toUnmodifiableSet());
}

private Set<String> getAllMetadataDataFilesFromTableDirectory(String tableLocation)
{
return getTableFiles(tableLocation).stream()
.filter(path -> path.contains("/metadata"))
.collect(Collectors.toUnmodifiableSet());
}

private String getExtendedStatisticsFileFromTableDirectory(String tableLocation)
{
return getOnlyElement(getTableFiles(tableLocation).stream()
.filter(path -> path.contains("/_trino_meta"))
.collect(Collectors.toUnmodifiableSet()));
}
}
2 changes: 2 additions & 0 deletions plugin/trino-hive/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@
<configuration>
<excludes>
<exclude>**/TestHiveGlueMetastore.java</exclude>
<exclude>**/TestHiveS3AndGlueMetastoreTest.java</exclude>
<exclude>**/TestTrinoS3FileSystemAwsS3.java</exclude>
<exclude>**/TestFullParquetReader.java</exclude>
<exclude>**/Test*FailureRecoveryTest.java</exclude>
Expand Down Expand Up @@ -584,6 +585,7 @@
<configuration>
<includes>
<include>**/TestHiveGlueMetastore.java</include>
<include>**/TestHiveS3AndGlueMetastoreTest.java</include>
<include>**/TestTrinoS3FileSystemAwsS3.java</include>
</includes>
</configuration>
Expand Down
Loading

0 comments on commit b9cd773

Please sign in to comment.