天天看点

canal-adapter:sqlRs has error

canal-adapter:配置后,增量和全量还是没有同步且报错support -sqlRs has error

(单表同步没有问题,关联表没有同步)

ERROR com.alibaba.otter.canal.client.adapter.support.U           til - sqlRs has error
ERROR c.a.otter.canal.client.adapter.es7x.etl.ESEtlSer           vice - java.lang.RuntimeException: java.lang.NullPointerException
           

具体原因,虽然sql写法没有问题,但是需要满足aliyun的canal的sql规则:

sql映射说明:

sql支持多表关联自由组合, 但是有一定的限制:

1.主表不能为子查询语句
2.只能使用left outer join即最左表一定要是主表
3.关联从表如果是子查询不能有多张表
4.主sql中不能有where查询条件(从表子查询中可以有where条件但是不推荐, 可能会造成数据同步的不一致, 比如修改了where条件中的字段内容)
5.关联条件只允许主外键的'='操作不能出现其他常量判断比如: on a.role_id=b.id and b.statues=1
6.关联条件必须要有一个字段出现在主查询语句中比如: on a.role_id=b.id 其中的 a.role_id 或者 b.id 必须出现在主select语句中
           

提示:必须要满足以上六中规则才可以实现同步增量|全量

例如:正确关联表同步配置

select a.id as _id, a.name, a.role_id, b.role_name, a.c_time from user a 
left join role b on b.id = a.role_id
           

注:这里join操作只能是left outer join, 第一张表必须为主表!!

关联条件必须要有一个字段出现在主查询语句中比如: b.id = a.role_id 其中的 a.role_id 或者 b.id 必须出现在主select语句中

该sql对应的es mapping示例:

{
    "mytest_user": {
        "mappings": {
            "_doc": {
                "properties": {
                    "name": {
                        "type": "text"
                    },
                    "role_id": {   //这个关联条件必须要有
                        "type": "long"
                    },
                    "role_name": {
                        "type": "text"
                    },
                    "c_time": {
                        "type": "date"
                    }
                }
            }
        }
    }
}