AWS DMS映射规则中OR/AND运算符使用问题求助
解决AWS DMS源过滤的复杂条件问题
你遇到的问题是同一表的多个include类型selection规则只会生效第一个,这是因为AWS DMS对同一对象的多个selection规则处理逻辑有限制,无法直接通过多规则实现OR组合的复杂条件。可以通过以下两种方式解决:
方案1:使用custom运算符实现完整条件
利用DMS源过滤支持的custom运算符,直接将你的SQL逻辑写入filter条件中,无需拆分多个规则:
{ "rule-type": "selection", "rule-id": "9005", "rule-name": "FilterTableOneByDate", "object-locator": { "schema-name": "dbo", "table-name": "table_one" }, "rule-action": "include", "filters": [ { "filter-type": "source", "filter-conditions": [ { "filter-operator": "custom", "value": "(updated_at IS NULL AND created_at >= '2023-04-01') OR (updated_at IS NOT NULL AND updated_at >= '2023-04-01')" } ] } ] }
方案2:简化条件后使用custom运算符
你的原始SQL逻辑可以简化为COALESCE(updated_at, created_at) >= '2023-04-01'(当updated_at为null时,用created_at替代比较),这样配置更简洁:
{ "rule-type": "selection", "rule-id": "9005", "rule-name": "FilterTableOneByDate", "object-locator": { "schema-name": "dbo", "table-name": "table_one" }, "rule-action": "include", "filters": [ { "filter-type": "source", "filter-conditions": [ { "filter-operator": "custom", "value": "COALESCE(updated_at, created_at) >= '2023-04-01'" } ] } ] }
注意:使用custom运算符时,条件语句要符合源数据库的SQL语法,确保函数(如COALESCE)在源数据库中可用。
内容的提问来源于stack exchange,提问作者marcin2x4
相关产品推荐
相关产品推荐

