summaryrefslogtreecommitdiff
path: root/src/mongo/db/index/expression_params.h
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2015-06-20 00:22:50 -0400
committerMark Benvenuto <mark.benvenuto@mongodb.com>2015-06-20 10:56:02 -0400
commit9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch)
tree3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/db/index/expression_params.h
parent01965cf52bce6976637ecb8f4a622aeb05ab256a (diff)
downloadmongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/db/index/expression_params.h')
-rw-r--r--src/mongo/db/index/expression_params.h269
1 files changed, 135 insertions, 134 deletions
diff --git a/src/mongo/db/index/expression_params.h b/src/mongo/db/index/expression_params.h
index e7b190f5eb9..a7613b027d3 100644
--- a/src/mongo/db/index/expression_params.h
+++ b/src/mongo/db/index/expression_params.h
@@ -34,150 +34,151 @@
namespace mongo {
- class ExpressionParams {
- public:
- static void parseTwoDParams(const BSONObj& infoObj, TwoDIndexingParams* out) {
- BSONObjIterator i(infoObj.getObjectField("key"));
-
- while (i.more()) {
- BSONElement e = i.next();
- if (e.type() == String && IndexNames::GEO_2D == e.valuestr()) {
- uassert(16800, "can't have 2 geo fields", out->geo.size() == 0);
- uassert(16801, "2d has to be first in index", out->other.size() == 0);
- out->geo = e.fieldName();
- } else {
- int order = 1;
- if (e.isNumber()) {
- order = static_cast<int>(e.Number());
- }
- out->other.push_back(std::make_pair(e.fieldName(), order));
+class ExpressionParams {
+public:
+ static void parseTwoDParams(const BSONObj& infoObj, TwoDIndexingParams* out) {
+ BSONObjIterator i(infoObj.getObjectField("key"));
+
+ while (i.more()) {
+ BSONElement e = i.next();
+ if (e.type() == String && IndexNames::GEO_2D == e.valuestr()) {
+ uassert(16800, "can't have 2 geo fields", out->geo.size() == 0);
+ uassert(16801, "2d has to be first in index", out->other.size() == 0);
+ out->geo = e.fieldName();
+ } else {
+ int order = 1;
+ if (e.isNumber()) {
+ order = static_cast<int>(e.Number());
}
+ out->other.push_back(std::make_pair(e.fieldName(), order));
}
-
- uassert(16802, "no geo field specified", out->geo.size());
-
- GeoHashConverter::Parameters hashParams;
- Status paramStatus = GeoHashConverter::parseParameters(infoObj, &hashParams);
- uassertStatusOK(paramStatus);
-
- out->geoHashConverter.reset(new GeoHashConverter(hashParams));
}
- static void parseHashParams(const BSONObj& infoObj,
- HashSeed* seedOut,
- int* versionOut,
- std::string* fieldOut) {
-
- // Default _seed to DEFAULT_HASH_SEED if "seed" is not included in the index spec
- // or if the value of "seed" is not a number
-
- // *** WARNING ***
- // Choosing non-default seeds will invalidate hashed sharding
- // Changing the seed default will break existing indexes and sharded collections
- if (infoObj["seed"].eoo()) {
- *seedOut = BSONElementHasher::DEFAULT_HASH_SEED;
- }
- else {
- *seedOut = infoObj["seed"].numberInt();
- }
-
- // In case we have hashed indexes based on other hash functions in the future, we store
- // a hashVersion number. If hashVersion changes, "makeSingleHashKey" will need to change
- // accordingly. Defaults to 0 if "hashVersion" is not included in the index spec or if
- // the value of "hashversion" is not a number
- *versionOut = infoObj["hashVersion"].numberInt();
-
- // Get the hashfield name
- BSONElement firstElt = infoObj.getObjectField("key").firstElement();
- massert(16765, "error: no hashed index field",
- firstElt.str().compare(IndexNames::HASHED) == 0);
- *fieldOut = firstElt.fieldName();
+ uassert(16802, "no geo field specified", out->geo.size());
+
+ GeoHashConverter::Parameters hashParams;
+ Status paramStatus = GeoHashConverter::parseParameters(infoObj, &hashParams);
+ uassertStatusOK(paramStatus);
+
+ out->geoHashConverter.reset(new GeoHashConverter(hashParams));
+ }
+
+ static void parseHashParams(const BSONObj& infoObj,
+ HashSeed* seedOut,
+ int* versionOut,
+ std::string* fieldOut) {
+ // Default _seed to DEFAULT_HASH_SEED if "seed" is not included in the index spec
+ // or if the value of "seed" is not a number
+
+ // *** WARNING ***
+ // Choosing non-default seeds will invalidate hashed sharding
+ // Changing the seed default will break existing indexes and sharded collections
+ if (infoObj["seed"].eoo()) {
+ *seedOut = BSONElementHasher::DEFAULT_HASH_SEED;
+ } else {
+ *seedOut = infoObj["seed"].numberInt();
}
- static void parseHaystackParams(const BSONObj& infoObj,
- std::string* geoFieldOut,
- std::vector<std::string>* otherFieldsOut,
- double* bucketSizeOut) {
-
- BSONElement e = infoObj["bucketSize"];
- uassert(16777, "need bucketSize", e.isNumber());
- *bucketSizeOut = e.numberDouble();
- uassert(16769, "bucketSize cannot be zero", *bucketSizeOut != 0.0);
-
- // Example:
- // db.foo.ensureIndex({ pos : "geoHaystack", type : 1 }, { bucketSize : 1 })
- BSONObjIterator i(infoObj.getObjectField("key"));
- while (i.more()) {
- BSONElement e = i.next();
- if (e.type() == String && IndexNames::GEO_HAYSTACK == e.valuestr()) {
- uassert(16770, "can't have more than one geo field", geoFieldOut->size() == 0);
- uassert(16771, "the geo field has to be first in index",
- otherFieldsOut->size() == 0);
- *geoFieldOut = e.fieldName();
- } else {
- uassert(16772, "geoSearch can only have 1 non-geo field for now",
- otherFieldsOut->size() == 0);
- otherFieldsOut->push_back(e.fieldName());
- }
+ // In case we have hashed indexes based on other hash functions in the future, we store
+ // a hashVersion number. If hashVersion changes, "makeSingleHashKey" will need to change
+ // accordingly. Defaults to 0 if "hashVersion" is not included in the index spec or if
+ // the value of "hashversion" is not a number
+ *versionOut = infoObj["hashVersion"].numberInt();
+
+ // Get the hashfield name
+ BSONElement firstElt = infoObj.getObjectField("key").firstElement();
+ massert(
+ 16765, "error: no hashed index field", firstElt.str().compare(IndexNames::HASHED) == 0);
+ *fieldOut = firstElt.fieldName();
+ }
+
+ static void parseHaystackParams(const BSONObj& infoObj,
+ std::string* geoFieldOut,
+ std::vector<std::string>* otherFieldsOut,
+ double* bucketSizeOut) {
+ BSONElement e = infoObj["bucketSize"];
+ uassert(16777, "need bucketSize", e.isNumber());
+ *bucketSizeOut = e.numberDouble();
+ uassert(16769, "bucketSize cannot be zero", *bucketSizeOut != 0.0);
+
+ // Example:
+ // db.foo.ensureIndex({ pos : "geoHaystack", type : 1 }, { bucketSize : 1 })
+ BSONObjIterator i(infoObj.getObjectField("key"));
+ while (i.more()) {
+ BSONElement e = i.next();
+ if (e.type() == String && IndexNames::GEO_HAYSTACK == e.valuestr()) {
+ uassert(16770, "can't have more than one geo field", geoFieldOut->size() == 0);
+ uassert(
+ 16771, "the geo field has to be first in index", otherFieldsOut->size() == 0);
+ *geoFieldOut = e.fieldName();
+ } else {
+ uassert(16772,
+ "geoSearch can only have 1 non-geo field for now",
+ otherFieldsOut->size() == 0);
+ otherFieldsOut->push_back(e.fieldName());
}
}
-
- static void parse2dsphereParams(const BSONObj& infoObj,
- S2IndexingParams* out) {
- // Set up basic params.
- out->maxKeysPerInsert = 200;
-
- // This is advisory.
- out->maxCellsInCovering = 50;
-
- // Near distances are specified in meters...sometimes.
- out->radius = kRadiusOfEarthInMeters;
-
- // These are not advisory.
- out->finestIndexedLevel = configValueWithDefaultInt(infoObj,
- "finestIndexedLevel",
- S2::kAvgEdge.GetClosestLevel(500.0 / out->radius));
-
- out->coarsestIndexedLevel = configValueWithDefaultInt(infoObj,
- "coarsestIndexedLevel",
- S2::kAvgEdge.GetClosestLevel(100 * 1000.0 / out->radius));
-
- static const std::string kIndexVersionFieldName("2dsphereIndexVersion");
-
- // Determine which version of this index we're using. If none was set in the descriptor,
- // assume S2_INDEX_VERSION_1 (alas, the first version predates the existence of the version
- // field).
- out->indexVersion = static_cast<S2IndexVersion>(configValueWithDefaultInt(infoObj,
- kIndexVersionFieldName,
- S2_INDEX_VERSION_1));
-
- uassert(16747, "coarsestIndexedLevel must be >= 0", out->coarsestIndexedLevel >= 0);
- uassert(16748, "finestIndexedLevel must be <= 30", out->finestIndexedLevel <= 30);
- uassert(16749, "finestIndexedLevel must be >= coarsestIndexedLevel",
- out->finestIndexedLevel >= out->coarsestIndexedLevel);
-
- massert(17395,
- mongoutils::str::stream() << "unsupported geo index version { " << kIndexVersionFieldName
- << " : " << out->indexVersion << " }, only support versions: ["
- << S2_INDEX_VERSION_1 << "," << S2_INDEX_VERSION_2 << "]",
- out->indexVersion == S2_INDEX_VERSION_2 || out->indexVersion == S2_INDEX_VERSION_1);
- }
-
- private:
- static double configValueWithDefaultDouble(const BSONObj& infoObj,
- const std::string& name,
- double def) {
- BSONElement e = infoObj[name];
- if (e.isNumber()) { return e.numberDouble(); }
- return def;
+ }
+
+ static void parse2dsphereParams(const BSONObj& infoObj, S2IndexingParams* out) {
+ // Set up basic params.
+ out->maxKeysPerInsert = 200;
+
+ // This is advisory.
+ out->maxCellsInCovering = 50;
+
+ // Near distances are specified in meters...sometimes.
+ out->radius = kRadiusOfEarthInMeters;
+
+ // These are not advisory.
+ out->finestIndexedLevel = configValueWithDefaultInt(
+ infoObj, "finestIndexedLevel", S2::kAvgEdge.GetClosestLevel(500.0 / out->radius));
+
+ out->coarsestIndexedLevel =
+ configValueWithDefaultInt(infoObj,
+ "coarsestIndexedLevel",
+ S2::kAvgEdge.GetClosestLevel(100 * 1000.0 / out->radius));
+
+ static const std::string kIndexVersionFieldName("2dsphereIndexVersion");
+
+ // Determine which version of this index we're using. If none was set in the descriptor,
+ // assume S2_INDEX_VERSION_1 (alas, the first version predates the existence of the version
+ // field).
+ out->indexVersion = static_cast<S2IndexVersion>(
+ configValueWithDefaultInt(infoObj, kIndexVersionFieldName, S2_INDEX_VERSION_1));
+
+ uassert(16747, "coarsestIndexedLevel must be >= 0", out->coarsestIndexedLevel >= 0);
+ uassert(16748, "finestIndexedLevel must be <= 30", out->finestIndexedLevel <= 30);
+ uassert(16749,
+ "finestIndexedLevel must be >= coarsestIndexedLevel",
+ out->finestIndexedLevel >= out->coarsestIndexedLevel);
+
+ massert(17395,
+ mongoutils::str::stream() << "unsupported geo index version { "
+ << kIndexVersionFieldName << " : " << out->indexVersion
+ << " }, only support versions: [" << S2_INDEX_VERSION_1
+ << "," << S2_INDEX_VERSION_2 << "]",
+ out->indexVersion == S2_INDEX_VERSION_2 || out->indexVersion == S2_INDEX_VERSION_1);
+ }
+
+private:
+ static double configValueWithDefaultDouble(const BSONObj& infoObj,
+ const std::string& name,
+ double def) {
+ BSONElement e = infoObj[name];
+ if (e.isNumber()) {
+ return e.numberDouble();
}
+ return def;
+ }
- static int configValueWithDefaultInt(const BSONObj& infoObj, const std::string& name, int def) {
- BSONElement e = infoObj[name];
- if (e.isNumber()) { return e.numberInt(); }
- return def;
+ static int configValueWithDefaultInt(const BSONObj& infoObj, const std::string& name, int def) {
+ BSONElement e = infoObj[name];
+ if (e.isNumber()) {
+ return e.numberInt();
}
-
- };
+ return def;
+ }
+};
} // namespace mongo