Java 类名:com.alibaba.alink.operator.batch.dataproc.RebalanceBatchOp
Python 类名:RebalanceBatchOp
功能介绍
该组件对数据进行 rebalance。
实现原理
将数据按轮转(round-robin)的方式划分分区,后续每个 worker 处理一个分区,各个分区间负载相等。
可以用于优化数据倾斜带来的性能问题。
参数说明
名称 | 中文名称 | 描述 | 类型 | 是否必须? | 取值范围 | 默认值 |
---|---|---|---|---|---|---|
代码示例
Python 代码
from pyalink.alink import *
import pandas as pd
useLocalEnv(1)
df = pd.DataFrame([
["0,0,0"],
["0.1,0.1,0.1"],
["0.2,0.2,0.2"],
["9,9,9"],
["9.1,9.1,9.1"],
["9.2,9.2,9.2"]
])
inOp = BatchOperator.fromDataframe(df, schemaStr='Y string')
inOp.link(RebalanceBatchOp()).print()
Java 代码
import org.apache.flink.types.Row;
import com.alibaba.alink.operator.batch.BatchOperator;
import com.alibaba.alink.operator.batch.dataproc.RebalanceBatchOp;
import com.alibaba.alink.operator.batch.source.MemSourceBatchOp;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
public class RebalanceBatchOpTest {
@Test
public void testRebalanceBatchOp() throws Exception {
List <Row> df = Arrays.asList(
Row.of("0,0,0"),
Row.of("0.1,0.1,0.1"),
Row.of("0.2,0.2,0.2"),
Row.of("9,9,9"),
Row.of("9.1,9.1,9.1"),
Row.of("9.2,9.2,9.2")
);
BatchOperator <?> inOp = new MemSourceBatchOp(df, "Y string");
inOp.link(new RebalanceBatchOp()).print();
}
}
运行结果
| Y | | —- |
| 0,0,0 |
| 0.1,0.1,0.1 |
| 0.2,0.2,0.2 |
| 9,9,9 |
| 9.1,9.1,9.1 |
| 9.2,9.2,9.2 |