Skip to content

Commit 37cd324

Browse files
Merge pull request #37 from thoughtspot/1.8.6
1.8.6 this update fixes a type error and examples that are publicly facing and need immediately approval
2 parents 9c695d1 + 4827532 commit 37cd324

File tree

4 files changed

+65
-41
lines changed

4 files changed

+65
-41
lines changed

examples_v2/set_obj_id.py

Lines changed: 61 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
#
2+
# Set of scripts showing:
3+
# (1) How to set obj_id on objects + export TML with obj_id instead of GUID
4+
# (2) Scripts for generating automatic obj_ids from existing objects that do not have them
5+
# to build out a mapping of GUID:obj_id to generate the update REST API commands
6+
#
7+
18
import json
29
import os
310
import requests.exceptions
@@ -22,50 +29,56 @@
2229
print(e)
2330
print(e.response.content)
2431
exit()
25-
def create_obj_id_update_request(guid: str, obj_id: str):
26-
update_req = {
27-
"headers_update":
28-
(
29-
{'identifier': guid,
30-
'attributes': (
31-
{
32-
'name': 'obj_id',
33-
'value': obj_id
34-
}
35-
)
36-
}
37-
)
38-
}
39-
return update_req
4032

33+
# Simple example of setting a single obj_id on a known GUID
34+
def set_one_object():
35+
resp = ts.metadata_update_obj_id(new_obj_id='Conn.DB_Name.TableName', guid='43ab8a16-473a-44dc-9c78-4346eeb51f6c')
36+
print(json.dumps(resp, indent=2))
4137

42-
# { 'guid' : 'obj_id' }
43-
def create_multi_obj_id_update_request(guid_obj_id_map: Dict):
44-
update_req = {
45-
"headers_update": []
38+
# Simple example of setting multiple at once using the full request format
39+
def set_multiple_objects():
40+
req = {
41+
"metadata": [
42+
{
43+
"new_obj_id": "Table_A",
44+
"metadata_identifier": "43ab8a16-473a-44dc-9c78-4346eeb51f6c"
45+
},
46+
{
47+
"new_obj_id": "Table_B",
48+
"metadata_identifier": "4346eeb51f6c-9c78-473a-44dc-43ab8a16"
49+
},
50+
]
4651
}
47-
for guid in guid_obj_id_map:
48-
header_item = {
49-
'identifier': guid,
50-
'attributes': (
51-
{
52-
'name': 'obj_id',
53-
'value': guid_obj_id_map[guid]
54-
}
55-
)
56-
}
57-
update_req["headers_update"].append(header_item)
58-
59-
return update_req
6052

61-
def set_one_object():
62-
# Simple example of setting a Table object to have a Full Qualified Name as the obj_id
63-
update_req = create_obj_id_update_request(guid='43ab8a16-473a-44dc-9c78-4346eeb51f6c', obj_id='Conn.DB_Name.TableName')
64-
65-
resp = ts.metadata_headers_update(request=update_req)
53+
resp = ts.metadata_update_obj_id(request_override=req)
6654
print(json.dumps(resp, indent=2))
6755

68-
56+
# Build out full request from simple GUID:obj_id Dict
57+
def build_multiple_objects_update_request_by_guid(guid_obj_id_map: Dict):
58+
req = {
59+
"metadata": []
60+
}
61+
for g in guid_obj_id_map:
62+
req["metadata"].append(
63+
{"metadata_identifier": g,
64+
"new_obj_id": guid_obj_id_map[g]}
65+
)
66+
return req
67+
68+
# Build out full request from simple current_obj_id:new_obj_id Dict
69+
def build_multiple_objects_update_request_by_obj_id(cur_obj_id_new_obj_id_map: Dict):
70+
req = {
71+
"metadata": []
72+
}
73+
for c in cur_obj_id_new_obj_id_map:
74+
req["metadata"].append(
75+
{"current_obj_id": c,
76+
"new_obj_id": cur_obj_id_new_obj_id_map[c]}
77+
)
78+
return req
79+
80+
# Wrapper of Export TML of a single item, with lookup via GUID or obj_id, and saving to disk with
81+
# standard naming pattern
6982
def export_tml_with_obj_id(guid:Optional[str] = None,
7083
obj_id: Optional[str] = None,
7184
save_to_disk=True):
@@ -120,6 +133,12 @@ def export_tml_with_obj_id(guid:Optional[str] = None,
120133

121134
return yaml_tml
122135

136+
137+
#
138+
# Objects may have null obj_ids or will have the GUID attached on the auto-generated obj_id
139+
# To standardize for using across the entire set of Orgs, you'll need to create your own naming patterns
140+
# This shows retrieving all the objects and using either Table Attributes or Name to generate unique obj_id
141+
#
123142
def retrieve_dev_org_objects_for_mapping(org_name: Optional[str] = None, org_id: Optional[int] = None):
124143

125144
if org_id is None:
@@ -242,6 +261,10 @@ def retrieve_dev_org_objects_for_mapping(org_name: Optional[str] = None, org_id:
242261

243262
return final_guid_obj_id_map
244263

264+
265+
#
266+
# Looks at a guid:obj_id mapping and discovers any duplicate obj_ids generated by the initial auto-generation
267+
#
245268
def find_duplicate_obj_ids(initial_map: Dict) -> Dict:
246269
cnt = Counter(initial_map.values())
247270

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = thoughtspot_rest_api_v1
3-
version = 1.8.5
3+
version = 1.8.6
44
description = Library implementing the ThoughtSpot V1 REST API
55
long_description = file: README.md
66
long_description_content_type = text/markdown
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.8.5'
1+
__version__ = '1.8.6'

src/thoughtspot_rest_api_v1/tsrestapiv2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,8 @@ def metadata_headers_update(self, request: Dict):
706706
endpoint = 'metadata/headers/update'
707707
return self.post_request(endpoint=endpoint, request=request)
708708

709-
def metadata_update_obj_id(self, new_obj_id: str, guid: Optional[str], current_obj_id: Optional[str],
709+
def metadata_update_obj_id(self, new_obj_id: Optional[str] = None, guid: Optional[str] = None,
710+
current_obj_id: Optional[str] = None,
710711
request_override: Optional[Dict] = None):
711712
endpoint = 'metadata/update-obj-id'
712713
if request_override is not None:

0 commit comments

Comments
 (0)