-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Support views in Delta lake Connector #11763
Merged
Merged
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,6 +190,9 @@ protected QueryRunner createQueryRunner() | |
protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) | ||
{ | ||
switch (connectorBehavior) { | ||
case SUPPORTS_CREATE_VIEW: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a follow-up to this PR, could you please create an issue (with |
||
return true; | ||
|
||
case SUPPORTS_RENAME_SCHEMA: | ||
return false; | ||
|
||
|
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
166 changes: 166 additions & 0 deletions
166
...a-lake/src/test/java/io/trino/plugin/deltalake/BaseDeltaLakeSharedMetastoreViewsTest.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,166 @@ | ||
/* | ||
* 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.ImmutableMap; | ||
import io.trino.Session; | ||
import io.trino.plugin.deltalake.metastore.TestingDeltaLakeMetastoreModule; | ||
import io.trino.plugin.hive.TestingHivePlugin; | ||
import io.trino.plugin.hive.metastore.HiveMetastore; | ||
import io.trino.testing.AbstractTestQueryFramework; | ||
import io.trino.testing.DistributedQueryRunner; | ||
import io.trino.testing.QueryRunner; | ||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Optional; | ||
|
||
import static com.google.common.io.MoreFiles.deleteRecursively; | ||
import static com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE; | ||
import static com.google.inject.util.Modules.EMPTY_MODULE; | ||
import static io.trino.testing.TestingNames.randomNameSuffix; | ||
import static io.trino.testing.TestingSession.testSessionBuilder; | ||
import static java.lang.String.format; | ||
|
||
/** | ||
* Tests querying views on a schema which has a mix of Hive and Delta Lake tables. | ||
*/ | ||
public abstract class BaseDeltaLakeSharedMetastoreViewsTest | ||
ebyhr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
extends AbstractTestQueryFramework | ||
{ | ||
protected static final String DELTA_CATALOG_NAME = "delta_lake"; | ||
protected static final String HIVE_CATALOG_NAME = "hive"; | ||
protected static final String SCHEMA = "test_shared_schema_views_" + randomNameSuffix(); | ||
|
||
private String dataDirectory; | ||
private HiveMetastore metastore; | ||
|
||
@Override | ||
protected QueryRunner createQueryRunner() | ||
throws Exception | ||
{ | ||
Session session = testSessionBuilder() | ||
.setCatalog(DELTA_CATALOG_NAME) | ||
.setSchema(SCHEMA) | ||
.build(); | ||
DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(session).build(); | ||
|
||
this.dataDirectory = queryRunner.getCoordinator().getBaseDataDir().resolve("delta_lake_data").toString(); | ||
this.metastore = createTestMetastore(dataDirectory); | ||
|
||
queryRunner.installPlugin(new TestingDeltaLakePlugin(Optional.of(new TestingDeltaLakeMetastoreModule(metastore)), EMPTY_MODULE)); | ||
queryRunner.createCatalog(DELTA_CATALOG_NAME, "delta-lake"); | ||
|
||
queryRunner.installPlugin(new TestingHivePlugin(metastore)); | ||
|
||
ImmutableMap<String, String> hiveProperties = ImmutableMap.<String, String>builder() | ||
.put("hive.allow-drop-table", "true") | ||
.buildOrThrow(); | ||
|
||
queryRunner.createCatalog(HIVE_CATALOG_NAME, "hive", hiveProperties); | ||
queryRunner.execute("CREATE SCHEMA " + SCHEMA); | ||
|
||
return queryRunner; | ||
} | ||
|
||
protected abstract HiveMetastore createTestMetastore(String dataDirectory); | ||
|
||
ebyhr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Test | ||
public void testViewWithLiteralColumnCreatedInDeltaLakeIsReadableInHive() | ||
{ | ||
String deltaViewName = "delta_view_" + randomNameSuffix(); | ||
String deltaView = format("%s.%s.%s", DELTA_CATALOG_NAME, SCHEMA, deltaViewName); | ||
String deltaViewOnHiveCatalog = format("%s.%s.%s", HIVE_CATALOG_NAME, SCHEMA, deltaViewName); | ||
try { | ||
assertUpdate(format("CREATE VIEW %s AS SELECT 1 bee", deltaView)); | ||
assertQuery(format("SELECT * FROM %s", deltaView), "VALUES 1"); | ||
assertQuery(format("SELECT * FROM %s", deltaViewOnHiveCatalog), "VALUES 1"); | ||
assertQuery(format("SELECT table_type FROM %s.information_schema.tables WHERE table_name = '%s' AND table_schema='%s'", HIVE_CATALOG_NAME, deltaViewName, SCHEMA), "VALUES 'VIEW'"); | ||
} | ||
finally { | ||
assertUpdate(format("DROP VIEW IF EXISTS %s", deltaView)); | ||
} | ||
} | ||
|
||
@Test | ||
public void testViewOnDeltaLakeTableCreatedInDeltaLakeIsReadableInHive() | ||
{ | ||
String deltaTableName = "delta_table_" + randomNameSuffix(); | ||
String deltaTable = format("%s.%s.%s", DELTA_CATALOG_NAME, SCHEMA, deltaTableName); | ||
String deltaViewName = "delta_view_" + randomNameSuffix(); | ||
String deltaView = format("%s.%s.%s", DELTA_CATALOG_NAME, SCHEMA, deltaViewName); | ||
String deltaViewOnHiveCatalog = format("%s.%s.%s", HIVE_CATALOG_NAME, SCHEMA, deltaViewName); | ||
try { | ||
assertUpdate(format("CREATE TABLE %s AS SELECT 1 bee", deltaTable), 1); | ||
assertUpdate(format("CREATE VIEW %s AS SELECT * from %s", deltaView, deltaTable)); | ||
assertQuery(format("SELECT * FROM %s", deltaView), "VALUES 1"); | ||
assertQuery(format("SELECT * FROM %s", deltaViewOnHiveCatalog), "VALUES 1"); | ||
assertQuery(format("SELECT table_type FROM %s.information_schema.tables WHERE table_name = '%s' AND table_schema='%s'", HIVE_CATALOG_NAME, deltaViewName, SCHEMA), "VALUES 'VIEW'"); | ||
} | ||
finally { | ||
assertUpdate(format("DROP TABLE IF EXISTS %s", deltaTable)); | ||
assertUpdate(format("DROP VIEW IF EXISTS %s", deltaView)); | ||
} | ||
} | ||
|
||
@Test | ||
public void testViewWithLiteralColumnCreatedInHiveIsReadableInDeltaLake() | ||
{ | ||
String trinoViewOnHiveName = "trino_view_on_hive_" + randomNameSuffix(); | ||
String trinoViewOnHive = format("%s.%s.%s", HIVE_CATALOG_NAME, SCHEMA, trinoViewOnHiveName); | ||
String trinoViewOnHiveOnDeltaCatalog = format("%s.%s.%s", DELTA_CATALOG_NAME, SCHEMA, trinoViewOnHiveName); | ||
try { | ||
assertUpdate(format("CREATE VIEW %s AS SELECT 1 bee", trinoViewOnHive)); | ||
assertQuery(format("SELECT * FROM %s", trinoViewOnHive), "VALUES 1"); | ||
assertQuery(format("SELECT * FROM %s", trinoViewOnHiveOnDeltaCatalog), "VALUES 1"); | ||
assertQuery(format("SELECT table_type FROM %s.information_schema.tables WHERE table_name = '%s' AND table_schema='%s'", HIVE_CATALOG_NAME, trinoViewOnHiveName, SCHEMA), "VALUES 'VIEW'"); | ||
} | ||
finally { | ||
assertUpdate(format("DROP VIEW IF EXISTS %s", trinoViewOnHive)); | ||
} | ||
} | ||
|
||
@Test | ||
public void testViewOnHiveTableCreatedInHiveIsReadableInDeltaLake() | ||
{ | ||
String hiveTableName = "hive_table_" + randomNameSuffix(); | ||
String hiveTable = format("%s.%s.%s", HIVE_CATALOG_NAME, SCHEMA, hiveTableName); | ||
String trinoViewOnHiveName = "trino_view_on_hive_" + randomNameSuffix(); | ||
String trinoViewOnHive = format("%s.%s.%s", HIVE_CATALOG_NAME, SCHEMA, trinoViewOnHiveName); | ||
String trinoViewOnHiveOnDeltaCatalog = format("%s.%s.%s", DELTA_CATALOG_NAME, SCHEMA, trinoViewOnHiveName); | ||
try { | ||
assertUpdate(format("CREATE TABLE %s AS SELECT 1 bee", hiveTable), 1); | ||
assertUpdate(format("CREATE VIEW %s AS SELECT 1 bee", trinoViewOnHive)); | ||
assertQuery(format("SELECT * FROM %s", trinoViewOnHive), "VALUES 1"); | ||
assertQuery(format("SELECT * FROM %s", trinoViewOnHiveOnDeltaCatalog), "VALUES 1"); | ||
assertQuery(format("SELECT table_type FROM %s.information_schema.tables WHERE table_name = '%s' AND table_schema='%s'", DELTA_CATALOG_NAME, trinoViewOnHiveName, SCHEMA), "VALUES 'VIEW'"); | ||
} | ||
finally { | ||
assertUpdate(format("DROP TABLE IF EXISTS %s", hiveTable)); | ||
assertUpdate(format("DROP VIEW IF EXISTS %s", trinoViewOnHive)); | ||
} | ||
} | ||
|
||
@AfterClass(alwaysRun = true) | ||
public void cleanup() | ||
throws IOException | ||
{ | ||
if (metastore != null) { | ||
metastore.dropDatabase(SCHEMA, false); | ||
deleteRecursively(Path.of(dataDirectory), ALLOW_INSECURE); | ||
} | ||
} | ||
} | ||
ebyhr marked this conversation as resolved.
Show resolved
Hide resolved
|
30 changes: 30 additions & 0 deletions
30
...a-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakeSharedFileMetastoreViews.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,30 @@ | ||
/* | ||
* 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 io.trino.plugin.hive.metastore.HiveMetastore; | ||
|
||
import java.io.File; | ||
|
||
import static io.trino.plugin.hive.metastore.file.FileHiveMetastore.createTestingFileHiveMetastore; | ||
|
||
public class TestDeltaLakeSharedFileMetastoreViews | ||
extends BaseDeltaLakeSharedMetastoreViewsTest | ||
{ | ||
@Override | ||
protected HiveMetastore createTestMetastore(String dataDirectory) | ||
{ | ||
return createTestingFileHiveMetastore(new File(dataDirectory)); | ||
} | ||
} |
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.
The PR is missing a test where Trino views for Delta gets created on a Glue backed metastore.
Consider either such a test either in
trino-delta-lake
.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.
Test added