Support prefix seek in UserCollectedProperties
Summary: We'll need the prefix seek support for property aggregation. Test Plan: make all check Reviewers: haobo, sdong, dhruba Reviewed By: haobo CC: leveldb Differential Revision: https://reviews.facebook.net/D15963
This commit is contained in:
parent
ca5f1a225a
commit
e6b3e3b4db
@ -4,7 +4,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <map>
|
||||||
#include "rocksdb/status.h"
|
#include "rocksdb/status.h"
|
||||||
|
|
||||||
namespace rocksdb {
|
namespace rocksdb {
|
||||||
@ -14,7 +14,16 @@ namespace rocksdb {
|
|||||||
// collected properties.
|
// collected properties.
|
||||||
// The value of the user-collected properties are encoded as raw bytes --
|
// The value of the user-collected properties are encoded as raw bytes --
|
||||||
// users have to interprete these values by themselves.
|
// users have to interprete these values by themselves.
|
||||||
typedef std::unordered_map<std::string, std::string> UserCollectedProperties;
|
// Note: To do prefix seek/scan in `UserCollectedProperties`, you can do
|
||||||
|
// something similar to:
|
||||||
|
//
|
||||||
|
// UserCollectedProperties props = ...;
|
||||||
|
// for (auto pos = props.lower_bound(prefix);
|
||||||
|
// pos != props.end() && pos->first.compare(0, prefix.size(), prefix) == 0;
|
||||||
|
// ++pos) {
|
||||||
|
// ...
|
||||||
|
// }
|
||||||
|
typedef std::map<std::string, std::string> UserCollectedProperties;
|
||||||
|
|
||||||
// TableProperties contains a bunch of read-only properties of its associated
|
// TableProperties contains a bunch of read-only properties of its associated
|
||||||
// table.
|
// table.
|
||||||
|
@ -938,6 +938,44 @@ class TableTest {
|
|||||||
class GeneralTableTest : public TableTest {};
|
class GeneralTableTest : public TableTest {};
|
||||||
class BlockBasedTableTest : public TableTest {};
|
class BlockBasedTableTest : public TableTest {};
|
||||||
class PlainTableTest : public TableTest {};
|
class PlainTableTest : public TableTest {};
|
||||||
|
class TablePropertyTest {};
|
||||||
|
|
||||||
|
// This test serves as the living tutorial for the prefix scan of user collected
|
||||||
|
// properties.
|
||||||
|
TEST(TablePropertyTest, PrefixScanTest) {
|
||||||
|
UserCollectedProperties props{{"num.111.1", "1"},
|
||||||
|
{"num.111.2", "2"},
|
||||||
|
{"num.111.3", "3"},
|
||||||
|
{"num.333.1", "1"},
|
||||||
|
{"num.333.2", "2"},
|
||||||
|
{"num.333.3", "3"},
|
||||||
|
{"num.555.1", "1"},
|
||||||
|
{"num.555.2", "2"},
|
||||||
|
{"num.555.3", "3"}, };
|
||||||
|
|
||||||
|
// prefixes that exist
|
||||||
|
for (const std::string& prefix : {"num.111", "num.333", "num.555"}) {
|
||||||
|
int num = 0;
|
||||||
|
for (auto pos = props.lower_bound(prefix);
|
||||||
|
pos != props.end() &&
|
||||||
|
pos->first.compare(0, prefix.size(), prefix) == 0;
|
||||||
|
++pos) {
|
||||||
|
++num;
|
||||||
|
auto key = prefix + "." + std::to_string(num);
|
||||||
|
ASSERT_EQ(key, pos->first);
|
||||||
|
ASSERT_EQ(std::to_string(num), pos->second);
|
||||||
|
}
|
||||||
|
ASSERT_EQ(3, num);
|
||||||
|
}
|
||||||
|
|
||||||
|
// prefixes that don't exist
|
||||||
|
for (const std::string& prefix :
|
||||||
|
{"num.000", "num.222", "num.444", "num.666"}) {
|
||||||
|
auto pos = props.lower_bound(prefix);
|
||||||
|
ASSERT_TRUE(pos == props.end() ||
|
||||||
|
pos->first.compare(0, prefix.size(), prefix) != 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// This test include all the basic checks except those for index size and block
|
// This test include all the basic checks except those for index size and block
|
||||||
// size, which will be conducted in separated unit tests.
|
// size, which will be conducted in separated unit tests.
|
||||||
|
Loading…
Reference in New Issue
Block a user