10BC0 Feature/aql subquery execution block impl execute implementation batch sub queries by mchacki · Pull Request #11318 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
213 commits
Select commit Hold shift + click to select a range
35fe0e5
Added first draft of AqlCallObject
mchacki Oct 22, 2019
ead968c
Added AqlItemBlockInputRange
goedderz Oct 22, 2019
7c6bcba
Added Header file for AqlCallStack with comments. No implementation yet.
mchacki Oct 22, 2019
22d2977
Added AqlCallStack first draft implementation. Made everything compile
mchacki Oct 22, 2019
3ab4488
Added empty dummy stubs for execute() in ExecutionBlock
mchacki Oct 22, 2019
b079d78
Implementation of new API in FilterExecutor. Rough implementation in …
mchacki Oct 24, 2019
eb120a0
Fixed off by one error in InputRange. Fixed FilterExecutor
mchacki Oct 24, 2019
cb2cef2
Added some more tests if executor cannot fulfill atMost
mchacki Oct 24, 2019
a46941e
Added heplper functions to the AqlCall struct to avoid mangeling arou…
mchacki Oct 25, 2019
e248e45
Add a member DataRange to ExecutionBlockImpl. Also now all Fetcher ex…
mchacki Oct 25, 2019
c40cfc0
Added preliminary minimal implementation of execute to DependencyProx…
mchacki Oct 25, 2019
dccbbcf
Merge branch 'devel' of github.com:arangodb/arangodb into feature/Aql…
hkernbach Oct 28, 2019
2368252
added first implementation of count collect datarange produceRows fun…
hkernbach Oct 28, 2019
acb414f
Revert "added first implementation of count collect datarange produce…
hkernbach Oct 28, 2019
b66f314
Merge branch 'feature/AqlSubqueryOperationsStack' of ssh://github.com…
mchacki Oct 29, 2019
5b0b8ce
Merge branch 'devel' into feature/AqlSubqueryOperationsStack
Oct 30, 2019
e0205b5
First draft of execute implementation, not yet handling ShadowRows th…
mchacki Oct 30, 2019
3eff385
Merge branch 'feature/AqlSubqueryOperationsStack' of ssh://github.com…
mchacki Oct 30, 2019
96c0fda
First working draft of execute() call in ExecutionBlockImpl. Tests ar…
mchacki Oct 31, 2019
4d019a1
Removed non finished implementation from this Branch. It moved to sep…
mchacki Oct 31, 2019
aa275b4
working - not done yet
hkernbach Nov 8, 2019
fd33b7f
Revert "working - not done yet"
hkernbach Nov 8, 2019
4d030f4
Intermediate devel pull, might not compile
mchacki Nov 18, 2019
0300467
Finally merged with latest devel, seems to work
mchacki Nov 18, 2019
907628e
Merge branch 'feature/AqlSubqueryOperationsStack' of ssh://github.com…
mchacki Nov 18, 2019
11be23e
Merge branch 'devel' of ssh://github.com/arangodb/ArangoDB into featu…
mchacki Nov 18, 2019
c703b11
first implementation of a ShadowRow fetching interface on AqlItemBloc…
mchacki Nov 18, 2019
7911767
single row fetcher, execute + tests
hkernbach Nov 20, 2019
45f7771
Merge
hkernbach Nov 20, 2019
b91be5f
Fixed SingleRowFetcherTest. Also an AqlItemBlockInputRange can now ha…
mchacki Nov 27, 2019
8ba440c
Another fix on handling of shadow rows in InputRanges
mchacki Nov 27, 2019
b5dacbd
Improved human readable output of SortLimit test, while validating th…
mchacki Nov 27, 2019
a6281da
Removed debug profile execution of a query
mchacki Nov 27, 2019
7a8a1dc
Use simpleVPack printing for Trace of Execute, better to read by humans
mchacki Nov 27, 2019
40569e0
Merge branch 'feature/AqlSubqueryOperationsStack' of ssh://github.com…
mchacki Nov 28, 2019
d636a10
Merge branch 'devel' of ssh://github.com/arangodb/ArangoDB into featu…
mchacki Nov 28, 2019
2b13d48
Merge branch 'feature/AqlSubqueryOperationsStack' of ssh://github.com…
mchacki Nov 28, 2019
8307d15
Added tests for AqlItemBlockInputRange and adjusted implementation ac…
mchacki Nov 29, 2019
c973149
Fixed issue where ExecutionBlockImpl returns DONE, although there are…
mchacki Dec 2, 2019
d83e3ac
Final modification of ShadowRows in FilterExecutor. All but profiling…
mchacki Dec 2, 2019
9c8ae9d
Removed debug log includes
mchacki Dec 2, 2019
990c487
Merge branch 'devel' of ssh://github.com/arangodb/ArangoDB into featu…
mchacki Dec 3, 2019
e4dcdbc
Merge branch 'feature/AqlSubqueryOperationsStack' of ssh://github.com…
mchacki Dec 3, 2019
292bd2a
Moved responsibility for the client call into the output row. This ca…
mchacki Dec 3, 2019
ba3eea6
Fixed FilterExecutorTest
mchacki Dec 4, 2019
d8f80f9
Expose required features to AqlCall controlled by the output aql item…
mchacki Dec 4, 2019
6d18de7
Fixed bug with AqlCallStack pop operation that actually caused invali…
mchacki Dec 5, 2019
c84be59
outputRow now honors limits whan called for isFull.
mchacki Dec 5, 2019
2eb29ad
Fixed isFull() in OutputAqlItemRow
mchacki Dec 5, 2019
7151867
Use the inbound call in skipRows for executors, in order to do a more…
mchacki Dec 5, 2019
26c1996
Make linker happy with operator< on CallLimit
mchacki Dec 6, 2019
dfd6d49
Implement operator+ on AqlCall::Limit, also use std::visit for readab…
mchacki Dec 6, 2019
86db29c
FilterExecutor getSome now propagates offset + min(limits) to upstrea…
mchacki Dec 6, 2019
aa4323f
Fixed profiler tests for filter. These cannot be guaranteed anymore a…
mchacki Dec 6, 2019
63f76e5
Fixed JSLint
mchacki Dec 6, 2019
df27560
Merge branch 'devel' into feature/AqlSubqueryExecutionBlockImplExecut…
Dec 13, 2019
7cddcfa
Remove special casing for FilterExecutor
Dec 13, 2019
73cf9af
Merge branch 'devel' into feature/AqlSubqueryExecutionBlockImplExecut…
Dec 13, 2019
63b0da1
Merge branch 'feature/AqlSubqueryExecutionBlockImplExecuteImplementat…
Dec 13, 2019
247e668
Merge branch 'devel' of github.com:arangodb/arangodb into feature/Aql…
goedderz Dec 13, 2019
c9d1f2f
Merge branch 'feature/AqlSubqueryOperationsStack' of github.com:arang…
goedderz Dec 13, 2019
9123516
Add skeleton skip code
Dec 13, 2019
b27d945
Replace C&P accident
Dec 13, 2019
7ad6c9e
Simplify and implement skip for new executor interface
Dec 13, 2019
64186d3
Fixup skipping for filter executor
Dec 13, 2019
266b8ad
Rename some methods for clarity and consistency
Dec 20, 2019
1628196
Introduce function to allocate an output block
Dec 24, 2019
7e8180f
Fix skipSome simulation bug
Dec 24, 2019
4e86d17
Some small cleanups
Dec 24, 2019
cfaf773
Merge branch 'devel' into feature/AqlSubqueryExecutionBlockImplExecut…
Dec 24, 2019
1ec2b8a
Merge branch 'devel' of ssh://github.com/arangodb/ArangoDB into featu…
mchacki Jan 2, 2020
f5ef0e7
Replaced assertion on atMost on the output size. Otherwise we got int…
mchacki Jan 2, 2020
862d316
Attempt at fixing execute
Jan 6, 2020
44d60bc
Merge branch 'devel' of github.com:arangodb/arangodb into feature/Aql…
goedderz Jan 10, 2020
2f938c5
Merge branch 'feature/AqlSubqueryOperationsStack' into feature/AqlSub…
goedderz Jan 10, 2020
f3ec9c2
Merge branch 'devel' of ssh://github.com/arangodb/ArangoDB into featu…
mchacki Jan 13, 2020
397fee6
Merge branch 'devel' of github.com:arangodb/arangodb into feature/Aql…
goedderz Jan 15, 2020
a79a89e
Merge branch 'feature/AqlSubqueryOperationsStack' of github.com:arang…
goedderz Jan 15, 2020
9ee9a0f
Merge branch 'devel' of github.com:arangodb/arangodb into feature/Aql…
goedderz Jan 16, 2020
0624998
Merge branch 'feature/AqlSubqueryOperationsStack' into feature/AqlSub…
goedderz Jan 16, 2020
12b1b2b
Merge branch 'devel' of github.com:arangodb/arangodb into feature/Aql…
goedderz Jan 17, 2020
131c004
Merge branch 'feature/AqlSubqueryOperationsStack' of github.com:arang…
goedderz Jan 17, 2020
a656f39
Fix merge conflict
goedderz Jan 17, 2020
508461e
Merge branch 'feature/AqlSubqueryOperationsStack' of github.com:arang…
goedderz Jan 17, 2020
41c6d36
Merge branch 'devel' of ssh://github.com/arangodb/ArangoDB into featu…
mchacki Jan 23, 2020
e03496a
Merge branch 'feature/AqlSubqueryOperationsStack' of ssh://github.com…
mchacki Jan 23, 2020
fdd0fed
Merge branch 'feature/AqlSubqueryExecutionBlockImplExecuteImplementat…
mchacki Jan 23, 2020
7ac26a3
Merge branch 'devel' into feature/AqlSubqueryOperationsStack
Jan 24, 2020
c9c54e3
Merge branch 'feature/AqlSubqueryOperationsStack' into feature/AqlSub…
Jan 24, 2020
10BC0
beb7003
Feature/aql subquery execution block impl execute implementation exec…
mchacki Jan 24, 2020
ba5435b
Merge branch 'devel' of ssh://github.com/arangodb/ArangoDB into featu…
mchacki Jan 24, 2020
1d5e5a5
Merge branch 'feature/AqlSubqueryOperationsStack' of ssh://github.com…
mchacki Jan 24, 2020
5b3e717
Feature/aql subquery execution block impl execute implementation shor…
mchacki Jan 27, 2020
56d9cf0
Feature/aql subquery execution block impl execute implementation exec…
mchacki Jan 28, 2020
7222d3e
Feature/aql subquery execution block impl execute implementation sort…
Jan 31, 2020
efd40c3
Merge branch 'devel' into feature/AqlSubqueryExecutionBlockImplExecut…
Feb 3, 2020
2b2625b
Merge branch 'devel' into feature/AqlSubqueryExecutionBlockImplExecut…
Feb 3, 2020
30d9f27
ReturnExecutor New style (#10831)
Feb 11, 2020
d4d3cd3
Merge branch 'devel' into feature/AqlSubqueryExecutionBlockImplExecut…
Feb 11, 2020
4028320
Merge branch 'devel' into feature/AqlSubqueryOperationsStack
Feb 11, 2020
3596c54
Merge branch 'devel' of github.com:arangodb/arangodb into feature/Aql…
goedderz Feb 12, 2020
a576003
Merge branch 'feature/AqlSubqueryOperationsStack' of github.com:arang…
goedderz Feb 12, 2020
6359f0c
Tweak ExecutorTestHelper to test pipelines
Feb 12, 2020
c509e18
Revert "Tweak ExecutorTestHelper to test pipelines"
Feb 12, 2020
94da545
Added Stats return value to skipRowsRange (#11081)
mchacki Feb 13, 2020
518c042
Additional Assertion in ExecutionBlockImpl (#11077)
mchacki Feb 13, 2020
54043f3
Feature/aql subquery operations stack id executor (#10986)
mchacki Feb 14, 2020
3963940
Merge branch 'devel' of ssh://github.com/arangodb/ArangoDB into featu…
mchacki Feb 14, 2020
da03a1c
Merge branch 'feature/AqlSubqueryOperationsStack' of ssh://github.com…
mchacki Feb 14, 2020
44fdb29
Replaced the operator== and operator!= with `isSameBlockAndIndex`. (#…
Feb 14, 2020
95a7326
New style IndexExecutor. (#11029)
Feb 14, 2020
10cc623
Merge branch 'devel' of ssh://github.com/arangodb/ArangoDB into featu…
mchacki Feb 17, 2020
df13bbb
Merge branch 'feature/AqlSubqueryOperationsStack' of ssh://github.com…
mchacki Feb 17, 2020
2157a75
Merge branch 'feature/AqlSubqueryExecutionBlockImplExecuteImplementat…
mchacki Feb 17, 2020
dac0a10
Feature/aql subquery execution block impl execute implementation debu…
mchacki Feb 18, 2020
1871aeb
Feature/aql subquery operations stack hashed collect executor (#11103)
mchacki Feb 18, 2020
1a54762
Feature/aql subquery operations stack enumerate list (#10988)
hkernbach Feb 18, 2020
6d6edc9
Feature/aql subquery execution block impl execute implementation inje…
mchacki Feb 20, 2020
2077958
Tweak ExecutorTestHelper to test pipelines (#11079)
markuspf Feb 20, 2020
2e2e214
AQL execute in LimitExecutor (#10886)
goedderz Feb 21, 2020
e7f36c3
Feature/aql subquery operations stack calculation exec enumerate exec…
hkernbach Feb 21, 2020
557d5c5
Quickfix for compilation error due to merge
Feb 24, 2020
e6a31b7
Feature/aql subquery execution block impl execute implementation k sh…
markuspf Feb 25, 2020
b81dc94
Feature/aql subquery execution block impl execute implementation trav…
markuspf Feb 25, 2020
d8c41c2
Merge branch 'devel' of github.com:arangodb/arangodb into feature/Aql…
goedderz Feb 25, 2020
4fa0860
Merge branch 'feature/AqlSubqueryOperationsStack' of github.com:arang…
goedderz Feb 25, 2020
4dadc22
Move SubqueryStartExecutor to new interface (#11025)
markuspf Feb 26, 2020
1cd9adb
Feature/aql subquery execute remote node api flag (#11159)
goedderz Feb 27, 2020
be42def
Feature/aql subquery operations stack i research view executor (#11140)
hkernbach Feb 27, 2020
abd2740
Move SingleRemoteModificationExecutor to new interface (#11166)
markuspf Feb 27, 2020
39ecda2
Merge remote-tracking branch 'origin/devel' into feature/AqlSubqueryE…
Feb 27, 2020
9bf96cd
New style DistinctCollect (#11096)
Feb 27, 2020
c2ae621
Feature/aql subquery execution block impl execute implementation nore…
mchacki Feb 28, 2020
4fe26a9
Moved Constrained sort to execute API (#11173)
mchacki Feb 28, 2020
a0d6ec1
Feature/aql subquery operations stack aql item block input matrix (#1…
hkernbach Feb 28, 2020
28b9c04
Feature/aql subquery execute in restaqlhandler (#11175)
goedderz Feb 28, 2020
08ceffe
Support executors with multiple dependencies (#11181)
markuspf Feb 29, 2020
3ae0061
Move ModificationExecutors to new interface (#11165)
markuspf Feb 29, 2020
d4e7299
Feature/aql subquery operations stack materialize executor (#11192)
hkernbach Feb 29, 2020
9a76c0c
Feature/aql subquery execute remote (#11197)
goedderz Feb 29, 2020
98c7eb6
Added test for distinct collect with random order. (#11184)
Feb 29, 2020
609b0ff
Feature/aql subquery execution block impl execute implementation subq…
Feb 29, 2020
9bb106d
Feature/aql subquery execution block impl execute implementation coun…
mchacki Feb 29, 2020
2262370
Activate CalculationExecutors (#11177)
mchacki Feb 29, 2020
c69dc93
Fixed compile bug-due to hidden merge conflict
mchacki Feb 29, 2020
341ef5f
Feature/aql subquery execution block impl execute implementation base…
mchacki Mar 2, 2020
c653260
Fix memory leak in traversal (#11210)
markuspf Mar 3, 2020
41ce860
AqlSubqueryExecutionBlockImplExecuteImplementation use moveValueInto …
markuspf Mar 3, 2020
26242a1
Feature/aql subquery execution block impl execute implementation gath…
mchacki Mar 3, 2020
fd763cb
Feature/aql subquery execute parallel gather (#11215)
goedderz Mar 3, 2020
4794ebe
Feature/aql subquery execute parallel gather 2 (#11221)
goedderz Mar 10, 2020
25de4de
Feature/aql subquery execution block impl execute implementation bypa…
mchacki Mar 12, 2020
cb42580
Add some FilterExecutor and CalculationExecutor tests (#11231)
markuspf Mar 12, 2020
10b24b2
Merge devel into feature/AqlSubqueryExecutionBlockImplExecuteImplemen…
mchacki Mar 12, 2020
4b09567
Fixed assertion in SubqueryStart. On initial call it can be called wi…
mchacki Mar 13, 2020
ace0317
Added methods to count available rows in AqlItemBlockInputRange
mchacki Mar 13, 2020
b8d4b48
Allow a path to Ask the Executor how many rows are going to be produc…
mchacki Mar 13, 2020
94d7729
Let Return and SubqueryExecutors present how many data rows are to be…
mchacki Mar 13, 2020
db8a775
Implement a fast forwarding of Rows in IdExecutor
mchacki Mar 13, 2020
591d877
Merge branch 'devel' of ssh://github.com/arangodb/ArangoDB into featu…
mchacki Mar 13, 2020
e431ccf
Initialize all the bools
mchacki Mar 13, 2020
7c1069c
Fixed ASAN warning
mchacki Mar 13, 2020
bc40f02
Fixed ASAN warning in ShortestPathExecutor
mchacki Mar 13, 2020
c86f8fe
Merge branch 'feature/AqlSubqueryExecutionBlockImplExecuteImplementat…
mchacki Mar 13, 2020
350f6d0
Fixed invalid access in block allocation if input is empty
mchacki Mar 13, 2020
a102483
Merge branch 'devel' of ssh://github.com/arangodb/ArangoDB into featu…
mchacki Mar 15, 2020
014d1a4
Reactivated expectedNumberOfRows on all SingleRowFetcher executors
mchacki Mar 15, 2020
dafce76
Deactivated Debug Logging in Enumerate Collection Executor test
mchacki Mar 15, 2020
920521b
Fixed SubqueryStartExecutor produceRows estimate
mchacki Mar 15, 2020
33b9d94
For now SubqueryEndExecutor cannot define expected number of rows. We…
mchacki Mar 15, 2020
9f618e4
SubqueryStart will have more output then limit defines (ShadowRow)
mchacki Mar 15, 2020
b00eff8
Fixed Filter numberOfExpectedRows
mchacki Mar 15, 2020
a6fd85c
Removed do-copy row test from ID executor. It now uses a fast-forward…
mchacki Mar 15, 2020
31f0b2e
Only estimate the number of Rows if the range is complete.
mchacki Mar 15, 2020
a6003ea
On Collect nodes we sometimes produce an additional empty row
mchacki Mar 15, 2020
9b853b3
Merge branch 'devel' of ssh://github.com/arangodb/ArangoDB into featu…
mchacki Mar 15, 2020
37f5e1f
Fixed endles loop in ParallelUnsortedGather, if the initial input is …
mchacki Mar 15, 2020
1e68460
Removed isRelevant and all it's belong APIs from AqlCall. Has never b…
mchacki Mar 16, 2020
0460fee
Added AqlCallList, this is supposed to be emplaced in the call-stack …
mchacki Mar 16, 2020
8dc3be0
Prepared AqlCallStack to contain one (or even more but not used) look…
mchacki Mar 17, 2020
85fe3c8
Merge branch 'devel' of ssh://github.com/arangodb/ArangoDB into featu…
mchacki Mar 17, 2020
ac2b963
Allow batching of Subqueries. Temporarily disabled expectedNumberOfRo…
mchacki Mar 17, 2020
fec7dfd
Merge branch 'devel' of ssh://github.com/arangodb/ArangoDB into featu…
mchacki Mar 17, 2020
1c47be3
Reactivated expectedNumberOfRows, and fixed the estimate on SUbqueryS…
mchacki Mar 17, 2020
a40d7c4
Adapted SubqueryStartExecutorTest to new Execution methodology
mchacki Mar 18, 2020
a36d0ca
Fixed SubqueryStart handling of continuous subqueries
mchacki Mar 18, 2020
49eab6d
Adapted AqlItemBlockRangeTest to check for HASMORE instead
mchacki Mar 18, 2020
e8e2503
Fixed singleRowFetcherTest to new state change in ShadowRows
mchacki Mar 18, 2020
a0d219a
Activated DISABLED tests, they actually work now.
mchacki Mar 18, 2020
bbc86cd
Fixed empty subquery situation when forwarding
mchacki Mar 19, 2020
1f11032
Added a generic test framework for the Shared API of Fetchers
mchacki Mar 19, 2020
a9b91a5
Made AqlItemMatrix pass the InputRangeTests
mchacki Mar 19, 2020
a1d66dc
Fixed remaining GTests. Handling of consecutive Subqueries was not co…
mchacki Mar 19, 2020
21fd2bc
Attempt to fix Modification executors in SubqueryByPassing variants
mchacki Mar 20, 2020
7b63bb8
Removed wrong assertion
mchacki Mar 20, 2020
53d634e
Merge branch 'devel' of ssh://github.com/arangodb/ArangoDB into featu…
mchacki Mar 20, 2020
ece5b7a
Made MultiInputRange ready for RangeTest. Test is red still. Also avo…
mchacki Mar 20, 2020
dc0eb91
ShadowRows in MultiRange is the Maximum, not a Sum.
mchacki Mar 20, 2020
b2e165c
Initialize all the dependencies
mchacki Mar 20, 2020
a8638dd
Merge branch 'devel' of ssh://github.com/arangodb/ArangoDB into featu…
mchacki Mar 20, 2020
c960f53
Add unused flag, because it is not used in one constexpr, but all the…
mchacki Mar 23, 2020
0089e8f
Merge branch 'devel' of ssh://github.com/arangodb/ArangoDB into featu…
mchacki Mar 23, 2020
10a282d
Fixed compile issue
mchacki Mar 23, 2020
3ed641c
Merge branch 'devel' of ssh://github.com/arangodb/ArangoDB into featu…
mchacki Mar 24, 2020
998575a
Apply suggestions from code review
mchacki Mar 24, 2020
ec2b645
Added comments to AqlCallList and AqlCallStack to explain their diffe…
mchacki Mar 24, 2020
d9905c0
Memorized -> Memoized
mchacki Mar 24, 2020
589a109
Explained the countShadowRows for MultiRanges
mchacki Mar 24, 2020
620f108
Added clarification comment
mchacki Mar 24, 2020
b1622db
Do not try to write an if, that's impossible. Instead, only try to re…
mchacki Mar 24, 2020
9a4610d
Added a comment why expectedNumbrOfRows is actually correct
mchacki Mar 24, 2020
4ca7f54
Apply suggestions from code review
mchacki Mar 25, 2020
0b6e1f1
Update arangod/Aql/ExecutionBlockImpl.cpp
mchacki Mar 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions arangod/Aql/AllRowsFetcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ std::pair<ExecutionState, AqlItemMatrix const*> AllRowsFetcher::fetchAllRows() {
}

std::tuple<ExecutionState, SkipResult, AqlItemBlockInputMatrix> AllRowsFetcher::execute(AqlCallStack& stack) {
if (!stack.isRelevant()) {
auto [state, skipped, block] = _dependencyProxy->execute(stack);
return {state, skipped, AqlItemBlockInputMatrix{block}};
}
TRI_ASSERT(stack.peek().getOffset() == 0);
TRI_ASSERT(!stack.peek().needsFullCount());
// We allow a 0 hardLimit for bypassing
Expand Down
264 changes: 264 additions & 0 deletions arangod/Aql/AqlCallList.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2019 ArangoDB GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Michael Hackstein
////////////////////////////////////////////////////////////////////////////////

#include "AqlCallList.h"

#include "Basics/StaticStrings.h"
#include "Basics/voc-errors.h"
#include "Containers/Enumerate.h"
#include "Logger/LogMacros.h"
#include "Logger/Logger.h"

#include <velocypack/Builder.h>
#include <velocypack/Collection.h>
#include <velocypack/Slice.h>
#include <velocypack/velocypack-aliases.h>

#include <iostream>
#include <map>
#include <string_view>

using namespace arangodb;
using namespace arangodb::aql;

namespace {
// hack for MSVC
auto getStringView(VPackSlice slice) -> std::string_view {
velocypack::StringRef ref = slice.stringRef();
return std::string_view(ref.data(), ref.size());
}
} // namespace

AqlCallList::AqlCallList(AqlCall const& call) : _specificCalls{call} {}

AqlCallList::AqlCallList(AqlCall const& specificCall, AqlCall const& defaultCall)
: _specificCalls{specificCall}, _defaultCall{defaultCall} {}

[[nodiscard]] auto AqlCallList::popNextCall() -> AqlCall {
TRI_ASSERT(hasMoreCalls());
if (!_specificCalls.empty()) {
// We only implemented for a single given call.
TRI_ASSERT(_specificCalls.size() == 1);
auto res = _specificCalls.back();
_specificCalls.pop_back();
return res;
}
TRI_ASSERT(_defaultCall.has_value());
return _defaultCall.value();
}

[[nodiscard]] auto AqlCallList::peekNextCall() const -> AqlCall const& {
TRI_ASSERT(hasMoreCalls());
if (!_specificCalls.empty()) {
// We only implemented for a single given call.
TRI_ASSERT(_specificCalls.size() == 1);
return _specificCalls.back();
}
TRI_ASSERT(_defaultCall.has_value());
return _defaultCall.value();
}

[[nodiscard]] auto AqlCallList::hasMoreCalls() const noexcept -> bool {
return !_specificCalls.empty() || _defaultCall.has_value();
}

[[nodiscard]] auto AqlCallList::modifyNextCall() -> AqlCall& {
TRI_ASSERT(hasMoreCalls());
if (_specificCalls.empty()) {
TRI_ASSERT(_defaultCall.has_value());
// We need to emplace a copy of defaultCall into the specific calls
// This can then be modified and eventually be consumed
_specificCalls.emplace_back(_defaultCall.value());
}
return _specificCalls.back();
}

auto AqlCallList::fromVelocyPack(VPackSlice slice) -> ResultT<AqlCallList> {
if (ADB_UNLIKELY(!slice.isObject())) {
using namespace std::string_literals;
return Result(TRI_ERROR_TYPE_ERROR,
"When deserializating AqlCallList: Expected object, got "s +
slice.typeName());
}

auto expectedPropertiesFound = std::map<std::string_view, bool>{};
expectedPropertiesFound.emplace(StaticStrings::AqlCallListSpecific, false);
expectedPropertiesFound.emplace(StaticStrings::AqlCallListDefault, false);

auto const readSpecific = [](velocypack::Slice slice) -> ResultT<std::vector<AqlCall>> {
if (ADB_UNLIKELY(!slice.isArray())) {
auto message = std::string{"When deserializating AqlCall: When reading " +
StaticStrings::AqlCallListSpecific +
": "
"Unexpected type "};
message += slice.typeName();
return Result(TRI_ERROR_TYPE_ERROR, std::move(message));
}
std::vector<AqlCall> res;
res.reserve(slice.length());
for (auto const& c : VPackArrayIterator(slice)) {
auto maybeAqlCall = AqlCall::fromVelocyPack(c);
if (ADB_UNLIKELY(maybeAqlCall.fail())) {
auto message = std::string{"When deserializing AqlCallList: entry "};
message += std::to_string(res.size());
message += ": ";
message += std::move(maybeAqlCall).errorMessage();
return Result(TRI_ERROR_TYPE_ERROR, std::move(message));
}
res.emplace_back(maybeAqlCall.get());
}
return res;
};

auto const readDefault = [](velocypack::Slice slice) -> ResultT<std::optional<AqlCall>> {
if (ADB_UNLIKELY(!slice.isObject() && !slice.isNull())) {
auto message =
std::string{"When deserializating AqlCallList: When reading " +
StaticStrings::AqlCallListDefault +
": "
"Unexpected type "};
message += slice.typeName();
return Result(TRI_ERROR_TYPE_ERROR, std::move(message));
}
if (slice.isNull()) {
return {std::nullopt};
}
auto maybeAqlCall = AqlCall::fromVelocyPack(slice);
if (ADB_UNLIKELY(maybeAqlCall.fail())) {
auto message = std::string{"When deserializing AqlCallList: default "};
message += std::move(maybeAqlCall).errorMessage();
return Result(TRI_ERROR_TYPE_ERROR, std::move(message));
}
return {std::move(maybeAqlCall.get())};
};

AqlCallList result{AqlCall{}};

for (auto const it : velocypack::ObjectIterator(slice)) {
auto const keySlice = it.key;
if (ADB_UNLIKELY(!keySlice.isString())) {
return Result(TRI_ERROR_TYPE_ERROR,
"When deserializating AqlCallList: Key is not a string");
}
auto const key = getStringView(keySlice);

if (auto propIt = expectedPropertiesFound.find(key);
ADB_LIKELY(propIt != expectedPropertiesFound.end())) {
if (ADB_UNLIKELY(propIt->second)) {
return Result(
TRI_ERROR_TYPE_ERROR,
"When deserializating AqlCallList: Encountered duplicate key");
}
propIt->second = true;
}

if (key == StaticStrings::AqlCallListSpecific) {
auto maybeCalls = readSpecific(it.value);
if (maybeCalls.fail()) {
return std::move(maybeCalls).result();
}
result._specificCalls = maybeCalls.get();
} else if (key == StaticStrings::AqlCallListDefault) {
auto maybeCall = readDefault(it.value);
if (maybeCall.fail()) {
return std::move(maybeCall).result();
}
result._defaultCall = maybeCall.get();
} else {
LOG_TOPIC("c30c1", WARN, Logger::AQL)
<< "When deserializating AqlCallList: Encountered unexpected key " << key;
// If you run into this assertion during rolling upgrades after adding a
// new attribute, remove it in the older version.
TRI_ASSERT(false);
}
}

for (auto const& it : expectedPropertiesFound) {
if (ADB_UNLIKELY(!it.second)) {
auto message = std::string{"When deserializating AqlCall: missing key "};
message += it.first;
return Result(TRI_ERROR_TYPE_ERROR, std::move(message));
}
}

return result;
}

auto AqlCallList::toVelocyPack(VPackBuilder& builder) const -> void {
// We need to have something that is serializable
TRI_ASSERT(hasMoreCalls());
builder.openObject();
builder.add(VPackValue(StaticStrings::AqlCallListSpecific));

{
builder.openArray();
for (auto const& call : _specificCalls) {
call.toVelocyPack(builder);
}
builder.close();
}
builder.add(VPackValue(StaticStrings::AqlCallListDefault));
if (_defaultCall.has_value()) {
_defaultCall.value().toVelocyPack(builder);
} else {
builder.add(VPackSlice::nullSlice());
}

builder.close();
}

auto AqlCallList::toString() const -> std::string {
auto stream = std::stringstream{};
stream << *this;
return stream.str();
}

bool arangodb::aql::operator==(AqlCallList const& left, AqlCallList const& right) {
if (left._specificCalls.size() != right._specificCalls.size()) {
return false;
}
// Sorry call does not implement operator!=
if (!(left._defaultCall == right._defaultCall)) {
return false;
}
for (auto const& [index, call] : enumerate(left._specificCalls)) {
if (!(call == right._specificCalls[index])) {
return false;
}
}
return true;
}

auto arangodb::aql::operator<<(std::ostream& out, AqlCallList const& list) -> std::ostream& {
out << "specific: [ ";
for (auto const& [index, call] : enumerate(list._specificCalls)) {
if (index > 0) {
out << ", ";
}
out << call;
}
out << " ]";
if (list._defaultCall.has_value()) {
out << " default: " << list._defaultCall.value();
}
return out;
}
Loading
0