Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@
import com.google.inject.Inject;
import com.google.inject.name.Named;
import io.trino.tempto.BeforeTestWithContext;
import io.trino.tests.product.hive.Engine;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.util.Optional;

import static io.trino.tests.product.TestGroups.DELTA_LAKE_DATABRICKS;
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.hive.Engine.DELTA;
import static io.trino.tests.product.hive.Engine.TRINO;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Engine can be moved out of .....product.hive, pre-existing though.

import static io.trino.tests.product.hive.util.TemporaryHiveTable.randomTableSuffix;
import static io.trino.tests.product.utils.QueryExecutors.onDelta;
import static io.trino.tests.product.utils.QueryExecutors.onTrino;
Expand All @@ -33,9 +38,6 @@
public class TestDeltaLakeDropTableCompatibility
extends BaseTestDeltaLakeS3Storage
{
private static final Engine TRINO_ENGINE = new TrinoEngine();
private static final Engine DATABRICKS_ENGINE = new DatabricksEngine();

@Inject
@Named("s3.server_type")
private String s3ServerType;
Expand All @@ -53,39 +55,62 @@ public void setup()
public static Object[][] engineConfigurations()
{
return new Object[][] {
{TRINO_ENGINE, TRINO_ENGINE, true},
{TRINO_ENGINE, TRINO_ENGINE, false},
{TRINO_ENGINE, DATABRICKS_ENGINE, true},
{TRINO_ENGINE, DATABRICKS_ENGINE, false},
{DATABRICKS_ENGINE, TRINO_ENGINE, true},
{DATABRICKS_ENGINE, TRINO_ENGINE, false},
{DATABRICKS_ENGINE, DATABRICKS_ENGINE, true},
{DATABRICKS_ENGINE, DATABRICKS_ENGINE, false},
{TRINO, TRINO, true},
{TRINO, TRINO, false},
{TRINO, DELTA, true},
{TRINO, DELTA, false},
{DELTA, TRINO, true},
{DELTA, TRINO, false},
{DELTA, DELTA, true},
{DELTA, DELTA, false},
};
}

@Test(groups = {DELTA_LAKE_DATABRICKS, DELTA_LAKE_OSS, PROFILE_SPECIFIC_TESTS}, dataProvider = "engineConfigurations")
public void testDatabricksManagedTableDroppedFromTrino(Engine creator, Engine dropper, boolean explicitLocation)
{
testCleanupOnDrop(creator, dropper, explicitLocation);
}

private void testCleanupOnDrop(Engine creator, Engine dropper, boolean explicitLocation)
{
String schemaName = "schema_with_location_" + randomTableSuffix();
String schemaLocation = format("s3://%s/databricks-compatibility-test-%s", bucketName, schemaName);
String tableName = explicitLocation ? "external_table" : "managed_table";
creator.createSchema(schemaName, format("s3://%s/databricks-compatibility-test-%s", bucketName, schemaName));
Optional<String> tableLocation = explicitLocation
? Optional.of(format("s3://" + bucketName + "/databricks-compatibility-test-%s/%s", schemaName, tableName))
: Optional.empty();

switch (creator) {
case TRINO:
onTrino().executeQuery(format("CREATE SCHEMA delta.%s WITH (location = '%s')", schemaName, schemaLocation));
break;
case DELTA:
onDelta().executeQuery(format("CREATE SCHEMA %s LOCATION \"%s\"", schemaName, schemaLocation));
break;
default:
throw new UnsupportedOperationException("Unsupported engine: " + creator);
}
try {
onTrino().executeQuery("USE delta." + schemaName);
String tableLocation = explicitLocation ?
format("s3://" + bucketName + "/databricks-compatibility-test-%s/%s", schemaName, tableName) :
"";
creator.createTable(schemaName, tableName, tableLocation);
switch (creator) {
case TRINO:
onTrino().executeQuery(format(
"CREATE TABLE %s.%s (a, b) %s AS VALUES (1, 2), (2, 3), (3, 4)",
schemaName,
tableName,
tableLocation.map(location -> "WITH (location = '" + location + "')").orElse("")));
break;
case DELTA:
onDelta().executeQuery(format(
"CREATE TABLE %s.%s USING DELTA %s AS VALUES (1, 2), (2, 3), (3, 4)",
schemaName,
tableName,
tableLocation.map(location -> "LOCATION \"" + location + "\"").orElse("")));
break;
default:
throw new UnsupportedOperationException("Unsupported engine: " + creator);
}

ObjectListing tableFiles = s3.listObjects(bucketName, "databricks-compatibility-test-" + schemaName + "/" + tableName);
assertThat(tableFiles.getObjectSummaries()).isNotEmpty();

dropper.dropTable(schemaName, tableName);
dropper.queryExecutor().executeQuery("DROP TABLE " + schemaName + "." + tableName);
tableFiles = s3.listObjects(bucketName, "databricks-compatibility-test-" + schemaName + "/" + tableName);
if (explicitLocation) {
assertThat(tableFiles.getObjectSummaries()).isNotEmpty();
Expand All @@ -99,59 +124,4 @@ private void testCleanupOnDrop(Engine creator, Engine dropper, boolean explicitL
onDelta().executeQuery("DROP SCHEMA " + schemaName);
}
}

private interface Engine
{
void createSchema(String schemaName, String location);

void createTable(String schemaName, String tableName, String location);

void dropTable(String schemaName, String tableName);
}

private static class TrinoEngine
implements Engine
{
@Override
public void createSchema(String schemaName, String location)
{
onTrino().executeQuery(format("CREATE SCHEMA delta.%s WITH (location = '%s')", schemaName, location));
}

@Override
public void createTable(String schemaName, String tableName, String location)
{
String locationStatement = location.isEmpty() ? "" : "WITH (location = '" + location + "')";
onTrino().executeQuery(format("CREATE TABLE %s.%s (a, b) %s AS VALUES (1, 2), (2, 3), (3, 4)", schemaName, tableName, locationStatement));
}

@Override
public void dropTable(String schemaName, String tableName)
{
onTrino().executeQuery("DROP TABLE " + schemaName + "." + tableName);
}
}

private static class DatabricksEngine
implements Engine
{
@Override
public void createSchema(String schemaName, String location)
{
onDelta().executeQuery(format("CREATE SCHEMA %s LOCATION \"%s\"", schemaName, location));
}

@Override
public void createTable(String schemaName, String tableName, String location)
{
String locationStatement = location.isEmpty() ? "" : "LOCATION \"" + location + "\"";
onDelta().executeQuery(format("CREATE TABLE %s.%s USING DELTA %s AS VALUES (1, 2), (2, 3), (3, 4)", schemaName, tableName, locationStatement));
}

@Override
public void dropTable(String schemaName, String tableName)
{
onDelta().executeQuery("DROP TABLE " + schemaName + "." + tableName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import io.trino.tempto.query.QueryExecutor;

import static io.trino.tests.product.utils.QueryExecutors.onDelta;
import static io.trino.tests.product.utils.QueryExecutors.onHive;
import static io.trino.tests.product.utils.QueryExecutors.onTrino;

Expand All @@ -34,6 +35,13 @@ public QueryExecutor queryExecutor()
return onTrino();
}
},
DELTA {
@Override
public QueryExecutor queryExecutor()
{
return onDelta();
}
},
SPARK {
@Override
public QueryExecutor queryExecutor()
Expand Down