Search in sources :

Example 1 with BaseTable

use of org.apache.iceberg.BaseTable 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 BaseTable

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

the class HiveIcebergMetaHook method rollbackAlterTable.

@Override
public void rollbackAlterTable(org.apache.hadoop.hive.metastore.api.Table hmsTable, EnvironmentContext context) {
    if (Boolean.parseBoolean(context.getProperties().getOrDefault(MIGRATE_HIVE_TO_ICEBERG, "false"))) {
        LOG.debug("Initiating rollback for table {} at location {}", hmsTable.getTableName(), hmsTable.getSd().getLocation());
        context.getProperties().put(INITIALIZE_ROLLBACK_MIGRATION, "true");
        this.catalogProperties = getCatalogProperties(hmsTable);
        try {
            this.icebergTable = Catalogs.loadTable(conf, catalogProperties);
        } catch (NoSuchTableException nte) {
            // iceberg table was not yet created, no need to delete the metadata dir separately
            return;
        }
        // we want to keep the data files but get rid of the metadata directory
        String metadataLocation = ((BaseTable) this.icebergTable).operations().current().metadataFileLocation();
        try {
            Path path = new Path(metadataLocation).getParent();
            FileSystem.get(path.toUri(), conf).delete(path, true);
            LOG.debug("Metadata directory of iceberg table {} at location {} was deleted", icebergTable.name(), path);
        } catch (IOException e) {
        // the file doesn't exists, do nothing
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) BaseTable(org.apache.iceberg.BaseTable) NoSuchTableException(org.apache.iceberg.exceptions.NoSuchTableException) IOException(java.io.IOException)

Example 3 with BaseTable

use of org.apache.iceberg.BaseTable 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)

Aggregations

BaseTable (org.apache.iceberg.BaseTable)3 TableOperations (org.apache.iceberg.TableOperations)2 HdfsContext (com.facebook.presto.hive.HdfsContext)1 MetastoreContext (com.facebook.presto.hive.metastore.MetastoreContext)1 File (java.io.File)1 IOException (java.io.IOException)1 Path (org.apache.hadoop.fs.Path)1 Table (org.apache.iceberg.Table)1 TableMetadata (org.apache.iceberg.TableMetadata)1 NoSuchTableException (org.apache.iceberg.exceptions.NoSuchTableException)1