Skip to content

Commit d706c88

Browse files
committed
fix(schema-compiler): fix FILTER_PARAMS to populate set and notSet filters in cube's SQL query
1 parent 349597a commit d706c88

File tree

2 files changed

+90
-13
lines changed

2 files changed

+90
-13
lines changed

packages/cubejs-schema-compiler/src/adapter/BaseQuery.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3809,21 +3809,20 @@ export class BaseQuery {
38093809
if (!filterParamArg) {
38103810
throw new Error(`FILTER_PARAMS arg not found for ${filter.measure || filter.dimension}`);
38113811
}
3812-
if (
3813-
filterParams && filterParams.length
3814-
) {
3815-
if (typeof filterParamArg.__column() === 'function') {
3816-
// eslint-disable-next-line prefer-spread
3817-
return filterParamArg.__column().apply(
3818-
null,
3819-
filterParams.map(allocateParam),
3820-
);
3821-
} else {
3822-
return filter.conditionSql(filterParamArg.__column());
3823-
}
3824-
} else {
3812+
3813+
if (typeof filterParamArg.__column() !== 'function') {
3814+
return filter.conditionSql(filterParamArg.__column());
3815+
}
3816+
3817+
if (!filterParams || !filterParams.length) {
38253818
return '1 = 1';
38263819
}
3820+
3821+
// eslint-disable-next-line prefer-spread
3822+
return filterParamArg.__column().apply(
3823+
null,
3824+
filterParams.map(allocateParam),
3825+
);
38273826
}
38283827

38293828
filterGroupFunction() {

packages/cubejs-schema-compiler/test/unit/base-query.test.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,84 @@ describe('SQL Generation', () => {
17621762
expect(cubeSQL).toMatch(/\(\s*\(.*type\s*=\s*\$\d\$.*OR.*type\s*=\s*\$\d\$.*\)\s*AND\s*\(.*type\s*=\s*\$\d\$.*OR.*type\s*=\s*\$\d\$.*\)\s*\)/);
17631763
});
17641764

1765+
it('equals NULL filter', async () => {
1766+
await compilers.compiler.compile();
1767+
const query = new BaseQuery(compilers, {
1768+
measures: ['Order.count'],
1769+
filters: [
1770+
{
1771+
and: [
1772+
{
1773+
member: 'Order.type',
1774+
operator: 'equals',
1775+
values: [null],
1776+
},
1777+
]
1778+
}
1779+
],
1780+
});
1781+
const cubeSQL = query.cubeSql('Order');
1782+
expect(cubeSQL).toContain('where (((type IS NULL)))');
1783+
});
1784+
1785+
it('notSet(IS NULL) filter', async () => {
1786+
await compilers.compiler.compile();
1787+
const query = new BaseQuery(compilers, {
1788+
measures: ['Order.count'],
1789+
filters: [
1790+
{
1791+
and: [
1792+
{
1793+
member: 'Order.type',
1794+
operator: 'notSet',
1795+
},
1796+
]
1797+
}
1798+
],
1799+
});
1800+
const cubeSQL = query.cubeSql('Order');
1801+
expect(cubeSQL).toContain('where (((type IS NULL)))');
1802+
});
1803+
1804+
it('notEquals NULL filter', async () => {
1805+
await compilers.compiler.compile();
1806+
const query = new BaseQuery(compilers, {
1807+
measures: ['Order.count'],
1808+
filters: [
1809+
{
1810+
and: [
1811+
{
1812+
member: 'Order.type',
1813+
operator: 'notEquals',
1814+
values: [null],
1815+
},
1816+
]
1817+
}
1818+
],
1819+
});
1820+
const cubeSQL = query.cubeSql('Order');
1821+
expect(cubeSQL).toContain('where (((type IS NOT NULL)))');
1822+
});
1823+
1824+
it('set(IS NOT NULL) filter', async () => {
1825+
await compilers.compiler.compile();
1826+
const query = new BaseQuery(compilers, {
1827+
measures: ['Order.count'],
1828+
filters: [
1829+
{
1830+
and: [
1831+
{
1832+
member: 'Order.type',
1833+
operator: 'set',
1834+
},
1835+
]
1836+
}
1837+
],
1838+
});
1839+
const cubeSQL = query.cubeSql('Order');
1840+
expect(cubeSQL).toContain('where (((type IS NOT NULL)))');
1841+
});
1842+
17651843
it('propagate filter params from view into cube\'s query', async () => {
17661844
await compilers.compiler.compile();
17671845
const query = new BaseQuery(compilers, {

0 commit comments

Comments
 (0)