@@ -259,11 +259,9 @@ struct AggregatorSum final : public Aggregator {
259
259
return AqlValue (AqlValueHintNull ());
260
260
}
261
261
262
- builder.clear ();
263
- builder.add (VPackValue (sum));
264
- AqlValue temp (builder.slice ());
262
+ double v = sum;
265
263
reset ();
266
- return temp ;
264
+ return AqlValue ( AqlValueHintDouble (v)) ;
267
265
}
268
266
269
267
double sum;
@@ -343,6 +341,8 @@ struct AggregatorAverageStep1 final : public AggregatorAverage {
343
341
reset ();
344
342
return temp;
345
343
}
344
+
345
+ arangodb::velocypack::Builder builder;
346
346
};
347
347
348
348
// / @brief the coordinator variant of AVERAGE, aggregating partial sums and counts
@@ -475,6 +475,8 @@ struct AggregatorVarianceBaseStep1 final : public AggregatorVarianceBase {
475
475
reset ();
476
476
return temp;
477
477
}
478
+
479
+ arangodb::velocypack::Builder builder;
478
480
};
479
481
480
482
// / @brief the coordinator variant of VARIANCE
@@ -663,6 +665,7 @@ struct AggregatorUnique : public Aggregator {
663
665
664
666
MemoryBlockAllocator allocator;
665
667
std::unordered_set<velocypack::Slice, basics::VelocyPackHelper::VPackHash, basics::VelocyPackHelper::VPackEqual> seen;
668
+ arangodb::velocypack::Builder builder;
666
669
};
667
670
668
671
// / @brief the coordinator variant of UNIQUE
@@ -740,6 +743,7 @@ struct AggregatorSortedUnique : public Aggregator {
740
743
741
744
MemoryBlockAllocator allocator;
742
745
std::set<velocypack::Slice, basics::VelocyPackHelper::VPackLess<true >> seen;
746
+ arangodb::velocypack::Builder builder;
743
747
};
744
748
745
749
// / @brief the coordinator variant of SORTED_UNIQUE
@@ -804,6 +808,7 @@ struct AggregatorCountDistinct : public Aggregator {
804
808
805
809
MemoryBlockAllocator allocator;
806
810
std::unordered_set<velocypack::Slice, basics::VelocyPackHelper::VPackHash, basics::VelocyPackHelper::VPackEqual> seen;
811
+ arangodb::velocypack::Builder builder;
807
812
};
808
813
809
814
// / @brief the coordinator variant of COUNT_DISTINCT
@@ -1000,13 +1005,11 @@ std::unordered_map<std::string, std::string> const aliases = {
1000
1005
1001
1006
std::unique_ptr<Aggregator> Aggregator::fromTypeString (transaction::Methods* trx,
1002
1007
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 );
1004
1011
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);
1010
1013
}
1011
1014
1012
1015
std::unique_ptr<Aggregator> Aggregator::fromVPack (transaction::Methods* trx,
@@ -1020,6 +1023,16 @@ std::unique_ptr<Aggregator> Aggregator::fromVPack(transaction::Methods* trx,
1020
1023
THROW_ARANGO_EXCEPTION_MESSAGE (TRI_ERROR_INTERNAL, " invalid aggregator type" );
1021
1024
}
1022
1025
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
+
1023
1036
std::string Aggregator::translateAlias (std::string const & name) {
1024
1037
auto it = ::aliases.find (name);
1025
1038
0 commit comments