-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Delta Lake $properties system table
- Loading branch information
Showing
10 changed files
with
286 additions
and
1 deletion.
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
111 changes: 111 additions & 0 deletions
111
...in/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakePropertiesTable.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,111 @@ | ||
/* | ||
* 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; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableSet; | ||
import io.trino.plugin.deltalake.transactionlog.MetadataEntry; | ||
import io.trino.plugin.deltalake.transactionlog.ProtocolEntry; | ||
import io.trino.plugin.deltalake.util.PageListBuilder; | ||
import io.trino.spi.Page; | ||
import io.trino.spi.connector.ColumnMetadata; | ||
import io.trino.spi.connector.ConnectorPageSource; | ||
import io.trino.spi.connector.ConnectorSession; | ||
import io.trino.spi.connector.ConnectorTableMetadata; | ||
import io.trino.spi.connector.ConnectorTransactionHandle; | ||
import io.trino.spi.connector.FixedPageSource; | ||
import io.trino.spi.connector.SchemaTableName; | ||
import io.trino.spi.connector.SystemTable; | ||
import io.trino.spi.predicate.TupleDomain; | ||
|
||
import java.util.List; | ||
|
||
import static io.trino.spi.type.VarcharType.VARCHAR; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
public class DeltaLakePropertiesTable | ||
implements SystemTable | ||
{ | ||
private static final String DELTA_FEATURE_PREFIX = "delta.feature."; | ||
private static final String MIN_READER_VERSION_KEY = "delta.minReaderVersion"; | ||
private static final String MIN_WRITER_VERSION_KEY = "delta.minWriterVersion"; | ||
|
||
private static final List<ColumnMetadata> COLUMNS = ImmutableList.<ColumnMetadata>builder() | ||
.add(new ColumnMetadata("key", VARCHAR)) | ||
.add(new ColumnMetadata("value", VARCHAR)) | ||
.build(); | ||
|
||
private final ConnectorTableMetadata tableMetadata; | ||
private final MetadataEntry metadataEntry; | ||
private final ProtocolEntry protocolEntry; | ||
|
||
public DeltaLakePropertiesTable(SchemaTableName tableName, MetadataEntry metadataEntry, ProtocolEntry protocolEntry) | ||
{ | ||
this.metadataEntry = requireNonNull(metadataEntry, "metadataEntry is null"); | ||
this.protocolEntry = requireNonNull(protocolEntry, "protocolEntry is null"); | ||
this.tableMetadata = new ConnectorTableMetadata(requireNonNull(tableName, "tableName is null"), COLUMNS); | ||
} | ||
|
||
@Override | ||
public Distribution getDistribution() | ||
{ | ||
return Distribution.SINGLE_COORDINATOR; | ||
} | ||
|
||
@Override | ||
public ConnectorTableMetadata getTableMetadata() | ||
{ | ||
return tableMetadata; | ||
} | ||
|
||
@Override | ||
public ConnectorPageSource pageSource(ConnectorTransactionHandle transactionHandle, ConnectorSession session, TupleDomain<Integer> constraint) | ||
{ | ||
return new FixedPageSource(buildPages()); | ||
} | ||
|
||
private List<Page> buildPages() | ||
{ | ||
PageListBuilder pagesBuilder = PageListBuilder.forTable(tableMetadata); | ||
|
||
metadataEntry.getConfiguration().forEach((key, value) -> { | ||
pagesBuilder.beginRow(); | ||
pagesBuilder.appendVarchar(key); | ||
pagesBuilder.appendVarchar(value); | ||
pagesBuilder.endRow(); | ||
}); | ||
|
||
pagesBuilder.beginRow(); | ||
pagesBuilder.appendVarchar(MIN_READER_VERSION_KEY); | ||
pagesBuilder.appendVarchar(String.valueOf(protocolEntry.getMinReaderVersion())); | ||
pagesBuilder.endRow(); | ||
|
||
pagesBuilder.beginRow(); | ||
pagesBuilder.appendVarchar(MIN_WRITER_VERSION_KEY); | ||
pagesBuilder.appendVarchar(String.valueOf(protocolEntry.getMinWriterVersion())); | ||
pagesBuilder.endRow(); | ||
|
||
ImmutableSet.<String>builder() | ||
.addAll(protocolEntry.getReaderFeatures().orElseGet(ImmutableSet::of)) | ||
.addAll(protocolEntry.getWriterFeatures().orElseGet(ImmutableSet::of)) | ||
.build().forEach(feature -> { | ||
pagesBuilder.beginRow(); | ||
pagesBuilder.appendVarchar(DELTA_FEATURE_PREFIX + feature); | ||
pagesBuilder.appendVarchar("supported"); | ||
pagesBuilder.endRow(); | ||
}); | ||
|
||
return pagesBuilder.build(); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -17,4 +17,5 @@ public enum DeltaLakeTableType | |
{ | ||
DATA, | ||
HISTORY, | ||
PROPERTIES, | ||
} |
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
99 changes: 99 additions & 0 deletions
99
...src/main/java/io/trino/tests/product/deltalake/TestDeltaLakeSystemTableCompatibility.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,99 @@ | ||
/* | ||
* 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.tests.product.deltalake; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import io.trino.tempto.assertions.QueryAssert.Row; | ||
import io.trino.tempto.query.QueryResult; | ||
import io.trino.testng.services.Flaky; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.List; | ||
|
||
import static io.trino.tempto.assertions.QueryAssert.Row.row; | ||
import static io.trino.testing.TestingNames.randomNameSuffix; | ||
import static io.trino.tests.product.TestGroups.DELTA_LAKE_DATABRICKS; | ||
import static io.trino.tests.product.TestGroups.DELTA_LAKE_EXCLUDE_104; | ||
import static io.trino.tests.product.TestGroups.DELTA_LAKE_EXCLUDE_113; | ||
import static io.trino.tests.product.TestGroups.DELTA_LAKE_EXCLUDE_73; | ||
import static io.trino.tests.product.TestGroups.DELTA_LAKE_EXCLUDE_91; | ||
import static io.trino.tests.product.TestGroups.DELTA_LAKE_OSS; | ||
import static io.trino.tests.product.TestGroups.PROFILE_SPECIFIC_TESTS; | ||
import static io.trino.tests.product.deltalake.util.DeltaLakeTestUtils.DATABRICKS_COMMUNICATION_FAILURE_ISSUE; | ||
import static io.trino.tests.product.deltalake.util.DeltaLakeTestUtils.DATABRICKS_COMMUNICATION_FAILURE_MATCH; | ||
import static io.trino.tests.product.deltalake.util.DeltaLakeTestUtils.dropDeltaTableWithRetry; | ||
import static io.trino.tests.product.utils.QueryExecutors.onDelta; | ||
import static io.trino.tests.product.utils.QueryExecutors.onTrino; | ||
import static java.lang.String.format; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class TestDeltaLakeSystemTableCompatibility | ||
extends BaseTestDeltaLakeS3Storage | ||
{ | ||
@Test(groups = {DELTA_LAKE_DATABRICKS, DELTA_LAKE_EXCLUDE_73, DELTA_LAKE_EXCLUDE_91, DELTA_LAKE_EXCLUDE_104, DELTA_LAKE_EXCLUDE_113, DELTA_LAKE_OSS, PROFILE_SPECIFIC_TESTS}) | ||
@Flaky(issue = DATABRICKS_COMMUNICATION_FAILURE_ISSUE, match = DATABRICKS_COMMUNICATION_FAILURE_MATCH) | ||
public void testTablePropertiesCaseSensitivity() | ||
{ | ||
String tableName = "test_dl_table_properties_case_sensitivity_" + randomNameSuffix(); | ||
String tableDirectory = "databricks-compatibility-test-" + tableName; | ||
|
||
onDelta().executeQuery(format("CREATE TABLE default.%s (col INT) USING DELTA LOCATION 's3://%s/%s' TBLPROPERTIES ('test_key'='test_value', 'Test_Key'='Test_Mixed_Case')", | ||
tableName, | ||
bucketName, | ||
tableDirectory)); | ||
List<Row> expectedRows = ImmutableList.of( | ||
row("test_key", "test_value"), | ||
row("Test_Key", "Test_Mixed_Case")); | ||
try { | ||
QueryResult deltaResult = onDelta().executeQuery("SHOW TBLPROPERTIES default." + tableName); | ||
QueryResult trinoResult = onTrino().executeQuery("SELECT * FROM default.\"" + tableName + "$properties\""); | ||
assertThat(deltaResult).contains(expectedRows); | ||
assertThat(trinoResult).contains(expectedRows); | ||
assertThat(trinoResult.rows()).containsExactlyInAnyOrderElementsOf(deltaResult.rows()); | ||
} | ||
finally { | ||
dropDeltaTableWithRetry("default." + tableName); | ||
} | ||
} | ||
|
||
@Test(groups = {DELTA_LAKE_DATABRICKS, DELTA_LAKE_EXCLUDE_73, DELTA_LAKE_EXCLUDE_91, DELTA_LAKE_EXCLUDE_104, DELTA_LAKE_EXCLUDE_113, DELTA_LAKE_OSS, PROFILE_SPECIFIC_TESTS}) | ||
@Flaky(issue = DATABRICKS_COMMUNICATION_FAILURE_ISSUE, match = DATABRICKS_COMMUNICATION_FAILURE_MATCH) | ||
public void testTablePropertiesWithTableFeatures() | ||
{ | ||
String tableName = "test_dl_table_properties_with_features_" + randomNameSuffix(); | ||
String tableDirectory = "databricks-compatibility-test-" + tableName; | ||
|
||
onDelta().executeQuery(format("CREATE TABLE default.%s (col INT) USING DELTA LOCATION 's3://%s/%s'" + | ||
" TBLPROPERTIES ('delta.minReaderVersion'='3', 'delta.minWriterVersion'='7', 'delta.columnMapping.mode'='id')", | ||
tableName, | ||
bucketName, | ||
tableDirectory)); | ||
|
||
List<Row> expectedRows = ImmutableList.of( | ||
row("delta.columnMapping.mode", "id"), | ||
row("delta.feature.columnMapping", "supported"), | ||
row("delta.minReaderVersion", "3"), | ||
row("delta.minWriterVersion", "7")); | ||
try { | ||
QueryResult deltaResult = onDelta().executeQuery("SHOW TBLPROPERTIES default." + tableName); | ||
QueryResult trinoResult = onTrino().executeQuery("SELECT * FROM default.\"" + tableName + "$properties\""); | ||
assertThat(deltaResult).contains(expectedRows); | ||
assertThat(trinoResult).contains(expectedRows); | ||
assertThat(trinoResult.rows()).containsExactlyInAnyOrderElementsOf(deltaResult.rows()); | ||
} | ||
finally { | ||
dropDeltaTableWithRetry("default." + tableName); | ||
} | ||
} | ||
} |
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