@@ -50,6 +50,9 @@ const char* kCollectionParentsTable = "collection_parent";
50
50
const char * kRemoteDocumentReadTimeTable = " remote_document_read_time" ;
51
51
const char * kBundlesTable = " bundles" ;
52
52
const char * kNamedQueriesTable = " named_queries" ;
53
+ const char * kIndexConfigurationTable = " index_configuration" ;
54
+ const char * kIndexStateTable = " index_state" ;
55
+ const char * kIndexEntriesTable = " index_entries" ;
53
56
54
57
/* *
55
58
* Labels for the components of keys. These serve to make keys self-describing.
@@ -115,6 +118,15 @@ enum ComponentLabel {
115
118
/* * A component containing the name of a named query. */
116
119
QueryName = 18 ,
117
120
121
+ /* * A component containing a index id. */
122
+ IndexId = 19 ,
123
+
124
+ /* * A component containing an array index value. */
125
+ IndexArrayValue = 20 ,
126
+
127
+ /* * A component containing a directional index value. */
128
+ IndexDirectionalValue = 21 ,
129
+
118
130
/* *
119
131
* A path segment describes just a single segment in a resource path. Path
120
132
* segments that occur sequentially in a key represent successive segments in
@@ -201,6 +213,18 @@ class Reader {
201
213
return ReadLabeledString (ComponentLabel::QueryName);
202
214
}
203
215
216
+ int32_t ReadIndexId () {
217
+ return ReadLabeledInt32 (ComponentLabel::IndexId);
218
+ }
219
+
220
+ std::string ReadIndexArrayValue () {
221
+ return ReadLabeledString (ComponentLabel::IndexArrayValue);
222
+ }
223
+
224
+ std::string ReadIndexDirectionalValue () {
225
+ return ReadLabeledString (ComponentLabel::IndexDirectionalValue);
226
+ }
227
+
204
228
/* *
205
229
* Reads a snapshot version, encoded as a component label and a pair of
206
230
* seconds (int64) and nanoseconds (int32).
@@ -567,6 +591,21 @@ std::string Reader::Describe() {
567
591
if (ok_) {
568
592
absl::StrAppend (&description, " query_name=" , query_name);
569
593
}
594
+ } else if (label == ComponentLabel::IndexId) {
595
+ int32_t index_id = ReadIndexId ();
596
+ if (ok_) {
597
+ absl::StrAppend (&description, " index_id=" , index_id);
598
+ }
599
+ } else if (label == ComponentLabel::IndexArrayValue) {
600
+ std::string value = ReadIndexArrayValue ();
601
+ if (ok_) {
602
+ absl::StrAppend (&description, " array_value=" , std::move (value));
603
+ }
604
+ } else if (label == ComponentLabel::IndexDirectionalValue) {
605
+ std::string value = ReadIndexDirectionalValue ();
606
+ if (ok_) {
607
+ absl::StrAppend (&description, " directional_value=" , std::move (value));
608
+ }
570
609
} else {
571
610
absl::StrAppend (&description, " unknown label=" , static_cast <int >(label));
572
611
Fail ();
@@ -650,6 +689,18 @@ class Writer {
650
689
}
651
690
}
652
691
692
+ void WriteIndexId (int32_t id) {
693
+ WriteLabeledInt32 (ComponentLabel::IndexId, id);
694
+ }
695
+
696
+ void WriteIndexArrayValue (absl::string_view value) {
697
+ WriteLabeledString (ComponentLabel::IndexArrayValue, value);
698
+ }
699
+
700
+ void WriteIndexDirectionalValue (absl::string_view value) {
701
+ WriteLabeledString (ComponentLabel::IndexDirectionalValue, value);
702
+ }
703
+
653
704
private:
654
705
/* * Writes a component label to the given key destination. */
655
706
void WriteComponentLabel (ComponentLabel label) {
@@ -1094,6 +1145,87 @@ bool LevelDbNamedQueryKey::Decode(absl::string_view key) {
1094
1145
return reader.ok ();
1095
1146
}
1096
1147
1148
+ std::string LevelDbIndexConfigurationKey::KeyPrefix () {
1149
+ Writer writer;
1150
+ writer.WriteTableName (kIndexConfigurationTable );
1151
+ return writer.result ();
1152
+ }
1153
+
1154
+ std::string LevelDbIndexConfigurationKey::Key (int32_t id) {
1155
+ Writer writer;
1156
+ writer.WriteTableName (kIndexConfigurationTable );
1157
+ writer.WriteIndexId (id);
1158
+ writer.WriteTerminator ();
1159
+ return writer.result ();
1160
+ }
1161
+
1162
+ bool LevelDbIndexConfigurationKey::Decode (absl::string_view key) {
1163
+ Reader reader{key};
1164
+ reader.ReadTableNameMatching (kIndexConfigurationTable );
1165
+ index_id_ = reader.ReadIndexId ();
1166
+ reader.ReadTerminator ();
1167
+ return reader.ok ();
1168
+ }
1169
+
1170
+ std::string LevelDbIndexStateKey::KeyPrefix () {
1171
+ Writer writer;
1172
+ writer.WriteTableName (kIndexStateTable );
1173
+ return writer.result ();
1174
+ }
1175
+
1176
+ std::string LevelDbIndexStateKey::Key (int32_t index_id,
1177
+ absl::string_view user_id) {
1178
+ Writer writer;
1179
+ writer.WriteTableName (kIndexStateTable );
1180
+ writer.WriteIndexId (index_id);
1181
+ writer.WriteUserId (user_id);
1182
+ writer.WriteTerminator ();
1183
+ return writer.result ();
1184
+ }
1185
+
1186
+ bool LevelDbIndexStateKey::Decode (absl::string_view key) {
1187
+ Reader reader{key};
1188
+ reader.ReadTableNameMatching (kIndexStateTable );
1189
+ index_id_ = reader.ReadIndexId ();
1190
+ user_id_ = reader.ReadUserId ();
1191
+ reader.ReadTerminator ();
1192
+ return reader.ok ();
1193
+ }
1194
+
1195
+ std::string LevelDbIndexEntryKey::KeyPrefix () {
1196
+ Writer writer;
1197
+ writer.WriteTableName (kIndexEntriesTable );
1198
+ return writer.result ();
1199
+ }
1200
+
1201
+ std::string LevelDbIndexEntryKey::Key (int32_t index_id,
1202
+ absl::string_view user_id,
1203
+ absl::string_view array_value,
1204
+ absl::string_view dicrectional_value,
1205
+ absl::string_view document_key) {
1206
+ Writer writer;
1207
+ writer.WriteTableName (kIndexEntriesTable );
1208
+ writer.WriteIndexId (index_id);
1209
+ writer.WriteUserId (user_id);
1210
+ writer.WriteIndexArrayValue (array_value);
1211
+ writer.WriteIndexDirectionalValue (dicrectional_value);
1212
+ writer.WriteDocumentId (document_key);
1213
+ writer.WriteTerminator ();
1214
+ return writer.result ();
1215
+ }
1216
+
1217
+ bool LevelDbIndexEntryKey::Decode (absl::string_view key) {
1218
+ Reader reader{key};
1219
+ reader.ReadTableNameMatching (kIndexEntriesTable );
1220
+ index_id_ = reader.ReadIndexId ();
1221
+ user_id_ = reader.ReadUserId ();
1222
+ array_value_ = reader.ReadIndexArrayValue ();
1223
+ directional_value_ = reader.ReadIndexDirectionalValue ();
1224
+ document_key_ = reader.ReadDocumentId ();
1225
+ reader.ReadTerminator ();
1226
+ return reader.ok ();
1227
+ }
1228
+
1097
1229
} // namespace local
1098
1230
} // namespace firestore
1099
1231
} // namespace firebase
0 commit comments