我有一个 MySQL 数据库,其中的记录包含 JSON 类型字段。 JSON 类型字段的示例是
{....
"callAttributes": {"teamId": "Red", "operatorId": "White", "customerPhoneNumber": "06123456"}
....}
使用 Apache Superset 版本 3.0.2 创建了一个带有饼图和云图的仪表板,以显示各种操作员的记录细分。
select
CAST(JSON_UNQUOTE(JSON_EXTRACT(iridevoice_bi.speech.doc, '$.callAttributes.teamId')) AS NCHAR) as Team,
CAST(JSON_UNQUOTE(JSON_EXTRACT(iridevoice_bi.speech.doc, '$.callAttributes.operatorId')) AS NCHAR) as Agent
from iridevoice_bi.speech
where JSON_EXTRACT(iridevoice_bi.speech.doc, '$.callAttributes.operatorId') is not null AND
JSON_EXTRACT(iridevoice_bi.speech.doc, '$.callAttributes.teamId') is not null
但是当我尝试通过选择运算符(即代理)进行交叉过滤时,超集“美化”了云图,因为它生成了一个带有“不可能”条件的 where 子句。
SELECT `Agent` AS `Agent`,
count(`Agent`) AS `COUNT(Agent)`
FROM
(select CAST(JSON_UNQUOTE(JSON_EXTRACT(iridevoice_bi.speech.doc, '$.callAttributes.teamId')) AS NCHAR) as Team,
CAST(JSON_UNQUOTE(JSON_EXTRACT(iridevoice_bi.speech.doc, '$.callAttributes.operatorId')) AS NCHAR) as Agent
from iridevoice_bi.speech
where JSON_EXTRACT(iridevoice_bi.speech.doc, '$.callAttributes.operatorId') is not null
AND JSON_EXTRACT(iridevoice_bi.speech.doc, '$.callAttributes.teamId') is not null) AS virtual_table
**WHERE `Agent` IS NULL
OR `Agent` IN (NULL)
AND (1 != 1)**
GROUP BY `Agent`
LIMIT 100;
这可能是一个错误吗?有谁知道怎么解决吗
找到了我的问题的解决方案:只需在查询中将 JSON_EXTRACT 替换为 JSON_VALUE ,超集就变成了好孩子:)它不再在 where 子句中添加不可能的条件,并且交叉过滤是完美的