@Override public String getTableName() { return partition.getTableName(); } @Override public Map<String, String> getParameters() { return partition.getParameters(); }
@Override public String toString() { return String.format("Deregister partition %s.%s %s on Hive metastore %s.", this.partition.getDbName(), this.partition.getTableName(), Arrays.toString(this.partition.getValues().toArray()), this.metastoreURI.isPresent() ? this.metastoreURI.get() : "default"); } }
public static String getQualifiedName(Partition partition) { return partition.getDbName() + "." + partition.getTableName() + partition.getValues(); }
public HiveObjectRef buildPartitionReference(Partition part) { return new HiveObjectRef(HiveObjectType.PARTITION, part.getDbName(), part.getTableName(), part.getValues(), null); }
private static boolean partitionMatches(Partition partition, String databaseName, String tableName, List<String> parts) { if (!partition.getDbName().equals(databaseName) || !partition.getTableName().equals(tableName)) { return false; } List<String> values = partition.getValues(); if (values.size() != parts.size()) { return false; } for (int i = 0; i < values.size(); i++) { String part = parts.get(i); if (!part.isEmpty() && !values.get(i).equals(part)) { return false; } } return true; }
public static Partition fromMetastoreApiPartition(org.apache.hadoop.hive.metastore.api.Partition partition) { StorageDescriptor storageDescriptor = partition.getSd(); if (storageDescriptor == null) { throw new PrestoException(HIVE_INVALID_METADATA, "Partition does not contain a storage descriptor: " + partition); } Partition.Builder partitionBuilder = Partition.builder() .setDatabaseName(partition.getDbName()) .setTableName(partition.getTableName()) .setValues(partition.getValues()) .setColumns(storageDescriptor.getCols().stream() .map(ThriftMetastoreUtil::fromMetastoreApiFieldSchema) .collect(toList())) .setParameters(partition.getParameters()); fromMetastoreApiStorageDescriptor(storageDescriptor, partitionBuilder.getStorageBuilder(), format("%s.%s", partition.getTableName(), partition.getValues())); return partitionBuilder.build(); }
private void dropPartition(Partition partition, boolean ifExists, boolean deleteData) throws HCatException, MetaException, TException { try { hmsClient.dropPartition(partition.getDbName(), partition.getTableName(), partition.getValues(), deleteData); } catch (NoSuchObjectException e) { if (!ifExists) { throw new ObjectNotFoundException( "NoSuchObjectException while dropping partition: " + partition.getValues(), e); } } }
@Override public String toString() { return isPartition() ? StatsUtils.getFullyQualifiedTableName(part.getDbName(), part.getTableName()) + "@" + part.getValues() : Warehouse.getQualifiedName(tab); } }
@Override public AlterPartitionMessage buildAlterPartitionMessage(Table table, Partition before, Partition after, Long writeId) { return new JSONAlterPartitionMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, before.getDbName(), before.getTableName(), table.getTableType(), MessageBuilder.getPartitionKeyValues(table,before), writeId, now()); }
@Override public String toString() { return isPartition() ? part.getDbName() + "." + part.getTableName() + "@" + part.getValues() : tab.getDbName() + "." + tab.getTableName(); } }
@Override public void execute() throws IOException { HiveTable hiveTable = HiveMetaStoreUtils.getHiveTable(this.table); try (HiveRegister hiveRegister = HiveRegister.get(this.props, this.metastoreURI)) { hiveRegister.dropPartitionIfExists(this.partition.getDbName(), this.partition.getTableName(), hiveTable.getPartitionKeys(), this.partition.getValues()); } }
private boolean startAddPartition( RawStore ms, Partition part, List<FieldSchema> partitionKeys, boolean ifNotExists) throws TException { MetaStoreServerUtils.validatePartitionNameCharacters(part.getValues(), partitionValidationPattern); boolean doesExist = ms.doesPartitionExist(part.getCatName(), part.getDbName(), part.getTableName(), partitionKeys, part.getValues()); if (doesExist && !ifNotExists) { throw new AlreadyExistsException("Partition already exists: " + part); } return !doesExist; }
private boolean isValidPartition( Partition part, List<FieldSchema> partitionKeys, boolean ifNotExists) throws MetaException { MetaStoreServerUtils.validatePartitionNameCharacters(part.getValues(), partitionValidationPattern); boolean doesExist = doesPartitionExist(part.getCatName(), part.getDbName(), part.getTableName(), partitionKeys, part.getValues()); if (doesExist && !ifNotExists) { throw new MetaException("Partition already exists: " + part); } return !doesExist; }
@Override public List<Partition> add_partitions( List<Partition> parts, boolean ifNotExists, boolean needResults) throws TException { if (parts.isEmpty()) { return needResults ? new ArrayList<>() : null; } Partition part = parts.get(0); AddPartitionsRequest req = new AddPartitionsRequest( part.getDbName(), part.getTableName(), parts, ifNotExists); req.setNeedResult(needResults); AddPartitionsResult result = client.add_partitions_req(req); return needResults ? filterHook.filterPartitions(result.getPartitions()) : null; }
private void validatePartition(Partition expectedPartition, Partition actualPartition) { assertEquals(expectedPartition.getValues(), actualPartition.getValues()); assertEquals(expectedPartition.getDbName(), actualPartition.getDbName()); assertEquals(expectedPartition.getTableName(), actualPartition.getTableName()); }
HCatPartition(HCatTable hcatTable, Partition partition) throws HCatException { this.hcatTable = hcatTable; this.tableName = partition.getTableName(); this.dbName = partition.getDbName(); this.createTime = partition.getCreateTime(); this.lastAccessTime = partition.getLastAccessTime(); this.parameters = partition.getParameters(); this.values = partition.getValues(); if (hcatTable != null && partition.getValuesSize() != hcatTable.getPartCols().size()) { throw new HCatException("Mismatched number of partition columns between table:" + hcatTable.getDbName() + "." + hcatTable.getTableName() + " and partition " + partition.getValues()); } this.sd = partition.getSd(); this.columns = getColumns(this.sd); }
@Override public boolean addPartition(Partition part) throws InvalidObjectException, MetaException { boolean succ = rawStore.addPartition(part); // in case of event based cache update, cache will be updated during commit. if (succ && !canUseEvents) { String dbName = normalizeIdentifier(part.getDbName()); String tblName = normalizeIdentifier(part.getTableName()); String catName = part.isSetCatName() ? normalizeIdentifier(part.getCatName()) : DEFAULT_CATALOG_NAME; if (!shouldCacheTable(catName, dbName, tblName)) { return succ; } sharedCache.addPartitionToCache(catName, dbName, tblName, part); } return succ; }
private void validateAlterPartition(Partition expectedOldPartition, Partition expectedNewPartition, String actualOldPartitionDbName, String actualOldPartitionTblName,List<String> actualOldPartitionValues, Partition actualNewPartition) { assertEquals(expectedOldPartition.getValues(), actualOldPartitionValues); assertEquals(expectedOldPartition.getDbName(), actualOldPartitionDbName); assertEquals(expectedOldPartition.getTableName(), actualOldPartitionTblName); validatePartition(expectedNewPartition, actualNewPartition); }
@Test public void testAddPartitionUpperCase() throws Exception { String tableLocation = metaStore.getWarehouseRoot() + "/" + TABLE_NAME; createTable(DB_NAME, TABLE_NAME, getMonthPartCol(), tableLocation); Partition partition = buildPartition(Lists.newArrayList("APRIL"), getMonthPartCol(), 1); client.add_partition(partition); Partition part = client.getPartition(DB_NAME, TABLE_NAME, "month=APRIL"); Assert.assertNotNull(part); Assert.assertEquals(TABLE_NAME, part.getTableName()); Assert.assertEquals(DB_NAME, part.getDbName()); Assert.assertEquals("APRIL", part.getValues().get(0)); Assert.assertEquals(tableLocation + "/month=APRIL", part.getSd().getLocation()); Assert.assertTrue(metaStore.isPathExists(new Path(part.getSd().getLocation()))); }
@Test public void testAddPartitionDifferentNamesAndTypesInColAndTableCol() throws Exception { createTable(); Partition partition = new PartitionBuilder() .setDbName(DB_NAME) .setTableName(TABLE_NAME) .addValue("1000") .addCol("time", "int") .build(metaStore.getConf()); client.add_partition(partition); Partition part = client.getPartition(DB_NAME, TABLE_NAME, "year=1000"); Assert.assertNotNull(part); Assert.assertEquals(TABLE_NAME, part.getTableName()); Assert.assertEquals("1000", part.getValues().get(0)); Assert.assertTrue(metaStore.isPathExists(new Path(part.getSd().getLocation()))); }