8000 Feature/aql subquery execution block impl execute implementation by mchacki · Pull Request #10606 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Feature/aql subquery execution block impl execute implementation #10606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
160 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
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
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
3b4b517
Added CHANGELOG entry
mchacki Mar 13, 2020
7878f52
Merge branch 'devel' into feature/AqlSubqueryExecutionBlockImplExecut…
mchacki Mar 13, 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
Prev Previous commit
Next Next commit
Feature/aql subquery operations stack aql item block input matrix (#1…
…1167)

* added new file to cmakelist

* added new method skipAllRemainingDataRows

* added first implementation of execute - AllRowsFetcher

* impl is now using skipAllRemainingDataRows method, also execute methods now using Fetcher::DataRange instead of inputRange

* impl is now using skipAllRemainingDataRows method, also execute methods now using Fetcher::DataRange instead of inputRange - header file

* AllRowsFetcher now using AqlItemBlockInputMatrix as DataRange, first implementation of execute

* first implementation of AqlItemBlockInputMatrix

* more cleanup

* optimized execut elogic

* optimized logic in inputmatrix, still a few todos left

* added SortExecutor as newStyle

* added produceRows and skipRows

* logs (to be removed), skipAllRemainingRows

* logs

* inputMatrix

* changed return type of skipAllRemainingDataRows

* impl logs

* logs, added clear method

* sort test

* typo, log

* latest changes

* cleanup, assert

* rm logs

* added more todos

* todo

* new method names, compile again

* Reset ExecutorReturnedDone for SubqueryStart and SubqueryEnd.

* InputMatrix needs to return state DONE on every input request. It guarantees that we have all input

* Removed invalid Assertion, and removed early return if output is full.

* Removed DebugLogging from CalculationTest

* Fixed skipping in SortExecutor

* Fixed upstreamState return of AqlItemMatrix. It is only finalState iff there is no data

* Let the InputMatrix drop all rows after FullCount

* Allow bypassing with hardLimit 0 in InputMatrix

* Disabled the old-code assertion. This way the SortExecutor tests we have will be red, but not crash, allowing the jenkins to produce meaningfull results

* Fix assert in WAITING case

* Add rudimentary sort executor GTests

* Fixed assertion on InputMatrix that starts right away with a shadowRow

* Removed declared but not implemented function

* changed from: peekDataRowAndState -> to: peekDataRow

Co-authored-by: Michael Hackstein <michael@arangodb.com>
  • Loading branch information
hkernbach and mchacki authored Feb 28, 2020
commit a0d6ec193f02203e44e2270be0146d8aa5147b86
47 changes: 47 additions & 0 deletions arangod/Aql/AllRowsFetcher.cpp
10000
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
////////////////////////////////////////////////////////////////////////////////

#include "AllRowsFetcher.h"
#include <Logger/LogMacros.h>

#include "Aql/AqlItemBlock.h"
#include "Aql/AqlItemMatrix.h"
Expand Down Expand Up @@ -59,6 +60,52 @@ std::pair<ExecutionState, AqlItemMatrix const*> AllRowsFetcher::fetchAllRows() {
return {ExecutionState::DONE, nullptr};
}

std::tuple<ExecutionState, size_t, 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
// bot otherwise we do not allow any limit
TRI_ASSERT(!stack.peek().hasHardLimit() || stack.peek().getLimit() == 0);
TRI_ASSERT(!stack.peek().hasSoftLimit());

if (_aqlItemMatrix == nullptr) {
_aqlItemMatrix = std::make_unique<AqlItemMatrix>(getNrInputRegisters());
}
// We can only execute More if we are not Stopped yet.
TRI_ASSERT(!_aqlItemMatrix->stoppedOnShadowRow());
while (true) {
auto [state, skipped, block] = _dependencyProxy->execute(stack);
TRI_ASSERT(skipped == 0);

// we will either build a complete fetched AqlItemBlockInputMatrix or return an empty one
if (state == ExecutionState::WAITING) {
TRI_ASSERT(block == nullptr);
// On waiting we have nothing to return
return {state, 0, AqlItemBlockInputMatrix{ExecutorState::HASMORE}};
}
TRI_ASSERT(block != nullptr || state == ExecutionState::DONE);

if (block != nullptr) {
// we need to store the block for later creation of AqlItemBlockInputMatrix
_aqlItemMatrix->addBlock(std::move(block));
}

// If we find a ShadowRow or ExecutionState == Done, we're done fetching.
if (_aqlItemMatrix->stoppedOnShadowRow() || state == ExecutionState::DONE) {
if (state == ExecutionState::HASMORE) {
return {state, 0,
AqlItemBlockInputMatrix{ExecutorState::HASMORE, _aqlItemMatrix.get()}};
}
return {state, 0,
AqlItemBlockInputMatrix{ExecutorState::DONE, _aqlItemMatrix.get()}};
}
}
}

std::pair<ExecutionState, InputAqlItemRow> AllRowsFetcher::fetchRow(size_t atMost) {
switch (_dataFetchedState) {
case ALL_DATA_FETCHED:
Expand Down
25 changes: 15 additions & 10 deletions arangod/Aql/AllRowsFetcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
#include <cstddef>
#include <memory>

// TODO REMOVE ME TEMPORARY
#include "Aql/AqlItemBlockInputRange.h"
#include "Aql/AqlItemBlockInputMatrix.h"

namespace arangodb {
namespace aql {
Expand Down Expand Up @@ -90,22 +89,28 @@ class AllRowsFetcher {

public:
explicit AllRowsFetcher(DependencyProxy<BlockPassthrough::Disable>& executionBlock);

TEST_VIRTUAL ~AllRowsFetcher() = default;

// TODO FIXME, this Range does not work here.
using DataRange = AqlItemBlockInputRange;
using DataRange = AqlItemBlockInputMatrix;

protected:
// only for testing! Does not initialize _dependencyProxy!
AllRowsFetcher() = default;

public:
// TODO implement and document
std::tuple<ExecutionState, size_t, DataRange> execute(/* TODO: add"justDoIt"-style parameter */) {
TRI_ASSERT(false);
THROW_ARANGO_EXCEPTION(TRI_ERROR_NOT_IMPLEMENTED);
}
/**
* @brief Execute the given call stack
*
* @param stack Call stack, on top of stack there is current subquery, bottom is the main query.
* @return std::tuple<ExecutionState, size_t, DataRange>
* ExecutionState => DONE, all queries are done, there will be no more
* ExecutionState => HASMORE, there are more results for queries, might be on other subqueries
* ExecutionState => WAITING, we need to do I/O to solve the request, save local state and return WAITING to caller immediately
*
* size_t => Amount of documents skipped
* DataRange => Resulting data
*/
std::tuple<ExecutionState, size_t, DataRange> execute(AqlCallStack& stack);

/**
* @brief Fetch one new AqlItemRow from upstream.
Expand Down
142 changes: 142 additions & 0 deletions arangod/Aql/AqlItemBlockInputMatrix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
////////////////////////////////////////////////////////////////////////////////
/// 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 Tobias Gödderz
////////////////////////////////////////////////////////////////////////////////

#include "AqlItemBlockInputMatrix.h"
#include "Aql/ShadowAqlItemRow.h"

#include <Logger/LogMacros.h>
#include <velocypack/Builder.h>
#include <velocypack/velocypack-aliases.h>
#include <numeric>

using namespace arangodb;
using namespace arangodb::aql;

AqlItemBlockInputMatrix::AqlItemBlockInputMatrix(ExecutorState state)
: _finalState{state}, _aqlItemMatrix{nullptr} {
TRI_ASSERT(_aqlItemMatrix == nullptr);
TRI_ASSERT(!hasDataRow());
}

// only used for block passthrough
AqlItemBlockInputMatrix::AqlItemBlockInputMatrix(arangodb::aql::SharedAqlItemBlockPtr const& block)
: _block{block}, _aqlItemMatrix{nullptr} {
TRI_ASSERT(_aqlItemMatrix == nullptr);
TRI_ASSERT(!hasDataRow());
}

AqlItemBlockInputMatrix::AqlItemBlockInputMatrix(ExecutorState state, AqlItemMatrix* aqlItemMatrix)
: _finalState{state}, _aqlItemMatrix{aqlItemMatrix} {
TRI_ASSERT(_block == nullptr);
TRI_ASSERT(_aqlItemMatrix != nullptr);
if (_aqlItemMatrix->size() == 0 && _aqlItemMatrix->stoppedOnShadowRow()) {
// Fast forward to initialize the _shadowRow
skipAllRemainingDataRows();
}
}

SharedAqlItemBlockPtr AqlItemBlockInputMatrix::getBlock() const noexcept {
TRI_ASSERT(_aqlItemMatrix == nullptr);
return _block;
}

std::pair<ExecutorState, AqlItemMatrix const*> AqlItemBlockInputMatrix::getMatrix() noexcept {
TRI_ASSERT(_aqlItemMatrix != nullptr);
TRI_ASSERT(_block == nullptr);
TRI_ASSERT(!_shadowRow.isInitialized());

// We are always done. This InputMatrix
// guarantees that we have all data in our hand at once.
return {ExecutorState::DONE, _aqlItemMatrix};
}

ExecutorState AqlItemBlockInputMatrix::upstreamState() const noexcept {
if (hasDataRow() || hasShadowRow()) {
return ExecutorState::DONE;
}
return _finalState;
}

bool AqlItemBlockInputMatrix::upstreamHasMore() const noexcept {
return upstreamState() == ExecutorState::HASMORE;
}

bool AqlItemBlockInputMatrix::hasDataRow() const noexcept {
if (_aqlItemMatrix == nullptr) {
return false;
}
return (!_shadowRow.isInitialized() && _aqlItemMatrix->size() != 0);
}

std::pair<ExecutorState, ShadowAqlItemRow> AqlItemBlockInputMatrix::nextShadowRow() {
auto tmpShadowRow = _shadowRow;

if (_aqlItemMatrix->size() == 0 && _aqlItemMatrix->stoppedOnShadowRow() &&
!_aqlItemMatrix->peekShadowRow().isRelevant()) {
// next row will be a shadow row
_shadowRow = _aqlItemMatrix->popShadowRow();
} else {
_shadowRow = ShadowAqlItemRow{CreateInvalidShadowRowHint()};
}

auto state = ExecutorState::HASMORE;
if (_shadowRow.isInitialized()) {
TRI_ASSERT(!_shadowRow.isRelevant());
state = ExecutorState::HASMORE;
} else if (_aqlItemMatrix->stoppedOnShadowRow() &&
_aqlItemMatrix->peekShadowRow().isRelevant()) {
state = ExecutorState::DONE;
} else {
state = _finalState;
}

return {state, tmpShadowRow};
}

ShadowAqlItemRow AqlItemBlockInputMatrix::peekShadowRow() const {
return _shadowRow;
}

bool AqlItemBlockInputMatrix::hasShadowRow() const noexcept {
return _shadowRow.isInitialized();
}

void AqlItemBlockInputMatrix::skipAllRemainingDataRows() {
if (_aqlItemMatrix == nullptr) {
// Have not been initialized.
// We need to be called before.
TRI_ASSERT(!hasShadowRow());
TRI_ASSERT(!hasDataRow());
return;
}
if (!hasShadowRow()) {
if (_aqlItemMatrix->stoppedOnShadowRow()) {
_shadowRow = _aqlItemMatrix->popShadowRow();
TRI_ASSERT(_shadowRow.isRelevant());
} else {
TRI_ASSERT(_finalState == ExecutorState::DONE);
_aqlItemMatrix->clear();
}
}
// Else we did already skip once.
// nothing to do
}
67 changes: 67 additions & 0 deletions arangod/Aql/AqlItemBlockInputMatrix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
////////////////////////////////////////////////////////////////////////////////
/// 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 Tobias Gödderz
////////////////////////////////////////////////////////////////////////////////

#ifndef ARANGOD_AQL_AQLITEMBLOCKMATRIXITERATOR_H
#define ARANGOD_AQL_AQLITEMBLOCKMATRIXITERATOR_H

#include "Aql/AqlItemMatrix.h"
#include "Aql/ExecutionState.h"
#include "Aql/InputAqlItemRow.h"
#include "Aql/SharedAqlItemBlockPtr.h"

namespace arangodb::aql {

class ShadowAqlItemRow;

class AqlItemBlockInputMatrix {
public:
explicit AqlItemBlockInputMatrix(ExecutorState state);

AqlItemBlockInputMatrix(arangodb::aql::SharedAqlItemBlockPtr const&);

AqlItemBlockInputMatrix(ExecutorState state, AqlItemMatrix* aqlItemMatrix);

std::pair<ExecutorState, ShadowAqlItemRow> nextShadowRow();
ShadowAqlItemRow peekShadowRow() const;
bool hasShadowRow() const noexcept;
bool hasDataRow() const noexcept;

arangodb::aql::SharedAqlItemBlockPtr getBlock() const noexcept;
std::pair<ExecutorState, AqlItemMatrix const*> getMatrix() noexcept;

ExecutorState upstreamState() const noexcept;
bool upstreamHasMore() const noexcept;
void skipAllRemainingDataRows();

private:
arangodb::aql::SharedAqlItemBlockPtr _block{nullptr};
ExecutorState _finalState{ExecutorState::HASMORE};

// Only if _aqlItemMatrix is set (and NOT a nullptr), we have a valid and usable
// DataRange object available to work with.
AqlItemMatrix* _aqlItemMatrix;
ShadowAqlItemRow _shadowRow{CreateInvalidShadowRowHint{}};
};

} // namespace arangodb::aql

#endif // ARANGOD_AQL_AQLITEMBLOCKINPUTITERATOR_H
22 changes: 20 additions & 2 deletions arangod/Aql/AqlItemBlockInputRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ bool AqlItemBlockInputRange::hasDataRow() const noexcept {
return isIndexValid(_rowIndex) && !isShadowRowAtIndex(_rowIndex);
}

// TODO: Implement peekDataRow (without state). e.g. IResearchViewExecutor does not need the state!
std::pair<ExecutorState, InputAqlItemRow> AqlItemBlockInputRange::peekDataRow() const {
if (hasDataRow()) {
return std::make_pair(nextState<LookAhead::NEXT, RowType::DATA>(),
Expand Down Expand Up @@ -95,7 +96,14 @@ bool AqlItemBlockInputRange::isShadowRowAtIndex(std::size_t index) const noexcep
return _block->isShadowRow(index);
}

std::pair<ExecutorState, ShadowAqlItemRow> AqlItemBlockInputRange::peekShadowRow() const {
arangodb::aql::ShadowAqlItemRow AqlItemBlockInputRange::peekShadowRow() const {
if (hasShadowRow()) {
return ShadowAqlItemRow{_block, _rowIndex};
}
return ShadowAqlItemRow{CreateInvalidShadowRowHint{}};
}

std::pair<ExecutorState, ShadowAqlItemRow> AqlItemBlockInputRange::peekShadowRowAndState() const {
if (hasShadowRow()) {
return std::make_pair(nextState<LookAhead::NEXT, RowType::SHADOW>(),
ShadowAqlItemRow{_block, _rowIndex});
Expand All @@ -105,14 +113,24 @@ std::pair<ExecutorState, ShadowAqlItemRow> AqlItemBlockInputRange::peekShadowRow
}

std::pair<ExecutorState, ShadowAqlItemRow> AqlItemBlockInputRange::nextShadowRow() {
auto res = peekShadowRow();
auto res = peekShadowRowAndState();
if (res.second.isInitialized()) {
// Advance the current row.
_rowIndex++;
}
return res;
}

void AqlItemBlockInputRange::skipAllRemainingDataRows() {
ExecutorState state;
InputAqlItemRow row{CreateInvalidInputRowHint{}};

while (hasDataRow()) {
std::tie(state, row) = nextDataRow();
TRI_ASSERT(row.isInitialized());
}
}

template <AqlItemBlockInputRange::LookAhead doPeek, AqlItemBlockInputRange::RowType type>
ExecutorState AqlItemBlockInputRange::nextState() const noexcept {
size_t testRowIndex = _rowIndex;
Expand Down
5 changes: 4 additions & 1 deletion arangod/Aql/AqlItemBlockInputRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ class AqlItemBlockInputRange {

bool hasShadowRow() const noexcept;

std::pair<ExecutorState, arangodb::aql::ShadowAqlItemRow> peekShadowRow() const;
arangodb::aql::ShadowAqlItemRow peekShadowRow() const;
std::pair<ExecutorState, arangodb::aql::ShadowAqlItemRow> peekShadowRowAndState() const;

std::pair<ExecutorState, arangodb::aql::ShadowAqlItemRow> nextShadowRow();

void skipAllRemainingDataRows();

// Subtract up to this many rows from the local `_skipped` state; return
// the number actually skipped. Does not skip data rows.
[[nodiscard]] auto skip(std::size_t) noexcept -> std::size_t;
Expand Down
Loading
0