From 07bb9ac0ac5585863ae461b00ad4335ed166192c Mon Sep 17 00:00:00 2001 From: Vadim Ogievetsky Date: Wed, 29 May 2024 15:43:39 -0700 Subject: [PATCH] fix double filter that results in false --- src/external/utils/druidFilterBuilder.ts | 2 +- test/simulate/simulateDruid.mocha.js | 51 ++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/external/utils/druidFilterBuilder.ts b/src/external/utils/druidFilterBuilder.ts index 221e3201..f5870653 100644 --- a/src/external/utils/druidFilterBuilder.ts +++ b/src/external/utils/druidFilterBuilder.ts @@ -131,7 +131,7 @@ export class DruidFilterBuilder { if (filter.value === true) { return null; } else { - throw new Error('should never get here'); + return { type: 'false' }; } } else if (filter instanceof NotExpression) { return { diff --git a/test/simulate/simulateDruid.mocha.js b/test/simulate/simulateDruid.mocha.js index 44d7fb5e..31bff279 100644 --- a/test/simulate/simulateDruid.mocha.js +++ b/test/simulate/simulateDruid.mocha.js @@ -524,6 +524,57 @@ describe('simulate Druid', () => { }); }); + it('works with double filtered expression with no overlap', () => { + const ex = $('diamonds') + .split('$color', 'Color') + .apply( + 'Price', + $('diamonds') + .filter( + $('time').overlap({ + start: new Date('2015-03-12T00:00:00Z'), + end: new Date('2015-03-15T00:00:00Z'), + }), + ) + .filter( + $('time').overlap({ + start: new Date('2015-03-17T00:00:00Z'), + end: new Date('2015-03-19T00:00:00Z'), + }), + ) + .sum('$price'), + ); + + const queryPlan = ex.simulateQueryPlan(context); + expect(queryPlan[0][0]).to.deep.equal({ + aggregations: [ + { + aggregator: { + fieldName: 'price', + name: 'Price', + type: 'doubleSum', + }, + filter: { + type: 'false', + }, + name: 'Price', + type: 'filtered', + }, + ], + dataSource: 'diamonds-compact', + dimensions: [ + { + dimension: 'color', + outputName: 'Color', + type: 'default', + }, + ], + granularity: 'all', + intervals: '2015-03-12T00Z/2015-03-19T00Z', + queryType: 'groupBy', + }); + }); + it('works on OVERLAP (single value) filter', () => { const ex = ply() .apply('diamonds', $('diamonds').filter("$color.overlap(['D'])"))