Skip to content

Commit

Permalink
Add create/drop dynamic catalog tests for lake connectors
Browse files Browse the repository at this point in the history
  • Loading branch information
anusudarsan committed Jan 8, 2025
1 parent 509508a commit 70943f9
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,29 @@ public void testDropSchemaExternalFiles()

protected abstract String bucketUrl();

@Test
void testCreateDropDynamicCatalog()
{
String catalog = "new_catalog_" + randomNameSuffix();
String createCatalogSql = """
CREATE CATALOG %1$s USING delta_lake
WITH (
"hive.metastore" = 'thrift',
"hive.metastore.uri" = '%2$s'
)""".formatted(catalog, hiveHadoop.getHiveMetastoreEndpoint().toString());
assertUpdate(createCatalogSql);
assertCatalogs(ImmutableList.of("system", "delta", "hive", "tpch", catalog));

assertUpdate("DROP CATALOG " + catalog);
assertCatalogs(ImmutableList.of("system", "delta", "hive", "tpch"));
// re-add the same catalog
assertUpdate(createCatalogSql);
assertCatalogs(ImmutableList.of("system", "delta", "hive", "tpch", catalog));

assertUpdate("DROP CATALOG " + catalog);
assertCatalogs(ImmutableList.of("system", "delta", "hive", "tpch"));
}

@Test
public void testCreateTableInNonexistentSchemaFails()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
*/
package io.trino.plugin.deltalake.metastore.glue;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.trino.plugin.deltalake.DeltaLakeQueryRunner;
import io.trino.plugin.hive.BaseS3AndGlueMetastoreTest;
import io.trino.testing.QueryRunner;
import org.junit.jupiter.api.Test;

import java.net.URI;
import java.util.Set;
Expand All @@ -26,6 +28,7 @@
import static com.google.common.collect.Iterables.getOnlyElement;
import static io.trino.plugin.hive.metastore.glue.TestingGlueHiveMetastore.createTestingGlueHiveMetastore;
import static io.trino.testing.SystemEnvironmentUtils.requireEnv;
import static io.trino.testing.TestingNames.randomNameSuffix;
import static org.assertj.core.api.Assertions.assertThat;

public class TestDeltaS3AndGlueMetastoreTest
Expand Down Expand Up @@ -106,4 +109,27 @@ private String getExtendedStatisticsFileFromTableDirectory(String tableLocation)
.filter(path -> path.contains("/_trino_meta"))
.collect(Collectors.toUnmodifiableSet()));
}

@Test
void testCreateDropDynamicCatalog()
{
String catalog = "new_catalog_" + randomNameSuffix();
String createCatalogSql = """
CREATE CATALOG %1$s USING delta_lake
WITH (
"hive.metastore" = 'glue',
"hive.metastore.glue.default-warehouse-dir" = '%2$s'
)""".formatted(catalog, schemaPath());
assertUpdate(createCatalogSql);
assertCatalogs(ImmutableList.of("system", "delta", "tpch", catalog));

assertUpdate("DROP CATALOG " + catalog);
assertCatalogs(ImmutableList.of("system", "delta", "tpch"));
// re-add the same catalog
assertUpdate(createCatalogSql);
assertCatalogs(ImmutableList.of("system", "delta", "tpch", catalog));

assertUpdate("DROP CATALOG " + catalog);
assertCatalogs(ImmutableList.of("system", "delta", "tpch"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,37 @@ protected void verifySelectAfterInsertFailurePermissible(Throwable e)
.containsPattern("io.trino.spi.TrinoException: Cannot read from a table tpch.test_insert_select_\\w+ that was modified within transaction, you need to commit the transaction first");
}

@Test
void testCreateDropDynamicCatalog()
{
String catalog = "new_catalog_" + randomNameSuffix();
String createCatalogSql = "CREATE CATALOG %s USING hive".formatted(catalog);
assertUpdate(createCatalogSql);
assertCatalogs(availableCatalogs(Optional.of(catalog)));

assertUpdate("DROP CATALOG " + catalog);
assertCatalogs(availableCatalogs(Optional.empty()));
// re-add the same catalog
assertUpdate(createCatalogSql);
assertCatalogs(availableCatalogs(Optional.of(catalog)));

assertUpdate("DROP CATALOG " + catalog);
assertCatalogs(availableCatalogs(Optional.empty()));
}

private static List<String> availableCatalogs(Optional<String> catalog)
{
ImmutableList.Builder<String> catalogs = ImmutableList.builder();
catalogs.add("system")
.add("hive")
.add("hive_bucketed")
.add("hive_timestamp_nanos")
.add("mock_dynamic_listing")
.add("tpch");
catalog.ifPresent(catalogs::add);
return catalogs.build();
}

@Test
@Override
public void testDelete()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package io.trino.plugin.hive;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.trino.Session;
import io.trino.plugin.base.util.UncheckedCloseable;
Expand Down Expand Up @@ -442,4 +443,22 @@ public void testCreateFunction()
assertUpdate("DROP FUNCTION " + name2 + "(varchar)");
assertQueryFails("DROP FUNCTION " + name2 + "(varchar)", "line 1:1: Function not found");
}

@Test
void testCreateDropDynamicCatalog()
{
String catalog = "new_catalog_" + randomNameSuffix();
String createCatalogSql = "CREATE CATALOG %s USING hive".formatted(catalog);
assertUpdate(createCatalogSql);
assertCatalogs(ImmutableList.of("system", "hive", "tpch", catalog));

assertUpdate("DROP CATALOG " + catalog);
assertCatalogs(ImmutableList.of("system", "hive", "tpch"));
// re-add the same catalog
assertUpdate(createCatalogSql);
assertCatalogs(ImmutableList.of("system", "hive", "tpch", catalog));

assertUpdate("DROP CATALOG " + catalog);
assertCatalogs(ImmutableList.of("system", "hive", "tpch"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
*/
package io.trino.plugin.hudi;

import com.google.common.collect.ImmutableList;
import io.trino.plugin.hudi.testing.TpchHudiTablesInitializer;
import io.trino.testing.BaseConnectorTest;
import io.trino.testing.QueryRunner;
import io.trino.testing.TestingConnectorBehavior;
import org.junit.jupiter.api.Test;

import static io.trino.plugin.hudi.testing.HudiTestUtils.COLUMNS_TO_HIDE;
import static io.trino.testing.TestingNames.randomNameSuffix;
import static org.assertj.core.api.Assertions.assertThat;

public class TestHudiConnectorTest
Expand Down Expand Up @@ -87,4 +89,22 @@ public void testHideHiveSysSchema()
assertThat(computeActual("SHOW SCHEMAS").getOnlyColumnAsSet()).doesNotContain("sys");
assertQueryFails("SHOW TABLES IN hudi.sys", ".*Schema 'sys' does not exist");
}

@Test
void testCreateDropDynamicCatalog()
{
String catalog = "new_catalog_" + randomNameSuffix();
String createCatalogSql = "CREATE CATALOG %1$s USING hudi".formatted(catalog);
assertUpdate(createCatalogSql);
assertCatalogs(ImmutableList.of("system", "hudi", "mock_dynamic_listing", "tpch", catalog));

assertUpdate("DROP CATALOG " + catalog);
assertCatalogs(ImmutableList.of("system", "hudi", "mock_dynamic_listing", "tpch"));
// re-add the same catalog
assertUpdate(createCatalogSql);
assertCatalogs(ImmutableList.of("system", "hudi", "mock_dynamic_listing", "tpch", catalog));

assertUpdate("DROP CATALOG " + catalog);
assertCatalogs(ImmutableList.of("system", "hudi", "mock_dynamic_listing", "tpch"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@ public void testShowCreateTable()
"\\)");
}

@Test
void testCreateDropDynamicCatalog()
{
String catalog = "new_catalog_" + randomNameSuffix();
String createCatalogSql = "CREATE CATALOG %s USING iceberg".formatted(catalog);
assertUpdate(createCatalogSql);
assertCatalogs(ImmutableList.of("system", "iceberg", "tpch", catalog));

assertUpdate("DROP CATALOG " + catalog);
assertCatalogs(ImmutableList.of("system", "iceberg", "tpch"));
// re-add the same catalog
assertUpdate(createCatalogSql);
assertCatalogs(ImmutableList.of("system", "iceberg", "tpch", catalog));

assertUpdate("DROP CATALOG " + catalog);
assertCatalogs(ImmutableList.of("system", "iceberg", "tpch"));
}

@Test
public void testHiddenPathColumn()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package io.trino.plugin.iceberg.catalog.glue;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.trino.plugin.base.util.UncheckedCloseable;
import io.trino.plugin.hive.BaseS3AndGlueMetastoreTest;
Expand Down Expand Up @@ -149,4 +150,22 @@ private void testAnalyzeWithProvidedTableLocation(boolean partitioned, LocationP
assertQuery("SHOW STATS FOR " + tableName, expectedStatistics);
}
}

@Test
void testCreateDropDynamicCatalog()
{
String catalog = "new_catalog_" + randomNameSuffix();
String createCatalogSql = "CREATE CATALOG %s USING iceberg".formatted(catalog);
assertUpdate(createCatalogSql);
assertCatalogs(ImmutableList.of("system", "iceberg", "tpch", catalog));

assertUpdate("DROP CATALOG " + catalog);
assertCatalogs(ImmutableList.of("system", "iceberg", "tpch"));
// re-add the same catalog
assertUpdate(createCatalogSql);
assertCatalogs(ImmutableList.of("system", "iceberg", "tpch", catalog));

assertUpdate("DROP CATALOG " + catalog);
assertCatalogs(ImmutableList.of("system", "iceberg", "tpch"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,17 @@ protected void assertNoDataRead(@Language("SQL") String sql)
results -> assertThat(results.getRowCount()).isEqualTo(0));
}

protected void assertCatalogs(List<String> catalogs)
{
List<MaterializedRow> showCatalogs = computeActual("SHOW CATALOGS").getMaterializedRows();
assertThat(showCatalogs)
.extracting(row -> {
assertThat(row.getFieldCount()).isEqualTo(1);
return row.getField(0);
})
.containsExactlyInAnyOrderElementsOf(catalogs);
}

protected MaterializedResult computeExpected(@Language("SQL") String sql, List<? extends Type> resultTypes)
{
return h2QueryRunner.execute(getSession(), sql, resultTypes);
Expand Down

0 comments on commit 70943f9

Please sign in to comment.