-
Notifications
You must be signed in to change notification settings - Fork 7
/
database.py
1554 lines (1195 loc) · 45.8 KB
/
database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""The main module of the TinyFlux package, containing the TinyFlux class."""
import copy
from datetime import datetime, timezone
from functools import wraps
from typing import (
Any,
Callable,
Dict,
Iterable,
Iterator,
List,
Mapping,
Optional,
Tuple,
Union,
)
from .index import Index
from .measurement import Measurement
from .point import (
FieldValue,
FieldSet,
Point,
TagSet,
validate_fields,
validate_tags,
)
from .queries import (
CompoundQuery,
MeasurementQuery,
SimpleQuery,
TagQuery,
Query,
)
from .storages import CSVStorage, Storage
def append_op(method: Callable[..., Any]) -> Callable[..., Any]:
"""Decorate an append operation with assertion.
Ensures storage can be appended to before doing anything.
"""
@wraps(method)
def op(self: Any, *args: Any, **kwargs: Any) -> Any:
"""Decorate."""
assert self._storage.can_append
return method(self, *args, **kwargs)
return op
def read_op(method: Callable[..., Any]) -> Callable[..., Any]:
"""Decorate a read operation with assertion.
Ensures storage can be read from before doing anything.
"""
@wraps(method)
def op(self: Any, *args: Any, **kwargs: Any) -> Any:
"""Decorate."""
assert self._storage.can_read
if self._auto_index and not self._index.valid:
self.reindex()
return method(self, *args, **kwargs)
return op
def temp_storage_op(method: Callable[..., Any]) -> Callable[..., Any]:
"""Decorate a db operation that requires auxiliary storage.
Initializes temporary storage, invokes method, and cleans-up storage after
op has run.
"""
@wraps(method)
def op(self: Any, *args: Any, **kwargs: Any) -> Any:
"""Decorate."""
# Init temp storage in the storage class.
self._storage._init_temp_storage()
# Invoke op.
rst = method(self, *args, **kwargs)
# Clean-up temp storage.
self._storage._cleanup_temp_storage()
return rst
return op
def write_op(method: Callable[..., Any]) -> Callable[..., Any]:
"""Decorate a write operation with assertion.
Ensures storage can be written to before doing anything.
"""
@wraps(method)
def op(self: Any, *args: Any, **kwargs: Any) -> Any:
"""Decorate."""
assert self._storage.can_write
return method(self, *args, **kwargs)
return op
class TinyFlux:
"""The TinyFlux class containing the interface for the TinyFlux package.
A facade singleton for the TinyFlux program. Manages the lifecycles of
Storage, Index, and Measurement instances. Handles Points and Queries.
TinyFlux will reindex data in memory by default. To turn off this feature,
set the value of 'auto_index' to false in the constructor keyword
arguments.
TinyFlux will use the CSV store by default. To use a different store, pass
a derived Storage subclass to the 'storage' keyword argument of the
constructor.
All other args and kwargs are passed to the Storage instance.
Data Storage Model:
Data in TinyFlux is represented as Point objects. These are serialized
and inserted into the TinyFlux storage layer in append-only fashion,
providing the lowest-latency write op possible. This is of primary
importance for time-series data which can often be written at a high-
frequency. The schema of the storage layer is not rigid, allowing for
variable metadata structures to be stored to the same data store.
Attributes:
storage: A reference to the Storage instance.
index: A reference to the Index instance.
Usage:
>>> from tinyflux import TinyFlux
>>> db = TinyFlux("my_tf_db.csv")
"""
# The name of the default table.
default_measurement_name = "_default"
# The class that will be used by default to create storage instances.
default_storage_class = CSVStorage
_auto_index: bool
_storage: Storage
_index: Index
_measurements: Dict[str, Measurement]
_open: bool
def __init__(
self: Any, *args: Any, auto_index: bool = True, **kwargs: Any
):
"""Initialize a new instance of TinyFlux.
If 'auto_index' is set to True, an index will be built in-memory for
efficient querying.
Please note, this operation can take some time. If you need to insert
into TinyFlux immediately after initializing the DB, set
'auto-index' to False.
Args:
auto_index: Reindexing of data will be performed automatically.
storage: Class of Storage instance.
"""
self._auto_index = auto_index
# Init storage.
storage = kwargs.pop("storage", self.default_storage_class)
self._storage = storage(*args, **kwargs)
# Init index.
if not isinstance(self._auto_index, bool):
raise TypeError("'auto_index' must be True/False.")
self._index = Index(valid=self._storage._initially_empty)
# Init references to measurements.
self._measurements = {}
self._open = True
# Reindex if auto_index is True.
if self._auto_index and not self._storage._initially_empty:
self.reindex()
@property
def storage(self) -> Storage:
"""Get a reference to the storage instance."""
return self._storage
@property
def index(self) -> Index:
"""Get a reference to the index instance."""
return self._index
def __enter__(self) -> "TinyFlux":
"""Use the database as a context manager.
Using the database as a context manager ensures that the
'tinyflux.database.tinyflux.close' method is called upon leaving
the context.
"""
return self
def __exit__(self, *args: Any) -> None:
"""Close the storage instance when leaving a context."""
if self._open:
self.close()
return
def __iter__(self) -> Iterator[Point]:
"""Return an iterater for all Points in the storage layer."""
for item in self._storage:
yield self._storage._deserialize_storage_item(item)
def __len__(self) -> int:
"""Get the number of Points in the storage layer."""
# If the index is valid, check it.
if self._auto_index and self._index.valid:
return len(self._index)
# Otherwise, we get it from storage class.
return len(self._storage)
def __repr__(self) -> str:
"""Get a printable representation of the TinyFlux instance."""
if self._auto_index and self._index.valid:
args = [
f"all_points_count={len(self._index)}",
f"auto_index_ON={self._auto_index}",
f"index_valid={self._index.valid}",
]
else:
args = [
f"auto_index_ON={self._auto_index}",
f"index_valid={self._index.valid}",
]
return f'<{type(self).__name__} {", ".join(args)}>'
@read_op
def all(self, sorted: bool = True) -> List[Point]:
"""Get all data in the storage layer as Points.
Args:
sorted: Whether or not to return points sorted by time.
Returns:
A list of Points.
"""
points = self._storage.read()
if sorted:
points.sort(key=lambda x: (x is None, x.time))
return points
def close(self) -> None:
"""Close the database.
This may be needed if the storage instance used for this database
needs to perform cleanup operations like closing file handles.
To ensure this method is called, the tinyflux instance can be used as a
context manager:
>>> with TinyFlux('data.csv') as db:
db.insert(Point())
Upon leaving this context, the 'close' method will be called.
"""
self._open = False
self._storage.close()
return
@read_op
def contains(
self, query: Query, measurement: Optional[str] = None
) -> bool:
"""Check whether the database contains a point matching a query.
Defines a function that iterates over storage items and submits it to
the storage layer.
Args:
query: A Query.
measurement: An optional measurement to filter by.
Returns:
True if point found, else False.
"""
# If the index is valid, check it.
if self._index.valid:
if measurement:
mq = MeasurementQuery() == measurement
index_rst = self._index.search(mq & query)
else:
index_rst = self._index.search(query)
# Return whether or not items were found in the index.
return len(index_rst._items) > 0
# Return value.
contains = False
# Search without help of the index.
for item in self._storage:
# Filter by measurement.
if (
measurement
and self._storage._deserialize_measurement(item) != measurement
):
continue
# Evaluate query against storage item.
if query(self._storage._deserialize_storage_item(item)):
contains = True
break
return contains
@read_op
def count(self, query: Query, measurement: Optional[str] = None) -> int:
"""Count the points matching a query in the database.
Args:
query: a Query.
measurement: An optional measurement to filter by.
Returns:
A count of matching points in the measurement.
"""
# If the index is valid, check it.
if self._index.valid:
if measurement:
mq = MeasurementQuery() == measurement
index_rst = self._index.search(mq & query)
else:
index_rst = self._index.search(query)
# Return count of items.
return len(index_rst._items)
# Return value.
count = 0
# Search without help of the index.
for item in self._storage:
# Filter by measurement.
if (
measurement
and not self._storage._deserialize_measurement(item)
== measurement
):
continue
if query(self._storage._deserialize_storage_item(item)):
count += 1
return count
@read_op
@write_op
@temp_storage_op
def drop_measurement(self, name: str) -> int:
"""Drop a specific measurement from the database.
If 'auto-index' is True, a new index will be built.
Args:
name: The name of the measurement.
Returns:
The count of removed items.
Raises:
OSError if storage cannot be written to.
"""
if name in self._measurements:
del self._measurements[name]
return self._remove_helper(MeasurementQuery() == name, name)
@read_op
def get(
self, query: Query, measurement: Optional[str] = None
) -> Optional[Point]:
"""Get exactly one point specified by a query from the database.
Returns None if the point doesn't exist.
Args:
query: A Query.
measurement: An optional measurement to filter by.
Returns:
First found Point or None.
"""
use_index = self._index.valid
# If we are auto-indexing and the index is valid, check it.
if use_index:
if measurement:
mq = MeasurementQuery() == measurement
index_rst = self._index.search(mq & query)
else:
index_rst = self._index.search(query)
# No items from the index.
if not index_rst._items:
return None
# Items, but it's all of them.
if len(index_rst._items) == len(self._index):
use_index = False
# Return value.
got_point = None
# Search with help of the index.
if use_index:
for i, item in enumerate(self._storage):
# Not a candidate.
if i not in index_rst._items:
continue
# Candidate, no further evaluation necessary.
got_point = self._storage._deserialize_storage_item(item)
break
else:
# Evaluate all points until match.
for item in self._storage:
# Filter by measurement.
if (
measurement
and self._storage._deserialize_measurement(item)
!= measurement
):
continue
# Evaluate query against storage item.
_point = self._storage._deserialize_storage_item(item)
if query(_point):
got_point = _point
break
# Put a timezone on it.
if got_point:
if not got_point.time: # pragma: no cover
raise ValueError
got_point.time.replace(tzinfo=timezone.utc)
return got_point
@read_op
def get_field_keys(self, measurement: Optional[str] = None) -> List[str]:
"""Get all field keys in the database.
Args:
measurement: Optional measurement to filter by.
Returns:
List of field keys, sorted.
"""
# If index is valid, get keys from index.
if self._index.valid:
return sorted(self._index.get_field_keys(measurement))
# Otherwise, go through storage.
rst = set({})
for item in self._storage:
# Filter by measurement.
if (
measurement
and self._storage._deserialize_measurement(item) != measurement
):
continue
# Match, add to results.
_point = self._storage._deserialize_storage_item(item)
for fk in _point.fields.keys():
rst.add(fk)
return sorted(rst)
@read_op
def get_field_values(
self, field_key: str, measurement: Optional[str] = None
) -> List[FieldValue]:
"""Get field values in the database.
Args:
field_key: Field key to get values for.
measurement: Optional measurement to filter by.
Returns:
List of field values.
"""
# If index is valid, get keys from index.
if self._index.valid:
return self._index.get_field_values(field_key, measurement)
# Otherwise, go through storage.
rst = []
for item in self._storage:
# Filter by measurement.
if (
measurement
and self._storage._deserialize_measurement(item) != measurement
):
continue
# Match, add to results.
_point = self._storage._deserialize_storage_item(item)
# Filter for matching field key.
for fk, fv in _point.fields.items():
if fk == field_key:
rst.append(fv)
return rst
@read_op
def get_measurements(self) -> List[str]:
"""Get the names of all measurements in the database.
Returns:
Names of all measurements in storage as a set.
"""
# Check the index.
if self._index.valid:
return sorted(self._index.get_measurements())
# Return value.
names = set({})
# Otherwise, check storage.
for item in self._storage:
names.add(self._storage._deserialize_measurement(item))
return sorted(names)
@read_op
def get_tag_keys(self, measurement: Optional[str] = None) -> List[str]:
"""Get all tag keys in the database.
Args:
measurement: Optional measurement to filter by.
Returns:
List of field keys, sorted.
"""
# If index is valid, get tag keys.
if self._index.valid:
return sorted(self._index.get_tag_keys(measurement))
# Otherwise, go through storage.
rst = set({})
for item in self._storage:
# Filter by measurement.
if (
measurement
and self._storage._deserialize_measurement(item) != measurement
):
continue
# Match, add to results.
_point = self._storage._deserialize_storage_item(item)
for tk in _point.tags.keys():
rst.add(tk)
return sorted(rst)
@read_op
def get_tag_values(
self,
tag_keys: List[str] = [],
measurement: Optional[str] = None,
) -> Dict[str, List[Optional[str]]]:
"""Get all tag values in the database.
Args:
tag_keys: Optional list of tag keys to get associated values for.
measurement: Optional measurement to filter by.
Returns:
Mapping of tag_keys to associated tag values as a sorted list.
"""
# If index is valid, get tag values.
if self._index.valid:
rst = self._index.get_tag_values(tag_keys, measurement)
return {
i: sorted(j, key=lambda x: (x is None, x))
for i, j in rst.items()
}
# Otherwise, go through storage.
relevant_tags = set(tag_keys)
rst = {i: set({}) for i in sorted(relevant_tags)}
for item in self._storage:
# Filter by measurement.
if (
measurement
and self._storage._deserialize_measurement(item) != measurement
):
continue
# Match, add to results.
_point = self._storage._deserialize_storage_item(item)
for tk, tv in _point.tags.items():
if relevant_tags and tk not in relevant_tags:
continue
rst[tk] = rst[tk].union({tv}) if tk in rst else set([tv])
return {
i: sorted(j, key=lambda x: (x is None, x)) for i, j in rst.items()
}
@read_op
def get_timestamps(
self, measurement: Optional[str] = None
) -> List[datetime]:
"""Get all timestamps in the database.
Returns timestamps in order of insertion in the database, as time-aware
datetime objects with UTC timezone.
Args:
measurement: Optional measurement to filter by.
Returns:
List of timestamps by insertion order.
"""
# If index is valid, get timestamps.
if self._index.valid:
return [
datetime.fromtimestamp(i).astimezone(timezone.utc)
for i in self._index.get_timestamps(measurement)
]
# Otherwise, go through storage.
rst: List[datetime] = []
for item in self._storage:
# Filter by measurement.
if (
measurement
and self._storage._deserialize_measurement(item) != measurement
):
continue
# Match, add to results.
_time = self._storage._deserialize_timestamp(item)
rst.append(_time.replace(tzinfo=timezone.utc))
return rst
@append_op
def insert(self, point: Point, measurement: Optional[str] = None) -> int:
"""Insert a Point into the database.
Args:
point: A Point object.
measurement: An optional measurement to filter by.
Returns:
1 if success.
Raises:
OSError if storage cannot be appendex to.
TypeError if point is not a Point instance.
"""
return self._insert_helper([point], measurement)
@append_op
def insert_multiple(
self, points: Iterable[Any], measurement: Optional[str] = None
) -> int:
"""Insert Points into the database.
Args:
points: An iterable of Point objects.
measurement: An optional measurement to insert Points into.
Returns:
The count of inserted points.
Raises:
OSError if storage cannot be appendex to.
TypeError if point is not a Point instance.
"""
return self._insert_helper(points, measurement)
def measurement(self, name: str, **kwargs: Any) -> Measurement:
"""Return a reference to a measurement in this database.
Chained methods will be handled by the Measurement class, and operate
on the subset of Points belonging to the measurement.
A measurement does not need to exist in the storage layer for a
Measurement object to be created.
Args:
name: Name of the measurement
Returns:
Reference to the measurement.
"""
# Check _measurements for the name.
if name in self._measurements:
return self._measurements[name]
# Otherwise, create a new Measurement object.
measurement = Measurement(
name,
self,
**kwargs,
)
self._measurements[name] = measurement
return measurement
def reindex(self) -> None:
"""Build a new in-memory index.
Raises:
OSError if storage cannot be written to.
"""
assert self._storage.can_read
# Pass if the index is already valid.
if self._index.valid:
print("Index already valid.")
return
# Build the index.
self._index.build(
self._storage._deserialize_storage_item(i) for i in self._storage
)
return
@read_op
@write_op
@temp_storage_op
def remove(self, query: Query, measurement: Optional[str] = None) -> int:
"""Remove Points from this database by query.
This is irreversible.
Args:
query: A query to remove Points by.
measurement: An optional measurement to filter by.
Returns:
The count of removed points.
Raises:
OSError if storage cannot be written to.
"""
return self._remove_helper(query, measurement)
@write_op
def remove_all(self) -> None:
"""Remove all Points from this database.
This is irreversible.
Raises:
OSError if storage cannot be written to.
"""
self._reset_database()
return
@read_op
def search(
self,
query: Query,
measurement: Optional[str] = None,
sorted: bool = True,
) -> List[Point]:
"""Get all points specified by a query.
Args:
query: A Query.
measurement: An optional measurement to filter by.
sorted: Whether or not to return the points sorted by time.
Returns:
A list of found Points.
"""
use_index = self._index.valid
# If we are auto-indexing and the index is valid, check it.
if use_index:
if measurement:
mq = MeasurementQuery() == measurement
index_rst = self._index.search(mq & query)
else:
index_rst = self._index.search(query)
# No items from the index.
if not index_rst._items:
return []
# Items, but it's all of them.
if len(index_rst._items) == len(self._index):
use_index = False
# Return value.
found_points: List[Point] = []
# Search using help of index.
if use_index:
j = 0
for i, item in enumerate(self._storage):
# Not a candidate, skip.
if i not in index_rst._items:
continue
# Match or candidate match.
found_points.append(
self._storage._deserialize_storage_item(item)
)
j += 1
# If we are out of items, break.
if j == len(index_rst._items):
break
# Search without index.
else:
for item in self._storage:
# Filter by measurement.
if (
measurement
and self._storage._deserialize_measurement(item)
!= measurement
):
continue
# Match, add to results.
_point = self._storage._deserialize_storage_item(item)
if query(_point):
found_points.append(_point)
# Put a timezone on it.
for fp in found_points:
if not fp.time: # pragma: no cover
raise ValueError
fp.time.replace(tzinfo=timezone.utc)
# Sort.
if sorted:
found_points.sort(key=lambda x: (x.time is None, x.time))
return found_points
@read_op
def select(
self,
select_keys: Union[str, Iterable[str]],
query: Query,
measurement: Optional[str] = None,
) -> List[Union[Any, Tuple[Any, ...]]]:
"""Get specified attributes from Points specified by a query.
'select_keys' should be an iterable of attributres including 'time',
'measurement', and tag keys and tag values. Passing 'tags' or 'fields'
in the 'select_keys' iterable will not retrieve all tag and/or field
values. Tag and field keys must be specified individually.
Args:
select_keys: A Point attribute or iterable of Point attributes.
query: A Query.
measurement: An optional measurement to filter by.
Returns:
A list of Point attribute values.
"""
# Validate bad keys.
if not hasattr(select_keys, "__iter__"):
raise ValueError("'keys' must be a string or iterable of strings.")
keys: List[Any] = (
[select_keys]
if isinstance(select_keys, str)
else list(select_keys)
)
# Validate bad keys.
for key in keys:
if key == "time":
continue
elif key == "measurement":
continue
elif key.startswith("tags.") and len(key) > 5:
continue
elif key.startswith("fields.") and len(key) > 7:
continue
else:
raise ValueError(f"Invalid key `{key}`.")
use_index = self._index.valid
results = []
# If we are auto-indexing and the index is valid, check it.
if use_index:
if measurement:
mq = MeasurementQuery() == measurement
index_rst = self._index.search(mq & query)
else:
index_rst = self._index.search(query)
# No items from the index.
if not index_rst._items:
return []
j = 0
for i, item in enumerate(self._storage):
# Not in result set, skip.
if i not in index_rst._items:
continue
_point = self._storage._deserialize_storage_item(item)
# Result set.
result: List[Any] = []
for key in keys:
if key == "time":
result.append(_point.time)
elif key == "measurement":
result.append(_point.measurement)
elif key.startswith("tags."):
tag_key = key[5:]
if (
tag_key in self._index._tags
and tag_key in _point.tags
):
result.append(_point.tags[tag_key])
else:
result.append(None)
else: # key.startswith("fields."):
field_key = key[7:]
if (
field_key in self._index._fields
and field_key in _point.fields
):
result.append(_point.fields[field_key])
else:
result.append(None)
results.append(result)