当前位置:网站首页>spark调优(二):UDF减少JOIN和判断
spark调优(二):UDF减少JOIN和判断
2022-07-06 15:38:00 【InfoQ】
1. 起因
2. 优化开始
2.1 改成java代码编写程序
2.2 使用UDF
public class UDF implements UDF2<Long, Long, Long> {
Map<Long, TreeMap<Long, Long>> map;
public TripUDF(Broadcast<Map<Long, TreeMap<Long, Long>>> bmap) {
this.map = bmap.getValue();
}
@Override
public Long call(Long id, Long time) throws Exception {
if (map.containsKey(terminalId)) {
Map.Entry<Long, Long> a = map.get(id).floorEntry(time);
Map.Entry<Long, Long> b = map.get(id).ceilingEntry(time);
if (null != a && null != b) {
if (a.getValue().equals(b.getValue())) {
return a.getValue();
}
}
}
return -1L;
}
}
tablea join tableb
on tablea.id=tableb.id and
tablea.time >= tableb.timeStart and
tablea.time <= tableb.timeEnd
String udfMethod = "structureMap";
spark.udf().register(udfMethod, new UDF(broadcast1), DataTypes.StringType);
select id,time,structureMap(id,time) as tag from tablea
结束语
边栏推荐
- (shuttle) navigation return interception: willpopscope
- mysql拆分字符串作为查询条件的示例代码
- POJ 1258 Agri-Net
- Flutter life cycle
- Interview question: AOF rewriting mechanism, redis interview must ask!!!
- npm无法安装sharp
- 机试刷题1
- Enterprises do not want to replace the old system that has been used for ten years
- Machine test question 1
- DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
猜你喜欢
Matlab tips (27) grey prediction
Cocoscreator+typescripts write an object pool by themselves
Rust knowledge mind map XMIND
让我们,从头到尾,通透网络I/O模型
MATLAB小技巧(27)灰色预测
机试刷题1
How to confirm the storage mode of the current system by program?
cuda 探索
#DAYU200体验官# 在DAYU200运行基于ArkUI-eTS的智能晾晒系统页面
Cloud native technology container knowledge points
随机推荐
CSDN 上传图片取消自动加水印的方法
ICLR 2022 | 基于对抗自注意力机制的预训练语言模型
允许全表扫描 那个语句好像不生效set odps.sql.allow.fullscan=true;我
Windows auzre background operation interface of Microsoft's cloud computing products
AcWing 4300. Two operations (minimum number of BFS searches)
Cloud native technology container knowledge points
Sword finger offer question brushing record 1
Interview question: AOF rewriting mechanism, redis interview must ask!!!
【Unity】升级版·Excel数据解析,自动创建对应C#类,自动创建ScriptableObject生成类,自动序列化Asset文件
dockermysql修改root账号密码并赋予权限
Return keyword
Method of canceling automatic watermarking of uploaded pictures by CSDN
Void keyword
Machine test question 1
ACL 2022 | 序列标注的小样本NER:融合标签语义的双塔BERT模型
How to confirm the storage mode of the current system by program?
Comparison between variable and "zero value"
Aardio - construct a multi button component with customplus library +plus
专为决策树打造,新加坡国立大学&清华大学联合提出快速安全的联邦学习新系统
面试题:AOF重写机制,redis面试必问!!!