Method to copy partition parameters from source partition to destination partition
@param completeSourcePartitionName dbName@tableName@partitionName
@param completeDestPartitionName dbName@tableName@partitionName
965391
@VisibleForTesting
  public boolean copyPartitionParams(String completeSourcePartitionName, String completeDestPartitionName,
      List<String> whitelist, List<String> blacklist) {
    Optional<Partition> sourcePartitionOptional = getPartitionObject(completeSourcePartitionName);
    Optional<Partition> destPartitionOptional = getPartitionObject(completeDestPartitionName);
    if ((!sourcePartitionOptional.isPresent()) || (!destPartitionOptional.isPresent())) {
      return false;
    }
    Map<String, String> sourceParams = sourcePartitionOptional.get().getParameters();
    Map<String, String> destParams = destPartitionOptional.get().getParameters();

    for (Map.Entry<String, String> param : sourceParams.entrySet()) {
      if (!matched(whitelist, blacklist, param.getKey())) {
        continue;
      }
      destParams.put(param.getKey(), param.getValue());
    }
    destPartitionOptional.get().setParameters(destParams);
    if (!dropPartition(completeDestPartitionName)) {
      return false;
    }
    if (!addPartition(destPartitionOptional.get(), completeDestPartitionName)) {
      return false;
    }
    return true;
  }
1355787
public function dropPartition(string $dataBaseTableName, string $partition_id)
    {

        $partition_id = trim($partition_id, '\'');
        $this->settings()->set('replication_alter_partitions_sync', 2);
        $state = $this->write('ALTER TABLE {dataBaseTableName} DROP PARTITION :partion_id',
            [
                'dataBaseTableName' => $dataBaseTableName,
                'partion_id'        => $partition_id,
            ]);

        return $state;
    }
1255656
public void copy(ConnectionContext source) {
        this.connection = source.connection;
        this.session = source.session;
        this.destination = source.destination;
    }
1220286
private void compactPartition(int partitionNumber) throws IOException {
		// stop if no garbage exists
		if(this.partitions.get(partitionNumber).isCompacted()) {
			return;
		}
		// release all segments owned by compaction partition
		this.compactionMemory.clearAllMemory(availableMemory);
		this.compactionMemory.allocateSegments(1);
		T tempHolder = this.buildSideSerializer.createInstance();
		InMemoryPartition<T> partition = this.partitions.remove(partitionNumber);
		final int numPartitions = this.partitions.size() + 1; // dropped one earlier
		long pointer = 0L;
		int pointerOffset = 0;
		int bucketOffset = 0;
		final int bucketsPerSegment = this.bucketsPerSegmentMask + 1;
		for (int i = 0, bucket = partitionNumber; i < this.buckets.length && bucket < this.numBuckets; i++) {
			MemorySegment segment = this.buckets[i];
			// go over all buckets in the segment belonging to the partition
			for (int k = bucket % bucketsPerSegment; k < bucketsPerSegment && bucket < this.numBuckets; k += numPartitions, bucket += numPartitions) {
				bucketOffset = k * HASH_BUCKET_SIZE;
				if((int)segment.get(bucketOffset + HEADER_PARTITION_OFFSET) != partitionNumber) {
					throw new IOException("Accessed wrong bucket! ");
				}
				int count = segment.getInt(bucketOffset + HEADER_COUNT_OFFSET);
				for (int j = 0; j < NUM_ENTRIES_PER_BUCKET && j < count; j++) {
					pointerOffset = bucketOffset + BUCKET_POINTER_START_OFFSET + (j * POINTER_LEN);
					pointer = segment.getLong(pointerOffset);
					partition.readRecordAt(pointer, tempHolder);
					pointer = this.compactionMemory.appendRecord(tempHolder);
					segment.putLong(pointerOffset, pointer);
				}
				long overflowPointer = segment.getLong(bucketOffset + HEADER_FORWARD_OFFSET);
				if(overflowPointer != BUCKET_FORWARD_POINTER_NOT_SET) {
					// scan overflow buckets
					int current = NUM_ENTRIES_PER_BUCKET;
					bucketOffset = (int) (overflowPointer & 0xffffffff);
					pointerOffset = ((int) (overflowPointer & 0xffffffff)) + BUCKET_POINTER_START_OFFSET;
					int overflowSegNum = (int) (overflowPointer >>> 32);
					count += partition.overflowSegments[overflowSegNum].getInt(bucketOffset + HEADER_COUNT_OFFSET);
					while(current < count) {
						pointer = partition.overflowSegments[overflowSegNum].getLong(pointerOffset);
						partition.readRecordAt(pointer, tempHolder);
						pointer = this.compactionMemory.appendRecord(tempHolder);
						partition.overflowSegments[overflowSegNum].putLong(pointerOffset, pointer);
						current++;
						if(current % NUM_ENTRIES_PER_BUCKET == 0) {
							count += partition.overflowSegments[overflowSegNum].getInt(bucketOffset + HEADER_COUNT_OFFSET);
							overflowPointer = partition.overflowSegments[overflowSegNum].getLong(bucketOffset + HEADER_FORWARD_OFFSET);
							if(overflowPointer == BUCKET_FORWARD_POINTER_NOT_SET) {
								break;
							}
							overflowSegNum = (int) (overflowPointer >>> 32);
							bucketOffset = (int) (overflowPointer & 0xffffffff);
							pointerOffset = ((int) (overflowPointer & 0xffffffff)) + BUCKET_POINTER_START_OFFSET;
						} else {
							pointerOffset += POINTER_LEN;
						}
					}
				}
			}
		}
		// swap partition with compaction partition
		this.compactionMemory.setPartitionNumber(partitionNumber);
		this.partitions.add(partitionNumber, compactionMemory);
		this.compactionMemory = partition;
		this.partitions.get(partitionNumber).overflowSegments = this.compactionMemory.overflowSegments;
		this.partitions.get(partitionNumber).numOverflowSegments = this.compactionMemory.numOverflowSegments;
		this.partitions.get(partitionNumber).nextOverflowBucket = this.compactionMemory.nextOverflowBucket;
		this.partitions.get(partitionNumber).setCompaction(true);
		this.compactionMemory.resetRecordCounter();
		this.compactionMemory.setPartitionNumber(-1);
		// try to allocate maximum segment count
		int maxSegmentNumber = 0;
		for (InMemoryPartition<T> e : this.partitions) {
			if(e.getBlockCount() > maxSegmentNumber) {
				maxSegmentNumber = e.getBlockCount();
			}
		}
		this.compactionMemory.allocateSegments(maxSegmentNumber);
		if(this.compactionMemory.getBlockCount() > maxSegmentNumber) {
			this.compactionMemory.releaseSegments(maxSegmentNumber, availableMemory);
		}
	}
15471
@Override
    public Map<String, Optional<Partition>> getPartitionsByNames(String databaseName, String tableName, List<String> partitionNames)
    {
        requireNonNull(partitionNames, "partitionNames is null");
        if (partitionNames.isEmpty()) {
            return ImmutableMap.of();
        }

        List<Partition> partitions = batchGetPartition(databaseName, tableName, partitionNames);

        Map<String, List<String>> partitionNameToPartitionValuesMap = partitionNames.stream()
                .collect(toMap(identity(), HiveUtil::toPartitionValues));
        Map<List<String>, Partition> partitionValuesToPartitionMap = partitions.stream()
                .collect(toMap(Partition::getValues, identity()));

        ImmutableMap.Builder<String, Optional<Partition>> resultBuilder = ImmutableMap.builder();
        for (Entry<String, List<String>> entry : partitionNameToPartitionValuesMap.entrySet()) {
            Partition partition = partitionValuesToPartitionMap.get(entry.getValue());
            resultBuilder.put(entry.getKey(), Optional.ofNullable(partition));
        }
        return resultBuilder.build();
    }
317005
public final void initSourceName(String sourceName)
    {
        if (sourceName == null) throw new IllegalArgumentException();
        if (this.sourceName != null) throw new IllegalStateException();
        this.sourceName = sourceName;
    }
188401
public void setResourcePartition(java.util.Collection<StringFilter> resourcePartition) {
        if (resourcePartition == null) {
            this.resourcePartition = null;
            return;
        }

        this.resourcePartition = new java.util.ArrayList<StringFilter>(resourcePartition);
    }
368386
public void addStmtProcedure(String name, String sql, String partitionInfoString) {
        addProcedures(new ProcedureInfo(new String[0], name, sql,
                ProcedurePartitionData.fromPartitionInfoString(partitionInfoString)));
    }
805809
protected boolean isCopyTransCompleteForSourceDocument(final CopyTransResource copyTransResource, final String zanataId) {
        final CopyTransStatus status = copyTransResource.getCopyTransStatus(details.getProject(), details.getVersion(), zanataId);
        performZanataRESTCallWaiting();
        return !status.isInProgress();
    }
942582
public final int setPartitionColumnName(String partitionColumnName) {
        if (partitionColumnName == null || partitionColumnName.trim().isEmpty()) {
            return PARTITION_ID_INDEX;
        }
        int idx = -1;
        for (String name : m_source.columnNames) {
            if (name.equalsIgnoreCase(partitionColumnName)) {
                idx = m_source.columnNames.indexOf(name);
                break;
            }
        }
        if (idx == -1) {
            m_partitionColumnIndex = PARTITION_ID_INDEX;
            m_logger.error("Export configuration error: specified " + m_source.tableName + "." + partitionColumnName
                    + " does not exist. A default partition or routing key will be used.");
        } else {
            m_partitionColumnIndex = idx;
        }
        return m_partitionColumnIndex;
    }
628251
protected void moveResource(CmsDbContext dbc, CmsResource source, String destination) throws CmsException {

        List<CmsResource> resources = null;

        if (source.isFolder()) {
            if (!CmsResource.isFolder(destination)) {
                // ensure folder name end's with a /
                destination = destination.concat("/");
            }
            // collect all resources in the folder without checking permissions
            resources = m_driverManager.readChildResources(dbc, source, CmsResourceFilter.ALL, true, true, false);
        }

        // target permissions will be checked later
        m_driverManager.moveResource(dbc, source, destination, false);

        // make sure lock is set
        CmsResource destinationResource = m_driverManager.readResource(dbc, destination, CmsResourceFilter.ALL);
        try {
            // the destination must always get a new lock
            m_driverManager.lockResource(dbc, destinationResource, CmsLockType.EXCLUSIVE);
        } catch (Exception e) {
            // could happen with with shared locks on single files
            if (LOG.isWarnEnabled()) {
                LOG.warn(e);
            }
        }

        if (resources != null) {
            // now walk through all sub-resources in the folder
            for (int i = 0; i < resources.size(); i++) {
                CmsResource childResource = resources.get(i);
                String childDestination = destination.concat(childResource.getName());
                // recurse with child resource
                moveResource(dbc, childResource, childDestination);
            }
        }
        CmsProject currentProject = dbc.getRequestContext().getCurrentProject();
        if (!currentProject.isOnlineProject()) {
            List<CmsResource> movedResources = m_driverManager.readChildResources(
                dbc,
                destinationResource,
                CmsResourceFilter.ALL,
                true,
                true,
                false);
            movedResources.add(destinationResource);
            for (CmsResource res : movedResources) {
                m_driverManager.repairCategories(dbc, dbc.getRequestContext().getCurrentProject().getUuid(), res);
            }
        }
    }
1103690
@Override
    public void onSourceDrained(int partitionId, String tableName) {
        ExportDataSource source;
        synchronized(m_dataSourcesByPartition) {
            Map<String, ExportDataSource> sources = m_dataSourcesByPartition.get(partitionId);

            if (sources == null) {
                if (!m_removingPartitions.contains(partitionId)) {
                     exportLog.error("Could not find export data sources for partition "
                            + partitionId + ". The export cleanup stream is being discarded.");
                }
                return;
            }

            source = sources.get(tableName);
            if (source == null) {
                exportLog.warn("Could not find export data source for signature " + partitionId +
                        " name " + tableName + ". The export cleanup stream is being discarded.");
                return;
            }

            // Remove source and partition entry if empty
            sources.remove(tableName);
            if (sources.isEmpty()) {
                m_dataSourcesByPartition.remove(partitionId);
                removeMailbox(partitionId);
            }
        }

        //Do closing outside the synchronized block. Do not wait on future since
        // we're invoked from the source's executor thread.
        exportLog.info("Drained on unused partition " + partitionId + ": " + source);
        source.closeAndDelete();
    }
1084794
private void partitionFinished(PartitionReplyMsg msg) {

        JoblogUtil.logToJobLogAndTraceOnly(Level.FINE, "partition.ended", new Object[] {
                                                                                         msg.getPartitionPlanConfig().getPartitionNumber(),
                                                                                         msg.getBatchStatus(),
                                                                                         msg.getExitStatus(),
                                                                                         msg.getPartitionPlanConfig().getStepName(),
                                                                                         msg.getPartitionPlanConfig().getTopLevelNameInstanceExecutionInfo().getInstanceId(),
                                                                                         msg.getPartitionPlanConfig().getTopLevelNameInstanceExecutionInfo().getExecutionId() },
                                           logger);

        finishedWork.add(msg);
    }
848838
public static boolean checkPartitionBelongsToNode(int partition,
                                                      int nodeId,
                                                      Cluster cluster,
                                                      StoreDefinition storeDef) {
        List<Integer> nodePartitions = cluster.getNodeById(nodeId).getPartitionIds();
        List<Integer> replicatingPartitions = new RoutingStrategyFactory().updateRoutingStrategy(storeDef,
                                                                                                 cluster)
                                                                          .getReplicatingPartitionList(partition);
        replicatingPartitions.retainAll(nodePartitions);
        return replicatingPartitions.size() > 0;
    }
912169
def append_partition_by_name(self, db_name, tbl_name, part_name):
    
    self.send_append_partition_by_name(db_name, tbl_name, part_name)
    return self.recv_append_partition_by_name()
1122382
def get_partitions_ps(self, db_name, tbl_name, part_vals, max_parts):
    
    self.send_get_partitions_ps(db_name, tbl_name, part_vals, max_parts)
    return self.recv_get_partitions_ps()
1172878
private void serializePartitionInfoToState() {
    List<PartitionDescriptor> descriptors = new ArrayList<>();

    for (DataWriter writer : partitionWriters.asMap().values()) {
      Descriptor descriptor = writer.getDataDescriptor();
      if (null == descriptor) {
        log.warn("Drop partition info as writer {} returns a null PartitionDescriptor", writer.toString());
        continue;
      }

      if (!(descriptor instanceof PartitionDescriptor)) {
        log.warn("Drop partition info as writer {} does not return a PartitionDescriptor", writer.toString());
        continue;
      }

      descriptors.add((PartitionDescriptor)descriptor);
    }

    if (descriptors.size() > 0) {
      state.setProp(getPartitionsKey(branchId), PartitionDescriptor.toPartitionJsonList(descriptors));
    } else {
      log.info("Partitions info not available. Will not serialize partitions");
    }
  }