Skip to content
This repository has been archived by the owner on Feb 14, 2025. It is now read-only.

Commit

Permalink
Merge branch 'disambiguate' into v2_main
Browse files Browse the repository at this point in the history
  • Loading branch information
boonhapus committed Feb 9, 2025
2 parents 3ad11bc + 8cecd77 commit d3983af
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/thoughtspot_tml/__project__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.3.0"
__version__ = "2.3.1"
64 changes: 44 additions & 20 deletions src/thoughtspot_tml/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,28 +353,52 @@ def disambiguate(
tml.guid = guid_mapping[tml.guid]

elif delete_unmapped_guids:
tml.guid = None

IS_IDENTITY = ft.partial(lambda A: isinstance(A, (_scriptability.Identity, _scriptability.SchemaSchemaTable)))

# DEVNOTE: @boonhapus, might need to add more scans for
# - PinnedVisualization.viz_guid
# - PersonalisedViewEDocProto.view_guid
attrs = _recursive_scan(tml, check=IS_IDENTITY)

if not attrs:
log.debug(f"could not find any attributes to disambiguate on {tml}")
tml.guid = None # type: ignore[assignment]

ATTEMPT_TO_REMAP = {
# DEV NOTE: @boonhapus, 2025/02/09
# 1. Check each object based on the partial.
# 2. If it matches.. search for the mapping key (in priority order)
# 3. Replace it with the mapping value.
# 4. If no mapping was found, and delete_unmapped_guids is True, set the key to None
#
# LOGICAL_TABLE TABLE refernces
_scriptability.Identity: {
"check": ft.partial(lambda A: isinstance(A, _scriptability.Identity)),
"search": ("fqn", "name"),
"map": "fqn",
},
# MODEL TABLE refernces
_scriptability.SchemaSchemaTable: {
"check": ft.partial(lambda A: isinstance(A, _scriptability.SchemaSchemaTable)),
"search": ("fqn", "name"),
"map": "fqn",
},
# LIVEBOARD ANSWER.viz_guid
_scriptability.PinnedVisualization: {
"check": ft.partial(lambda A: isinstance(A, _scriptability.PinnedVisualization)),
"search": ("viz_guid",),
"map": "viz_guid",
},
# PERSONALIZED LIVEBOARDS
_scriptability.PersonalisedViewEDocProto: {
"check": ft.partial(lambda A: isinstance(A, _scriptability.PersonalisedViewEDocProto)),
"search": ("view_guid",),
"map": "view_guid",
},
}

for attribute in attrs:
# NAME -> GUID
if attribute.name in guid_mapping:
attribute.fqn = guid_mapping[attribute.name]
for _, remapping_info in ATTEMPT_TO_REMAP.items():
for attribute in _recursive_scan(tml, check=remapping_info["check"]):
for subattr in remapping_info["search"]:
identifier = getattr(attribute, subattr)

# ENVT_A.GUID -> ENVT_B.GUID
elif attribute.fqn in guid_mapping:
attribute.fqn = guid_mapping[attribute.fqn]
if identifier in guid_mapping:
setattr(attribute, remapping_info["map"], guid_mapping[identifier])
break

elif delete_unmapped_guids:
attribute.fqn = None
else:
if delete_unmapped_guids:
setattr(attribute, subattr, None)

return tml

0 comments on commit d3983af

Please sign in to comment.