LOG.info("HCatClient dropPartitions(db=" + dbName + ",table=" + tableName + ", partitionSpec: ["+ partitionSpec + "])."); try { dbName = checkDB(dbName); Table table = hmsClient.getTable(dbName, tableName); dropPartitionsUsingExpressions(table, partitionSpec, ifExists, deleteData); dropPartitionsIteratively(dbName, tableName, partitionSpec, ifExists, deleteData); dropPartitionsIteratively(dbName, tableName, partitionSpec, ifExists, deleteData);
@Override public List<HCatPartition> deserializePartitions(List<String> hcatPartitionStringReps) throws HCatException { List<HCatPartition> partitions = new ArrayList<HCatPartition>(hcatPartitionStringReps.size()); MetadataSerializer deserializer = MetadataSerializer.get(); HCatTable table = null; for (String partString : hcatPartitionStringReps) { HCatPartition partition; if (table == null) { partition = deserializePartition(partString); table = partition.hcatTable(); } else { partition = deserializer.deserializePartition(partString); if (partition.getDatabaseName().equals(table.getDbName()) && partition.getTableName().equals(table.getTableName())) { partition.hcatTable(table); } else { throw new HCatException("All partitions are not of the same table: " + table.getDbName() + "." + table.getTableName()); } } partitions.add(partition); } return partitions; }
private void dropPartitionsIteratively(String dbName, String tableName, Map<String, String> partitionSpec, boolean ifExists, boolean deleteData) throws HCatException, TException { LOG.info("HCatClient: Dropping partitions iteratively."); List<Partition> partitions = hmsClient.listPartitionsByFilter(dbName, tableName, getFilterString(partitionSpec), (short) -1); for (Partition partition : partitions) { dropPartition(partition, ifExists, deleteData); } }
@Override public List<HCatPartition> getPartitions(String dbName, String tblName, Map<String, String> partitionSpec) throws HCatException { return listPartitionsByFilter(dbName, tblName, getFilterString(partitionSpec)); }
@Override public HCatPartitionSpec getPartitionSpecs(String dbName, String tableName, Map<String, String> partitionSelector, int maxPartitions) throws HCatException { return listPartitionSpecsByFilter(dbName, tableName, getFilterString(partitionSelector), maxPartitions); }
@Override public void dropTable(String dbName, String tableName, boolean ifExists) throws HCatException { try { hmsClient.dropTable(checkDB(dbName), tableName, true, ifExists); } catch (NoSuchObjectException e) { if (!ifExists) { throw new ObjectNotFoundException( "NoSuchObjectException while dropping table.", e); } } catch (MetaException e) { throw new HCatException("MetaException while dropping table.", e); } catch (TException e) { throw new ConnectionFailureException( "TException while dropping table.", e); } }
@Override public List<HCatPartition> getPartitions(String dbName, String tblName) throws HCatException { List<HCatPartition> hcatPtns = new ArrayList<HCatPartition>(); try { HCatTable hcatTable = getTable(dbName, tblName); List<Partition> hivePtns = hmsClient.listPartitions( checkDB(dbName), tblName, (short) -1); for (Partition ptn : hivePtns) { hcatPtns.add(new HCatPartition(hcatTable, ptn)); } } catch (NoSuchObjectException e) { throw new ObjectNotFoundException( "NoSuchObjectException while retrieving partition.", e); } catch (MetaException e) { throw new HCatException( "MetaException while retrieving partition.", e); } catch (TException e) { throw new ConnectionFailureException( "TException while retrieving partition.", e); } return hcatPtns; }
@Override public HCatPartition deserializePartition(String hcatPartitionStringRep) throws HCatException { HCatPartition hcatPartition = MetadataSerializer.get().deserializePartition(hcatPartitionStringRep); hcatPartition.hcatTable(getTable(hcatPartition.getDatabaseName(), hcatPartition.getTableName())); return hcatPartition; }
String location) throws HCatException { Table hiveTable = getHiveTableLike(checkDB(dbName), existingTblName, newTableName, ifNotExists, location); if (hiveTable != null) {
private void dropPartitionsUsingExpressions(Table table, Map<String, String> partitionSpec, boolean ifExists, boolean deleteData) throws SemanticException, TException { LOG.info("HCatClient: Dropping partitions using partition-predicate Expressions."); ExprNodeGenericFuncDesc partitionExpression = new ExpressionBuilder(table, partitionSpec).build(); ObjectPair<Integer, byte[]> serializedPartitionExpression = new ObjectPair<>(partitionSpec.size(), SerializationUtilities.serializeExpressionToKryo(partitionExpression)); hmsClient.dropPartitions(table.getDbName(), table.getTableName(), Arrays.asList(serializedPartitionExpression), deleteData && !isExternal(table), // Delete data? ifExists, // Fail if table doesn't exist? false); // Need results back? }
@Override public void dropPartitions(String dbName, String tableName, Map<String, String> partitionSpec, boolean ifExists) throws HCatException { dropPartitions(dbName, tableName, partitionSpec, ifExists, true); }
@Override public void dropDatabase(String dbName, boolean ifExists, DropDBMode mode) throws HCatException { boolean isCascade = mode.toString().equalsIgnoreCase("cascade"); try { hmsClient.dropDatabase(checkDB(dbName), true, ifExists, isCascade); } catch (NoSuchObjectException e) { if (!ifExists) { throw new ObjectNotFoundException( "NoSuchObjectException while dropping db.", e); } } catch (InvalidOperationException e) { throw new HCatException( "InvalidOperationException while dropping db.", e); } catch (MetaException e) { throw new HCatException("MetaException while dropping db.", e); } catch (TException e) { throw new ConnectionFailureException("TException while dropping db.", e); } }
HCatPartition partition = null; try { HCatTable hcatTable = getTable(dbName, tableName); List<HCatFieldSchema> partitionColumns = hcatTable.getPartCols(); if (partitionColumns.size() != partitionSpec.size()) { Partition hivePartition = hmsClient.getPartition(checkDB(dbName), tableName, ptnValues); if (hivePartition != null) {
@Override public HCatPartitionSpec deserializePartitionSpec(List<String> hcatPartitionSpecStrings) throws HCatException { HCatPartitionSpec hcatPartitionSpec = MetadataSerializer.get() .deserializePartitionSpec(hcatPartitionSpecStrings); hcatPartitionSpec .hcatTable(getTable(hcatPartitionSpec.getDbName(), hcatPartitionSpec.getTableName())); return hcatPartitionSpec; } }
@Override public List<HCatPartition> getPartitions(String dbName, String tblName, Map<String, String> partitionSpec) throws HCatException { return listPartitionsByFilter(dbName, tblName, getFilterString(partitionSpec)); }
@Override public HCatPartitionSpec getPartitionSpecs(String dbName, String tableName, Map<String, String> partitionSelector, int maxPartitions) throws HCatException { return listPartitionSpecsByFilter(dbName, tableName, getFilterString(partitionSelector), maxPartitions); }
String location) throws HCatException { Table hiveTable = getHiveTableLike(checkDB(dbName), existingTblName, newTableName, ifNotExists, location); if (hiveTable != null) {
private void dropPartitionsUsingExpressions(Table table, Map<String, String> partitionSpec, boolean ifExists, boolean deleteData) throws SemanticException, TException { LOG.info("HCatClient: Dropping partitions using partition-predicate Expressions."); ExprNodeGenericFuncDesc partitionExpression = new ExpressionBuilder(table, partitionSpec).build(); ObjectPair<Integer, byte[]> serializedPartitionExpression = new ObjectPair<>(partitionSpec.size(), SerializationUtilities.serializeExpressionToKryo(partitionExpression)); hmsClient.dropPartitions(table.getDbName(), table.getTableName(), Arrays.asList(serializedPartitionExpression), deleteData && !isExternal(table), // Delete data? ifExists, // Fail if table doesn't exist? false); // Need results back? }
@Override public void dropPartitions(String dbName, String tableName, Map<String, String> partitionSpec, boolean ifExists) throws HCatException { dropPartitions(dbName, tableName, partitionSpec, ifExists, true); }
LOG.info("HCatClient dropPartitions(db=" + dbName + ",table=" + tableName + ", partitionSpec: ["+ partitionSpec + "])."); try { dbName = checkDB(dbName); Table table = hmsClient.getTable(dbName, tableName); dropPartitionsUsingExpressions(table, partitionSpec, ifExists, deleteData); dropPartitionsIteratively(dbName, tableName, partitionSpec, ifExists, deleteData); dropPartitionsIteratively(dbName, tableName, partitionSpec, ifExists, deleteData);