Skip to content

Commit

Permalink
check on query condition inside dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwalguptaofficial committed Nov 26, 2024
1 parent af9fdcf commit 0024871
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
13 changes: 9 additions & 4 deletions src/worker/executors/select/join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ class Join {
}
}
catch (ex) {
console.error(ex);
return promiseReject(
new LogHelper(ERROR_TYPE.InvalidJoinQuery, ex.message)
);
Expand All @@ -214,6 +215,7 @@ class Join {
});
}
catch (ex) {
console.error(ex);
return promiseReject(
new LogHelper(ERROR_TYPE.InvalidJoinQuery, ex.message)
);
Expand Down Expand Up @@ -351,10 +353,13 @@ class Join {
const table2 = jointblInfo.table2;
const tableSchemaOf1stTable = this.getTable(table1.table);
const tableSchemaOf2ndTable = this.getTable(table2.table);
if (tableSchemaOf1stTable == null || tableSchemaOf2ndTable == null) {
return new LogHelper(ERROR_TYPE.InvalidJoinQuery,
`The 'on' condition references tables or columns ('${table1.table}.${table1.column}', '${table2.table}.${table2.column}') that do not exist or are not part of the join. Ensure that the tables and columns used in the 'on' condition match those specified in the 'from' and 'with' clauses.`
);

if (process.env.NODE_ENV !== 'production') {
if (tableSchemaOf1stTable == null || tableSchemaOf2ndTable == null) {
return new LogHelper(ERROR_TYPE.InvalidJoinQuery,
`The 'on' condition references tables or columns ('${table1.table}.${table1.column}', '${table2.table}.${table2.column}') that do not exist or are not part of the join. Ensure that the tables and columns used in the 'on' condition match those specified in the 'from' and 'with' clauses.`
);
}
}

let err: LogHelper;
Expand Down
34 changes: 22 additions & 12 deletions test/cases/select/join.js
Original file line number Diff line number Diff line change
Expand Up @@ -924,12 +924,17 @@ describe('Test join', function () {
on: "Orders_invalid.customerId=Customers.customerId"
}
}).catch(function (err) {
const error = {
"message": "The 'on' condition references tables or columns ('Orders_invalid.customerId', 'Customers.customerId') that do not exist or are not part of the join. Ensure that the tables and columns used in the 'on' condition match those specified in the 'from' and 'with' clauses.",
"type": "invalid_join_query"
};
expect(err).to.eql(error);
done();
if (isRuningForProd() || isRuningForSauce()) {
done();
}
else {
const error = {
"message": "The 'on' condition references tables or columns ('Orders_invalid.customerId', 'Customers.customerId') that do not exist or are not part of the join. Ensure that the tables and columns used in the 'on' condition match those specified in the 'from' and 'with' clauses.",
"type": "invalid_join_query"
};
expect(err).to.eql(error);
done();
}
})
});

Expand All @@ -942,12 +947,17 @@ describe('Test join', function () {
on: "Orders.customerId=Customers_invalid.customerId"
}
}).catch(function (err) {
const error = {
"message": "The 'on' condition references tables or columns ('Orders.customerId', 'Customers_invalid.customerId') that do not exist or are not part of the join. Ensure that the tables and columns used in the 'on' condition match those specified in the 'from' and 'with' clauses.",
"type": "invalid_join_query"
};
expect(err).to.eql(error);
done();
if (isRuningForProd() || isRuningForSauce()) {
done();
}
else {
const error = {
"message": "The 'on' condition references tables or columns ('Orders.customerId', 'Customers_invalid.customerId') that do not exist or are not part of the join. Ensure that the tables and columns used in the 'on' condition match those specified in the 'from' and 'with' clauses.",
"type": "invalid_join_query"
};
expect(err).to.eql(error);
done();
}
})
});

Expand Down

0 comments on commit 0024871

Please sign in to comment.