Skip to content

Commit c882a50

Browse files
mesejoclaude
andcommitted
refactor(catalog): simplify _parse_schema_in for single UnboundTable guarantee
Now that has_unbound_table enforces at most one UnboundTable at build time, replace the early-return loop with an explicit next()/None pattern that makes the single-match assumption clear. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 09ba1d5 commit c882a50

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

python/xorq/catalog/catalog.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -563,18 +563,25 @@ def _parse_schema_in(data) -> dict | None:
563563
if not isinstance(data, dict):
564564
return None
565565
definitions = data.get("definitions", {})
566-
nodes = definitions.get("nodes", {})
567566
schemas = definitions.get("schemas", {})
568-
for node_def in nodes.values():
569-
if isinstance(node_def, dict) and node_def.get("op") == "UnboundTable":
570-
schema_ref = CatalogEntry._resolve_schema_ref(
571-
node_def.get("schema_ref")
572-
)
573-
if schema_ref:
574-
schema_dict = schemas.get(schema_ref)
575-
if isinstance(schema_dict, dict):
576-
return CatalogEntry._schema_dict_to_str_dict(schema_dict)
577-
return None
567+
# At most one UnboundTable is allowed (enforced by has_unbound_table strict mode)
568+
node_def = next(
569+
(
570+
n
571+
for n in definitions.get("nodes", {}).values()
572+
if isinstance(n, dict) and n.get("op") == "UnboundTable"
573+
),
574+
None,
575+
)
576+
if node_def is None:
577+
return None
578+
schema_ref = CatalogEntry._resolve_schema_ref(node_def.get("schema_ref"))
579+
if not schema_ref:
580+
return None
581+
schema_dict = schemas.get(schema_ref)
582+
if not isinstance(schema_dict, dict):
583+
return None
584+
return CatalogEntry._schema_dict_to_str_dict(schema_dict)
578585

579586
@cached_property
580587
def backends(self) -> tuple:

0 commit comments

Comments
 (0)