Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/make/makeFilterCondition.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ function processBinaryExpression(
side,
prefixLeft,
prefixTable,
aliases
aliases,
inSwitchStatement
);
}

Expand Down Expand Up @@ -378,6 +379,7 @@ function processQueryOperator(
* @param {boolean} [prefixLeft] - include $$ for inner variables
* @param {boolean} [prefixTable] - include the table in the prefix
* @param {string[]} [aliases] - the aliases used in the joins
* @param {boolean} [inSwitchStatement] - specifies if we are in a switch for special conditions, default false
* @returns {any} - the filter expression
*/
function processOperator(
Expand All @@ -388,7 +390,8 @@ function processOperator(
side,
prefixLeft,
prefixTable,
aliases
aliases,
inSwitchStatement = false
) {
const operation = operatorMap[queryPart.operator];
if (!operation) {
Expand All @@ -402,7 +405,8 @@ function processOperator(
'left',
prefixLeft,
prefixTable,
aliases
aliases,
inSwitchStatement
);
const secondFilter = makeFilterCondition(
queryPart.right,
Expand All @@ -412,7 +416,8 @@ function processOperator(
'right',
prefixLeft,
prefixTable,
aliases
aliases,
inSwitchStatement
);
return {
[operation]: [firstFilter, secondFilter],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@synatic/noql",
"version": "4.1.17",
"version": "4.1.18",
"description": "Convert SQL statements to mongo queries or aggregates",
"main": "index.js",
"files": [
Expand Down
156 changes: 156 additions & 0 deletions test/bug-fix-tests/bug-fix.json
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,162 @@
"Funded": 0
}
]
},
"case-2": {
"pipeline": [
{
"$project": {
"_id": "$_id",
"Id": "$Id",
"Account": "$Account__c",
"AccountName": "$Account_Name",
"AccountFundingStatus": "$Account_Account_Funding_Status",
"AccountLegalName": "$Account_Legal_Name__c",
"AccountContractPrinciple": "$Account_Contract_Principle",
"ApplicationStatus": "$Application_Status__c",
"ClosedBy": "$Closed_By__c",
"Funded": {
"$switch": {
"branches": [
{
"case": {
"$and": [
{
"$and": [
{
"$and": [
{
"$and": [
{
"$and": [
{
"$and": [
{
"$and": [
{
"$and": [
{
"$and": [
{
"$and": [
{
"$ne": [
"$Source_Initiative",
"Automated Mining"
]
},
{
"$eq": [
"$Product__c",
"merchantcashadvance"
]
}
]
},
{
"$eq": [
"$Type__c",
"New Deal"
]
}
]
},
{
"$ne": [
"$Sales_Executive_User",
"Pool of Hope"
]
}
]
},
{
"$ne": [
"$Closed_By__c",
"System"
]
}
]
},
{
"$ne": [
"$Account_Name",
null
]
}
]
},
{
"$ne": [
"$Account_Account_Funding_Status",
"Contactless"
]
}
]
},
{
"$and": [
{
"$not": {
"$in": [
"$Closed_Reason_New__c",
[
"Duplicate",
"Qualifying Criteria",
"Contact data wrong",
"poor contactability",
"unsupported industry",
"MC Balance too high",
"wants to become MC partner",
"poor MC payment efficiency"
]
]
}
},
{
"$eq": [
"$Application_Status__c",
"Complete"
]
}
]
}
]
},
{
"$ne": [
"$Closed_By__c",
"Underwriting"
]
}
]
},
{
"$eq": [
"$Credit_Status__c",
"Approved"
]
}
]
},
{
"$eq": [
"$Status__c",
"Active - Disbursed"
]
}
]
},
"then": 1
}
],
"default": {
"$literal": 0
}
}
}
}
}
]
}
}
}
42 changes: 42 additions & 0 deletions test/bug-fix-tests/bug-fix.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2012,5 +2012,47 @@ describe('bug-fixes', function () {
schemas: {},
});
});
it('should generate and execute a valid query when complicated', async () => {
// noinspection SqlNoDataSourceInspection
const queryString = `
SELECT
_id,
Id,
Account__c AS Account,
Account_Name AS AccountName,
Account_Account_Funding_Status AS AccountFundingStatus,
Account_Legal_Name__c AS AccountLegalName,
Account_Contract_Principle AS AccountContractPrinciple,
Application_Status__c AS ApplicationStatus,
Closed_By__c AS ClosedBy,
CASE
WHEN Source_Initiative != 'Automated Mining'
AND Product__c = 'merchantcashadvance'
AND Type__c = 'New Deal'
AND Sales_Executive_User != 'Pool of Hope'
AND Closed_By__c != 'System'
AND Account_Name IS NOT NULL
AND Account_Account_Funding_Status != 'Contactless'
AND Closed_Reason_New__c NOT IN ('Duplicate','Qualifying Criteria','Contact data wrong','poor contactability','unsupported industry','MC Balance too high','wants to become MC partner','poor MC payment efficiency')
AND Application_Status__c = 'Complete'
AND Closed_By__c != 'Underwriting'
AND Credit_Status__c = 'Approved'
AND Status__c = 'Active - Disbursed'
THEN 1
ELSE 0
END AS "Funded"
FROM public."global-00--00--flat-offers-full-set"
`;
await queryResultTester({
queryString: queryString,
casePath: 'nin.case-2',
mode: 'write',
outputPipeline: true,
skipDbQuery: true,
optimizeJoins: false,
unsetId: true,
schemas: {},
});
});
});
});
Loading