您可以使用PartitionMapper以编程方式为分区步骤定义分区的动态数量。
映射器需要创建一个PartitionPlan对象,该对象设置分区数量并为每个分区提供特定于分区的属性。
您的映射器的mapPartitions()方法将类似于以下大纲:
public PartitionPlan mapPartitions() throws Exception {
int numPartitions = // calculate number of partitions, however you want
// create an array of Properties objects, one for each partition
Properties[] props = new Properties[numPartitions];
for (int i = 0; i < numPartitions; i++) {
// create a Properties object for this partition
props[i] = new Properties();
props[i].setProperty("abc", ...);
props[i].setProperty("xyz", ...);
}
// use the built-in PartitionPlanImpl from the spec or your own impl
PartitionPlan partitionPlan = new PartitionPlanImpl();
partitionPlan.setPartitions(numPartitions);
// cet the Properties[] onto your plan
partitionPlan.setPartitionProperties(props);
return partitionPlan;
}
然后您可以像这样引用特定于分区的属性值进行替换(这与引用静态定义的分区属性的方式相同):
<batchlet ref="myBatchlet">
<properties>
<property name="propABC" value="#{partitionPlan['abc']}" />
<property name="propXYZ" value="#{partitionPlan['xyz']}" />
</properties>
</batchlet>