[英]How to detect conflicting strings from a list of JSON given a Complex JSON?
给定多个条件的组合以及介于两者之间的运算符,例如。
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 字符串存储在一个列中并且需要针对该列进行查询
已经尝试过 MySQL JSON 函数,如 JSON_CONTAINS,但如果嵌套 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"
}
}
}
}
}
}]
}
}
}
SQL 中没有复杂的框架可以满足您的要求。 使用 Java - 这很简单。
但是-您可以在 mysql 中使用以下输入构建逻辑
1.) 使用带有文本条件的 JSON_SEARCH 1.) "condition" 2.) "actionnItem" 并给出“全部”搜索以返回所有匹配的字符串路径https://dev.mysql.com/doc/refman/5.7/en /json-search-functions.html#function_json-search
2.) 您将有两个输出集用于条件和操作项
3.) 现在每个都有两个单独的 while 循环,并从步骤 1/2 中确定的路径解析,并根据您的 JSON 格式再次对运算符、数据字段和其他文本执行 json_search。
Detailed JSON functions are available here - https://dev.mysql.com/doc/refman/5.7/en/json-function-reference.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.