8000 Feature/aql item block compression (#6514) · CoericK/arangodb@f8aae28 · GitHub
[go: up one dir, main page]

10000
Skip to content

Commit f8aae28

Browse files
authored
Feature/aql item block compression (arangodb#6514)
1 parent 65fff00 commit f8aae28

File tree

6 files changed

+279
-157
lines changed

6 files changed

+279
-157
lines changed

arangod/Aql/Aggregator.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,9 @@ struct AggregatorSum final : public Aggregator {
259259
return AqlValue(AqlValueHintNull());
260260
}
261261

262-
builder.clear();
263-
builder.add(VPackValue(sum));
264-
AqlValue temp(builder.slice());
262+
double v = sum;
265263
reset();
266-
return temp;
264+
return AqlValue(AqlValueHintDouble(v));
267265
}
268266

269267
double sum;
@@ -343,6 +341,8 @@ struct AggregatorAverageStep1 final : public AggregatorAverage {
343341
reset();
344342
return temp;
345343
}
344+
345+
arangodb::velocypack::Builder builder;
346346
};
347347

348348
/// @brief the coordinator variant of AVERAGE, aggregating partial sums and counts
@@ -475,6 +475,8 @@ struct AggregatorVarianceBaseStep1 final : public AggregatorVarianceBase {
475475
reset();
476476
return temp;
477477
}
478+
479+
arangodb::velocypack::Builder builder;
478480
};
479481

480482
/// @brief the coordinator variant of VARIANCE
@@ -663,6 +665,7 @@ struct AggregatorUnique : public Aggregator {
663665

664666
MemoryBlockAllocator allocator;
665667
std::unordered_set<velocypack::Slice, basics::VelocyPackHelper::VPackHash, basics::VelocyPackHelper::VPackEqual> seen;
668+
arangodb::velocypack::Builder builder;
666669
};
667670

668671
/// @brief the coordinator variant of UNIQUE
@@ -740,6 +743,7 @@ struct AggregatorSortedUnique : public Aggregator {
740743

741744
MemoryBlockAllocator allocator;
742745
std::set<velocypack::Slice, basics::VelocyPackHelper::VPackLess<true>> seen;
746+
arangodb::velocypack::Builder builder;
743747
};
744748

745749
/// @brief the coordinator variant of SORTED_UNIQUE
@@ -804,6 +808,7 @@ struct AggregatorCountDistinct : public Aggregator {
804808

805809
MemoryBlockAllocator allocator;
806810
std::unordered_set<velocypack::Slice, basics::VelocyPackHelper::VPackHash, basics::VelocyPackHelper::VPackEqual> seen;
811+
arangodb::velocypack::Builder builder;
807812
};
808813

809814
/// @brief the coordinator variant of COUNT_DISTINCT
@@ -1000,13 +1005,11 @@ std::unordered_map<std::string, std::string> const aliases = {
10001005

10011006
std::unique_ptr<Aggregator> Aggregator::fromTypeString(transaction::Methods* trx,
10021007
std::string const& type) {
1003-
auto it = ::aggregators.find(translateAlias(type));
1008+
// will always return a valid generator function or throw an exception
1009+
auto generator = Aggregator::factoryFromTypeString(type);
1010+
TRI_ASSERT(generator != nullptr);
10041011

1005-
if (it != ::aggregators.end()) {
1006-
return (*it).second.generator(trx);
1007-
}
1008-
// aggregator function name should have been validated before
1009-
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, "invalid aggregator type");
1012+
return (*generator)(trx);
10101013
}
10111014

10121015
std::unique_ptr<Aggregator> Aggregator::fromVPack(transaction::Methods* trx,
@@ -1020,6 +1023,16 @@ std::unique_ptr<Aggregator> Aggregator::fromVPack(transaction::Methods* trx,
10201023
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, "invalid aggregator type");
10211024
}
10221025

1026+
std::function<std::unique_ptr<Aggregator>(transaction::Methods*)> const* Aggregator::factoryFromTypeString(std::string const& type) {
1027+
auto it = ::aggregators.find(translateAlias(type));
1028+
1029+
if (it != ::aggregators.end()) {
1030+
return &((*it).second.generator);
1031+
}
1032+
// aggregator function name should have been validated before
1033+
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, "invalid aggregator type");
1034+
}
1035+
10231036
std::string Aggregator::translateAlias(std::string const& name) {
10241037
auto it = ::aliases.find(name);
10251038

arangod/Aql/Aggregator.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "Basics/Common.h"
2828
#include "Aql/AqlValue.h"
2929

30-
#include <velocypack/Builder.h>
3130
#include <velocypack/Slice.h>
3231

3332
namespace arangodb {
@@ -51,10 +50,14 @@ struct Aggregator {
5150
/// @brief creates an aggregator from a name string
5251
static std::unique_ptr<Aggregator> fromTypeString(transaction::Methods*,
5352
std::string const& type);
54-
53+
5554
/// @brief creates an aggregator from a velocypack slice
5655
static std::unique_ptr<Aggregator> fromVPack(transaction::Methods*,
5756
arangodb::velocypack::Slice const&, char const* nameAttribute);
57+
58+
/// @brief return a pointer to an aggregator factory for an aggregator type
59+
/// throws if the aggregator cannot be found
60+
static std::function<std::unique_ptr<Aggregator>(transaction::Methods*)> const* factoryFromTypeString(std::string const& type);
5861

5962
/// @brief translates an alias to an actual aggregator name
6063
/// returns the original value if the name was not an alias
@@ -87,8 +90,6 @@ struct Aggregator {
8790

8891
protected:
8992
transaction::Methods* trx;
90-
91-
arangodb::velocypack::Builder builder;
9293
};
9394

9495
} // namespace arangodb::aql

0 commit comments

Comments
 (0)
0