@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; }
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()); }
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(); }
@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()); }
private void setPartitionSkipProperty( IMetaStoreClient msClient, String tblName, String partName, String val) throws Exception { Partition part = msClient.getPartition(ss.getCurrentDatabase(), tblName, partName); part.getParameters().put(StatsUpdaterThread.SKIP_STATS_AUTOUPDATE_PROPERTY, val); msClient.alter_partition(part.getCatName(), part.getDbName(), tblName, part); }
private static void getPartitionMetaDataInformation(StringBuilder tableInfo, Partition part) { formatOutput("Partition Value:", part.getValues().toString(), tableInfo); formatOutput("Database:", part.getTPartition().getDbName(), tableInfo); formatOutput("Table:", part.getTable().getTableName(), tableInfo); formatOutput("CreateTime:", formatDate(part.getTPartition().getCreateTime()), tableInfo); formatOutput("LastAccessTime:", formatDate(part.getTPartition().getLastAccessTime()), tableInfo); formatOutput("Location:", part.getLocation(), tableInfo); if (part.getTPartition().getParameters().size() > 0) { tableInfo.append("Partition Parameters:").append(LINE_DELIM); displayAllParameters(part.getTPartition().getParameters(), tableInfo); } }
@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()))); }
private void verifyAndUnsetColStats(String tblName, String partName, List<String> cols, IMetaStoreClient msClient) throws Exception { Partition part = msClient.getPartition(ss.getCurrentDatabase(), tblName, partName); verifyAndUnsetColStatsVal(part.getParameters(), cols); EnvironmentContext ec = new EnvironmentContext(); // Make sure metastore doesn't mess with our bogus stats updates. ec.putToProperties(StatsSetupConst.DO_NOT_UPDATE_STATS, StatsSetupConst.TRUE); msClient.alter_partition(part.getCatName(), part.getDbName(), tblName, part, ec); // Double-check. part = msClient.getPartition(ss.getCurrentDatabase(), tblName, partName); for (String col : cols) { assertFalse(StatsSetupConst.areColumnStatsUptoDate(part.getParameters(), col)); } }