fdb-record-layer 0.1.0b1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fdb_record_layer/__init__.py +295 -0
- fdb_record_layer/core/__init__.py +60 -0
- fdb_record_layer/core/context.py +367 -0
- fdb_record_layer/core/exceptions.py +140 -0
- fdb_record_layer/core/record.py +123 -0
- fdb_record_layer/core/store.py +1029 -0
- fdb_record_layer/cursors/__init__.py +0 -0
- fdb_record_layer/cursors/base.py +366 -0
- fdb_record_layer/cursors/result.py +187 -0
- fdb_record_layer/expressions/__init__.py +0 -0
- fdb_record_layer/expressions/base.py +158 -0
- fdb_record_layer/expressions/concat.py +124 -0
- fdb_record_layer/expressions/field.py +127 -0
- fdb_record_layer/expressions/nest.py +112 -0
- fdb_record_layer/expressions/record_type.py +58 -0
- fdb_record_layer/indexes/__init__.py +66 -0
- fdb_record_layer/indexes/builder.py +463 -0
- fdb_record_layer/indexes/count_index.py +470 -0
- fdb_record_layer/indexes/maintainer.py +240 -0
- fdb_record_layer/indexes/rank_index.py +434 -0
- fdb_record_layer/indexes/registry.py +171 -0
- fdb_record_layer/indexes/text_index.py +213 -0
- fdb_record_layer/indexes/value_index.py +189 -0
- fdb_record_layer/metadata/__init__.py +57 -0
- fdb_record_layer/metadata/evolution.py +515 -0
- fdb_record_layer/metadata/index.py +153 -0
- fdb_record_layer/metadata/meta_data_builder.py +334 -0
- fdb_record_layer/metadata/meta_data_store.py +416 -0
- fdb_record_layer/metadata/record_metadata.py +172 -0
- fdb_record_layer/planner/__init__.py +46 -0
- fdb_record_layer/planner/cascades/__init__.py +128 -0
- fdb_record_layer/planner/cascades/cost_model.py +413 -0
- fdb_record_layer/planner/cascades/expressions.py +578 -0
- fdb_record_layer/planner/cascades/memo.py +486 -0
- fdb_record_layer/planner/cascades/planner.py +531 -0
- fdb_record_layer/planner/cascades/rule.py +654 -0
- fdb_record_layer/planner/heuristic.py +511 -0
- fdb_record_layer/planner/scan_comparisons.py +325 -0
- fdb_record_layer/plans/__init__.py +54 -0
- fdb_record_layer/plans/base.py +242 -0
- fdb_record_layer/plans/filter_plan.py +292 -0
- fdb_record_layer/plans/index_plan.py +250 -0
- fdb_record_layer/plans/intersection_plan.py +161 -0
- fdb_record_layer/plans/scan_plan.py +186 -0
- fdb_record_layer/plans/union_plan.py +171 -0
- fdb_record_layer/query/__init__.py +95 -0
- fdb_record_layer/query/comparisons.py +234 -0
- fdb_record_layer/query/components.py +335 -0
- fdb_record_layer/query/predicates.py +194 -0
- fdb_record_layer/query/query.py +457 -0
- fdb_record_layer/relational/__init__.py +51 -0
- fdb_record_layer/relational/database.py +778 -0
- fdb_record_layer/relational/result_set.py +400 -0
- fdb_record_layer/relational/schema.py +429 -0
- fdb_record_layer/relational/sql/__init__.py +225 -0
- fdb_record_layer/relational/sql/ast.py +914 -0
- fdb_record_layer/relational/sql/lexer.py +497 -0
- fdb_record_layer/relational/sql/parser.py +1083 -0
- fdb_record_layer/relational/sql/translator.py +684 -0
- fdb_record_layer/relational/sql/types.py +666 -0
- fdb_record_layer/serialization/__init__.py +0 -0
- fdb_record_layer/serialization/proto_serializer.py +136 -0
- fdb_record_layer/serialization/serializer.py +63 -0
- fdb_record_layer/utils/__init__.py +162 -0
- fdb_record_layer/utils/batch.py +478 -0
- fdb_record_layer/utils/cache.py +646 -0
- fdb_record_layer/utils/circuit_breaker.py +316 -0
- fdb_record_layer/utils/health.py +389 -0
- fdb_record_layer/utils/lifecycle.py +491 -0
- fdb_record_layer/utils/logging.py +319 -0
- fdb_record_layer/utils/metrics.py +744 -0
- fdb_record_layer/utils/pool.py +442 -0
- fdb_record_layer-0.1.0b1.dist-info/METADATA +255 -0
- fdb_record_layer-0.1.0b1.dist-info/RECORD +77 -0
- fdb_record_layer-0.1.0b1.dist-info/WHEEL +5 -0
- fdb_record_layer-0.1.0b1.dist-info/licenses/LICENSE +190 -0
- fdb_record_layer-0.1.0b1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
"""FDB Record Layer - Python implementation of FoundationDB Record Layer.
|
|
2
|
+
|
|
3
|
+
A record-oriented database layer built on FoundationDB providing:
|
|
4
|
+
- Protobuf-based schema definition
|
|
5
|
+
- Automatic secondary index maintenance
|
|
6
|
+
- Query execution with index selection
|
|
7
|
+
- Async-first API with continuation support
|
|
8
|
+
|
|
9
|
+
Example:
|
|
10
|
+
>>> import fdb_record_layer as frl
|
|
11
|
+
>>> from my_proto_pb2 import Person, DESCRIPTOR
|
|
12
|
+
>>>
|
|
13
|
+
>>> # Define schema
|
|
14
|
+
>>> metadata = (
|
|
15
|
+
... frl.RecordMetaDataBuilder(DESCRIPTOR)
|
|
16
|
+
... .set_record_type("Person", primary_key=frl.field("id"))
|
|
17
|
+
... .add_index("Person", "email_idx", frl.field("email"))
|
|
18
|
+
... .build()
|
|
19
|
+
... )
|
|
20
|
+
>>>
|
|
21
|
+
>>> # Use the store
|
|
22
|
+
>>> db = frl.FDBDatabase()
|
|
23
|
+
>>> async with db.open_context() as ctx:
|
|
24
|
+
... store = frl.FDBRecordStore(ctx, subspace, metadata)
|
|
25
|
+
... await store.save_record(person)
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
__version__ = "0.1.0"
|
|
29
|
+
|
|
30
|
+
# Tracking for optional dependencies
|
|
31
|
+
_HAS_FDB = False
|
|
32
|
+
_HAS_PROTOBUF = False
|
|
33
|
+
|
|
34
|
+
# Core imports - require FDB
|
|
35
|
+
try:
|
|
36
|
+
from fdb_record_layer.core.context import FDBDatabase, FDBRecordContext
|
|
37
|
+
|
|
38
|
+
_HAS_FDB = True
|
|
39
|
+
except ImportError:
|
|
40
|
+
FDBDatabase = None # type: ignore
|
|
41
|
+
FDBRecordContext = None # type: ignore
|
|
42
|
+
|
|
43
|
+
# Exceptions (no external dependencies)
|
|
44
|
+
from fdb_record_layer.core.exceptions import (
|
|
45
|
+
IndexNotFoundException,
|
|
46
|
+
InvalidPrimaryKeyException,
|
|
47
|
+
MetaDataException,
|
|
48
|
+
QueryException,
|
|
49
|
+
RecordLayerException,
|
|
50
|
+
RecordNotFoundException,
|
|
51
|
+
RecordTypeNotFoundException,
|
|
52
|
+
SchemaEvolutionException,
|
|
53
|
+
SerializationException,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
# Record types (no external dependencies)
|
|
57
|
+
from fdb_record_layer.core.record import FDBQueriedRecord, FDBStoredRecord, IndexEntry
|
|
58
|
+
|
|
59
|
+
# Store imports - require FDB
|
|
60
|
+
try:
|
|
61
|
+
from fdb_record_layer.core.store import FDBRecordStore, FDBRecordStoreBuilder
|
|
62
|
+
except ImportError:
|
|
63
|
+
FDBRecordStore = None # type: ignore
|
|
64
|
+
FDBRecordStoreBuilder = None # type: ignore
|
|
65
|
+
|
|
66
|
+
# Cursors (no external dependencies)
|
|
67
|
+
from fdb_record_layer.cursors.base import (
|
|
68
|
+
FilterCursor,
|
|
69
|
+
ListCursor,
|
|
70
|
+
MapCursor,
|
|
71
|
+
RecordCursor,
|
|
72
|
+
from_list,
|
|
73
|
+
)
|
|
74
|
+
from fdb_record_layer.cursors.result import (
|
|
75
|
+
NoNextReason,
|
|
76
|
+
RecordCursorContinuation,
|
|
77
|
+
RecordCursorResult,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
# Key expressions (no external dependencies)
|
|
81
|
+
from fdb_record_layer.expressions.base import (
|
|
82
|
+
EMPTY,
|
|
83
|
+
FanType,
|
|
84
|
+
KeyExpression,
|
|
85
|
+
LiteralKeyExpression,
|
|
86
|
+
empty,
|
|
87
|
+
literal,
|
|
88
|
+
)
|
|
89
|
+
from fdb_record_layer.expressions.concat import ConcatenateKeyExpression, concat
|
|
90
|
+
from fdb_record_layer.expressions.field import FieldKeyExpression, field
|
|
91
|
+
from fdb_record_layer.expressions.nest import NestKeyExpression, nest
|
|
92
|
+
from fdb_record_layer.expressions.record_type import RecordTypeKeyExpression, record_type
|
|
93
|
+
|
|
94
|
+
# Indexes (no external dependencies)
|
|
95
|
+
from fdb_record_layer.indexes.maintainer import IndexMaintainer, IndexScanRange
|
|
96
|
+
from fdb_record_layer.indexes.value_index import ValueIndexMaintainer
|
|
97
|
+
|
|
98
|
+
# Metadata (no external dependencies)
|
|
99
|
+
from fdb_record_layer.metadata.index import (
|
|
100
|
+
FormerIndex,
|
|
101
|
+
Index,
|
|
102
|
+
IndexOptions,
|
|
103
|
+
IndexState,
|
|
104
|
+
IndexType,
|
|
105
|
+
)
|
|
106
|
+
from fdb_record_layer.metadata.meta_data_builder import (
|
|
107
|
+
RecordMetaDataBuilder,
|
|
108
|
+
build_record_metadata,
|
|
109
|
+
)
|
|
110
|
+
from fdb_record_layer.metadata.record_metadata import RecordMetaData, RecordType
|
|
111
|
+
|
|
112
|
+
# Serialization - requires protobuf
|
|
113
|
+
try:
|
|
114
|
+
from fdb_record_layer.serialization.proto_serializer import (
|
|
115
|
+
CompressedSerializer,
|
|
116
|
+
ProtobufSerializer,
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
_HAS_PROTOBUF = True
|
|
120
|
+
except ImportError:
|
|
121
|
+
CompressedSerializer = None # type: ignore
|
|
122
|
+
ProtobufSerializer = None # type: ignore
|
|
123
|
+
|
|
124
|
+
# Planners (no external dependencies)
|
|
125
|
+
from fdb_record_layer.planner.heuristic import HeuristicPlanner, RecordQueryPlanner
|
|
126
|
+
|
|
127
|
+
# Plans (no external dependencies)
|
|
128
|
+
from fdb_record_layer.plans.base import (
|
|
129
|
+
ExecutionContext,
|
|
130
|
+
PlanComplexity,
|
|
131
|
+
RecordQueryPlan,
|
|
132
|
+
)
|
|
133
|
+
from fdb_record_layer.plans.filter_plan import FilterPlan
|
|
134
|
+
from fdb_record_layer.plans.index_plan import IndexScanPlan
|
|
135
|
+
from fdb_record_layer.plans.scan_plan import ScanPlan
|
|
136
|
+
|
|
137
|
+
# Query components (no external dependencies)
|
|
138
|
+
from fdb_record_layer.query.comparisons import Comparison, ComparisonType
|
|
139
|
+
from fdb_record_layer.query.components import (
|
|
140
|
+
AndComponent,
|
|
141
|
+
FieldComponent,
|
|
142
|
+
NotComponent,
|
|
143
|
+
OrComponent,
|
|
144
|
+
QueryComponent,
|
|
145
|
+
)
|
|
146
|
+
from fdb_record_layer.query.predicates import Field
|
|
147
|
+
from fdb_record_layer.query.query import (
|
|
148
|
+
BoundRecordQuery,
|
|
149
|
+
Query,
|
|
150
|
+
QueryBuilder,
|
|
151
|
+
RecordQuery,
|
|
152
|
+
RecordQueryBuilder,
|
|
153
|
+
)
|
|
154
|
+
from fdb_record_layer.serialization.serializer import RecordSerializer
|
|
155
|
+
|
|
156
|
+
# Health and Lifecycle utilities (no external dependencies)
|
|
157
|
+
from fdb_record_layer.utils.health import (
|
|
158
|
+
ComponentHealth,
|
|
159
|
+
HealthChecker,
|
|
160
|
+
HealthReport,
|
|
161
|
+
HealthStatus,
|
|
162
|
+
get_health_checker,
|
|
163
|
+
reset_health_checker,
|
|
164
|
+
)
|
|
165
|
+
from fdb_record_layer.utils.lifecycle import (
|
|
166
|
+
InFlightContext,
|
|
167
|
+
LifecycleManager,
|
|
168
|
+
LifecycleState,
|
|
169
|
+
ShutdownConfig,
|
|
170
|
+
get_lifecycle,
|
|
171
|
+
init_lifecycle,
|
|
172
|
+
reset_lifecycle,
|
|
173
|
+
shutdown,
|
|
174
|
+
)
|
|
175
|
+
from fdb_record_layer.utils.logging import (
|
|
176
|
+
LogContext,
|
|
177
|
+
StructuredFormatter,
|
|
178
|
+
configure_logging,
|
|
179
|
+
get_logger,
|
|
180
|
+
log_operation,
|
|
181
|
+
log_timing,
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
__all__ = [
|
|
185
|
+
# Version
|
|
186
|
+
"__version__",
|
|
187
|
+
# Core
|
|
188
|
+
"FDBDatabase",
|
|
189
|
+
"FDBRecordContext",
|
|
190
|
+
"FDBRecordStore",
|
|
191
|
+
"FDBRecordStoreBuilder",
|
|
192
|
+
"FDBStoredRecord",
|
|
193
|
+
"FDBQueriedRecord",
|
|
194
|
+
"IndexEntry",
|
|
195
|
+
# Exceptions
|
|
196
|
+
"RecordLayerException",
|
|
197
|
+
"RecordNotFoundException",
|
|
198
|
+
"RecordTypeNotFoundException",
|
|
199
|
+
"IndexNotFoundException",
|
|
200
|
+
"InvalidPrimaryKeyException",
|
|
201
|
+
"MetaDataException",
|
|
202
|
+
"SchemaEvolutionException",
|
|
203
|
+
"QueryException",
|
|
204
|
+
"SerializationException",
|
|
205
|
+
# Metadata
|
|
206
|
+
"RecordMetaData",
|
|
207
|
+
"RecordMetaDataBuilder",
|
|
208
|
+
"build_record_metadata",
|
|
209
|
+
"RecordType",
|
|
210
|
+
"Index",
|
|
211
|
+
"IndexType",
|
|
212
|
+
"IndexState",
|
|
213
|
+
"IndexOptions",
|
|
214
|
+
"FormerIndex",
|
|
215
|
+
# Key Expressions
|
|
216
|
+
"KeyExpression",
|
|
217
|
+
"FieldKeyExpression",
|
|
218
|
+
"ConcatenateKeyExpression",
|
|
219
|
+
"NestKeyExpression",
|
|
220
|
+
"RecordTypeKeyExpression",
|
|
221
|
+
"LiteralKeyExpression",
|
|
222
|
+
"FanType",
|
|
223
|
+
"EMPTY",
|
|
224
|
+
# Expression helpers
|
|
225
|
+
"field",
|
|
226
|
+
"concat",
|
|
227
|
+
"nest",
|
|
228
|
+
"record_type",
|
|
229
|
+
"empty",
|
|
230
|
+
"literal",
|
|
231
|
+
# Cursors
|
|
232
|
+
"RecordCursor",
|
|
233
|
+
"RecordCursorResult",
|
|
234
|
+
"RecordCursorContinuation",
|
|
235
|
+
"NoNextReason",
|
|
236
|
+
"ListCursor",
|
|
237
|
+
"MapCursor",
|
|
238
|
+
"FilterCursor",
|
|
239
|
+
"from_list",
|
|
240
|
+
# Indexes
|
|
241
|
+
"IndexMaintainer",
|
|
242
|
+
"IndexScanRange",
|
|
243
|
+
"ValueIndexMaintainer",
|
|
244
|
+
# Serialization
|
|
245
|
+
"RecordSerializer",
|
|
246
|
+
"ProtobufSerializer",
|
|
247
|
+
"CompressedSerializer",
|
|
248
|
+
# Query
|
|
249
|
+
"Query",
|
|
250
|
+
"QueryBuilder",
|
|
251
|
+
"RecordQuery",
|
|
252
|
+
"RecordQueryBuilder",
|
|
253
|
+
"BoundRecordQuery",
|
|
254
|
+
"QueryComponent",
|
|
255
|
+
"FieldComponent",
|
|
256
|
+
"AndComponent",
|
|
257
|
+
"OrComponent",
|
|
258
|
+
"NotComponent",
|
|
259
|
+
"Comparison",
|
|
260
|
+
"ComparisonType",
|
|
261
|
+
"Field",
|
|
262
|
+
# Planners
|
|
263
|
+
"RecordQueryPlanner",
|
|
264
|
+
"HeuristicPlanner",
|
|
265
|
+
# Plans
|
|
266
|
+
"RecordQueryPlan",
|
|
267
|
+
"ExecutionContext",
|
|
268
|
+
"PlanComplexity",
|
|
269
|
+
"ScanPlan",
|
|
270
|
+
"IndexScanPlan",
|
|
271
|
+
"FilterPlan",
|
|
272
|
+
# Health checks
|
|
273
|
+
"HealthChecker",
|
|
274
|
+
"HealthReport",
|
|
275
|
+
"HealthStatus",
|
|
276
|
+
"ComponentHealth",
|
|
277
|
+
"get_health_checker",
|
|
278
|
+
"reset_health_checker",
|
|
279
|
+
# Lifecycle management
|
|
280
|
+
"LifecycleManager",
|
|
281
|
+
"LifecycleState",
|
|
282
|
+
"ShutdownConfig",
|
|
283
|
+
"InFlightContext",
|
|
284
|
+
"get_lifecycle",
|
|
285
|
+
"init_lifecycle",
|
|
286
|
+
"reset_lifecycle",
|
|
287
|
+
"shutdown",
|
|
288
|
+
# Logging utilities
|
|
289
|
+
"LogContext",
|
|
290
|
+
"StructuredFormatter",
|
|
291
|
+
"configure_logging",
|
|
292
|
+
"get_logger",
|
|
293
|
+
"log_operation",
|
|
294
|
+
"log_timing",
|
|
295
|
+
]
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""Core components for FDB Record Layer."""
|
|
2
|
+
|
|
3
|
+
from fdb_record_layer.core.context import (
|
|
4
|
+
DEFAULT_RETRY_CONFIG,
|
|
5
|
+
FDBDatabase,
|
|
6
|
+
FDBRecordContext,
|
|
7
|
+
RetryConfig,
|
|
8
|
+
)
|
|
9
|
+
from fdb_record_layer.core.exceptions import (
|
|
10
|
+
ContinuationException,
|
|
11
|
+
IndexNotFoundException,
|
|
12
|
+
IndexStateException,
|
|
13
|
+
InvalidPrimaryKeyException,
|
|
14
|
+
MetaDataException,
|
|
15
|
+
MetaDataVersionMismatchError,
|
|
16
|
+
QueryException,
|
|
17
|
+
QueryPlanException,
|
|
18
|
+
RecordLayerException,
|
|
19
|
+
RecordNotFoundException,
|
|
20
|
+
RecordTypeNotFoundException,
|
|
21
|
+
SchemaEvolutionException,
|
|
22
|
+
SerializationException,
|
|
23
|
+
TransactionConflictError,
|
|
24
|
+
TransactionException,
|
|
25
|
+
TransactionRetryLimitExceeded,
|
|
26
|
+
TransactionTimeoutError,
|
|
27
|
+
)
|
|
28
|
+
from fdb_record_layer.core.record import FDBStoredRecord
|
|
29
|
+
from fdb_record_layer.core.store import FDBRecordStore, FDBRecordStoreBuilder
|
|
30
|
+
|
|
31
|
+
__all__ = [
|
|
32
|
+
# Context
|
|
33
|
+
"FDBDatabase",
|
|
34
|
+
"FDBRecordContext",
|
|
35
|
+
"RetryConfig",
|
|
36
|
+
"DEFAULT_RETRY_CONFIG",
|
|
37
|
+
# Store
|
|
38
|
+
"FDBRecordStore",
|
|
39
|
+
"FDBRecordStoreBuilder",
|
|
40
|
+
# Record
|
|
41
|
+
"FDBStoredRecord",
|
|
42
|
+
# Exceptions
|
|
43
|
+
"RecordLayerException",
|
|
44
|
+
"RecordNotFoundException",
|
|
45
|
+
"RecordTypeNotFoundException",
|
|
46
|
+
"IndexNotFoundException",
|
|
47
|
+
"InvalidPrimaryKeyException",
|
|
48
|
+
"MetaDataException",
|
|
49
|
+
"MetaDataVersionMismatchError",
|
|
50
|
+
"SchemaEvolutionException",
|
|
51
|
+
"IndexStateException",
|
|
52
|
+
"QueryException",
|
|
53
|
+
"QueryPlanException",
|
|
54
|
+
"SerializationException",
|
|
55
|
+
"ContinuationException",
|
|
56
|
+
"TransactionException",
|
|
57
|
+
"TransactionConflictError",
|
|
58
|
+
"TransactionRetryLimitExceeded",
|
|
59
|
+
"TransactionTimeoutError",
|
|
60
|
+
]
|