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);
}
}
}
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;
}
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);
}
}
}
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);
}
}
}
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);
}
Aggregations