From ef46576baacb5c12473018fd5911fd627076b81c Mon Sep 17 00:00:00 2001 From: Ryan Kotzen Date: Wed, 28 Aug 2024 15:35:26 +0200 Subject: [PATCH 1/8] adding test case --- test/bug-fix-tests/bug-fix.test.js | 31 +- test/bug-fix-tests/empty-results-ast.json | 371 ++++++++++++++++++++++ 2 files changed, 401 insertions(+), 1 deletion(-) create mode 100644 test/bug-fix-tests/empty-results-ast.json diff --git a/test/bug-fix-tests/bug-fix.test.js b/test/bug-fix-tests/bug-fix.test.js index 3965a26..6169701 100644 --- a/test/bug-fix-tests/bug-fix.test.js +++ b/test/bug-fix-tests/bug-fix.test.js @@ -1,7 +1,8 @@ const {setup, disconnect} = require('../utils/mongo-client.js'); const {buildQueryResultTester} = require('../utils/query-tester/index.js'); const {getAllSchemas} = require('../utils/get-all-schemas.js'); - +const {parseSQLtoAST} = require('../../lib/SQLParser'); +const fs = require('fs/promises'); describe('bug-fixes', function () { this.timeout(90000); const fileName = 'bug-fix'; @@ -1020,4 +1021,32 @@ describe('bug-fixes', function () { }); }); }); + describe('empty-results', () => { + it("should work with Avi's example", async () => { + const queryString = ` + SELECT bp.CustId, bp.PolId, bp.PolNo, bp.PolEffDate, bp.PolExpDate, lob.LineOfBus + FROM \`faizel-polinfo\` bp + INNER JOIN (SELECT PolId, LineOfBus + FROM \`faizel-lob\`) \`lob|optimize\` ON lob.PolId = bp.PolId AND lob.EffDate >= bp.PolEffDate + WHERE bp.Status != 'D' + AND lob.LineOfBus IN ('CGL','WORK','AUTOB', 'CUMBR','ELIAB', 'XLIB','INMRC', 'PROP', 'BOPGL', 'CFIRE', 'EMP LIAB OH', 'EPLI', 'MTRTK', 'PL', 'RFRBR', 'POLL' ) + AND TO_DATE(bp.PolExpDate) > TO_DATE('{@runInfo.timeStamp}') + AND bp.PolSubType != 'S' + AND bp.CustId = '38CE71B6-2B7C-421A-8BC9-000EF8149C93' + LIMIT 10`; + const ast = parseSQLtoAST(queryString); + await fs.writeFile( + './test/bug-fix-tests/empty-results-ast.json', + JSON.stringify(ast, null, 4), + {encoding: 'utf8'} + ); + // await queryResultTester({ + // queryString: queryString, + // casePath: 'empty-results.case1', + // mode: 'write', + // expectZeroResults: false, + // outputPipeline: true, + // }); + }); + }); }); diff --git a/test/bug-fix-tests/empty-results-ast.json b/test/bug-fix-tests/empty-results-ast.json new file mode 100644 index 0000000..6c47a67 --- /dev/null +++ b/test/bug-fix-tests/empty-results-ast.json @@ -0,0 +1,371 @@ +{ + "tableList": [ + "select::null::faizel-lob", + "select::null::faizel-polinfo" + ], + "columnList": [ + "select::faizel-polinfo::CustId", + "select::faizel-polinfo::PolId", + "select::faizel-polinfo::PolNo", + "select::faizel-polinfo::PolEffDate", + "select::faizel-polinfo::PolExpDate", + "select::lob::LineOfBus", + "select::null::PolId", + "select::null::LineOfBus", + "select::lob::PolId", + "select::lob::EffDate", + "select::faizel-polinfo::Status", + "select::faizel-polinfo::PolSubType" + ], + "ast": { + "with": null, + "type": "select", + "options": null, + "distinct": { + "type": null + }, + "columns": [ + { + "type": "expr", + "expr": { + "type": "column_ref", + "table": "bp", + "column": "CustId" + }, + "as": null + }, + { + "type": "expr", + "expr": { + "type": "column_ref", + "table": "bp", + "column": "PolId" + }, + "as": null + }, + { + "type": "expr", + "expr": { + "type": "column_ref", + "table": "bp", + "column": "PolNo" + }, + "as": null + }, + { + "type": "expr", + "expr": { + "type": "column_ref", + "table": "bp", + "column": "PolEffDate" + }, + "as": null + }, + { + "type": "expr", + "expr": { + "type": "column_ref", + "table": "bp", + "column": "PolExpDate" + }, + "as": null + }, + { + "type": "expr", + "expr": { + "type": "column_ref", + "table": "lob", + "column": "LineOfBus" + }, + "as": null + } + ], + "into": { + "position": null + }, + "from": [ + { + "db": null, + "table": "faizel-polinfo", + "as": "bp" + }, + { + "prefix": null, + "expr": { + "tableList": [ + "select::null::faizel-lob" + ], + "columnList": [ + "select::bp::CustId", + "select::bp::PolId", + "select::bp::PolNo", + "select::bp::PolEffDate", + "select::bp::PolExpDate", + "select::lob::LineOfBus", + "select::null::PolId", + "select::null::LineOfBus" + ], + "ast": { + "with": null, + "type": "select", + "options": null, + "distinct": { + "type": null + }, + "columns": [ + { + "type": "expr", + "expr": { + "type": "column_ref", + "table": null, + "column": "PolId" + }, + "as": null + }, + { + "type": "expr", + "expr": { + "type": "column_ref", + "table": null, + "column": "LineOfBus" + }, + "as": null + } + ], + "into": { + "position": null + }, + "from": [ + { + "db": null, + "table": "faizel-lob", + "as": null + } + ], + "where": null, + "groupby": null, + "having": null, + "orderby": null, + "limit": { + "seperator": "", + "value": [] + }, + "window": null + }, + "parentheses": true + }, + "as": "lob|optimize", + "join": "INNER JOIN", + "on": { + "type": "binary_expr", + "operator": "AND", + "left": { + "type": "binary_expr", + "operator": "=", + "left": { + "type": "column_ref", + "table": "lob", + "column": "PolId" + }, + "right": { + "type": "column_ref", + "table": "bp", + "column": "PolId" + } + }, + "right": { + "type": "binary_expr", + "operator": ">=", + "left": { + "type": "column_ref", + "table": "lob", + "column": "EffDate" + }, + "right": { + "type": "column_ref", + "table": "bp", + "column": "PolEffDate" + } + } + } + } + ], + "where": { + "type": "binary_expr", + "operator": "AND", + "left": { + "type": "binary_expr", + "operator": "AND", + "left": { + "type": "binary_expr", + "operator": "AND", + "left": { + "type": "binary_expr", + "operator": "!=", + "left": { + "type": "column_ref", + "table": "bp", + "column": "Status" + }, + "right": { + "type": "single_quote_string", + "value": "D" + } + }, + "right": { + "type": "binary_expr", + "operator": "AND", + "left": { + "type": "binary_expr", + "operator": "IN", + "left": { + "type": "column_ref", + "table": "lob", + "column": "LineOfBus" + }, + "right": { + "type": "expr_list", + "value": [ + { + "type": "single_quote_string", + "value": "CGL" + }, + { + "type": "single_quote_string", + "value": "WORK" + }, + { + "type": "single_quote_string", + "value": "AUTOB" + }, + { + "type": "single_quote_string", + "value": "CUMBR" + }, + { + "type": "single_quote_string", + "value": "ELIAB" + }, + { + "type": "single_quote_string", + "value": "XLIB" + }, + { + "type": "single_quote_string", + "value": "INMRC" + }, + { + "type": "single_quote_string", + "value": "PROP" + }, + { + "type": "single_quote_string", + "value": "BOPGL" + }, + { + "type": "single_quote_string", + "value": "CFIRE" + }, + { + "type": "single_quote_string", + "value": "EMP LIAB OH" + }, + { + "type": "single_quote_string", + "value": "EPLI" + }, + { + "type": "single_quote_string", + "value": "MTRTK" + }, + { + "type": "single_quote_string", + "value": "PL" + }, + { + "type": "single_quote_string", + "value": "RFRBR" + }, + { + "type": "single_quote_string", + "value": "POLL" + } + ] + } + }, + "right": { + "type": "binary_expr", + "operator": ">", + "left": { + "type": "function", + "name": "TO_DATE", + "args": { + "type": "expr_list", + "value": [ + { + "type": "column_ref", + "table": "bp", + "column": "PolExpDate" + } + ] + } + }, + "right": { + "type": "function", + "name": "TO_DATE", + "args": { + "type": "expr_list", + "value": [ + { + "type": "single_quote_string", + "value": "{@runInfo.timeStamp}" + } + ] + } + } + } + } + }, + "right": { + "type": "binary_expr", + "operator": "!=", + "left": { + "type": "column_ref", + "table": "bp", + "column": "PolSubType" + }, + "right": { + "type": "single_quote_string", + "value": "S" + } + } + }, + "right": { + "type": "binary_expr", + "operator": "=", + "left": { + "type": "column_ref", + "table": "bp", + "column": "CustId" + }, + "right": { + "type": "single_quote_string", + "value": "38CE71B6-2B7C-421A-8BC9-000EF8149C93" + } + } + }, + "groupby": null, + "having": null, + "orderby": null, + "limit": { + "seperator": "", + "value": [ + { + "type": "number", + "value": 10 + } + ] + }, + "window": null + } +} \ No newline at end of file From 127360e5f94e221ddb187154e43c8ce253058917 Mon Sep 17 00:00:00 2001 From: Ryan Kotzen Date: Wed, 28 Aug 2024 15:42:38 +0200 Subject: [PATCH 2/8] writing pipeline as well --- test/bug-fix-tests/bug-fix.test.js | 11 +- test/bug-fix-tests/empty-results-ast.json | 7 +- .../bug-fix-tests/empty-results-pipeline.json | 137 ++++++++++++++++++ 3 files changed, 150 insertions(+), 5 deletions(-) create mode 100644 test/bug-fix-tests/empty-results-pipeline.json diff --git a/test/bug-fix-tests/bug-fix.test.js b/test/bug-fix-tests/bug-fix.test.js index 6169701..b318cb4 100644 --- a/test/bug-fix-tests/bug-fix.test.js +++ b/test/bug-fix-tests/bug-fix.test.js @@ -1,7 +1,7 @@ const {setup, disconnect} = require('../utils/mongo-client.js'); const {buildQueryResultTester} = require('../utils/query-tester/index.js'); const {getAllSchemas} = require('../utils/get-all-schemas.js'); -const {parseSQLtoAST} = require('../../lib/SQLParser'); +const {parseSQLtoAST, makeMongoAggregate} = require('../../lib/SQLParser'); const fs = require('fs/promises'); describe('bug-fixes', function () { this.timeout(90000); @@ -1030,7 +1030,7 @@ describe('bug-fixes', function () { FROM \`faizel-lob\`) \`lob|optimize\` ON lob.PolId = bp.PolId AND lob.EffDate >= bp.PolEffDate WHERE bp.Status != 'D' AND lob.LineOfBus IN ('CGL','WORK','AUTOB', 'CUMBR','ELIAB', 'XLIB','INMRC', 'PROP', 'BOPGL', 'CFIRE', 'EMP LIAB OH', 'EPLI', 'MTRTK', 'PL', 'RFRBR', 'POLL' ) - AND TO_DATE(bp.PolExpDate) > TO_DATE('{@runInfo.timeStamp}') + AND TO_DATE(bp.PolExpDate) >= TO_DATE(bp.PolExpDate) AND bp.PolSubType != 'S' AND bp.CustId = '38CE71B6-2B7C-421A-8BC9-000EF8149C93' LIMIT 10`; @@ -1040,6 +1040,13 @@ describe('bug-fixes', function () { JSON.stringify(ast, null, 4), {encoding: 'utf8'} ); + const aggregate = makeMongoAggregate(queryString); + + await fs.writeFile( + './test/bug-fix-tests/empty-results-pipeline.json', + JSON.stringify(aggregate.pipeline, null, 4), + {encoding: 'utf8'} + ); // await queryResultTester({ // queryString: queryString, // casePath: 'empty-results.case1', diff --git a/test/bug-fix-tests/empty-results-ast.json b/test/bug-fix-tests/empty-results-ast.json index 6c47a67..63724a1 100644 --- a/test/bug-fix-tests/empty-results-ast.json +++ b/test/bug-fix-tests/empty-results-ast.json @@ -295,7 +295,7 @@ }, "right": { "type": "binary_expr", - "operator": ">", + "operator": ">=", "left": { "type": "function", "name": "TO_DATE", @@ -317,8 +317,9 @@ "type": "expr_list", "value": [ { - "type": "single_quote_string", - "value": "{@runInfo.timeStamp}" + "type": "column_ref", + "table": "bp", + "column": "PolExpDate" } ] } diff --git a/test/bug-fix-tests/empty-results-pipeline.json b/test/bug-fix-tests/empty-results-pipeline.json new file mode 100644 index 0000000..2917544 --- /dev/null +++ b/test/bug-fix-tests/empty-results-pipeline.json @@ -0,0 +1,137 @@ +[ + { + "$project": { + "bp": "$$ROOT" + } + }, + { + "$lookup": { + "from": "faizel-lob", + "as": "lob", + "let": { + "bp_PolId": "$bp.PolId", + "bp_PolEffDate": "$bp.PolEffDate" + }, + "pipeline": [ + { + "$match": { + "$expr": { + "$and": [ + { + "$eq": [ + "$PolId", + "$$bp_PolId" + ] + }, + { + "$gte": [ + "$EffDate", + "$$bp_PolEffDate" + ] + } + ] + } + } + }, + { + "$project": { + "PolId": "$PolId", + "LineOfBus": "$LineOfBus" + } + } + ] + } + }, + { + "$match": { + "$expr": { + "$gt": [ + { + "$size": "$lob" + }, + 0 + ] + } + } + }, + { + "$match": { + "$and": [ + { + "$and": [ + { + "$and": [ + { + "bp.Status": { + "$ne": "D" + } + }, + { + "$and": [ + { + "lob.LineOfBus": { + "$in": [ + "CGL", + "WORK", + "AUTOB", + "CUMBR", + "ELIAB", + "XLIB", + "INMRC", + "PROP", + "BOPGL", + "CFIRE", + "EMP LIAB OH", + "EPLI", + "MTRTK", + "PL", + "RFRBR", + "POLL" + ] + } + }, + { + "$expr": { + "$gte": [ + { + "$toDate": "$bp.PolExpDate" + }, + { + "$toDate": "$bp.PolExpDate" + } + ] + } + } + ] + } + ] + }, + { + "bp.PolSubType": { + "$ne": "S" + } + } + ] + }, + { + "bp.CustId": { + "$eq": "38CE71B6-2B7C-421A-8BC9-000EF8149C93" + } + } + ] + } + }, + { + "$project": { + "CustId": "$bp.CustId", + "PolId": "$bp.PolId", + "PolNo": "$bp.PolNo", + "PolEffDate": "$bp.PolEffDate", + "PolExpDate": "$bp.PolExpDate", + "LineOfBus": "$lob.LineOfBus" + } + }, + { + "$limit": 10 + } +] \ No newline at end of file From cc077091cd1d43b5f203eb25cfbc4aade2590947 Mon Sep 17 00:00:00 2001 From: Ryan Kotzen Date: Thu, 29 Aug 2024 06:43:56 +0200 Subject: [PATCH 3/8] checking in query from QA --- test/bug-fix-tests/bug-fix.test.js | 24 ++-- test/bug-fix-tests/empty-results-ast.json | 115 +++--------------- .../bug-fix-tests/empty-results-pipeline.json | 46 ++----- 3 files changed, 40 insertions(+), 145 deletions(-) diff --git a/test/bug-fix-tests/bug-fix.test.js b/test/bug-fix-tests/bug-fix.test.js index b318cb4..2aafd82 100644 --- a/test/bug-fix-tests/bug-fix.test.js +++ b/test/bug-fix-tests/bug-fix.test.js @@ -1024,16 +1024,26 @@ describe('bug-fixes', function () { describe('empty-results', () => { it("should work with Avi's example", async () => { const queryString = ` - SELECT bp.CustId, bp.PolId, bp.PolNo, bp.PolEffDate, bp.PolExpDate, lob.LineOfBus + SELECT bp.CustId, + bp.PolId, + bp.PolNo, + bp.PolEffDate, + bp.PolExpDate, + lob.LineOfBus FROM \`faizel-polinfo\` bp - INNER JOIN (SELECT PolId, LineOfBus - FROM \`faizel-lob\`) \`lob|optimize\` ON lob.PolId = bp.PolId AND lob.EffDate >= bp.PolEffDate + INNER JOIN ( + SELECT PolId, + LineOfBus + --,EffDate + FROM \`faizel-lob\`) \`lob|optimize\` + ON lob.PolId = bp.PolId + AND lob.EffDate >= bp.PolEffDate WHERE bp.Status != 'D' - AND lob.LineOfBus IN ('CGL','WORK','AUTOB', 'CUMBR','ELIAB', 'XLIB','INMRC', 'PROP', 'BOPGL', 'CFIRE', 'EMP LIAB OH', 'EPLI', 'MTRTK', 'PL', 'RFRBR', 'POLL' ) - AND TO_DATE(bp.PolExpDate) >= TO_DATE(bp.PolExpDate) + --AND lob.LineOfBus IN ('CGL','WORK','AUTOB', 'CUMBR','ELIAB', 'XLIB','INMRC', 'PROP', 'BOPGL', 'CFIRE', 'EMP LIAB OH', 'EPLI', 'MTRTK', 'PL', 'RFRBR', 'POLL' ) + AND TO_DATE(bp.PolExpDate) > CURRENT_DATE() AND bp.PolSubType != 'S' - AND bp.CustId = '38CE71B6-2B7C-421A-8BC9-000EF8149C93' - LIMIT 10`; + AND bp.CustId = 'test-customer-1' + LIMIT 10 `; const ast = parseSQLtoAST(queryString); await fs.writeFile( './test/bug-fix-tests/empty-results-ast.json', diff --git a/test/bug-fix-tests/empty-results-ast.json b/test/bug-fix-tests/empty-results-ast.json index 63724a1..482ca90 100644 --- a/test/bug-fix-tests/empty-results-ast.json +++ b/test/bug-fix-tests/empty-results-ast.json @@ -214,116 +214,29 @@ }, "right": { "type": "binary_expr", - "operator": "AND", + "operator": ">", "left": { - "type": "binary_expr", - "operator": "IN", - "left": { - "type": "column_ref", - "table": "lob", - "column": "LineOfBus" - }, - "right": { + "type": "function", + "name": "TO_DATE", + "args": { "type": "expr_list", "value": [ { - "type": "single_quote_string", - "value": "CGL" - }, - { - "type": "single_quote_string", - "value": "WORK" - }, - { - "type": "single_quote_string", - "value": "AUTOB" - }, - { - "type": "single_quote_string", - "value": "CUMBR" - }, - { - "type": "single_quote_string", - "value": "ELIAB" - }, - { - "type": "single_quote_string", - "value": "XLIB" - }, - { - "type": "single_quote_string", - "value": "INMRC" - }, - { - "type": "single_quote_string", - "value": "PROP" - }, - { - "type": "single_quote_string", - "value": "BOPGL" - }, - { - "type": "single_quote_string", - "value": "CFIRE" - }, - { - "type": "single_quote_string", - "value": "EMP LIAB OH" - }, - { - "type": "single_quote_string", - "value": "EPLI" - }, - { - "type": "single_quote_string", - "value": "MTRTK" - }, - { - "type": "single_quote_string", - "value": "PL" - }, - { - "type": "single_quote_string", - "value": "RFRBR" - }, - { - "type": "single_quote_string", - "value": "POLL" + "type": "column_ref", + "table": "bp", + "column": "PolExpDate" } ] } }, "right": { - "type": "binary_expr", - "operator": ">=", - "left": { - "type": "function", - "name": "TO_DATE", - "args": { - "type": "expr_list", - "value": [ - { - "type": "column_ref", - "table": "bp", - "column": "PolExpDate" - } - ] - } + "type": "function", + "name": "CURRENT_DATE", + "args": { + "type": "expr_list", + "value": [] }, - "right": { - "type": "function", - "name": "TO_DATE", - "args": { - "type": "expr_list", - "value": [ - { - "type": "column_ref", - "table": "bp", - "column": "PolExpDate" - } - ] - } - } + "over": null } } }, @@ -351,7 +264,7 @@ }, "right": { "type": "single_quote_string", - "value": "38CE71B6-2B7C-421A-8BC9-000EF8149C93" + "value": "test-customer-1" } } }, diff --git a/test/bug-fix-tests/empty-results-pipeline.json b/test/bug-fix-tests/empty-results-pipeline.json index 2917544..9429126 100644 --- a/test/bug-fix-tests/empty-results-pipeline.json +++ b/test/bug-fix-tests/empty-results-pipeline.json @@ -67,42 +67,14 @@ } }, { - "$and": [ - { - "lob.LineOfBus": { - "$in": [ - "CGL", - "WORK", - "AUTOB", - "CUMBR", - "ELIAB", - "XLIB", - "INMRC", - "PROP", - "BOPGL", - "CFIRE", - "EMP LIAB OH", - "EPLI", - "MTRTK", - "PL", - "RFRBR", - "POLL" - ] - } - }, - { - "$expr": { - "$gte": [ - { - "$toDate": "$bp.PolExpDate" - }, - { - "$toDate": "$bp.PolExpDate" - } - ] - } - } - ] + "$expr": { + "$gt": [ + { + "$toDate": "$bp.PolExpDate" + }, + "$$NOW" + ] + } } ] }, @@ -115,7 +87,7 @@ }, { "bp.CustId": { - "$eq": "38CE71B6-2B7C-421A-8BC9-000EF8149C93" + "$eq": "test-customer-1" } } ] From 843182d90029fb9842bb6dfc71d88b1299bf08e5 Mon Sep 17 00:00:00 2001 From: Ryan Kotzen Date: Thu, 29 Aug 2024 06:49:13 +0200 Subject: [PATCH 4/8] checking in example pipelines for this case --- .../empty-results-pipeline-4.0.0-works.json | 116 ++++++++++++++++++ .../empty-results-pipeline-4.1.3-broken.json | 109 ++++++++++++++++ 2 files changed, 225 insertions(+) create mode 100644 test/bug-fix-tests/empty-results-pipeline-4.0.0-works.json create mode 100644 test/bug-fix-tests/empty-results-pipeline-4.1.3-broken.json diff --git a/test/bug-fix-tests/empty-results-pipeline-4.0.0-works.json b/test/bug-fix-tests/empty-results-pipeline-4.0.0-works.json new file mode 100644 index 0000000..ae1bae2 --- /dev/null +++ b/test/bug-fix-tests/empty-results-pipeline-4.0.0-works.json @@ -0,0 +1,116 @@ +{ + "pipeline": [ + { + "$project": { + "bp": "$$ROOT" + } + }, + { + "$lookup": { + "from": "faizel-lob", + "as": "lob", + "let": { + "bp_PolId": "$bp.PolId", + "bp_PolEffDate": "$bp.PolEffDate" + }, + "pipeline": [ + { + "$match": { + "$expr": { + "$and": [ + { + "$eq": [ + "$PolId", + "$$bp_PolId" + ] + }, + { + "$gte": [ + "$EffDate", + "$$bp_PolEffDate" + ] + } + ] + } + } + }, + { + "$project": { + "PolId": "$PolId", + "LineOfBus": "$LineOfBus" + } + } + ] + } + }, + { + "$match": { + "$expr": { + "$gt": [ + { + "$size": "$lob" + }, + 0 + ] + } + } + }, + { + "$match": { + "$and": [ + { + "$and": [ + { + "$and": [ + { + "bp_Status": { + "$ne": "D" + } + }, + { + "$expr": { + "$gt": [ + { + "$toDate": "$bp.PolExpDate" + }, + "$$NOW" + ] + } + } + ] + }, + { + "bp_PolSubType": { + "$ne": "S" + } + } + ] + }, + { + "bp_CustId": { + "$eq": "test-customer-1" + } + } + ] + } + }, + { + "$project": { + "CustId": "$bp.CustId", + "PolId": "$bp.PolId", + "PolNo": "$bp.PolNo", + "PolEffDate": "$bp.PolEffDate", + "PolExpDate": "$bp.PolExpDate", + "LineOfBus": "$lob.LineOfBus" + } + }, + { + "$limit": 10 + } + ], + "collections": [ + "faizel-polinfo", + "faizel-lob" + ], + "type": "aggregate" +} diff --git a/test/bug-fix-tests/empty-results-pipeline-4.1.3-broken.json b/test/bug-fix-tests/empty-results-pipeline-4.1.3-broken.json new file mode 100644 index 0000000..1e88a61 --- /dev/null +++ b/test/bug-fix-tests/empty-results-pipeline-4.1.3-broken.json @@ -0,0 +1,109 @@ +[ + { + "$project": { + "bp": "$$ROOT" + } + }, + { + "$lookup": { + "from": "faizel-lob", + "as": "lob", + "let": { + "bp_PolId": "$bp.PolId", + "bp_PolEffDate": "$bp.PolEffDate" + }, + "pipeline": [ + { + "$project": { + "PolId": "$PolId", + "LineOfBus": "$LineOfBus" + } + }, + { + "$match": { + "$expr": { + "$and": [ + { + "$eq": [ + "$PolId", + "$$bp_PolId" + ] + }, + { + "$gte": [ + "$EffDate", + "$$bp_PolEffDate" + ] + } + ] + } + } + } + ] + } + }, + { + "$match": { + "$expr": { + "$gt": [ + { + "$size": "$lob" + }, + 0 + ] + } + } + }, + { + "$match": { + "$and": [ + { + "$and": [ + { + "$and": [ + { + "bp.Status": { + "$ne": "D" + } + }, + { + "$expr": { + "$gt": [ + { + "$toDate": "$bp.PolExpDate" + }, + "$$NOW" + ] + } + } + ] + }, + { + "bp.PolSubType": { + "$ne": "S" + } + } + ] + }, + { + "bp.CustId": { + "$eq": "test-customer-1" + } + } + ] + } + }, + { + "$project": { + "CustId": "$bp.CustId", + "PolId": "$bp.PolId", + "PolNo": "$bp.PolNo", + "PolEffDate": "$bp.PolEffDate", + "PolExpDate": "$bp.PolExpDate", + "LineOfBus": "$lob.LineOfBus" + } + }, + { + "$limit": 10 + } +] \ No newline at end of file From d9670c2981d9bafcfa5738a7bf06f381c42ec30a Mon Sep 17 00:00:00 2001 From: Ryan Kotzen Date: Thu, 29 Aug 2024 06:49:51 +0200 Subject: [PATCH 5/8] saving just the pipeline --- .../empty-results-pipeline-4.0.0-works.json | 201 +++++++++--------- 1 file changed, 97 insertions(+), 104 deletions(-) diff --git a/test/bug-fix-tests/empty-results-pipeline-4.0.0-works.json b/test/bug-fix-tests/empty-results-pipeline-4.0.0-works.json index ae1bae2..6497dc7 100644 --- a/test/bug-fix-tests/empty-results-pipeline-4.0.0-works.json +++ b/test/bug-fix-tests/empty-results-pipeline-4.0.0-works.json @@ -1,116 +1,109 @@ -{ - "pipeline": [ - { - "$project": { - "bp": "$$ROOT" - } - }, - { - "$lookup": { - "from": "faizel-lob", - "as": "lob", - "let": { - "bp_PolId": "$bp.PolId", - "bp_PolEffDate": "$bp.PolEffDate" +[ + { + "$project": { + "bp": "$$ROOT" + } + }, + { + "$lookup": { + "from": "faizel-lob", + "as": "lob", + "let": { + "bp_PolId": "$bp.PolId", + "bp_PolEffDate": "$bp.PolEffDate" + }, + "pipeline": [ + { + "$match": { + "$expr": { + "$and": [ + { + "$eq": [ + "$PolId", + "$$bp_PolId" + ] + }, + { + "$gte": [ + "$EffDate", + "$$bp_PolEffDate" + ] + } + ] + } + } }, - "pipeline": [ + { + "$project": { + "PolId": "$PolId", + "LineOfBus": "$LineOfBus" + } + } + ] + } + }, + { + "$match": { + "$expr": { + "$gt": [ { - "$match": { - "$expr": { - "$and": [ - { - "$eq": [ - "$PolId", - "$$bp_PolId" - ] - }, - { - "$gte": [ - "$EffDate", - "$$bp_PolEffDate" - ] - } - ] - } - } + "$size": "$lob" }, - { - "$project": { - "PolId": "$PolId", - "LineOfBus": "$LineOfBus" - } - } + 0 ] } - }, - { - "$match": { - "$expr": { - "$gt": [ + } + }, + { + "$match": { + "$and": [ + { + "$and": [ { - "$size": "$lob" - }, - 0 - ] - } - } - }, - { - "$match": { - "$and": [ - { - "$and": [ - { - "$and": [ - { - "bp_Status": { - "$ne": "D" - } - }, - { - "$expr": { - "$gt": [ - { - "$toDate": "$bp.PolExpDate" - }, - "$$NOW" - ] - } + "$and": [ + { + "bp_Status": { + "$ne": "D" + } + }, + { + "$expr": { + "$gt": [ + { + "$toDate": "$bp.PolExpDate" + }, + "$$NOW" + ] } - ] - }, - { - "bp_PolSubType": { - "$ne": "S" } + ] + }, + { + "bp_PolSubType": { + "$ne": "S" } - ] - }, - { - "bp_CustId": { - "$eq": "test-customer-1" } + ] + }, + { + "bp_CustId": { + "$eq": "test-customer-1" } - ] - } - }, - { - "$project": { - "CustId": "$bp.CustId", - "PolId": "$bp.PolId", - "PolNo": "$bp.PolNo", - "PolEffDate": "$bp.PolEffDate", - "PolExpDate": "$bp.PolExpDate", - "LineOfBus": "$lob.LineOfBus" - } - }, - { - "$limit": 10 + } + ] + } + }, + { + "$project": { + "CustId": "$bp.CustId", + "PolId": "$bp.PolId", + "PolNo": "$bp.PolNo", + "PolEffDate": "$bp.PolEffDate", + "PolExpDate": "$bp.PolExpDate", + "LineOfBus": "$lob.LineOfBus" } - ], - "collections": [ - "faizel-polinfo", - "faizel-lob" - ], - "type": "aggregate" -} + }, + { + "$limit": 10 + } +] From f07d67e9d66be299378c8d23f8a729bdbcc388b8 Mon Sep 17 00:00:00 2001 From: Ryan Kotzen Date: Thu, 29 Aug 2024 06:51:51 +0200 Subject: [PATCH 6/8] formatting json with prettier --- .../empty-results-pipeline-4.0.0-works.json | 10 +- .../empty-results-pipeline-4.1.3-broken.json | 186 +++++++++--------- .../bug-fix-tests/empty-results-pipeline.json | 186 +++++++++--------- 3 files changed, 182 insertions(+), 200 deletions(-) diff --git a/test/bug-fix-tests/empty-results-pipeline-4.0.0-works.json b/test/bug-fix-tests/empty-results-pipeline-4.0.0-works.json index 6497dc7..840c071 100644 --- a/test/bug-fix-tests/empty-results-pipeline-4.0.0-works.json +++ b/test/bug-fix-tests/empty-results-pipeline-4.0.0-works.json @@ -18,16 +18,10 @@ "$expr": { "$and": [ { - "$eq": [ - "$PolId", - "$$bp_PolId" - ] + "$eq": ["$PolId", "$$bp_PolId"] }, { - "$gte": [ - "$EffDate", - "$$bp_PolEffDate" - ] + "$gte": ["$EffDate", "$$bp_PolEffDate"] } ] } diff --git a/test/bug-fix-tests/empty-results-pipeline-4.1.3-broken.json b/test/bug-fix-tests/empty-results-pipeline-4.1.3-broken.json index 1e88a61..edf8ab5 100644 --- a/test/bug-fix-tests/empty-results-pipeline-4.1.3-broken.json +++ b/test/bug-fix-tests/empty-results-pipeline-4.1.3-broken.json @@ -1,109 +1,103 @@ [ - { - "$project": { - "bp": "$$ROOT" - } - }, - { - "$lookup": { - "from": "faizel-lob", - "as": "lob", - "let": { - "bp_PolId": "$bp.PolId", - "bp_PolEffDate": "$bp.PolEffDate" - }, - "pipeline": [ + { + "$project": { + "bp": "$$ROOT" + } + }, + { + "$lookup": { + "from": "faizel-lob", + "as": "lob", + "let": { + "bp_PolId": "$bp.PolId", + "bp_PolEffDate": "$bp.PolEffDate" + }, + "pipeline": [ + { + "$project": { + "PolId": "$PolId", + "LineOfBus": "$LineOfBus" + } + }, + { + "$match": { + "$expr": { + "$and": [ { - "$project": { - "PolId": "$PolId", - "LineOfBus": "$LineOfBus" - } + "$eq": ["$PolId", "$$bp_PolId"] }, { - "$match": { - "$expr": { - "$and": [ - { - "$eq": [ - "$PolId", - "$$bp_PolId" - ] - }, - { - "$gte": [ - "$EffDate", - "$$bp_PolEffDate" - ] - } - ] - } - } + "$gte": ["$EffDate", "$$bp_PolEffDate"] } - ] - } - }, - { - "$match": { - "$expr": { - "$gt": [ - { - "$size": "$lob" - }, - 0 - ] + ] } + } } - }, - { - "$match": { - "$and": [ + ] + } + }, + { + "$match": { + "$expr": { + "$gt": [ + { + "$size": "$lob" + }, + 0 + ] + } + } + }, + { + "$match": { + "$and": [ + { + "$and": [ + { + "$and": [ { - "$and": [ - { - "$and": [ - { - "bp.Status": { - "$ne": "D" - } - }, - { - "$expr": { - "$gt": [ - { - "$toDate": "$bp.PolExpDate" - }, - "$$NOW" - ] - } - } - ] - }, - { - "bp.PolSubType": { - "$ne": "S" - } - } - ] + "bp.Status": { + "$ne": "D" + } }, { - "bp.CustId": { - "$eq": "test-customer-1" - } + "$expr": { + "$gt": [ + { + "$toDate": "$bp.PolExpDate" + }, + "$$NOW" + ] + } } - ] - } - }, - { - "$project": { - "CustId": "$bp.CustId", - "PolId": "$bp.PolId", - "PolNo": "$bp.PolNo", - "PolEffDate": "$bp.PolEffDate", - "PolExpDate": "$bp.PolExpDate", - "LineOfBus": "$lob.LineOfBus" + ] + }, + { + "bp.PolSubType": { + "$ne": "S" + } + } + ] + }, + { + "bp.CustId": { + "$eq": "test-customer-1" + } } - }, - { - "$limit": 10 + ] + } + }, + { + "$project": { + "CustId": "$bp.CustId", + "PolId": "$bp.PolId", + "PolNo": "$bp.PolNo", + "PolEffDate": "$bp.PolEffDate", + "PolExpDate": "$bp.PolExpDate", + "LineOfBus": "$lob.LineOfBus" } -] \ No newline at end of file + }, + { + "$limit": 10 + } +] diff --git a/test/bug-fix-tests/empty-results-pipeline.json b/test/bug-fix-tests/empty-results-pipeline.json index 9429126..29cb113 100644 --- a/test/bug-fix-tests/empty-results-pipeline.json +++ b/test/bug-fix-tests/empty-results-pipeline.json @@ -1,109 +1,103 @@ [ - { - "$project": { - "bp": "$$ROOT" - } - }, - { - "$lookup": { - "from": "faizel-lob", - "as": "lob", - "let": { - "bp_PolId": "$bp.PolId", - "bp_PolEffDate": "$bp.PolEffDate" - }, - "pipeline": [ + { + "$project": { + "bp": "$$ROOT" + } + }, + { + "$lookup": { + "from": "faizel-lob", + "as": "lob", + "let": { + "bp_PolId": "$bp.PolId", + "bp_PolEffDate": "$bp.PolEffDate" + }, + "pipeline": [ + { + "$match": { + "$expr": { + "$and": [ { - "$match": { - "$expr": { - "$and": [ - { - "$eq": [ - "$PolId", - "$$bp_PolId" - ] - }, - { - "$gte": [ - "$EffDate", - "$$bp_PolEffDate" - ] - } - ] - } - } + "$eq": ["$PolId", "$$bp_PolId"] }, { - "$project": { - "PolId": "$PolId", - "LineOfBus": "$LineOfBus" - } + "$gte": ["$EffDate", "$$bp_PolEffDate"] } - ] - } - }, - { - "$match": { - "$expr": { - "$gt": [ - { - "$size": "$lob" - }, - 0 - ] + ] } + } + }, + { + "$project": { + "PolId": "$PolId", + "LineOfBus": "$LineOfBus" + } } - }, - { - "$match": { - "$and": [ + ] + } + }, + { + "$match": { + "$expr": { + "$gt": [ + { + "$size": "$lob" + }, + 0 + ] + } + } + }, + { + "$match": { + "$and": [ + { + "$and": [ + { + "$and": [ { - "$and": [ - { - "$and": [ - { - "bp.Status": { - "$ne": "D" - } - }, - { - "$expr": { - "$gt": [ - { - "$toDate": "$bp.PolExpDate" - }, - "$$NOW" - ] - } - } - ] - }, - { - "bp.PolSubType": { - "$ne": "S" - } - } - ] + "bp.Status": { + "$ne": "D" + } }, { - "bp.CustId": { - "$eq": "test-customer-1" - } + "$expr": { + "$gt": [ + { + "$toDate": "$bp.PolExpDate" + }, + "$$NOW" + ] + } } - ] - } - }, - { - "$project": { - "CustId": "$bp.CustId", - "PolId": "$bp.PolId", - "PolNo": "$bp.PolNo", - "PolEffDate": "$bp.PolEffDate", - "PolExpDate": "$bp.PolExpDate", - "LineOfBus": "$lob.LineOfBus" + ] + }, + { + "bp.PolSubType": { + "$ne": "S" + } + } + ] + }, + { + "bp.CustId": { + "$eq": "test-customer-1" + } } - }, - { - "$limit": 10 + ] + } + }, + { + "$project": { + "CustId": "$bp.CustId", + "PolId": "$bp.PolId", + "PolNo": "$bp.PolNo", + "PolEffDate": "$bp.PolEffDate", + "PolExpDate": "$bp.PolExpDate", + "LineOfBus": "$lob.LineOfBus" } -] \ No newline at end of file + }, + { + "$limit": 10 + } +] From a12daea7fea89030f4431db3768914a7f93e5aa7 Mon Sep 17 00:00:00 2001 From: Ryan Kotzen Date: Thu, 29 Aug 2024 07:15:51 +0200 Subject: [PATCH 7/8] refactoring test --- test/bug-fix-tests/bug-fix.test.js | 22 +- test/bug-fix-tests/empty-results-ast.json | 285 ------------------ .../empty-results-pipeline-4.0.0-works.json | 103 ------- .../empty-results-pipeline-4.1.3-broken.json | 103 ------- test/bug-fix-tests/expected-pipeline.json | 179 ----------- 5 files changed, 4 insertions(+), 688 deletions(-) delete mode 100644 test/bug-fix-tests/empty-results-ast.json delete mode 100644 test/bug-fix-tests/empty-results-pipeline-4.0.0-works.json delete mode 100644 test/bug-fix-tests/empty-results-pipeline-4.1.3-broken.json delete mode 100644 test/bug-fix-tests/expected-pipeline.json diff --git a/test/bug-fix-tests/bug-fix.test.js b/test/bug-fix-tests/bug-fix.test.js index 2aafd82..914f824 100644 --- a/test/bug-fix-tests/bug-fix.test.js +++ b/test/bug-fix-tests/bug-fix.test.js @@ -3,6 +3,9 @@ const {buildQueryResultTester} = require('../utils/query-tester/index.js'); const {getAllSchemas} = require('../utils/get-all-schemas.js'); const {parseSQLtoAST, makeMongoAggregate} = require('../../lib/SQLParser'); const fs = require('fs/promises'); +const emptyResultsBugPipeline = require('./empty-results-pipeline.json'); +const isEqual = require('lodash/isEqual'); +const assert = require('node:assert'); describe('bug-fixes', function () { this.timeout(90000); const fileName = 'bug-fix'; @@ -1044,26 +1047,9 @@ describe('bug-fixes', function () { AND bp.PolSubType != 'S' AND bp.CustId = 'test-customer-1' LIMIT 10 `; - const ast = parseSQLtoAST(queryString); - await fs.writeFile( - './test/bug-fix-tests/empty-results-ast.json', - JSON.stringify(ast, null, 4), - {encoding: 'utf8'} - ); const aggregate = makeMongoAggregate(queryString); - await fs.writeFile( - './test/bug-fix-tests/empty-results-pipeline.json', - JSON.stringify(aggregate.pipeline, null, 4), - {encoding: 'utf8'} - ); - // await queryResultTester({ - // queryString: queryString, - // casePath: 'empty-results.case1', - // mode: 'write', - // expectZeroResults: false, - // outputPipeline: true, - // }); + assert.ok(isEqual(aggregate.pipeline, emptyResultsBugPipeline)); }); }); }); diff --git a/test/bug-fix-tests/empty-results-ast.json b/test/bug-fix-tests/empty-results-ast.json deleted file mode 100644 index 482ca90..0000000 --- a/test/bug-fix-tests/empty-results-ast.json +++ /dev/null @@ -1,285 +0,0 @@ -{ - "tableList": [ - "select::null::faizel-lob", - "select::null::faizel-polinfo" - ], - "columnList": [ - "select::faizel-polinfo::CustId", - "select::faizel-polinfo::PolId", - "select::faizel-polinfo::PolNo", - "select::faizel-polinfo::PolEffDate", - "select::faizel-polinfo::PolExpDate", - "select::lob::LineOfBus", - "select::null::PolId", - "select::null::LineOfBus", - "select::lob::PolId", - "select::lob::EffDate", - "select::faizel-polinfo::Status", - "select::faizel-polinfo::PolSubType" - ], - "ast": { - "with": null, - "type": "select", - "options": null, - "distinct": { - "type": null - }, - "columns": [ - { - "type": "expr", - "expr": { - "type": "column_ref", - "table": "bp", - "column": "CustId" - }, - "as": null - }, - { - "type": "expr", - "expr": { - "type": "column_ref", - "table": "bp", - "column": "PolId" - }, - "as": null - }, - { - "type": "expr", - "expr": { - "type": "column_ref", - "table": "bp", - "column": "PolNo" - }, - "as": null - }, - { - "type": "expr", - "expr": { - "type": "column_ref", - "table": "bp", - "column": "PolEffDate" - }, - "as": null - }, - { - "type": "expr", - "expr": { - "type": "column_ref", - "table": "bp", - "column": "PolExpDate" - }, - "as": null - }, - { - "type": "expr", - "expr": { - "type": "column_ref", - "table": "lob", - "column": "LineOfBus" - }, - "as": null - } - ], - "into": { - "position": null - }, - "from": [ - { - "db": null, - "table": "faizel-polinfo", - "as": "bp" - }, - { - "prefix": null, - "expr": { - "tableList": [ - "select::null::faizel-lob" - ], - "columnList": [ - "select::bp::CustId", - "select::bp::PolId", - "select::bp::PolNo", - "select::bp::PolEffDate", - "select::bp::PolExpDate", - "select::lob::LineOfBus", - "select::null::PolId", - "select::null::LineOfBus" - ], - "ast": { - "with": null, - "type": "select", - "options": null, - "distinct": { - "type": null - }, - "columns": [ - { - "type": "expr", - "expr": { - "type": "column_ref", - "table": null, - "column": "PolId" - }, - "as": null - }, - { - "type": "expr", - "expr": { - "type": "column_ref", - "table": null, - "column": "LineOfBus" - }, - "as": null - } - ], - "into": { - "position": null - }, - "from": [ - { - "db": null, - "table": "faizel-lob", - "as": null - } - ], - "where": null, - "groupby": null, - "having": null, - "orderby": null, - "limit": { - "seperator": "", - "value": [] - }, - "window": null - }, - "parentheses": true - }, - "as": "lob|optimize", - "join": "INNER JOIN", - "on": { - "type": "binary_expr", - "operator": "AND", - "left": { - "type": "binary_expr", - "operator": "=", - "left": { - "type": "column_ref", - "table": "lob", - "column": "PolId" - }, - "right": { - "type": "column_ref", - "table": "bp", - "column": "PolId" - } - }, - "right": { - "type": "binary_expr", - "operator": ">=", - "left": { - "type": "column_ref", - "table": "lob", - "column": "EffDate" - }, - "right": { - "type": "column_ref", - "table": "bp", - "column": "PolEffDate" - } - } - } - } - ], - "where": { - "type": "binary_expr", - "operator": "AND", - "left": { - "type": "binary_expr", - "operator": "AND", - "left": { - "type": "binary_expr", - "operator": "AND", - "left": { - "type": "binary_expr", - "operator": "!=", - "left": { - "type": "column_ref", - "table": "bp", - "column": "Status" - }, - "right": { - "type": "single_quote_string", - "value": "D" - } - }, - "right": { - "type": "binary_expr", - "operator": ">", - "left": { - "type": "function", - "name": "TO_DATE", - "args": { - "type": "expr_list", - "value": [ - { - "type": "column_ref", - "table": "bp", - "column": "PolExpDate" - } - ] - } - }, - "right": { - "type": "function", - "name": "CURRENT_DATE", - "args": { - "type": "expr_list", - "value": [] - }, - "over": null - } - } - }, - "right": { - "type": "binary_expr", - "operator": "!=", - "left": { - "type": "column_ref", - "table": "bp", - "column": "PolSubType" - }, - "right": { - "type": "single_quote_string", - "value": "S" - } - } - }, - "right": { - "type": "binary_expr", - "operator": "=", - "left": { - "type": "column_ref", - "table": "bp", - "column": "CustId" - }, - "right": { - "type": "single_quote_string", - "value": "test-customer-1" - } - } - }, - "groupby": null, - "having": null, - "orderby": null, - "limit": { - "seperator": "", - "value": [ - { - "type": "number", - "value": 10 - } - ] - }, - "window": null - } -} \ No newline at end of file diff --git a/test/bug-fix-tests/empty-results-pipeline-4.0.0-works.json b/test/bug-fix-tests/empty-results-pipeline-4.0.0-works.json deleted file mode 100644 index 840c071..0000000 --- a/test/bug-fix-tests/empty-results-pipeline-4.0.0-works.json +++ /dev/null @@ -1,103 +0,0 @@ -[ - { - "$project": { - "bp": "$$ROOT" - } - }, - { - "$lookup": { - "from": "faizel-lob", - "as": "lob", - "let": { - "bp_PolId": "$bp.PolId", - "bp_PolEffDate": "$bp.PolEffDate" - }, - "pipeline": [ - { - "$match": { - "$expr": { - "$and": [ - { - "$eq": ["$PolId", "$$bp_PolId"] - }, - { - "$gte": ["$EffDate", "$$bp_PolEffDate"] - } - ] - } - } - }, - { - "$project": { - "PolId": "$PolId", - "LineOfBus": "$LineOfBus" - } - } - ] - } - }, - { - "$match": { - "$expr": { - "$gt": [ - { - "$size": "$lob" - }, - 0 - ] - } - } - }, - { - "$match": { - "$and": [ - { - "$and": [ - { - "$and": [ - { - "bp_Status": { - "$ne": "D" - } - }, - { - "$expr": { - "$gt": [ - { - "$toDate": "$bp.PolExpDate" - }, - "$$NOW" - ] - } - } - ] - }, - { - "bp_PolSubType": { - "$ne": "S" - } - } - ] - }, - { - "bp_CustId": { - "$eq": "test-customer-1" - } - } - ] - } - }, - { - "$project": { - "CustId": "$bp.CustId", - "PolId": "$bp.PolId", - "PolNo": "$bp.PolNo", - "PolEffDate": "$bp.PolEffDate", - "PolExpDate": "$bp.PolExpDate", - "LineOfBus": "$lob.LineOfBus" - } - }, - { - "$limit": 10 - } -] diff --git a/test/bug-fix-tests/empty-results-pipeline-4.1.3-broken.json b/test/bug-fix-tests/empty-results-pipeline-4.1.3-broken.json deleted file mode 100644 index edf8ab5..0000000 --- a/test/bug-fix-tests/empty-results-pipeline-4.1.3-broken.json +++ /dev/null @@ -1,103 +0,0 @@ -[ - { - "$project": { - "bp": "$$ROOT" - } - }, - { - "$lookup": { - "from": "faizel-lob", - "as": "lob", - "let": { - "bp_PolId": "$bp.PolId", - "bp_PolEffDate": "$bp.PolEffDate" - }, - "pipeline": [ - { - "$project": { - "PolId": "$PolId", - "LineOfBus": "$LineOfBus" - } - }, - { - "$match": { - "$expr": { - "$and": [ - { - "$eq": ["$PolId", "$$bp_PolId"] - }, - { - "$gte": ["$EffDate", "$$bp_PolEffDate"] - } - ] - } - } - } - ] - } - }, - { - "$match": { - "$expr": { - "$gt": [ - { - "$size": "$lob" - }, - 0 - ] - } - } - }, - { - "$match": { - "$and": [ - { - "$and": [ - { - "$and": [ - { - "bp.Status": { - "$ne": "D" - } - }, - { - "$expr": { - "$gt": [ - { - "$toDate": "$bp.PolExpDate" - }, - "$$NOW" - ] - } - } - ] - }, - { - "bp.PolSubType": { - "$ne": "S" - } - } - ] - }, - { - "bp.CustId": { - "$eq": "test-customer-1" - } - } - ] - } - }, - { - "$project": { - "CustId": "$bp.CustId", - "PolId": "$bp.PolId", - "PolNo": "$bp.PolNo", - "PolEffDate": "$bp.PolEffDate", - "PolExpDate": "$bp.PolExpDate", - "LineOfBus": "$lob.LineOfBus" - } - }, - { - "$limit": 10 - } -] diff --git a/test/bug-fix-tests/expected-pipeline.json b/test/bug-fix-tests/expected-pipeline.json deleted file mode 100644 index d7a9560..0000000 --- a/test/bug-fix-tests/expected-pipeline.json +++ /dev/null @@ -1,179 +0,0 @@ -{ - "pipeline": [ - { - "$project": { - "currentUser": "$$ROOT" - } - }, - { - "$lookup": { - "from": "nfk-establishments", - "as": "establishments", - "let": { - "currentUser__id": "$currentUser._id" - }, - "pipeline": [ - { - "$match": { - "$expr": { - "$eq": [ - "$user", - { - "$toString": "$$currentUser__id" - } - ] - } - } - }, - { - "$project": { - "user_establishment": "$$ROOT" - } - }, - { - "$lookup": { - "from": "nfk-user-county-establishments", - "as": "establishment", - "let": { - "user_establishment_establishment": "$user_establishment.establishment" - }, - "pipeline": [ - { - "$match": { - "$expr": { - "$eq": [ - "$$user_establishment_establishment", - { - "$toString": "$_id" - } - ] - } - } - } - ] - } - }, - { - "$set": { - "establishment": { - "$first": "$establishment" - } - } - }, - { - "$match": { - "user_establishment_user": { - "$eq": "66261fd83316a727b53610da" - } - } - }, - { - "$project": { - "user": "$user_establishment.user", - "$id": "$establishment._id", - "name": "$establishment.name", - "main$establishment": "$establishment.main_establishment", - "level": "$establishment.level" - } - }, - { - "$sort": { - "level": 1, - "name": 1 - } - } - ] - } - }, - { - "$lookup": { - "from": "nfk-user-county-establishments", - "as": "child_establishments", - "let": { - "currentUser_establishment": "$currentUser.establishment" - }, - "pipeline": [ - { - "$match": { - "$expr": { - "$or": [ - { - "$eq": ["$id", "$$currentUser_establishment"] - }, - { - "$eq": ["$main_establishment", "$$currentUser_establishment"] - } - ] - } - } - }, - { - "$project": { - "establishment": "$$ROOT" - } - }, - { - "$match": { - "$or": [ - { - "$expr": { - "$eq": [ - { - "$toString": "$establishment._id" - }, - "662545865f01249a315ff1fd" - ] - } - }, - { - "establishment_main_establishment": { - "$eq": "662545865f01249a315ff1fd" - } - } - ] - } - }, - { - "$project": { - "id": { - "$toString": "$establishment._id" - }, - "name": "$establishment.name", - "main_establishment": "$establishment.main_establishment", - "level": "$establishment.level" - } - }, - { - "$sort": { - "level": 1, - "name": 1 - } - } - ] - } - }, - { - "$match": { - "$expr": { - "$eq": [ - { - "$toString": "$currentUser._id" - }, - "66261fd83316a727b53610da" - ] - } - } - }, - { - "$project": { - "$id": "$currentUser._id", - "establishment": "$currentUser.establishment", - "access_all_child_establishments": "$currentUser.access_all_child_establishments", - "establishments": "$establishments", - "child_establishments": "$child_establishments" - } - } - ], - "collections": ["nfk-users", "nfk-establishments", "nfk-user-county-establishments"], - "type": "aggregate" -} From e1d044a5b3b340626d36ee0300ae400788b432a3 Mon Sep 17 00:00:00 2001 From: Ryan Kotzen Date: Thu, 29 Aug 2024 07:16:19 +0200 Subject: [PATCH 8/8] 4.1.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fc20046..d257087 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@synatic/noql", - "version": "4.1.4", + "version": "4.1.5", "description": "Convert SQL statements to mongo queries or aggregates", "main": "index.js", "files": [