Skip to content

Commit

Permalink
fixed issue #13632
Browse files Browse the repository at this point in the history
  • Loading branch information
jsteemann committed Mar 11, 2021
1 parent 19ca387 commit 6220ede
Show file tree
Hide file tree
Showing 3 changed files with 40 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.

* Fixed a problem that coordinators would vanish from the UI and the Health API
if one switched the agency Supervision into maintenance mode and kept left
that maintenance mode on for more than 24h.
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
34 changes: 33 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,39 @@ function ahuacatlFunctionsTestSuite () {
}
},

testReplaceNthIssue13632 : function () {
const cn = "UnitTestsCollection";
db._drop(cn);
db._create(cn);
try {
let query = `
LET values = [["t1", 0, 0], ["t1", 1, 0]]
FOR value_set IN values
LET t = value_set[0]
LET index = value_set[1]
LET value = value_set[2]
UPSERT {}
INSERT {v: {[t]: []}}
UPDATE {
'v' : {[t]: REPLACE_NTH(OLD.v[t], index, value, value)}
} IN ${cn}
RETURN [OLD, NEW]`;
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);
} finally {
db._drop(cn);
}
},

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

0 comments on commit 6220ede

Please sign in to comment.