Search in sources :

Example 1 with TrinoCatalog

use of io.trino.plugin.iceberg.catalog.TrinoCatalog in project trino by trinodb.

the class BaseTrinoCatalogTest method testUseUniqueTableLocations.

@Test
public void testUseUniqueTableLocations() throws IOException {
    TrinoCatalog catalog = createTrinoCatalog(true);
    Path tmpDirectory = Files.createTempDirectory("iceberg_catalog_test_rename_table_");
    tmpDirectory.toFile().deleteOnExit();
    String namespace = "test_unique_table_locations_" + randomTableSuffix();
    String table = "tableName";
    SchemaTableName schemaTableName = new SchemaTableName(namespace, table);
    catalog.createNamespace(SESSION, namespace, ImmutableMap.of(LOCATION_PROPERTY, tmpDirectory.toString()), new TrinoPrincipal(PrincipalType.USER, SESSION.getUser()));
    try {
        String location1 = catalog.defaultTableLocation(SESSION, schemaTableName);
        String location2 = catalog.defaultTableLocation(SESSION, schemaTableName);
        assertNotEquals(location1, location2);
        assertEquals(Path.of(location1).getParent(), tmpDirectory);
        assertEquals(Path.of(location2).getParent(), tmpDirectory);
    } finally {
        try {
            catalog.dropNamespace(SESSION, namespace);
        } catch (Exception e) {
            LOG.warn("Failed to clean up namespace: %s", namespace);
        }
    }
}
Also used : Path(java.nio.file.Path) TrinoPrincipal(io.trino.spi.security.TrinoPrincipal) SchemaTableName(io.trino.spi.connector.SchemaTableName) TrinoCatalog(io.trino.plugin.iceberg.catalog.TrinoCatalog) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 2 with TrinoCatalog

use of io.trino.plugin.iceberg.catalog.TrinoCatalog in project trino by trinodb.

the class TestIcebergV2 method updateTableToV2.

private Table updateTableToV2(String tableName) {
    IcebergTableOperationsProvider tableOperationsProvider = new FileMetastoreTableOperationsProvider(new HdfsFileIoProvider(hdfsEnvironment));
    TrinoCatalog catalog = new TrinoHiveCatalog(new CatalogName("hive"), CachingHiveMetastore.memoizeMetastore(metastore, 1000), hdfsEnvironment, new TestingTypeManager(), tableOperationsProvider, "test", false, false, false);
    BaseTable table = (BaseTable) loadIcebergTable(catalog, tableOperationsProvider, SESSION, new SchemaTableName("tpch", tableName));
    TableOperations operations = table.operations();
    TableMetadata currentMetadata = operations.current();
    operations.commit(currentMetadata, currentMetadata.upgradeToFormatVersion(2));
    return table;
}
Also used : TableMetadata(org.apache.iceberg.TableMetadata) BaseTable(org.apache.iceberg.BaseTable) TableOperations(org.apache.iceberg.TableOperations) FileMetastoreTableOperationsProvider(io.trino.plugin.iceberg.catalog.file.FileMetastoreTableOperationsProvider) TrinoHiveCatalog(io.trino.plugin.iceberg.catalog.hms.TrinoHiveCatalog) CatalogName(io.trino.plugin.base.CatalogName) IcebergTableOperationsProvider(io.trino.plugin.iceberg.catalog.IcebergTableOperationsProvider) SchemaTableName(io.trino.spi.connector.SchemaTableName) TrinoCatalog(io.trino.plugin.iceberg.catalog.TrinoCatalog) TestingTypeManager(io.trino.spi.type.TestingTypeManager)

Example 3 with TrinoCatalog

use of io.trino.plugin.iceberg.catalog.TrinoCatalog in project trino by trinodb.

the class BaseTrinoCatalogTest method testRenameTable.

@Test
public void testRenameTable() throws IOException {
    TrinoCatalog catalog = createTrinoCatalog(false);
    Path tmpDirectory = Files.createTempDirectory("iceberg_catalog_test_rename_table_");
    tmpDirectory.toFile().deleteOnExit();
    String namespace = "test_rename_table_" + randomTableSuffix();
    String targetNamespace = "test_rename_table_" + randomTableSuffix();
    String table = "tableName";
    SchemaTableName sourceSchemaTableName = new SchemaTableName(namespace, table);
    try {
        catalog.createNamespace(SESSION, namespace, ImmutableMap.of(), new TrinoPrincipal(PrincipalType.USER, SESSION.getUser()));
        catalog.createNamespace(SESSION, targetNamespace, ImmutableMap.of(), new TrinoPrincipal(PrincipalType.USER, SESSION.getUser()));
        catalog.newCreateTableTransaction(SESSION, sourceSchemaTableName, new Schema(Types.NestedField.of(1, true, "col1", Types.LongType.get())), PartitionSpec.unpartitioned(), tmpDirectory.toAbsolutePath().toString(), ImmutableMap.of()).commitTransaction();
        assertThat(catalog.listTables(SESSION, Optional.of(namespace))).contains(sourceSchemaTableName);
        // Rename within the same schema
        SchemaTableName targetSchemaTableName = new SchemaTableName(sourceSchemaTableName.getSchemaName(), "newTableName");
        catalog.renameTable(SESSION, sourceSchemaTableName, targetSchemaTableName);
        assertThat(catalog.listTables(SESSION, Optional.of(namespace))).doesNotContain(sourceSchemaTableName);
        assertThat(catalog.listTables(SESSION, Optional.of(namespace))).contains(targetSchemaTableName);
        // Move to a different schema
        sourceSchemaTableName = targetSchemaTableName;
        targetSchemaTableName = new SchemaTableName(targetNamespace, sourceSchemaTableName.getTableName());
        catalog.renameTable(SESSION, sourceSchemaTableName, targetSchemaTableName);
        assertThat(catalog.listTables(SESSION, Optional.of(namespace))).doesNotContain(sourceSchemaTableName);
        assertThat(catalog.listTables(SESSION, Optional.of(targetNamespace))).contains(targetSchemaTableName);
        catalog.dropTable(SESSION, targetSchemaTableName);
    } finally {
        try {
            catalog.dropNamespace(SESSION, namespace);
            catalog.dropNamespace(SESSION, targetNamespace);
        } catch (Exception e) {
            LOG.warn("Failed to clean up namespaces: %s, %s", namespace, targetNamespace);
        }
    }
}
Also used : Path(java.nio.file.Path) Schema(org.apache.iceberg.Schema) TrinoPrincipal(io.trino.spi.security.TrinoPrincipal) SchemaTableName(io.trino.spi.connector.SchemaTableName) TrinoCatalog(io.trino.plugin.iceberg.catalog.TrinoCatalog) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 4 with TrinoCatalog

use of io.trino.plugin.iceberg.catalog.TrinoCatalog in project trino by trinodb.

the class BaseTrinoCatalogTest method testCreateTable.

@Test
public void testCreateTable() throws IOException {
    TrinoCatalog catalog = createTrinoCatalog(false);
    Path tmpDirectory = Files.createTempDirectory("iceberg_catalog_test_create_table_");
    tmpDirectory.toFile().deleteOnExit();
    String namespace = "test_create_table_" + randomTableSuffix();
    String table = "tableName";
    SchemaTableName schemaTableName = new SchemaTableName(namespace, table);
    try {
        catalog.createNamespace(SESSION, namespace, ImmutableMap.of(), new TrinoPrincipal(PrincipalType.USER, SESSION.getUser()));
        catalog.newCreateTableTransaction(SESSION, schemaTableName, new Schema(Types.NestedField.of(1, true, "col1", Types.LongType.get())), PartitionSpec.unpartitioned(), tmpDirectory.toAbsolutePath().toString(), ImmutableMap.of()).commitTransaction();
        assertThat(catalog.listTables(SESSION, Optional.of(namespace))).contains(schemaTableName);
        assertThat(catalog.listTables(SESSION, Optional.empty())).contains(schemaTableName);
        Table icebergTable = catalog.loadTable(SESSION, schemaTableName);
        assertEquals(icebergTable.name(), quotedTableName(schemaTableName));
        assertEquals(icebergTable.schema().columns().size(), 1);
        assertEquals(icebergTable.schema().columns().get(0).name(), "col1");
        assertEquals(icebergTable.schema().columns().get(0).type(), Types.LongType.get());
        assertEquals(icebergTable.location(), tmpDirectory.toAbsolutePath().toString());
        assertEquals(icebergTable.properties(), ImmutableMap.of());
        catalog.dropTable(SESSION, schemaTableName);
        assertThat(catalog.listTables(SESSION, Optional.of(namespace))).doesNotContain(schemaTableName);
        assertThat(catalog.listTables(SESSION, Optional.empty())).doesNotContain(schemaTableName);
    } finally {
        try {
            catalog.dropNamespace(SESSION, namespace);
        } catch (Exception e) {
            LOG.warn("Failed to clean up namespace: %s", namespace);
        }
    }
}
Also used : Path(java.nio.file.Path) Table(org.apache.iceberg.Table) Schema(org.apache.iceberg.Schema) TrinoPrincipal(io.trino.spi.security.TrinoPrincipal) SchemaTableName(io.trino.spi.connector.SchemaTableName) TrinoCatalog(io.trino.plugin.iceberg.catalog.TrinoCatalog) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 5 with TrinoCatalog

use of io.trino.plugin.iceberg.catalog.TrinoCatalog in project trino by trinodb.

the class BaseTrinoCatalogTest method testCreateNamespaceWithLocation.

@Test
public void testCreateNamespaceWithLocation() {
    TrinoCatalog catalog = createTrinoCatalog(false);
    String namespace = "test_create_namespace_with_location_" + randomTableSuffix();
    catalog.createNamespace(SESSION, namespace, ImmutableMap.of(LOCATION_PROPERTY, "/a/path/"), new TrinoPrincipal(PrincipalType.USER, SESSION.getUser()));
    assertThat(catalog.listNamespaces(SESSION)).contains(namespace);
    assertEquals(catalog.loadNamespaceMetadata(SESSION, namespace), ImmutableMap.of(LOCATION_PROPERTY, "/a/path/"));
    assertEquals(catalog.defaultTableLocation(SESSION, new SchemaTableName(namespace, "table")), "/a/path/table");
    catalog.dropNamespace(SESSION, namespace);
    assertThat(catalog.listNamespaces(SESSION)).doesNotContain(namespace);
}
Also used : TrinoPrincipal(io.trino.spi.security.TrinoPrincipal) SchemaTableName(io.trino.spi.connector.SchemaTableName) TrinoCatalog(io.trino.plugin.iceberg.catalog.TrinoCatalog) Test(org.testng.annotations.Test)

Aggregations

TrinoCatalog (io.trino.plugin.iceberg.catalog.TrinoCatalog)6 SchemaTableName (io.trino.spi.connector.SchemaTableName)6 TrinoPrincipal (io.trino.spi.security.TrinoPrincipal)5 Test (org.testng.annotations.Test)5 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 Schema (org.apache.iceberg.Schema)2 CatalogName (io.trino.plugin.base.CatalogName)1 HdfsConfig (io.trino.plugin.hive.HdfsConfig)1 HdfsConfigurationInitializer (io.trino.plugin.hive.HdfsConfigurationInitializer)1 HdfsEnvironment (io.trino.plugin.hive.HdfsEnvironment)1 HiveHdfsConfiguration (io.trino.plugin.hive.HiveHdfsConfiguration)1 NoHdfsAuthentication (io.trino.plugin.hive.authentication.NoHdfsAuthentication)1 GlueHiveMetastoreConfig (io.trino.plugin.hive.metastore.glue.GlueHiveMetastoreConfig)1 GlueMetastoreStats (io.trino.plugin.hive.metastore.glue.GlueMetastoreStats)1 IcebergTableOperationsProvider (io.trino.plugin.iceberg.catalog.IcebergTableOperationsProvider)1 FileMetastoreTableOperationsProvider (io.trino.plugin.iceberg.catalog.file.FileMetastoreTableOperationsProvider)1 GlueIcebergTableOperationsProvider (io.trino.plugin.iceberg.catalog.glue.GlueIcebergTableOperationsProvider)1 TrinoGlueCatalog (io.trino.plugin.iceberg.catalog.glue.TrinoGlueCatalog)1 TrinoHiveCatalog (io.trino.plugin.iceberg.catalog.hms.TrinoHiveCatalog)1