agg_merge_impl.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. #pragma once
  6. #include <algorithm>
  7. #include <cstddef>
  8. #include <memory>
  9. #include <unordered_map>
  10. #include "rocksdb/merge_operator.h"
  11. #include "rocksdb/slice.h"
  12. #include "rocksdb/utilities/agg_merge.h"
  13. #include "utilities/cassandra/cassandra_options.h"
  14. namespace ROCKSDB_NAMESPACE {
  15. class AggMergeOperator : public MergeOperator {
  16. public:
  17. explicit AggMergeOperator();
  18. bool FullMergeV2(const MergeOperationInput& merge_in,
  19. MergeOperationOutput* merge_out) const override;
  20. bool PartialMergeMulti(const Slice& key,
  21. const std::deque<Slice>& operand_list,
  22. std::string* new_value, Logger* logger) const override;
  23. const char* Name() const override { return kClassName(); }
  24. static const char* kClassName() { return "AggMergeOperator.v1"; }
  25. bool AllowSingleOperand() const override { return true; }
  26. bool ShouldMerge(const std::vector<Slice>&) const override { return false; }
  27. private:
  28. class Accumulator;
  29. // Pack all merge operands into one value. This is called when aggregation
  30. // fails. The existing values are preserved and returned so that users can
  31. // debug the problem.
  32. static void PackAllMergeOperands(const MergeOperationInput& merge_in,
  33. MergeOperationOutput& merge_out);
  34. static Accumulator& GetTLSAccumulator();
  35. };
  36. std::string EncodeAggFuncAndPayloadNoCheck(const Slice& function_name,
  37. const Slice& value);
  38. } // namespace ROCKSDB_NAMESPACE