supaflow-python-sdk 1.0.74__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.
- supaflow_python_sdk/__init__.py +150 -0
- supaflow_python_sdk/_definition_validation.py +220 -0
- supaflow_python_sdk/_legacy_manifest.py +89 -0
- supaflow_python_sdk/_legacy_naming.py +50 -0
- supaflow_python_sdk/_precision_json.py +74 -0
- supaflow_python_sdk/base_connector.py +146 -0
- supaflow_python_sdk/capabilities.py +74 -0
- supaflow_python_sdk/catalog_naming.py +189 -0
- supaflow_python_sdk/child_settings.py +44 -0
- supaflow_python_sdk/compatibility.json +10 -0
- supaflow_python_sdk/connector_definition.py +279 -0
- supaflow_python_sdk/connector_fixture.py +13 -0
- supaflow_python_sdk/connector_identity.py +55 -0
- supaflow_python_sdk/connector_property.py +97 -0
- supaflow_python_sdk/connector_resource.py +388 -0
- supaflow_python_sdk/csv_record_emitter.py +288 -0
- supaflow_python_sdk/cursor_candidates.py +167 -0
- supaflow_python_sdk/errors.py +130 -0
- supaflow_python_sdk/field_capabilities.py +50 -0
- supaflow_python_sdk/helpers.py +98 -0
- supaflow_python_sdk/host_api.py +102 -0
- supaflow_python_sdk/job_context.py +39 -0
- supaflow_python_sdk/jsonl_record_emitter.py +727 -0
- supaflow_python_sdk/keyless_object_handling.py +19 -0
- supaflow_python_sdk/models.py +1052 -0
- supaflow_python_sdk/naming.py +267 -0
- supaflow_python_sdk/native_mapped_jsonl_record_emitter.py +180 -0
- supaflow_python_sdk/oauth.py +399 -0
- supaflow_python_sdk/openapi_schema_builder.py +778 -0
- supaflow_python_sdk/property_rules.py +27 -0
- supaflow_python_sdk/py.typed +0 -0
- supaflow_python_sdk/resource_options.py +9 -0
- supaflow_python_sdk/schema_compliance.py +481 -0
- supaflow_python_sdk/source.py +165 -0
- supaflow_python_sdk/source_namespace.py +325 -0
- supaflow_python_sdk/supa_id.py +422 -0
- supaflow_python_sdk/temporal_stage_value.py +136 -0
- supaflow_python_sdk/type_inference.py +583 -0
- supaflow_python_sdk/ui.py +45 -0
- supaflow_python_sdk/write_plan.py +112 -0
- supaflow_python_sdk-1.0.74.dist-info/METADATA +80 -0
- supaflow_python_sdk-1.0.74.dist-info/RECORD +44 -0
- supaflow_python_sdk-1.0.74.dist-info/WHEEL +5 -0
- supaflow_python_sdk-1.0.74.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
"""Source-side catalog/schema/name identity helpers for Python connectors.
|
|
2
|
+
|
|
3
|
+
Connectors that surface a multi-level source namespace (database
|
|
4
|
+
connectors, multi-database NoSQL stores, multi-tenant APIs) must
|
|
5
|
+
populate the structured ``catalog`` / ``schema`` / ``name`` fields on
|
|
6
|
+
``SchemaObjectInfo`` and resolve incoming ``ReadObjectMetadata`` by
|
|
7
|
+
those structured components -- not by parsing a flattened display
|
|
8
|
+
string. This module provides the shared building blocks so individual
|
|
9
|
+
connectors do not each invent the contract.
|
|
10
|
+
|
|
11
|
+
Boundary of this module:
|
|
12
|
+
|
|
13
|
+
* It does NOT impose a global case policy. SQL Server can fold case
|
|
14
|
+
for comparison; MongoDB identifiers are effectively case-sensitive.
|
|
15
|
+
Each connector supplies its own ``CasePolicy`` callable.
|
|
16
|
+
* It does NOT generate destination-safe table names. That lives in
|
|
17
|
+
``supaflow_python_sdk.naming`` (S3-style normalization). The two
|
|
18
|
+
modules answer different questions: ``naming`` shapes destination
|
|
19
|
+
identifiers; ``source_namespace`` carries source-side identity.
|
|
20
|
+
* It does NOT introduce a "database connector base class". The
|
|
21
|
+
helpers are deliberately functions over the existing dataclasses so
|
|
22
|
+
the framework stays lightweight until a third connector proves the
|
|
23
|
+
shape.
|
|
24
|
+
"""
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
from typing import Callable, Mapping, Sequence
|
|
28
|
+
|
|
29
|
+
from supaflow_python_sdk.models import (
|
|
30
|
+
ReadObjectMetadata,
|
|
31
|
+
SchemaFieldInfo,
|
|
32
|
+
SchemaObjectInfo,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# ---------------------------------------------------------------------------
|
|
37
|
+
# Case policy
|
|
38
|
+
# ---------------------------------------------------------------------------
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
CasePolicy = Callable[[str], str]
|
|
42
|
+
"""Function that normalises one identifier component for comparison.
|
|
43
|
+
|
|
44
|
+
The two canonical implementations:
|
|
45
|
+
|
|
46
|
+
* :data:`CASE_SENSITIVE` -- identity passthrough. Use for sources whose
|
|
47
|
+
identifiers are case-significant (MongoDB, most file systems on
|
|
48
|
+
Linux, JSON-based APIs).
|
|
49
|
+
* :data:`CASE_INSENSITIVE` -- ``str.casefold``. Use for sources whose
|
|
50
|
+
identifier comparison is case-insensitive (SQL Server, Snowflake's
|
|
51
|
+
default unquoted identifiers).
|
|
52
|
+
|
|
53
|
+
The connector is responsible for picking the right policy for its
|
|
54
|
+
source. The helpers in this module accept a ``case_policy`` argument
|
|
55
|
+
so the same lookup map can serve both kinds of sources without leaking
|
|
56
|
+
case semantics into Mongo or vice versa.
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def CASE_SENSITIVE(value: str) -> str:
|
|
61
|
+
"""Identity passthrough -- the safe default for new connectors."""
|
|
62
|
+
return value
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def CASE_INSENSITIVE(value: str) -> str:
|
|
66
|
+
"""``str.casefold`` -- safe for Unicode-aware case folding."""
|
|
67
|
+
return value.casefold()
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# ---------------------------------------------------------------------------
|
|
71
|
+
# Fully qualified name formatting
|
|
72
|
+
# ---------------------------------------------------------------------------
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def format_fqn(
|
|
76
|
+
catalog: str | None,
|
|
77
|
+
schema: str | None,
|
|
78
|
+
name: str,
|
|
79
|
+
*,
|
|
80
|
+
separator: str = ".",
|
|
81
|
+
) -> str:
|
|
82
|
+
"""Join non-None components into a display fully qualified name.
|
|
83
|
+
|
|
84
|
+
Connectors that omit one level (catalog-only sources like MongoDB
|
|
85
|
+
pass ``schema=None``) get a two-segment FQN ("catalog.name").
|
|
86
|
+
Three-segment relational sources like SQL Server pass all three.
|
|
87
|
+
Single-segment sources that have no namespace at all pass
|
|
88
|
+
``catalog=None, schema=None`` and get just ``name``.
|
|
89
|
+
|
|
90
|
+
Components carrying the ``separator`` character are NOT escaped --
|
|
91
|
+
that is the connector's responsibility (Mongo collection names can
|
|
92
|
+
legitimately contain dots, so the connector must validate at
|
|
93
|
+
discovery time that no component would re-introduce the separator).
|
|
94
|
+
"""
|
|
95
|
+
parts = [p for p in (catalog, schema, name) if p is not None and p != ""]
|
|
96
|
+
return separator.join(parts) if parts else name
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
# ---------------------------------------------------------------------------
|
|
100
|
+
# Object metadata builder
|
|
101
|
+
# ---------------------------------------------------------------------------
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
# Supaflow orchestration roles that imply parent-child execution
|
|
105
|
+
# linkage in Java's PipelineOrchestrator. A root object that supplies
|
|
106
|
+
# ``parent_object_name`` without one of these roles is almost certainly
|
|
107
|
+
# a bug at the call site (Java would treat the child as a top-level
|
|
108
|
+
# job), so the helper rejects the combination instead of silently
|
|
109
|
+
# emitting orchestration-broken metadata.
|
|
110
|
+
_PARENT_LINKED_ROLES = frozenset({"ASSOCIATION", "HISTORY"})
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def build_object_info_namespaced(
|
|
114
|
+
*,
|
|
115
|
+
catalog: str | None,
|
|
116
|
+
schema: str | None,
|
|
117
|
+
name: str,
|
|
118
|
+
fields: list[SchemaFieldInfo],
|
|
119
|
+
incremental_strategy: str = "UNSUPPORTED",
|
|
120
|
+
identity_strategy: str = "SOURCE_KEY",
|
|
121
|
+
source_object_type: str = "TABLE",
|
|
122
|
+
supa_role: str | None = None,
|
|
123
|
+
cursor_field_name: str | None = None,
|
|
124
|
+
primary_key: str | list[str] | None = None,
|
|
125
|
+
description: str | None = None,
|
|
126
|
+
parent_object_name: str | None = None,
|
|
127
|
+
fqn_separator: str = ".",
|
|
128
|
+
path_segments: tuple[str, ...] | None = None,
|
|
129
|
+
) -> SchemaObjectInfo:
|
|
130
|
+
"""Build a SchemaObjectInfo with structured catalog/schema/name.
|
|
131
|
+
|
|
132
|
+
The returned object's ``name`` is the in-namespace identifier
|
|
133
|
+
only (e.g., ``"orders"`` for a Mongo collection) -- NOT the
|
|
134
|
+
flattened display string. ``fully_qualified_name`` is composed
|
|
135
|
+
from the supplied components so downstream consumers comparing on
|
|
136
|
+
FQN see a deterministic value.
|
|
137
|
+
|
|
138
|
+
Two distinct kwargs control the two ``SchemaObjectInfo`` type-
|
|
139
|
+
related fields. They are intentionally separate -- the older
|
|
140
|
+
``build_object_info`` helper accepted a single ``object_type``
|
|
141
|
+
kwarg that only ever set ``SchemaObjectInfo.type``, which
|
|
142
|
+
silently left ``SchemaObjectInfo.object_type`` (the Supaflow
|
|
143
|
+
orchestration role) unset. Java's ``PipelineOrchestrator`` only
|
|
144
|
+
wires parent-child execution linkage when ``object_type`` is
|
|
145
|
+
``ASSOCIATION`` or ``HISTORY``; an unset value makes a
|
|
146
|
+
materialised child run as a top-level job. The split below makes
|
|
147
|
+
the contract impossible to get wrong:
|
|
148
|
+
|
|
149
|
+
* ``source_object_type`` -- catalog object kind, written to
|
|
150
|
+
``SchemaObjectInfo.type``. Valid values include ``"TABLE"``,
|
|
151
|
+
``"VIEW"``, ``"MATERIALIZED_VIEW"``. Default ``"TABLE"``.
|
|
152
|
+
* ``supa_role`` -- Supaflow orchestration role, written to
|
|
153
|
+
``SchemaObjectInfo.object_type``. Valid values are
|
|
154
|
+
``"PRIMARY"``, ``"ASSOCIATION"``, ``"HISTORY"``, ``"METADATA"``.
|
|
155
|
+
Default ``None`` (matches the existing Python schema contract
|
|
156
|
+
that roots leave ``object_type`` unset and let Java default to
|
|
157
|
+
PRIMARY).
|
|
158
|
+
|
|
159
|
+
Default behaviour for ``supa_role`` is parent-aware:
|
|
160
|
+
|
|
161
|
+
* ``parent_object_name`` is ``None`` and ``supa_role`` is ``None``
|
|
162
|
+
-> ``object_type`` stays ``None`` (root contract).
|
|
163
|
+
* ``parent_object_name`` is set and ``supa_role`` is ``None``
|
|
164
|
+
-> ``object_type`` is auto-set to ``"ASSOCIATION"`` so the
|
|
165
|
+
common "I am a child of X" call site Just Works without any
|
|
166
|
+
caller having to remember the orchestration role.
|
|
167
|
+
* ``parent_object_name`` is set and ``supa_role`` is explicitly
|
|
168
|
+
something other than ``"ASSOCIATION"`` / ``"HISTORY"``
|
|
169
|
+
(e.g., ``"PRIMARY"``) -> the helper raises ``ValueError``
|
|
170
|
+
because that combination silently breaks Java's parent-child
|
|
171
|
+
linkage, which is almost certainly a call-site bug.
|
|
172
|
+
* Any other explicit ``supa_role`` value is honoured verbatim.
|
|
173
|
+
|
|
174
|
+
Connectors that need to encode children (e.g., dlt-normalised
|
|
175
|
+
``orders__line_items``) keep the in-namespace ``name`` for the
|
|
176
|
+
child too and pass ``parent_object_name`` as the parent's
|
|
177
|
+
fully-qualified name so cross-catalog parent linkage stays
|
|
178
|
+
unambiguous.
|
|
179
|
+
"""
|
|
180
|
+
if parent_object_name is not None:
|
|
181
|
+
if supa_role is None:
|
|
182
|
+
supa_role = "ASSOCIATION"
|
|
183
|
+
elif supa_role not in _PARENT_LINKED_ROLES:
|
|
184
|
+
raise ValueError(
|
|
185
|
+
f"build_object_info_namespaced: parent_object_name="
|
|
186
|
+
f"{parent_object_name!r} requires supa_role in "
|
|
187
|
+
f"{sorted(_PARENT_LINKED_ROLES)}; got {supa_role!r}. "
|
|
188
|
+
"Java's PipelineOrchestrator only builds parent-child "
|
|
189
|
+
"execution linkage for ASSOCIATION and HISTORY roles -- "
|
|
190
|
+
"any other role on a parent-linked object would silently "
|
|
191
|
+
"run the child as a top-level job."
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
return SchemaObjectInfo(
|
|
195
|
+
name=name,
|
|
196
|
+
catalog=catalog,
|
|
197
|
+
schema=schema,
|
|
198
|
+
fully_qualified_name=format_fqn(catalog, schema, name, separator=fqn_separator),
|
|
199
|
+
fields=fields,
|
|
200
|
+
type=source_object_type,
|
|
201
|
+
incremental_strategy=incremental_strategy,
|
|
202
|
+
identity_strategy=identity_strategy,
|
|
203
|
+
cursor_field_locked=True if cursor_field_name else None,
|
|
204
|
+
primary_key_locked=True if primary_key else None,
|
|
205
|
+
description=description,
|
|
206
|
+
parent_object_name=parent_object_name,
|
|
207
|
+
object_type=supa_role,
|
|
208
|
+
path_segments=path_segments,
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
# ---------------------------------------------------------------------------
|
|
213
|
+
# Read-time resolution
|
|
214
|
+
# ---------------------------------------------------------------------------
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def _components_key(
|
|
218
|
+
catalog: str | None,
|
|
219
|
+
schema: str | None,
|
|
220
|
+
name: str,
|
|
221
|
+
*,
|
|
222
|
+
case_policy: CasePolicy,
|
|
223
|
+
) -> tuple[str | None, str | None, str]:
|
|
224
|
+
"""Normalise a (catalog, schema, name) triple under ``case_policy``."""
|
|
225
|
+
return (
|
|
226
|
+
case_policy(catalog) if catalog is not None else None,
|
|
227
|
+
case_policy(schema) if schema is not None else None,
|
|
228
|
+
case_policy(name),
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def build_components_index(
|
|
233
|
+
refs: Sequence[object],
|
|
234
|
+
*,
|
|
235
|
+
catalog_attr: str = "catalog",
|
|
236
|
+
schema_attr: str = "schema",
|
|
237
|
+
name_attr: str = "name",
|
|
238
|
+
case_policy: CasePolicy = CASE_SENSITIVE,
|
|
239
|
+
) -> dict[tuple[str | None, str | None, str], object]:
|
|
240
|
+
"""Build a (catalog, schema, name) -> ref index from connector refs.
|
|
241
|
+
|
|
242
|
+
``refs`` is a sequence of any per-object reference type the
|
|
243
|
+
connector uses internally (e.g., ``MongoObjectRef``). The three
|
|
244
|
+
``*_attr`` arguments are the attribute names on those refs that
|
|
245
|
+
hold the structured components -- defaulting to the obvious
|
|
246
|
+
``catalog`` / ``schema`` / ``name`` so most connectors do not need
|
|
247
|
+
to override.
|
|
248
|
+
"""
|
|
249
|
+
index: dict[tuple[str | None, str | None, str], object] = {}
|
|
250
|
+
for ref in refs:
|
|
251
|
+
key = _components_key(
|
|
252
|
+
getattr(ref, catalog_attr, None),
|
|
253
|
+
getattr(ref, schema_attr, None),
|
|
254
|
+
getattr(ref, name_attr),
|
|
255
|
+
case_policy=case_policy,
|
|
256
|
+
)
|
|
257
|
+
index[key] = ref
|
|
258
|
+
return index
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def resolve_object_ref(
|
|
262
|
+
metadata: ReadObjectMetadata,
|
|
263
|
+
*,
|
|
264
|
+
refs_by_components: Mapping[tuple[str | None, str | None, str], object],
|
|
265
|
+
refs_by_legacy_name: Mapping[str, object] | None = None,
|
|
266
|
+
case_policy: CasePolicy = CASE_SENSITIVE,
|
|
267
|
+
) -> object | None:
|
|
268
|
+
"""Resolve a connector ref from a ``ReadObjectMetadata``.
|
|
269
|
+
|
|
270
|
+
Resolution order:
|
|
271
|
+
|
|
272
|
+
1. Structured components: try
|
|
273
|
+
``(metadata.catalog, metadata.schema, metadata.name)`` against
|
|
274
|
+
``refs_by_components``, applying ``case_policy`` to each
|
|
275
|
+
non-None component.
|
|
276
|
+
2. Legacy flattened-name fallback: if the structured lookup misses
|
|
277
|
+
and ``refs_by_legacy_name`` is supplied, try
|
|
278
|
+
``metadata.name`` and ``metadata.fully_qualified_name``
|
|
279
|
+
against it. The same ``case_policy`` is applied to the lookup
|
|
280
|
+
key so case-insensitive sources resolve correctly when the
|
|
281
|
+
persisted casing differs from the request casing. **Callers
|
|
282
|
+
are responsible for pre-normalising
|
|
283
|
+
``refs_by_legacy_name`` keys with the same policy** at insert
|
|
284
|
+
time -- the resolver only normalises lookup keys, not the
|
|
285
|
+
map's keys, because dict lookup is one-direction. The legacy
|
|
286
|
+
branch lets a connector migrate to the namespaced contract
|
|
287
|
+
without breaking pipelines persisted under the old
|
|
288
|
+
"catalog.name"-as-name shape.
|
|
289
|
+
3. Otherwise, return ``None``. Callers fail loudly with a
|
|
290
|
+
configuration error -- silent fall-throughs hide real bugs
|
|
291
|
+
under reasonable-looking lookups.
|
|
292
|
+
"""
|
|
293
|
+
components = _components_key(
|
|
294
|
+
metadata.catalog,
|
|
295
|
+
metadata.schema,
|
|
296
|
+
metadata.name,
|
|
297
|
+
case_policy=case_policy,
|
|
298
|
+
)
|
|
299
|
+
ref = refs_by_components.get(components)
|
|
300
|
+
if ref is not None:
|
|
301
|
+
return ref
|
|
302
|
+
|
|
303
|
+
if refs_by_legacy_name is not None:
|
|
304
|
+
legacy = refs_by_legacy_name.get(case_policy(metadata.name))
|
|
305
|
+
if legacy is not None:
|
|
306
|
+
return legacy
|
|
307
|
+
if metadata.fully_qualified_name is not None:
|
|
308
|
+
legacy = refs_by_legacy_name.get(
|
|
309
|
+
case_policy(metadata.fully_qualified_name)
|
|
310
|
+
)
|
|
311
|
+
if legacy is not None:
|
|
312
|
+
return legacy
|
|
313
|
+
|
|
314
|
+
return None
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
__all__ = [
|
|
318
|
+
"CASE_SENSITIVE",
|
|
319
|
+
"CASE_INSENSITIVE",
|
|
320
|
+
"CasePolicy",
|
|
321
|
+
"build_components_index",
|
|
322
|
+
"build_object_info_namespaced",
|
|
323
|
+
"format_fqn",
|
|
324
|
+
"resolve_object_ref",
|
|
325
|
+
]
|