Skip to content

Commit 730e122

Browse files
committed
Expose generated identifier preflight
1 parent 63bb245 commit 730e122

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

‎src/openstatspec/sql/profiles.py‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,23 @@ def _exceeded(reason: str, message: str, **details: Any) -> TargetCapabilityExce
102102
)
103103

104104

105+
def preflight_identifier(
106+
profile: SqlProfile, identifier: str, *, role: str,
107+
) -> None:
108+
"""Validate one generated identifier against the effective profile."""
109+
identifier_bytes = len(identifier.encode("utf-8"))
110+
if identifier_bytes > profile.identifier_limit:
111+
raise _exceeded(
112+
"identifier_limit",
113+
f"{role} {identifier!r} is {identifier_bytes} bytes; "
114+
f"{profile.name} permits {profile.identifier_limit}.",
115+
identifier=identifier,
116+
identifier_bytes=identifier_bytes,
117+
maximum=profile.identifier_limit,
118+
role=role,
119+
)
120+
121+
105122
def preflight(
106123
profile: SqlProfile,
107124
variables_or_count: int | Iterable[Mapping[str, Any]],
@@ -143,15 +160,9 @@ def preflight(
143160
source_name=source_name, expected_physical_name=expected_name,
144161
actual_physical_name=actual_name,
145162
)
146-
identifier_bytes = len(expected_name.encode("utf-8"))
147-
if identifier_bytes > profile.identifier_limit:
148-
raise _exceeded(
149-
"identifier_limit",
150-
f"identifier {expected_name!r} is {identifier_bytes} bytes; "
151-
f"{profile.name} permits {profile.identifier_limit}.",
152-
identifier=expected_name, identifier_bytes=identifier_bytes,
153-
maximum=profile.identifier_limit,
154-
)
163+
preflight_identifier(
164+
profile, expected_name, role="physical variable identifier",
165+
)
155166
if variable.get("storage_kind") == "string":
156167
declared_width = variable.get("string_width")
157168
if declared_width is not None and (

0 commit comments

Comments
 (0)