8000 changed roundCosts to removeCosts (#10638) · waveray/arangodb@e9ded32 · GitHub 10000
[go: up one dir, main page]

Skip to content

Commit e9ded32

Browse files
hkernbachjsteemann
authored andcommitted
changed roundCosts to removeCosts (arangodb#10638)
1 parent 206fdec commit e9ded32

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

js/server/modules/@arangodb/aql-helper.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -381,20 +381,18 @@ function removeClusterNodesFromPlan (nodes) {
381381
});
382382
}
383383

384-
function roundCost (obj) {
384+
/// @brief recursively removes keys named "estimatedCost" or "selectivityEstimate" of a given object
385+
/// used in tests where we do not want to test those values because of floating-point values used in "AsserEqual"
386+
/// This method should only be used where we explicitly don't want to test those values.
387+
function removeCost (obj) {
385388
if (Array.isArray(obj)) {
386-
return obj.map(roundCost);
389+
return obj.map(removeCost);
387390
} else if (typeof obj === 'object') {
388391
var result = {};
389392
for (var key in obj) {
390393
if (obj.hasOwnProperty(key)) {
391-
if (key === "estimatedCost") {
392-
result[key] = Math.round(obj[key]);
393-
} else if (key === "selectivityEstimate") {
394-
// Round the estimate to 3 digits after ,
395-
result[key] = obj[key].toFixed(3);
396-
} else {
397-
result[key] = roundCost(obj[key]);
394+
if (key !== "estimatedCost" || key !== "selectivityEstimate") {
395+
result[key] = removeCost(obj[key]);
398396
}
399397
}
400398
}
@@ -422,4 +420,4 @@ exports.getQueryMultiplePlansAndExecutions = getQueryMultiplePlansAndExecutions;
422420
exports.removeAlwaysOnClusterRules = removeAlwaysOnClusterRules;
423421
exports.removeClusterNodes = removeClusterNodes;
424422
exports.removeClusterNodesFromPlan = removeClusterNodesFromPlan;
425-
exports.roundCost = roundCost;
423+
exports.removeCost = removeCost;

tests/js/server/aql/aql-graph-traverser.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const gm = require('@arangodb/general-graph');
4040
const vn = 'UnitTestVertexCollection';
4141
const en = 'UnitTestEdgeCollection';
4242
const isCluster = require('@arangodb/cluster').isCluster();
43-
const roundCost = require('@arangodb/aql-helper').roundCost;
43+
const removeCost = require('@arangodb/aql-helper').removeCost;
4444

4545
var _ = require('lodash');
4646
var vertex = {};
@@ -2218,13 +2218,19 @@ function optimizeInSuite() {
22182218
var noOptPlans = AQL_EXPLAIN(vertexQuery, bindVars, noOpt).plan;
22192219
assertEqual(optPlans.rules, []);
22202220
// This query cannot be optimized by traversal rule
2221-
assertEqual(roundCost(optPlans), roundCost(noOptPlans));
2221+
// we do not want to test estimatedCost or selectivityEstimate here
2222+
// 1.) subject to rounding errors and other fluctuations
2223+
// 2.) absolute numbers for estimatedCost and selectivityEstimate are an implementation detail and meaningless for this test.
2224+
assertEqual(removeCost(optPlans), removeCost(noOptPlans));
22222225

22232226
optPlans = AQL_EXPLAIN(edgeQuery, bindVars, opt).plan;
22242227
noOptPlans = AQL_EXPLAIN(edgeQuery, bindVars, noOpt).plan;
22252228
assertEqual(optPlans.rules, []);
22262229
// This query cannot be optimized by traversal rule
2227-
assertEqual(roundCost(optPlans), roundCost(noOptPlans));
2230+
// we do not want to test estimatedCost or selectivityEstimate here
2231+
// 1.) subject to rounding errors and other fluctuations
2232+
// 2.) absolute numbers for estimatedCost and selectivityEstimate are an implementation detail and meaningless for this test.
2233+
assertEqual(removeCost(optPlans), removeCost(noOptPlans));
22282234
}
22292235
};
22302236
}

0 commit comments

Comments
 (0)
0