我想在Cube.js的JSON查询中添加 OR 条件。但是,一旦我在过滤器中添加了一个条件,它总是会在SQL查询中添加 AND 条件。
下面是我正在尝试的JSON查询。
{
"dimensions": [
"Employee.name",
"Employee.company"
],
"timeDimensions": [],
"measures": [],
"filters": [
{
"dimension": "Employee.company",
"operator": "contains",
"values": [
"soft"
]
},
{
"dimension": "Employee.name",
"operator": "contains",
"values": [
"soft"
]
}
]
}
它在下面的SQL查询中生成。
SELECT
`employee`.name `employee__name`,
`employee`.company `employee__company`
FROM
DEMO.Employee AS `employee`
WHERE
`employee`.company LIKE CONCAT('%', 'soft', '%')
AND
`employee`.name LIKE CONCAT('%', 'soft', '%')
GROUP BY
1,
2;
如果要在SQL下生成,对Cube.js的JSON查询是什么
SELECT
`employee`.name `employee__name`,
`employee`.company `employee__company`
FROM
DEMO.Employee AS `employee`
WHERE
`employee`.company LIKE CONCAT('%', 'soft', '%')
OR
`employee`.name LIKE CONCAT('%', 'soft', '%')
GROUP BY
1,
2;
答案 0 :(得分:0)
尚未提供对逻辑运算符的API支持。同时,有几种解决方法:
cube(`Employee`, {
// ...
dimensions: {
companyAndName: {
sql: `CONCAT(${company}, ' ', ${name})`,
type: `string`
}
}
});
cube(`Employee`, {
// ...
segments: {
soft: {
sql: `${company} LIKE CONCAT('%', 'soft', '%') OR ${name} LIKE CONCAT('%', 'soft', '%')`
}
}
});