Search in sources :

Example 1 with TableOperations

use of org.apache.iceberg.TableOperations in project presto by prestodb.

the class IcebergUtil method getHiveIcebergTable.

public static Table getHiveIcebergTable(ExtendedHiveMetastore metastore, HdfsEnvironment hdfsEnvironment, ConnectorSession session, SchemaTableName table) {
    HdfsContext hdfsContext = new HdfsContext(session, table.getSchemaName(), table.getTableName());
    TableOperations operations = new HiveTableOperations(metastore, new MetastoreContext(session.getIdentity(), session.getQueryId(), session.getClientInfo(), session.getSource(), Optional.empty(), false, HiveColumnConverterProvider.DEFAULT_COLUMN_CONVERTER_PROVIDER), hdfsEnvironment, hdfsContext, table.getSchemaName(), table.getTableName());
    return new BaseTable(operations, quotedTableName(table));
}
Also used : TableOperations(org.apache.iceberg.TableOperations) BaseTable(org.apache.iceberg.BaseTable) MetastoreContext(com.facebook.presto.hive.metastore.MetastoreContext) HdfsContext(com.facebook.presto.hive.HdfsContext)

Example 2 with TableOperations

use of org.apache.iceberg.TableOperations in project hive by apache.

the class TestInputFormatReaderDeletes method createTable.

@Override
protected Table createTable(String name, Schema schema, PartitionSpec spec) throws IOException {
    Table table;
    File location = temp.newFolder(inputFormat, fileFormat.name());
    Assert.assertTrue(location.delete());
    helper = new TestHelper(conf, tables, location.toString(), schema, spec, fileFormat, temp);
    table = helper.createTable();
    TableOperations ops = ((BaseTable) table).operations();
    TableMetadata meta = ops.current();
    ops.commit(meta, meta.upgradeToFormatVersion(2));
    return table;
}
Also used : TableMetadata(org.apache.iceberg.TableMetadata) BaseTable(org.apache.iceberg.BaseTable) Table(org.apache.iceberg.Table) TableOperations(org.apache.iceberg.TableOperations) BaseTable(org.apache.iceberg.BaseTable) File(java.io.File)

Example 3 with TableOperations

use of org.apache.iceberg.TableOperations in project hive by apache.

the class HiveCatalog method dropTable.

@Override
public boolean dropTable(TableIdentifier identifier, boolean purge) {
    if (!isValidIdentifier(identifier)) {
        return false;
    }
    String database = identifier.namespace().level(0);
    TableOperations ops = newTableOps(identifier);
    TableMetadata lastMetadata;
    if (purge && ops.current() != null) {
        lastMetadata = ops.current();
    } else {
        lastMetadata = null;
    }
    try {
        clients.run(client -> {
            client.dropTable(database, identifier.name(), false, /* do not delete data */
            false);
            return null;
        });
        if (purge && lastMetadata != null) {
            CatalogUtil.dropTableData(ops.io(), lastMetadata);
        }
        LOG.info("Dropped table: {}", identifier);
        return true;
    } catch (NoSuchTableException | NoSuchObjectException e) {
        LOG.info("Skipping drop, table does not exist: {}", identifier, e);
        return false;
    } catch (TException e) {
        throw new RuntimeException("Failed to drop " + identifier, e);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new RuntimeException("Interrupted in call to dropTable", e);
    }
}
Also used : TableMetadata(org.apache.iceberg.TableMetadata) TException(org.apache.thrift.TException) TableOperations(org.apache.iceberg.TableOperations) BaseMetastoreTableOperations(org.apache.iceberg.BaseMetastoreTableOperations) NoSuchTableException(org.apache.iceberg.exceptions.NoSuchTableException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException)

Example 4 with TableOperations

use of org.apache.iceberg.TableOperations in project presto by prestodb.

the class IcebergHiveMetadata method beginCreateTable.

@Override
public ConnectorOutputTableHandle beginCreateTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, Optional<ConnectorNewTableLayout> layout) {
    SchemaTableName schemaTableName = tableMetadata.getTable();
    String schemaName = schemaTableName.getSchemaName();
    String tableName = schemaTableName.getTableName();
    Schema schema = toIcebergSchema(tableMetadata.getColumns());
    PartitionSpec partitionSpec = parsePartitionFields(schema, getPartitioning(tableMetadata.getProperties()));
    MetastoreContext metastoreContext = new MetastoreContext(session.getIdentity(), session.getQueryId(), session.getClientInfo(), session.getSource(), Optional.empty(), false, HiveColumnConverterProvider.DEFAULT_COLUMN_CONVERTER_PROVIDER);
    Database database = metastore.getDatabase(metastoreContext, schemaName).orElseThrow(() -> new SchemaNotFoundException(schemaName));
    HdfsContext hdfsContext = new HdfsContext(session, schemaName, tableName);
    String targetPath = getTableLocation(tableMetadata.getProperties());
    if (targetPath == null) {
        Optional<String> location = database.getLocation();
        if (!location.isPresent() || location.get().isEmpty()) {
            throw new PrestoException(NOT_SUPPORTED, "Database " + schemaName + " location is not set");
        }
        Path databasePath = new Path(location.get());
        Path resultPath = new Path(databasePath, tableName);
        targetPath = resultPath.toString();
    }
    TableOperations operations = new HiveTableOperations(metastore, new MetastoreContext(session.getIdentity(), session.getQueryId(), session.getClientInfo(), session.getSource(), Optional.empty(), false, HiveColumnConverterProvider.DEFAULT_COLUMN_CONVERTER_PROVIDER), hdfsEnvironment, hdfsContext, schemaName, tableName, session.getUser(), targetPath);
    if (operations.current() != null) {
        throw new TableAlreadyExistsException(schemaTableName);
    }
    ImmutableMap.Builder<String, String> propertiesBuilder = ImmutableMap.builderWithExpectedSize(2);
    FileFormat fileFormat = getFileFormat(tableMetadata.getProperties());
    propertiesBuilder.put(DEFAULT_FILE_FORMAT, fileFormat.toString());
    if (tableMetadata.getComment().isPresent()) {
        propertiesBuilder.put(TABLE_COMMENT, tableMetadata.getComment().get());
    }
    TableMetadata metadata = newTableMetadata(schema, partitionSpec, targetPath, propertiesBuilder.build());
    transaction = createTableTransaction(tableName, operations, metadata);
    return new IcebergWritableTableHandle(schemaName, tableName, SchemaParser.toJson(metadata.schema()), PartitionSpecParser.toJson(metadata.spec()), getColumns(metadata.schema(), typeManager), targetPath, fileFormat, metadata.properties());
}
Also used : Path(org.apache.hadoop.fs.Path) TableMetadata(org.apache.iceberg.TableMetadata) TableMetadata.newTableMetadata(org.apache.iceberg.TableMetadata.newTableMetadata) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) TableAlreadyExistsException(com.facebook.presto.hive.TableAlreadyExistsException) Schema(org.apache.iceberg.Schema) MetastoreContext(com.facebook.presto.hive.metastore.MetastoreContext) PrestoException(com.facebook.presto.spi.PrestoException) FileFormat(org.apache.iceberg.FileFormat) IcebergTableProperties.getFileFormat(com.facebook.presto.iceberg.IcebergTableProperties.getFileFormat) SchemaTableName(com.facebook.presto.spi.SchemaTableName) PartitionSpec(org.apache.iceberg.PartitionSpec) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) TableOperations(org.apache.iceberg.TableOperations) Database(com.facebook.presto.hive.metastore.Database) SchemaNotFoundException(com.facebook.presto.spi.SchemaNotFoundException) HdfsContext(com.facebook.presto.hive.HdfsContext)

Aggregations

TableOperations (org.apache.iceberg.TableOperations)4 TableMetadata (org.apache.iceberg.TableMetadata)3 HdfsContext (com.facebook.presto.hive.HdfsContext)2 MetastoreContext (com.facebook.presto.hive.metastore.MetastoreContext)2 BaseTable (org.apache.iceberg.BaseTable)2 TableAlreadyExistsException (com.facebook.presto.hive.TableAlreadyExistsException)1 Database (com.facebook.presto.hive.metastore.Database)1 IcebergTableProperties.getFileFormat (com.facebook.presto.iceberg.IcebergTableProperties.getFileFormat)1 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)1 PrestoException (com.facebook.presto.spi.PrestoException)1 SchemaNotFoundException (com.facebook.presto.spi.SchemaNotFoundException)1 SchemaTableName (com.facebook.presto.spi.SchemaTableName)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 File (java.io.File)1 Path (org.apache.hadoop.fs.Path)1 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)1 BaseMetastoreTableOperations (org.apache.iceberg.BaseMetastoreTableOperations)1 FileFormat (org.apache.iceberg.FileFormat)1 PartitionSpec (org.apache.iceberg.PartitionSpec)1