Search in sources :

Example 11 with AlterTableAddPartitionDesc

use of org.apache.hadoop.hive.ql.ddl.table.partition.add.AlterTableAddPartitionDesc in project hive by apache.

the class FSTableEvent method addPartitionDesc.

private AlterTableAddPartitionDesc addPartitionDesc(Path fromPath, ImportTableDesc tblDesc, Partition partition) throws SemanticException {
    try {
        Map<String, String> partitionSpec = EximUtil.makePartSpec(tblDesc.getPartCols(), partition.getValues());
        StorageDescriptor sd = partition.getSd();
        String location = sd.getLocation();
        if (!tblDesc.isExternal()) {
            /**
             * this is required for file listing of all files in a partition for managed table as described in
             * {@link org.apache.hadoop.hive.ql.exec.repl.bootstrap.events.filesystem.BootstrapEventsIterator}
             */
            location = new Path(fromPath, Warehouse.makePartName(tblDesc.getPartCols(), partition.getValues())).toString();
        }
        ColumnStatistics columnStatistics = null;
        long writeId = -1;
        if (partition.isSetColStats()) {
            ColumnStatistics colStats = partition.getColStats();
            ColumnStatisticsDesc colStatsDesc = new ColumnStatisticsDesc(colStats.getStatsDesc());
            colStatsDesc.setTableName(tblDesc.getTableName());
            colStatsDesc.setDbName(tblDesc.getDatabaseName());
            columnStatistics = new ColumnStatistics(colStatsDesc, colStats.getStatsObj());
            columnStatistics.setEngine(colStats.getEngine());
            writeId = partition.getWriteId();
        }
        AlterTableAddPartitionDesc.PartitionDesc partitionDesc = new AlterTableAddPartitionDesc.PartitionDesc(partitionSpec, location, partition.getParameters(), sd.getInputFormat(), sd.getOutputFormat(), sd.getNumBuckets(), sd.getCols(), sd.getSerdeInfo().getSerializationLib(), sd.getSerdeInfo().getParameters(), sd.getBucketCols(), sd.getSortCols(), columnStatistics, writeId);
        AlterTableAddPartitionDesc addPartitionDesc = new AlterTableAddPartitionDesc(tblDesc.getDatabaseName(), tblDesc.getTableName(), true, ImmutableList.of(partitionDesc));
        addPartitionDesc.setReplicationSpec(replicationSpec());
        return addPartitionDesc;
    } catch (Exception e) {
        throw new SemanticException(e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ColumnStatistics(org.apache.hadoop.hive.metastore.api.ColumnStatistics) AlterTableAddPartitionDesc(org.apache.hadoop.hive.ql.ddl.table.partition.add.AlterTableAddPartitionDesc) ColumnStatisticsDesc(org.apache.hadoop.hive.metastore.api.ColumnStatisticsDesc) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) AlterTableAddPartitionDesc(org.apache.hadoop.hive.ql.ddl.table.partition.add.AlterTableAddPartitionDesc) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException)

Aggregations

AlterTableAddPartitionDesc (org.apache.hadoop.hive.ql.ddl.table.partition.add.AlterTableAddPartitionDesc)11 Path (org.apache.hadoop.fs.Path)10 Database (org.apache.hadoop.hive.metastore.api.Database)4 ArrayList (java.util.ArrayList)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2 Partition (org.apache.hadoop.hive.metastore.api.Partition)2 StorageDescriptor (org.apache.hadoop.hive.metastore.api.StorageDescriptor)2 DDLWork (org.apache.hadoop.hive.ql.ddl.DDLWork)2 WriteEntity (org.apache.hadoop.hive.ql.hooks.WriteEntity)2 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)2 ImportSemanticAnalyzer.partSpecToString (org.apache.hadoop.hive.ql.parse.ImportSemanticAnalyzer.partSpecToString)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Warehouse (org.apache.hadoop.hive.metastore.Warehouse)1 ColumnStatistics (org.apache.hadoop.hive.metastore.api.ColumnStatistics)1