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 c0598f5 commit 0e6f6a2
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 @@
devel
-----

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

* Added a new metrics view to the web UI. This view can be used in a clustered
environment as well as in a single instance. Metrics are displayed either in
a tabular format or as plain text (Prometheus Text-based format).
Expand Down
8 changes: 5 additions & 3 deletions arangod/Aql/Functions.cpp
Expand Up @@ -7798,9 +7798,10 @@ AqlValue Functions::ReplaceNth(ExpressionContext* expressionContext,
THROW_ARANGO_EXCEPTION_PARAMS(TRI_ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, AFN);
}

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

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

uint64_t pos = length;
if (replaceOffset >= length) {
AqlValueMaterializer materializer(vopts);
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 0e6f6a2

Please sign in to comment.