1
0
Fork 0

fixed issue in `INTERSECTION` AQL function with duplicate elements in the source arrays

This commit is contained in:
Jan Steemann 2016-07-28 17:10:04 +02:00
parent 9f3b7a9080
commit ddecc740e6
3 changed files with 48 additions and 2 deletions

View File

@ -36,6 +36,9 @@ devel
v3.0.4 (XXXX-XX-XX)
-------------------
* fixed issue in `INTERSECTION` AQL function with duplicate elements
in the source arrays
* fixed issue #1970
* fixed issue #1967

View File

@ -2079,8 +2079,11 @@ AqlValue Functions::Intersection(arangodb::aql::Query* query,
auto found = values.find(it);
if (found != values.end()) {
// already seen
TRI_ASSERT((*found).second > 0);
++(found->second);
if ((*found).second < i) {
(*found).second = 0;
} else {
(*found).second = i + 1;
}
}
}
}

View File

@ -2439,6 +2439,26 @@ function ahuacatlFunctionsTestSuite () {
assertEqual(expected, actual[0].sort());
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test intersect function
////////////////////////////////////////////////////////////////////////////////
testIntersection11 : function () {
var expected = [ 1, 3 ];
var actual = getQueryResults("RETURN INTERSECTION([ 1, 1, 2, 2, 3, 3, 3 ], [ 1, 1, 3 ])");
assertEqual(expected, actual[0].sort());
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test intersect function
////////////////////////////////////////////////////////////////////////////////
testIntersection12 : function () {
var expected = [ 3 ];
var actual = getQueryResults("RETURN INTERSECTION([ 1, 1, 3 ], [ 2, 2, 3 ])");
assertEqual(expected, actual[0].sort());
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test intersection function
////////////////////////////////////////////////////////////////////////////////
@ -2539,6 +2559,26 @@ function ahuacatlFunctionsTestSuite () {
assertEqual(expected, actual[0].sort());
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test intersect function
////////////////////////////////////////////////////////////////////////////////
testIntersectionCxx11 : function () {
var expected = [ 1, 3 ];
var actual = getQueryResults("RETURN NOOPT(INTERSECTION([ 1, 1, 2, 2, 3, 3, 3 ], [ 1, 1, 3 ]))");
assertEqual(expected, actual[0].sort());
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test intersect function
////////////////////////////////////////////////////////////////////////////////
testIntersectionCxx12 : function () {
var expected = [ 3 ];
var actual = getQueryResults("RETURN NOOPT(INTERSECTION([ 1, 1, 3 ], [ 2, 2, 3 ]))");
assertEqual(expected, actual[0].sort());
},
testIntersectionAllDocuments : function () {
// Insert 10 elements
for (var i = 0; i < 10; ++i) {