Skip to content

Commit

Permalink
Merge pull request #315 from implydata/fix_double_filter
Browse files Browse the repository at this point in the history
fix double filter that results in false
  • Loading branch information
lorem--ipsum authored May 30, 2024
2 parents 76174d6 + 07bb9ac commit 5ee323d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/external/utils/druidFilterBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
51 changes: 51 additions & 0 deletions test/simulate/simulateDruid.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'])"))
Expand Down

0 comments on commit 5ee323d

Please sign in to comment.