SQL 兼容性问题
BI Connector Returns Empty Set Where MySQL Returns NULL Values
Some SQL aggregate functions (like SUM, MIN, or COUNT) return NULL if there are no matching values for that aggregate function. This response is effectively an empty row.
Given the exact same SQL query, the BI Connector does not return NULL for any aggregate functions; it returns an empty set instead.
例子
您正在分析一所大学去年开设的每门课程的学生测试表现。 您可以使用 Tableau 运行SQL查询来查找每个班级的统计信息,包括最高和最低测试分数以及班级中所有分数的总和和计数。
SELECT SUM(scores), COUNT(*), COUNT(scores), MAX(scores), MIN(scores) FROM students_2019 GROUP BY class;
遗憾的是,您不小心对明年班级的数据运行了查询,因此该查询没有可供查找的测试分数。
如果学生数据存储在 MySQL 中,此查询将返回一行,其中包含使用 SUM 、 MAX 和 MIN 函数计算得出的字段的NULL值,以及使用 、 和函数计算得出的字段的0值。使用COUNT函数。
SELECT SUM(scores), COUNT(*), COUNT(scores), MAX(scores), MIN(scores) FROM students_2019 GROUP BY class; +-------------+----------+---------------+-------------+-------------+ | sum(scores) | count(*) | count(scores) | max(scores) | min(scores) | +-------------+----------+---------------+-------------+-------------+ | NULL | 0 | 0 | NULL | NULL | +-------------+----------+---------------+-------------+-------------+
如果学生数据存储在 MongoDB 中并通过 BI Connector 访问,则此查询将返回一个空集。
SELECT SUM(scores), COUNT(*), COUNT(scores), MAX(scores), MIN(scores) FROM students_2019 GROUP BY class; Empty set (0.00 sec)
BI Connector由于映射错误而返回 NULL 值
可能出现已知映射错误,导致 BI Connector 返回所有NULL值。 当您查询的集合包含一个可以为NULL的数组字段,并且同一数组包含另一个也可以为NULL的字段时,就会出现此错误。 此错误的解决方法是创建一个带有$match筛选器的视图,该筛选器仅使用createView方法返回字段$type为array的文档。
例子
对于名为nextDeparture的collection,其中具有名为response.schedule (有时为NULL )的字段,您可以创建以下视图:
db.createView("nextDeparture_view", "nextDeparture", [ { "$project": { "response": { "$cond": { "if": { "$eq": ["$response.schedule", null] }, "then": { }, "else": "$response" } }, "name": 1 } } ])