8000 unified behavior of `RANGE` function · doublerebel/arangodb@7800085 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7800085

Browse files
committed
unified behavior of RANGE function
1 parent 31bdc67 commit 7800085

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

arangod/Aql/Functions.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4452,7 +4452,17 @@ AqlValue Functions::Range(arangodb::aql::Query* query,
44524452
double step = 0.0;
44534453
if (n == 3) {
44544454
auto const stepJson = ExtractFunctionParameter(trx, parameters, 2, false);
4455-
step = ValueToNumber(stepJson.json(), unused);
4455+
if (!TRI_IsNullJson(stepJson.json())) {
4456+
step = ValueToNumber(stepJson.json(), unused);
4457+
}
4458+
else {
4459+
// no step specified
4460+
if (from <= to) {
4461+
step = 1.0;
4462+
} else {
4463+
step = -1.0;
4464+
}
4465+
}
44564466
} else {
44574467
// no step specified
44584468
if (from <= to) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2953,10 +2953,10 @@ function AQL_REVERSE (value) {
29532953
function AQL_RANGE (from, to, step) {
29542954
'use strict';
29552955

2956-
from = AQL_TO_NUMBER(from);
2957-
to = AQL_TO_NUMBER(to);
2956+
from = AQL_TO_NUMBER(from) || 0;
2957+
to = AQL_TO_NUMBER(to) || 0;
29582958

2959-
if (step === undefined) {
2959+
if (step === undefined || step === null) {
29602960
if (from <= to) {
29612961
step = 1;
29622962
}
@@ -2968,7 +2968,7 @@ function AQL_RANGE (from, to, step) {
29682968
step = AQL_TO_NUMBER(step);
29692969

29702970
// check if we would run into an endless loop
2971-
if (step === 0) {
2971+
if (step === 0 || step === null) {
29722972
WARN("RANGE", INTERNAL.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH);
29732973
return null;
29742974
}

0 commit comments

Comments
 (0)
0