-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #461 from skalish/tc-golden-records
Add Golden Records project with update and publish functions.
- Loading branch information
Showing
16 changed files
with
221 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Golden Records | ||
|
||
* [Golden Records](/beta/golden_records/golden_records) | ||
* [Project](/beta/golden_records/project) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Golden Records | ||
============== | ||
|
||
.. autofunction:: tamr_client.golden_records.update | ||
.. autofunction:: tamr_client.golden_records.publish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Golden Records Project | ||
====================== | ||
|
||
.. autoclass:: tamr_client.GoldenRecordsProject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
""" | ||
Tamr - Golden Records | ||
See https://docs.tamr.com/docs/overview-golden-records | ||
""" | ||
from tamr_client.golden_records import project | ||
from tamr_client.golden_records._golden_records import ( | ||
_publish_async, | ||
_update_async, | ||
publish, | ||
update, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
Tamr - Golden Records | ||
See https://docs.tamr.com/docs/overview-golden-records | ||
The terminology used here is consistent with Tamr UI terminology | ||
Asynchronous versions of each function can be found with the suffix `_async` and may be of | ||
interest to power users | ||
""" | ||
from tamr_client import operation | ||
from tamr_client._types import GoldenRecordsProject, Operation, Session | ||
|
||
|
||
def update(session: Session, project: GoldenRecordsProject) -> Operation: | ||
"""Update the draft golden records and wait for the operation to complete | ||
Args: | ||
project: Tamr Golden Records project | ||
""" | ||
op = _update_async(session, project) | ||
return operation.wait(session, op) | ||
|
||
|
||
def publish(session: Session, project: GoldenRecordsProject) -> Operation: | ||
"""Publish the golden records and wait for the operation to complete | ||
Args: | ||
project: Tamr Golden Records project | ||
""" | ||
op = _publish_async(session, project) | ||
return operation.wait(session, op) | ||
|
||
|
||
def _update_async(session: Session, project: GoldenRecordsProject) -> Operation: | ||
r = session.post(str(project.url) + "/goldenRecords:refresh") | ||
return operation._from_response(project.url.instance, r) | ||
|
||
|
||
def _publish_async(session: Session, project: GoldenRecordsProject) -> Operation: | ||
r = session.post( | ||
str(project.url) + "/publishedGoldenRecords:refresh", | ||
params={"validate": "true", "version": "CURRENT"}, | ||
) | ||
return operation._from_response(project.url.instance, r) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from tamr_client._types import ( | ||
GoldenRecordsProject, | ||
JsonDict, | ||
URL, | ||
) | ||
|
||
|
||
def _from_json(url: URL, data: JsonDict) -> GoldenRecordsProject: | ||
"""Make golden records project from JSON data (deserialize) | ||
Args: | ||
url: Project URL | ||
data: Project JSON data from Tamr server | ||
""" | ||
return GoldenRecordsProject( | ||
url, name=data["name"], description=data.get("description") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
tests/tamr_client/fake_json/golden_records/test_golden_records/test_publish_async.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[ | ||
{ | ||
"request": { | ||
"method": "POST", | ||
"path": "projects/3/publishedGoldenRecords:refresh?validate=true&version=CURRENT" | ||
}, | ||
"response": { | ||
"status": 200, | ||
"json": { | ||
"id": "1", | ||
"type": "SPARK", | ||
"description": "Updating published datasets for GoldenRecords module", | ||
"status": { | ||
"state": "PENDING", | ||
"startTime": "", | ||
"endTime": "", | ||
"message": "Job has not yet been submitted to Spark" | ||
}, | ||
"created": { | ||
"username": "admin", | ||
"time": "2020-06-12T18:21:42.288Z", | ||
"version": "operation 1 created version" | ||
}, | ||
"lastModified": { | ||
"username": "admin", | ||
"time": "2020-06-12T18:21:42.288Z", | ||
"version": "operation 1 modified version" | ||
}, | ||
"relativeId": "operations/1" | ||
} | ||
} | ||
} | ||
] |
33 changes: 33 additions & 0 deletions
33
tests/tamr_client/fake_json/golden_records/test_golden_records/test_update_async.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[ | ||
{ | ||
"request": { | ||
"method": "POST", | ||
"path": "projects/3/goldenRecords:refresh" | ||
}, | ||
"response": { | ||
"status": 200, | ||
"json": { | ||
"id": "1", | ||
"type": "SPARK", | ||
"description": "Updating Golden Records", | ||
"status": { | ||
"state": "PENDING", | ||
"startTime": "", | ||
"endTime": "", | ||
"message": "Job has not yet been submitted to Spark" | ||
}, | ||
"created": { | ||
"username": "admin", | ||
"time": "2020-06-12T18:21:42.288Z", | ||
"version": "operation 1 created version" | ||
}, | ||
"lastModified": { | ||
"username": "admin", | ||
"time": "2020-06-12T18:21:42.288Z", | ||
"version": "operation 1 modified version" | ||
}, | ||
"relativeId": "operations/1" | ||
} | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import tamr_client as tc | ||
from tests.tamr_client import fake | ||
|
||
|
||
@fake.json | ||
def test_update_async(): | ||
s = fake.session() | ||
project = fake.golden_records_project() | ||
|
||
op = tc.golden_records._update_async(s, project) | ||
assert op.type == "SPARK" | ||
assert op.description == "Updating Golden Records" | ||
assert op.status == { | ||
"state": "PENDING", | ||
"startTime": "", | ||
"endTime": "", | ||
"message": "Job has not yet been submitted to Spark", | ||
} | ||
|
||
|
||
@fake.json | ||
def test_publish_async(): | ||
s = fake.session() | ||
project = fake.golden_records_project() | ||
|
||
op = tc.golden_records._publish_async(s, project) | ||
assert op.type == "SPARK" | ||
assert op.description == "Updating published datasets for GoldenRecords module" | ||
assert op.status == { | ||
"state": "PENDING", | ||
"startTime": "", | ||
"endTime": "", | ||
"message": "Job has not yet been submitted to Spark", | ||
} |