Search in sources :

Example 1 with TableSnapshot

use of org.apache.hadoop.hive.ql.io.AcidUtils.TableSnapshot in project hive by apache.

the class Hive method alterPartitions.

/**
 * Updates the existing table metadata with the new metadata.
 *
 * @param tblName
 *          name of the existing table
 * @param newParts
 *          new partitions
 * @param transactional
 *          Need to generate and save a table snapshot into the metastore?
 * @throws InvalidOperationException
 *           if the changes in metadata is not acceptable
 * @throws HiveException
 */
public void alterPartitions(String tblName, List<Partition> newParts, EnvironmentContext environmentContext, boolean transactional) throws InvalidOperationException, HiveException {
    String[] names = Utilities.getDbTableName(tblName);
    List<org.apache.hadoop.hive.metastore.api.Partition> newTParts = new ArrayList<org.apache.hadoop.hive.metastore.api.Partition>();
    try {
        AcidUtils.TableSnapshot tableSnapshot = null;
        if (transactional) {
            tableSnapshot = AcidUtils.getTableSnapshot(conf, newParts.get(0).getTable(), true);
        }
        // Remove the DDL time so that it gets refreshed
        for (Partition tmpPart : newParts) {
            if (tmpPart.getParameters() != null) {
                tmpPart.getParameters().remove(hive_metastoreConstants.DDL_TIME);
            }
            String location = tmpPart.getLocation();
            if (location != null) {
                location = Utilities.getQualifiedPath(conf, new Path(location));
                tmpPart.setLocation(location);
            }
            newTParts.add(tmpPart.getTPartition());
        }
        getMSC().alter_partitions(names[0], names[1], newTParts, environmentContext, tableSnapshot != null ? tableSnapshot.getValidWriteIdList() : null, tableSnapshot != null ? tableSnapshot.getWriteId() : -1);
    } catch (MetaException e) {
        throw new HiveException("Unable to alter partition. " + e.getMessage(), e);
    } catch (TException e) {
        throw new HiveException("Unable to alter partition. " + e.getMessage(), e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) TException(org.apache.thrift.TException) TableSnapshot(org.apache.hadoop.hive.ql.io.AcidUtils.TableSnapshot) ArrayList(java.util.ArrayList) AcidUtils(org.apache.hadoop.hive.ql.io.AcidUtils) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) HiveMetaException(org.apache.hadoop.hive.metastore.HiveMetaException)

Example 2 with TableSnapshot

use of org.apache.hadoop.hive.ql.io.AcidUtils.TableSnapshot in project hive by apache.

the class Hive method getTableColumnStatistics.

public List<ColumnStatisticsObj> getTableColumnStatistics(String dbName, String tableName, List<String> colNames, boolean checkTransactional) throws HiveException {
    PerfLogger perfLogger = SessionState.getPerfLogger();
    perfLogger.perfLogBegin(CLASS_NAME, PerfLogger.HIVE_GET_TABLE_COLUMN_STATS);
    List<ColumnStatisticsObj> retv = null;
    try {
        if (checkTransactional) {
            Table tbl = getTable(dbName, tableName);
            AcidUtils.TableSnapshot tableSnapshot = AcidUtils.getTableSnapshot(conf, tbl);
            retv = getMSC().getTableColumnStatistics(dbName, tableName, colNames, Constants.HIVE_ENGINE, tableSnapshot != null ? tableSnapshot.getValidWriteIdList() : null);
        } else {
            retv = getMSC().getTableColumnStatistics(dbName, tableName, colNames, Constants.HIVE_ENGINE);
        }
        return retv;
    } catch (Exception e) {
        LOG.debug("Failed getTableColumnStatistics", e);
        throw new HiveException(e);
    } finally {
        perfLogger.perfLogEnd(CLASS_NAME, PerfLogger.HIVE_GET_TABLE_COLUMN_STATS, "HS2-cache");
    }
}
Also used : ColumnStatisticsObj(org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj) HiveMaterializedViewUtils.extractTable(org.apache.hadoop.hive.ql.optimizer.calcite.rules.views.HiveMaterializedViewUtils.extractTable) TableSnapshot(org.apache.hadoop.hive.ql.io.AcidUtils.TableSnapshot) PerfLogger(org.apache.hadoop.hive.ql.log.PerfLogger) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) LockException(org.apache.hadoop.hive.ql.lockmgr.LockException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) HiveMetaException(org.apache.hadoop.hive.metastore.HiveMetaException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) TApplicationException(org.apache.thrift.TApplicationException) TException(org.apache.thrift.TException) SerDeException(org.apache.hadoop.hive.serde2.SerDeException) FileNotFoundException(java.io.FileNotFoundException) JDODataStoreException(javax.jdo.JDODataStoreException) AcidUtils(org.apache.hadoop.hive.ql.io.AcidUtils)

Example 3 with TableSnapshot

use of org.apache.hadoop.hive.ql.io.AcidUtils.TableSnapshot in project hive by apache.

the class Hive method getTableSnapshot.

private TableSnapshot getTableSnapshot(Table tbl, Long writeId) throws LockException {
    TableSnapshot tableSnapshot = null;
    if ((writeId != null) && (writeId > 0)) {
        ValidWriteIdList writeIds = AcidUtils.getTableValidWriteIdListWithTxnList(conf, tbl.getDbName(), tbl.getTableName());
        tableSnapshot = new TableSnapshot(writeId, writeIds.writeToString());
    } else {
        // Make sure we pass in the names, so we can get the correct snapshot for rename table.
        tableSnapshot = AcidUtils.getTableSnapshot(conf, tbl, tbl.getDbName(), tbl.getTableName(), true);
    }
    return tableSnapshot;
}
Also used : ValidWriteIdList(org.apache.hadoop.hive.common.ValidWriteIdList) TableSnapshot(org.apache.hadoop.hive.ql.io.AcidUtils.TableSnapshot)

Example 4 with TableSnapshot

use of org.apache.hadoop.hive.ql.io.AcidUtils.TableSnapshot in project hive by apache.

the class Hive method getAggrColStatsFor.

public AggrStats getAggrColStatsFor(String dbName, String tblName, List<String> colNames, List<String> partName, boolean checkTransactional) {
    PerfLogger perfLogger = SessionState.getPerfLogger();
    perfLogger.perfLogBegin(CLASS_NAME, PerfLogger.HIVE_GET_AGGR_COL_STATS);
    String writeIdList = null;
    try {
        if (checkTransactional) {
            Table tbl = getTable(dbName, tblName);
            AcidUtils.TableSnapshot tableSnapshot = AcidUtils.getTableSnapshot(conf, tbl);
            writeIdList = tableSnapshot != null ? tableSnapshot.getValidWriteIdList() : null;
        }
        AggrStats result = getMSC().getAggrColStatsFor(dbName, tblName, colNames, partName, Constants.HIVE_ENGINE, writeIdList);
        return result;
    } catch (Exception e) {
        LOG.debug("Failed getAggrColStatsFor", e);
        return new AggrStats(new ArrayList<ColumnStatisticsObj>(), 0);
    } finally {
        perfLogger.perfLogEnd(CLASS_NAME, PerfLogger.HIVE_GET_AGGR_COL_STATS, "HS2-cache");
    }
}
Also used : HiveMaterializedViewUtils.extractTable(org.apache.hadoop.hive.ql.optimizer.calcite.rules.views.HiveMaterializedViewUtils.extractTable) TableSnapshot(org.apache.hadoop.hive.ql.io.AcidUtils.TableSnapshot) AggrStats(org.apache.hadoop.hive.metastore.api.AggrStats) PerfLogger(org.apache.hadoop.hive.ql.log.PerfLogger) ArrayList(java.util.ArrayList) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) LockException(org.apache.hadoop.hive.ql.lockmgr.LockException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) HiveMetaException(org.apache.hadoop.hive.metastore.HiveMetaException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) TApplicationException(org.apache.thrift.TApplicationException) TException(org.apache.thrift.TException) SerDeException(org.apache.hadoop.hive.serde2.SerDeException) FileNotFoundException(java.io.FileNotFoundException) JDODataStoreException(javax.jdo.JDODataStoreException) AcidUtils(org.apache.hadoop.hive.ql.io.AcidUtils)

Example 5 with TableSnapshot

use of org.apache.hadoop.hive.ql.io.AcidUtils.TableSnapshot in project hive by apache.

the class Hive method getPartitionColumnStatistics.

public Map<String, List<ColumnStatisticsObj>> getPartitionColumnStatistics(String dbName, String tableName, List<String> partNames, List<String> colNames, boolean checkTransactional) throws HiveException {
    String writeIdList = null;
    try {
        if (checkTransactional) {
            Table tbl = getTable(dbName, tableName);
            AcidUtils.TableSnapshot tableSnapshot = AcidUtils.getTableSnapshot(conf, tbl);
            writeIdList = tableSnapshot != null ? tableSnapshot.getValidWriteIdList() : null;
        }
        return getMSC().getPartitionColumnStatistics(dbName, tableName, partNames, colNames, Constants.HIVE_ENGINE, writeIdList);
    } catch (Exception e) {
        LOG.debug("Failed getPartitionColumnStatistics", e);
        throw new HiveException(e);
    }
}
Also used : HiveMaterializedViewUtils.extractTable(org.apache.hadoop.hive.ql.optimizer.calcite.rules.views.HiveMaterializedViewUtils.extractTable) TableSnapshot(org.apache.hadoop.hive.ql.io.AcidUtils.TableSnapshot) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) LockException(org.apache.hadoop.hive.ql.lockmgr.LockException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) HiveMetaException(org.apache.hadoop.hive.metastore.HiveMetaException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) TApplicationException(org.apache.thrift.TApplicationException) TException(org.apache.thrift.TException) SerDeException(org.apache.hadoop.hive.serde2.SerDeException) FileNotFoundException(java.io.FileNotFoundException) JDODataStoreException(javax.jdo.JDODataStoreException) AcidUtils(org.apache.hadoop.hive.ql.io.AcidUtils)

Aggregations

TableSnapshot (org.apache.hadoop.hive.ql.io.AcidUtils.TableSnapshot)14 TException (org.apache.thrift.TException)13 HiveMetaException (org.apache.hadoop.hive.metastore.HiveMetaException)12 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)12 AcidUtils (org.apache.hadoop.hive.ql.io.AcidUtils)11 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)9 FileNotFoundException (java.io.FileNotFoundException)8 IOException (java.io.IOException)8 UnknownHostException (java.net.UnknownHostException)8 ExecutionException (java.util.concurrent.ExecutionException)8 JDODataStoreException (javax.jdo.JDODataStoreException)8 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)8 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)8 LockException (org.apache.hadoop.hive.ql.lockmgr.LockException)8 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)8 SerDeException (org.apache.hadoop.hive.serde2.SerDeException)8 TApplicationException (org.apache.thrift.TApplicationException)8 HiveMaterializedViewUtils.extractTable (org.apache.hadoop.hive.ql.optimizer.calcite.rules.views.HiveMaterializedViewUtils.extractTable)6 ArrayList (java.util.ArrayList)5 ValidWriteIdList (org.apache.hadoop.hive.common.ValidWriteIdList)5