Skip to content

Commit

Permalink
allow overlap with [null] (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
vogievetsky committed Feb 2, 2024
1 parent e6cb307 commit 3f0ec15
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/helper/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,20 @@ export function pipeWithError(src: ReadableStream, dest: WritableStream): any {
export function handleNullCheckIfNeeded<T>(
xs: T[],
nullCheck: string,
orAnd: 'OR' | 'AND',
andOr: 'AND' | 'OR',
fn: (withoutNull: T[]) => string,
): string {
if (!xs.length) {
// This should never happen in real usage but in general return the 'zero' value of the andOr op
return andOr === 'AND' ? 'FALSE' : 'TRUE';
}

const withoutNull = xs.filter(x => x != null);
if (withoutNull.length === xs.length) {
return fn(xs);
} else if (withoutNull.length === 0) {
return nullCheck;
} else {
return `(${nullCheck} ${orAnd} ${fn(withoutNull)})`;
return `(${nullCheck} ${andOr} ${fn(withoutNull)})`;
}
}
29 changes: 29 additions & 0 deletions test/simulate/simulateDruidSql.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,35 @@ describe('simulate DruidSql', () => {
]);
});

it('works with overlap of [null]', () => {
const ex = ply()
.apply('diamonds', $('diamonds'))
.apply('Tags', $('diamonds').split('$tags', 'Tag'));

const queryPlan = ex.simulateQueryPlan({
diamonds: External.fromJS({
engine: 'druidsql',
version: '0.20.0',
source: 'dia.monds',
timeAttribute: 'time',
attributes,
allowSelectQueries: true,
filter: $('pugs').overlap([null]),
}),
});
expect(queryPlan.length).to.equal(1);
expect(queryPlan).to.deep.equal([
[
{
context: {
sqlTimeZone: 'Etc/UTC',
},
query: 'SELECT\n"tags" AS "Tag"\nFROM "dia.monds" AS t\nWHERE "pugs" IS NULL\nGROUP BY 1',
},
],
]);
});

it('works with null and null string are both included in a filter expression (mvOverlap)', () => {
const ex = ply()
.apply('diamonds', $('diamonds').filter($('tags').mvOverlap(['tagA', 'tagB', null, 'null'])))
Expand Down

0 comments on commit 3f0ec15

Please sign in to comment.