Skip to content

Commit

Permalink
fixed issue #13632 (#13679)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsteemann committed Mar 12, 2021
1 parent a85cc29 commit 8f4fac3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,6 +1,8 @@
v3.7.10 (XXXX-XX-XX)
--------------------

* Fixed Github issue #13632: Query Fails on Upsert with Replace_nth.

* Backported AQL sort performance improvements from devel.
This change can improve the performance of local sorts operations, e.g.

Expand Down
8 changes: 5 additions & 3 deletions arangod/Aql/Functions.cpp
Expand Up @@ -7340,9 +7340,10 @@ AqlValue Functions::ReplaceNth(ExpressionContext* expressionContext,
THROW_ARANGO_EXCEPTION_PARAMS(TRI_ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, AFN);
}

AqlValueMaterializer materializer(trx);
VPackSlice arraySlice = materializer.slice(baseArray, false);
VPackSlice replaceValue = materializer.slice(newValue, false);
AqlValueMaterializer materializer1(trx);
VPackSlice arraySlice = materializer1.slice(baseArray, false);
AqlValueMaterializer materializer2(trx);
VPackSlice replaceValue = materializer2.slice(newValue, false);

transaction::BuilderLeaser builder(trx);
builder->openArray();
Expand All @@ -7359,6 +7360,7 @@ AqlValue Functions::ReplaceNth(ExpressionContext* expressionContext,

uint64_t pos = length;
if (replaceOffset >= length) {
AqlValueMaterializer materializer(trx);
VPackSlice paddVpValue = materializer.slice(paddValue, false);
while (pos < replaceOffset) {
builder->add(paddVpValue);
Expand Down
24 changes: 23 additions & 1 deletion tests/js/server/aql/aql-functions.js
Expand Up @@ -885,7 +885,6 @@ function ahuacatlFunctionsTestSuite () {
////////////////////////////////////////////////////////////////////////////////

testReplaceNthCxx : function () {

var testArray = [
null,
true,
Expand Down Expand Up @@ -939,6 +938,29 @@ function ahuacatlFunctionsTestSuite () {
}
},

testReplaceNthIssue13632 : function () {
let query = `
LET first = NOOPT({v: {t1: []}})
FOR s IN NOOPT([["t1", 0, 0, null], ["t1", 1, 0, first]])
LET t = s[0]
LET index = s[1]
LET value = s[2]
LET old = s[3]
RETURN [old, IS_NULL(old) ? first : MERGE(first, {v: {[t]: REPLACE_NTH(old.v[t], index, value, value)}})]
`;
let actual = getQueryResults(query);
assertEqual(2, actual.length);

let OLD, NEW;
[OLD, NEW] = actual[0];
assertNull(OLD);
assertEqual({ t1: [] }, NEW.v);

[OLD, NEW] = actual[1];
assertEqual({ t1: [] }, OLD.v);
assertEqual({ t1: [0, 0] }, NEW.v);
},

////////////////////////////////////////////////////////////////////////////////
/// @brief test replace_nth function
////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 8f4fac3

Please sign in to comment.