I'm want to add OR condition in the JSON query of Cube.js. But once I added one more condition in the filter it always adds AND condition in SQL query.
Below is the JSON query that I'm trying.
{
"dimensions": [
"Employee.name",
"Employee.company"
],
"timeDimensions": [],
"measures": [],
"filters": [
{
"dimension": "Employee.company",
"operator": "contains",
"values": [
"soft"
]
},
{
"dimension": "Employee.name",
"operator": "contains",
"values": [
"soft"
]
}
]
}
It generates below SQL query.
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;
What is the JSON query for Cube.js if I want to generate below SQL
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;
API support for logical operators isn't shipped yet. Meanwhile there're several workarounds:
cube(`Employee`, {
// ...
dimensions: {
companyAndName: {
sql: `CONCAT(${company}, ' ', ${name})`,
type: `string`
}
}
});
cube(`Employee`, {
// ...
segments: {
soft: {
sql: `${company} LIKE CONCAT('%', 'soft', '%') OR ${name} LIKE CONCAT('%', 'soft', '%')`
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With