【发布时间】:2020-11-27 00:14:03
【问题描述】:
给定多个条件的组合,其中包含运算符,例如
section = "ABC" AND type = "A" AND status = "RESPONDED" AND scores NOT_NULL AND scores.productA NOT_NULL AND scores.productA > 10 AND scores.productA < 30
这会导致多个操作,例如
priority = 3 AND hours = 24 AND isQualified = true
目标是找到与该字符串冲突的 JSON 字符串。冲突将是什么时候 相同的条件(相同或不同的顺序)导致不同的动作或导致具有不同值的动作 有一个 mysql 表,将这些 json 字符串存储在一个列中,需要针对该列进行查询
已经尝试过像 JSON_CONTAINS 这样的 MySQL JSON 函数,但是如果嵌套的 json 对象的顺序不同,它就不起作用。 还尝试使用 LIKE 对单个条件进行字符串比较,这些条件有效,但要发生匹配,我们 需要考虑条件的分组和加入它们的运算符。
任何建议都会很棒。理想情况下,能够在 SQL 级别执行此操作会很棒,但结合使用 SQL 来缩小范围,然后对缩小的值进行第二次传递也可能有效。
表示条件和动作的JSON字符串可以像
那样指定{
"actions": [{
"actionItem": {
"SetValueAction": {
"value": {
"long": 24
},
"dataField": {
"field": "hours",
"object": {
"className": "Message",
"objectName": "message"
}
}
}
}
}, {
"actionItem": {
"SetValueAction": {
"value": {
"boolean": true
},
"dataField": {
"field": "isQualified",
"object": {
"className": "Message",
"objectName": "message"
}
}
}
}
}, {
"actionItem": {
"SetValueAction": {
"value": {
"long": 3
},
"dataField": {
"field": "priority",
"object": {
"className": "Message",
"objectName": "message"
}
}
}
}
}],
"condition": {
"ConditionGroup": {
"logicalOperator": "AND",
"conditionGroupItems": [{
"Condition": {
"conditionItem": {
"FieldConstraint": {
"value": {
"string": "ABC"
},
"operator": "EQ",
"dataField": {
"field": "section",
"object": {
"className": "Message",
"objectName": "message"
}
}
}
}
}
}, {
"Condition": {
"conditionItem": {
"FieldConstraint": {
"value": {
"string": "A"
},
"operator": "EQ",
"dataField": {
"field": "type",
"object": {
"className": "Message",
"objectName": "message"
}
}
}
}
}
}, {
"Condition": {
"conditionItem": {
"FieldConstraint": {
"value": {
"string": "RESPONDED"
},
"operator": "EQ",
"dataField": {
"field": "status",
"object": {
"className": "Message",
"objectName": "message"
}
}
}
}
}
}, {
"Condition": {
"conditionItem": {
"FieldConstraint": {
"operator": "NOT_NULL",
"dataField": {
"field": "scores",
"object": {
"className": "Message",
"objectName": "message"
}
}
}
}
}
}, {
"Condition": {
"conditionItem": {
"FieldConstraint": {
"operator": "NOT_NULL",
"dataField": {
"field": "scores.productA",
"object": {
"className": "Message",
"objectName": "message"
}
}
}
}
}
}, {
"Condition": {
"conditionItem": {
"FieldConstraint": {
"value": {
"double": 10
},
"operator": "GT",
"dataField": {
"field": "scores.productA",
"object": {
"className": "Message",
"objectName": "message"
}
}
}
}
}
}, {
"Condition": {
"conditionItem": {
"FieldConstraint": {
"value": {
"double": 30
},
"operator": "LE",
"dataField": {
"field": "scores.productA",
"object": {
"className": "Message",
"objectName": "message"
}
}
}
}
}
}]
}
}
}
【问题讨论】: