Search in sources :

Example 1 with HivePartition

use of org.apache.gobblin.hive.HivePartition in project incubator-gobblin by apache.

the class HiveMetaStoreUtils method getPartition.

/**
 * Convert a {@link HivePartition} into a {@link Partition}.
 */
public static Partition getPartition(HivePartition hivePartition) {
    State props = hivePartition.getProps();
    Partition partition = new Partition();
    partition.setDbName(hivePartition.getDbName());
    partition.setTableName(hivePartition.getTableName());
    partition.setValues(hivePartition.getValues());
    partition.setParameters(getParameters(props));
    if (hivePartition.getCreateTime().isPresent()) {
        partition.setCreateTime(Ints.checkedCast(hivePartition.getCreateTime().get()));
    } else if (props.contains(HiveConstants.CREATE_TIME)) {
        partition.setCreateTime(props.getPropAsInt(HiveConstants.CREATE_TIME));
    }
    if (props.contains(HiveConstants.LAST_ACCESS_TIME)) {
        partition.setLastAccessTime(props.getPropAsInt(HiveConstants.LAST_ACCESS_TIME));
    }
    partition.setSd(getStorageDescriptor(hivePartition));
    return partition;
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) HivePartition(org.apache.gobblin.hive.HivePartition) State(org.apache.gobblin.configuration.State)

Example 2 with HivePartition

use of org.apache.gobblin.hive.HivePartition in project incubator-gobblin by apache.

the class HiveMetaStoreBasedRegister method registerPath.

@Override
protected void registerPath(HiveSpec spec) throws IOException {
    try (Timer.Context context = this.metricContext.timer(PATH_REGISTER_TIMER).time();
        AutoReturnableObject<IMetaStoreClient> client = this.clientPool.getClient()) {
        Table table = HiveMetaStoreUtils.getTable(spec.getTable());
        createDbIfNotExists(client.get(), table.getDbName());
        createOrAlterTable(client.get(), table, spec);
        Optional<HivePartition> partition = spec.getPartition();
        if (partition.isPresent()) {
            addOrAlterPartition(client.get(), table, HiveMetaStoreUtils.getPartition(partition.get()), spec);
        }
        HiveMetaStoreEventHelper.submitSuccessfulPathRegistration(eventSubmitter, spec);
    } catch (TException e) {
        HiveMetaStoreEventHelper.submitFailedPathRegistration(eventSubmitter, spec, e);
        throw new IOException(e);
    }
}
Also used : TException(org.apache.thrift.TException) HiveTable(org.apache.gobblin.hive.HiveTable) Table(org.apache.hadoop.hive.metastore.api.Table) Timer(com.codahale.metrics.Timer) IOException(java.io.IOException) IMetaStoreClient(org.apache.hadoop.hive.metastore.IMetaStoreClient) HivePartition(org.apache.gobblin.hive.HivePartition)

Example 3 with HivePartition

use of org.apache.gobblin.hive.HivePartition in project incubator-gobblin by apache.

the class HiveMetaStoreUtils method getHivePartition.

/**
 * Convert a {@link Partition} into a {@link HivePartition}.
 */
public static HivePartition getHivePartition(Partition partition) {
    State partitionProps = getPartitionProps(partition);
    State storageProps = getStorageProps(partition.getSd());
    State serDeProps = getSerDeProps(partition.getSd().getSerdeInfo());
    HivePartition hivePartition = new HivePartition.Builder().withDbName(partition.getDbName()).withTableName(partition.getTableName()).withPartitionValues(partition.getValues()).withProps(partitionProps).withStorageProps(storageProps).withSerdeProps(serDeProps).build();
    if (partition.getCreateTime() > 0) {
        hivePartition.setCreateTime(partition.getCreateTime());
    }
    if (partition.getSd().getCols() != null) {
        hivePartition.setColumns(getColumns(partition.getSd().getCols()));
    }
    if (partition.getSd().getBucketCols() != null) {
        hivePartition.setBucketColumns(partition.getSd().getBucketCols());
    }
    return hivePartition;
}
Also used : State(org.apache.gobblin.configuration.State) HivePartition(org.apache.gobblin.hive.HivePartition)

Aggregations

HivePartition (org.apache.gobblin.hive.HivePartition)3 State (org.apache.gobblin.configuration.State)2 Timer (com.codahale.metrics.Timer)1 IOException (java.io.IOException)1 HiveTable (org.apache.gobblin.hive.HiveTable)1 IMetaStoreClient (org.apache.hadoop.hive.metastore.IMetaStoreClient)1 Partition (org.apache.hadoop.hive.metastore.api.Partition)1 Table (org.apache.hadoop.hive.metastore.api.Table)1 TException (org.apache.thrift.TException)1