Search in sources :

Example 1 with TableIdentifier

use of org.apache.iceberg.catalog.TableIdentifier in project presto by prestodb.

the class IcebergHadoopMetadata method getSystemTable.

@Override
public Optional<SystemTable> getSystemTable(ConnectorSession session, SchemaTableName tableName) {
    IcebergTableName name = IcebergTableName.from(tableName.getTableName());
    TableIdentifier tableIdentifier = toIcebergTableIdentifier(tableName.getSchemaName(), name.getTableName());
    Table table;
    try {
        table = resourceFactory.getCatalog(session).loadTable(tableIdentifier);
    } catch (NoSuchTableException e) {
        return Optional.empty();
    }
    if (name.getSnapshotId().isPresent() && table.snapshot(name.getSnapshotId().get()) == null) {
        throw new PrestoException(ICEBERG_INVALID_SNAPSHOT_ID, format("Invalid snapshot [%s] for table: %s", name.getSnapshotId().get(), table));
    }
    return getIcebergSystemTable(tableName, table);
}
Also used : TableIdentifier(org.apache.iceberg.catalog.TableIdentifier) IcebergPrestoModelConverters.toIcebergTableIdentifier(com.facebook.presto.iceberg.util.IcebergPrestoModelConverters.toIcebergTableIdentifier) SystemTable(com.facebook.presto.spi.SystemTable) IcebergUtil.getHadoopIcebergTable(com.facebook.presto.iceberg.IcebergUtil.getHadoopIcebergTable) Table(org.apache.iceberg.Table) NoSuchTableException(org.apache.iceberg.exceptions.NoSuchTableException) PrestoException(com.facebook.presto.spi.PrestoException)

Example 2 with TableIdentifier

use of org.apache.iceberg.catalog.TableIdentifier in project presto by prestodb.

the class IcebergHadoopMetadata method renameTable.

@Override
public void renameTable(ConnectorSession session, ConnectorTableHandle tableHandle, SchemaTableName newTable) {
    TableIdentifier from = toIcebergTableIdentifier(((IcebergTableHandle) tableHandle).getSchemaTableName());
    TableIdentifier to = toIcebergTableIdentifier(newTable);
    resourceFactory.getCatalog(session).renameTable(from, to);
}
Also used : TableIdentifier(org.apache.iceberg.catalog.TableIdentifier) IcebergPrestoModelConverters.toIcebergTableIdentifier(com.facebook.presto.iceberg.util.IcebergPrestoModelConverters.toIcebergTableIdentifier)

Example 3 with TableIdentifier

use of org.apache.iceberg.catalog.TableIdentifier in project presto by prestodb.

the class IcebergHadoopMetadata method addColumn.

@Override
public void addColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnMetadata column) {
    TableIdentifier tableIdentifier = toIcebergTableIdentifier(((IcebergTableHandle) tableHandle).getSchemaTableName());
    Table icebergTable = resourceFactory.getCatalog(session).loadTable(tableIdentifier);
    icebergTable.updateSchema().addColumn(column.getName(), toIcebergType(column.getType())).commit();
}
Also used : TableIdentifier(org.apache.iceberg.catalog.TableIdentifier) IcebergPrestoModelConverters.toIcebergTableIdentifier(com.facebook.presto.iceberg.util.IcebergPrestoModelConverters.toIcebergTableIdentifier) SystemTable(com.facebook.presto.spi.SystemTable) IcebergUtil.getHadoopIcebergTable(com.facebook.presto.iceberg.IcebergUtil.getHadoopIcebergTable) Table(org.apache.iceberg.Table)

Example 4 with TableIdentifier

use of org.apache.iceberg.catalog.TableIdentifier in project presto by prestodb.

the class IcebergHadoopMetadata method dropTable.

@Override
public void dropTable(ConnectorSession session, ConnectorTableHandle tableHandle) {
    TableIdentifier tableIdentifier = toIcebergTableIdentifier(((IcebergTableHandle) tableHandle).getSchemaTableName());
    resourceFactory.getCatalog(session).dropTable(tableIdentifier);
}
Also used : TableIdentifier(org.apache.iceberg.catalog.TableIdentifier) IcebergPrestoModelConverters.toIcebergTableIdentifier(com.facebook.presto.iceberg.util.IcebergPrestoModelConverters.toIcebergTableIdentifier)

Example 5 with TableIdentifier

use of org.apache.iceberg.catalog.TableIdentifier in project hive by apache.

the class HiveIcebergMetaHook method getCatalogProperties.

/**
 * Calculates the properties we would like to send to the catalog.
 * <ul>
 * <li>The base of the properties is the properties stored at the Hive Metastore for the given table
 * <li>We add the {@link Catalogs#LOCATION} as the table location
 * <li>We add the {@link Catalogs#NAME} as TableIdentifier defined by the database name and table name
 * <li>We add the serdeProperties of the HMS table
 * <li>We remove some parameters that we don't want to push down to the Iceberg table props
 * </ul>
 * @param hmsTable Table for which we are calculating the properties
 * @return The properties we can provide for Iceberg functions, like {@link Catalogs}
 */
private static Properties getCatalogProperties(org.apache.hadoop.hive.metastore.api.Table hmsTable) {
    Properties properties = new Properties();
    hmsTable.getParameters().entrySet().stream().filter(e -> e.getKey() != null && e.getValue() != null).forEach(e -> {
        // translate key names between HMS and Iceberg where needed
        String icebergKey = HiveTableOperations.translateToIcebergProp(e.getKey());
        properties.put(icebergKey, e.getValue());
    });
    if (properties.get(Catalogs.LOCATION) == null && hmsTable.getSd() != null && hmsTable.getSd().getLocation() != null) {
        properties.put(Catalogs.LOCATION, hmsTable.getSd().getLocation());
    }
    if (properties.get(Catalogs.NAME) == null) {
        properties.put(Catalogs.NAME, TableIdentifier.of(hmsTable.getDbName(), hmsTable.getTableName()).toString());
    }
    SerDeInfo serdeInfo = hmsTable.getSd().getSerdeInfo();
    if (serdeInfo != null) {
        serdeInfo.getParameters().entrySet().stream().filter(e -> e.getKey() != null && e.getValue() != null).forEach(e -> {
            String icebergKey = HiveTableOperations.translateToIcebergProp(e.getKey());
            properties.put(icebergKey, e.getValue());
        });
    }
    // Remove HMS table parameters we don't want to propagate to Iceberg
    PROPERTIES_TO_REMOVE.forEach(properties::remove);
    return properties;
}
Also used : PartitionSpecProxy(org.apache.hadoop.hive.metastore.partition.spec.PartitionSpecProxy) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) CatalogUtil(org.apache.iceberg.CatalogUtil) UpdateSchema(org.apache.iceberg.UpdateSchema) FileSystem(org.apache.hadoop.fs.FileSystem) HiveSchemaUtil(org.apache.iceberg.hive.HiveSchemaUtil) Catalogs(org.apache.iceberg.mr.Catalogs) LoggerFactory(org.slf4j.LoggerFactory) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) TableMetadata(org.apache.iceberg.TableMetadata) DeleteFiles(org.apache.iceberg.DeleteFiles) Lists(org.apache.iceberg.relocated.com.google.common.collect.Lists) AlterTableType(org.apache.hadoop.hive.ql.ddl.table.AlterTableType) NameMapping(org.apache.iceberg.mapping.NameMapping) Map(java.util.Map) Configuration(org.apache.hadoop.conf.Configuration) NoSuchTableException(org.apache.iceberg.exceptions.NoSuchTableException) Path(org.apache.hadoop.fs.Path) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) Splitter(org.apache.iceberg.relocated.com.google.common.base.Splitter) EnumSet(java.util.EnumSet) TableMetadataParser(org.apache.iceberg.TableMetadataParser) MetaStoreUtils(org.apache.hadoop.hive.metastore.utils.MetaStoreUtils) BaseTable(org.apache.iceberg.BaseTable) Collection(java.util.Collection) HiveMetaHook(org.apache.hadoop.hive.metastore.HiveMetaHook) InputFormatConfig(org.apache.iceberg.mr.InputFormatConfig) Set(java.util.Set) ImmutableList(org.apache.iceberg.relocated.com.google.common.collect.ImmutableList) Schema(org.apache.iceberg.Schema) PartitionSpecParser(org.apache.iceberg.PartitionSpecParser) SchemaParser(org.apache.iceberg.SchemaParser) Objects(java.util.Objects) Type(org.apache.iceberg.types.Type) List(java.util.List) UpdateProperties(org.apache.iceberg.UpdateProperties) PartitionSpec(org.apache.iceberg.PartitionSpec) Optional(java.util.Optional) TableProperties(org.apache.iceberg.TableProperties) SessionStateUtil(org.apache.hadoop.hive.ql.session.SessionStateUtil) Expressions(org.apache.iceberg.expressions.Expressions) AcidUtils(org.apache.hadoop.hive.ql.io.AcidUtils) TypeInfoUtils(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils) ImmutableSet(org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet) ImmutableMap(org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap) Pair(org.apache.iceberg.util.Pair) MappingUtil(org.apache.iceberg.mapping.MappingUtil) BaseMetastoreTableOperations(org.apache.iceberg.BaseMetastoreTableOperations) UpdatePartitionSpec(org.apache.iceberg.UpdatePartitionSpec) TableName(org.apache.hadoop.hive.common.TableName) PartitionTransformSpec(org.apache.hadoop.hive.ql.parse.PartitionTransformSpec) Properties(java.util.Properties) Logger(org.slf4j.Logger) TableIdentifier(org.apache.iceberg.catalog.TableIdentifier) Table(org.apache.iceberg.Table) EnvironmentContext(org.apache.hadoop.hive.metastore.api.EnvironmentContext) NameMappingParser(org.apache.iceberg.mapping.NameMappingParser) IOException(java.io.IOException) FileFormat(org.apache.iceberg.FileFormat) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) Transaction(org.apache.iceberg.Transaction) Preconditions(org.apache.iceberg.relocated.com.google.common.base.Preconditions) FileIO(org.apache.iceberg.io.FileIO) Collections(java.util.Collections) org.apache.hadoop.hive.metastore.api.hive_metastoreConstants(org.apache.hadoop.hive.metastore.api.hive_metastoreConstants) PartitionTransform(org.apache.hadoop.hive.ql.parse.PartitionTransform) HiveTableOperations(org.apache.iceberg.hive.HiveTableOperations) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) UpdateProperties(org.apache.iceberg.UpdateProperties) TableProperties(org.apache.iceberg.TableProperties) Properties(java.util.Properties)

Aggregations

TableIdentifier (org.apache.iceberg.catalog.TableIdentifier)87 Test (org.junit.Test)69 Table (org.apache.iceberg.Table)56 PartitionSpec (org.apache.iceberg.PartitionSpec)27 Schema (org.apache.iceberg.Schema)25 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)16 BaseTable (org.apache.iceberg.BaseTable)15 UpdateSchema (org.apache.iceberg.UpdateSchema)15 List (java.util.List)13 NoSuchTableException (org.apache.iceberg.exceptions.NoSuchTableException)13 ArrayList (java.util.ArrayList)11 ImmutableList (org.apache.iceberg.relocated.com.google.common.collect.ImmutableList)11 IOException (java.io.IOException)10 Map (java.util.Map)10 Types (org.apache.iceberg.types.Types)10 HashMap (java.util.HashMap)9 Path (org.apache.hadoop.fs.Path)9 TableProperties (org.apache.iceberg.TableProperties)9 Collections (java.util.Collections)8 Properties (java.util.Properties)8