summaryrefslogtreecommitdiff
path: root/src/mongo/db/timeseries/metadata.cpp
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
commit4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch)
tree1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/db/timeseries/metadata.cpp
parentaa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff)
parent8f0827553e09872941945a093b647a4211a9db7f (diff)
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0' with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/db/timeseries/metadata.cpp')
-rw-r--r--src/mongo/db/timeseries/metadata.cpp123
1 files changed, 0 insertions, 123 deletions
diff --git a/src/mongo/db/timeseries/metadata.cpp b/src/mongo/db/timeseries/metadata.cpp
deleted file mode 100644
index a62e15685e9..00000000000
--- a/src/mongo/db/timeseries/metadata.cpp
+++ /dev/null
@@ -1,123 +0,0 @@
-/**
- * Copyright (C) 2022-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#include "mongo/db/timeseries/metadata.h"
-
-#include <boost/container/small_vector.hpp>
-
-namespace mongo::timeseries::metadata {
-namespace {
-
-void normalizeArray(const BSONObj& obj, BSONArrayBuilder& builder);
-void normalizeObject(const BSONObj& obj, BSONObjBuilder& builder);
-
-void normalizeArray(const BSONObj& obj, BSONArrayBuilder& builder) {
- for (auto& arrayElem : obj) {
- if (arrayElem.type() == BSONType::Array) {
- BSONArrayBuilder subArray = builder.subarrayStart();
- normalizeArray(arrayElem.Obj(), subArray);
- } else if (arrayElem.type() == BSONType::Object) {
- BSONObjBuilder subObject = builder.subobjStart();
- normalizeObject(arrayElem.Obj(), subObject);
- } else {
- builder.append(arrayElem);
- }
- }
-}
-
-void normalizeObject(const BSONObj& obj, BSONObjBuilder& builder) {
- // BSONObjIteratorSorted provides an abstraction similar to what this function does. However it
- // is using a lexical comparison that is slower than just doing a binary comparison of the field
- // names. That is all we need here as we are looking to create something that is binary
- // comparable no matter of field order provided by the user.
-
- // Helper that extracts the necessary data from a BSONElement that we can sort and re-construct
- // the same BSONElement from.
- struct Field {
- BSONElement element() const {
- return BSONElement(fieldName.rawData() - 1, // Include type byte before field name
- fieldName.size() + 1, // Include null terminator after field name
- totalSize);
- }
- bool operator<(const Field& rhs) const {
- return fieldName < rhs.fieldName;
- }
- StringData fieldName;
- int totalSize;
- };
-
- // Put all elements in a buffer, sort it and then continue normalize in sorted order
- auto num = obj.nFields();
- static constexpr std::size_t kNumStaticFields = 16;
- boost::container::small_vector<Field, kNumStaticFields> fields;
- fields.resize(num);
- BSONObjIterator bsonIt(obj);
- int i = 0;
- while (bsonIt.more()) {
- auto elem = bsonIt.next();
- fields[i++] = {elem.fieldNameStringData(), elem.size()};
- }
- auto it = fields.begin();
- auto end = fields.end();
- std::sort(it, end);
- for (; it != end; ++it) {
- auto elem = it->element();
- if (elem.type() == BSONType::Array) {
- BSONArrayBuilder subArray(builder.subarrayStart(elem.fieldNameStringData()));
- normalizeArray(elem.Obj(), subArray);
- } else if (elem.type() == BSONType::Object) {
- BSONObjBuilder subObject(builder.subobjStart(elem.fieldNameStringData()));
- normalizeObject(elem.Obj(), subObject);
- } else {
- builder.append(elem);
- }
- }
-}
-
-} // namespace
-
-void normalize(const BSONElement& elem, BSONObjBuilder& builder, boost::optional<StringData> as) {
- if (elem.type() == BSONType::Array) {
- BSONArrayBuilder subArray(
- builder.subarrayStart(as.has_value() ? as.value() : elem.fieldNameStringData()));
- normalizeArray(elem.Obj(), subArray);
- } else if (elem.type() == BSONType::Object) {
- BSONObjBuilder subObject(
- builder.subobjStart(as.has_value() ? as.value() : elem.fieldNameStringData()));
- normalizeObject(elem.Obj(), subObject);
- } else {
- if (as) {
- builder.appendAs(elem, as.value());
- } else {
- builder.append(elem);
- }
- }
-}
-
-} // namespace mongo::timeseries::metadata