Skip to content

Commit

Permalink
use 2-value IS NOT TRUE instead of 3-value NOT (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
vogievetsky authored Jan 8, 2024
1 parent 3036512 commit b7130bb
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .idea/prettier.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/watcherTasks.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/expressions/notExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class NotExpression extends ChainableExpression {
}

protected _getSQLChainableHelper(dialect: SQLDialect, operandSQL: string): string {
return `NOT(${operandSQL})`;
return `(${operandSQL}) IS NOT TRUE`;
}

protected specialSimplify(): Expression {
Expand Down
39 changes: 39 additions & 0 deletions test/functional/druidSqlFunctional.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,45 @@ describe('DruidSQL Functional', function () {
});
});

it('works with negation', () => {
const ex = $('wiki')
.filter($('cityName').isnt('Tokyo'))
.split($('cityName'), 'City')
.apply('Count', $('wiki').sum('$count'))
.sort('$Count', 'descending')
.limit(3);

return basicExecutor(ex).then(result => {
expect(result.toJS()).to.deep.equal({
attributes: [
{
name: 'City',
type: 'STRING',
},
{
name: 'Count',
type: 'NUMBER',
},
],
data: [
{
City: null,
Count: 371151,
},
{
City: 'Central District',
Count: 425,
},
{
City: 'Moscow',
Count: 330,
},
],
keys: ['City'],
});
});
});

it('can do compare column', () => {
const prevRange = TimeRange.fromJS({
start: new Date('2015-09-12T00:00:00Z'),
Expand Down
39 changes: 39 additions & 0 deletions test/functional/mySqlFunctional.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,45 @@ describe('MySQL Functional', function () {
});
});

it('works with negation', () => {
const ex = $('wiki')
.filter($('cityName').isnt('Tokyo'))
.split($('cityName'), 'City')
.apply('Count', $('wiki').sum('$count'))
.sort('$Count', 'descending')
.limit(3);

return basicExecutor(ex).then(result => {
expect(result.toJS()).to.deep.equal({
attributes: [
{
name: 'City',
type: 'STRING',
},
{
name: 'Count',
type: 'NUMBER',
},
],
data: [
{
City: null,
Count: 371151,
},
{
City: 'Central District',
Count: 425,
},
{
City: 'Moscow',
Count: 330,
},
],
keys: ['City'],
});
});
});

it('works with boolean GROUP BYs', () => {
const ex = $('wiki')
.split($('channel').is('en'), 'ChannelIsEn')
Expand Down
2 changes: 1 addition & 1 deletion test/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ exports.druidContext = {
populateCache: false,
};

exports.mySqlVersion = '5.7.29';
exports.mySqlVersion = '5.7.41';
exports.mySqlHost = `localhost:3306`;
exports.mySqlDatabase = 'datazoo';
exports.mySqlUser = 'datazoo';
Expand Down
4 changes: 2 additions & 2 deletions test/simulate/simulateDruidSql.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ describe('simulate DruidSql', () => {
sqlTimeZone: 'Etc/UTC',
},
query:
'SELECT\n"tags" AS "Tag"\nFROM "dia.monds" AS t\nWHERE (NOT((("pugs" IS NULL) OR "pugs" IN (\'pugA\',\'pugB\',\'null\'))) AND (("tags" IS NULL) OR "tags" IN (\'tagA\',\'tagB\',\'null\')))\nGROUP BY 1',
'SELECT\n"tags" AS "Tag"\nFROM "dia.monds" AS t\nWHERE (((("pugs" IS NULL) OR "pugs" IN (\'pugA\',\'pugB\',\'null\'))) IS NOT TRUE AND (("tags" IS NULL) OR "tags" IN (\'tagA\',\'tagB\',\'null\')))\nGROUP BY 1',
},
],
]);
Expand Down Expand Up @@ -256,7 +256,7 @@ describe('simulate DruidSql', () => {
sqlTimeZone: 'Etc/UTC',
},
query:
'SELECT\n"tags" AS "Tag"\nFROM "dia.monds" AS t\nWHERE (NOT((("pugs" IS NULL) OR "pugs" IN (\'pugA\',\'pugB\',\'\'))) AND (("tags" IS NULL) OR "tags" IN (\'tagA\',\'tagB\',\'null\',\'\')))\nGROUP BY 1',
'SELECT\n"tags" AS "Tag"\nFROM "dia.monds" AS t\nWHERE (((("pugs" IS NULL) OR "pugs" IN (\'pugA\',\'pugB\',\'\'))) IS NOT TRUE AND (("tags" IS NULL) OR "tags" IN (\'tagA\',\'tagB\',\'null\',\'\')))\nGROUP BY 1',
},
],
]);
Expand Down

0 comments on commit b7130bb

Please sign in to comment.