-
Notifications
You must be signed in to change notification settings - Fork 447
Add support for scheduling Data Update jobs #891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,74 @@ | ||
| #### | ||
| # This script demonstrates how to update the data within a published | ||
| # live-to-Hyper datasource on server. | ||
| # | ||
| # The sample is hardcoded against the `World Indicators` dataset and | ||
| # expects to receive the LUID of a published datasource containing | ||
| # that data. To create such a published datasource, you can use: | ||
| # ./publish_datasource.py --file ../test/assets/World\ Indicators.hyper | ||
| # which will print you the LUID of the datasource. | ||
| # | ||
| # Before running this script, the datasource will contain a region `Europe`. | ||
| # After running this script, that region will be gone. | ||
| # | ||
| #### | ||
|
|
||
| import argparse | ||
| import uuid | ||
| import logging | ||
|
|
||
| import tableauserverclient as TSC | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description='Delete the `Europe` region from a published `World Indicators` datasource.') | ||
| # Common options; please keep those in sync across all samples | ||
| parser.add_argument('--server', '-s', required=True, help='server address') | ||
| parser.add_argument('--site', '-S', help='site name') | ||
| parser.add_argument('--token-name', '-p', required=True, | ||
| help='name of the personal access token used to sign into the server') | ||
| parser.add_argument('--token-value', '-v', required=True, | ||
| help='value of the personal access token used to sign into the server') | ||
| parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error', | ||
| help='desired logging level (set to error by default)') | ||
| # Options specific to this sample | ||
| parser.add_argument('datasource_id', help="The LUID of the `World Indicators` datasource") | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| # Set logging level based on user input, or error by default | ||
| logging_level = getattr(logging, args.logging_level.upper()) | ||
| logging.basicConfig(level=logging_level) | ||
|
|
||
| tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) | ||
| server = TSC.Server(args.server, use_server_version=True) | ||
| with server.auth.sign_in(tableau_auth): | ||
| # We use a unique `request_id` for every request. | ||
| # In case the submission of the update job fails, we won't know wether the job was submitted | ||
| # or not. It could be that the server received the request, changed the data, but then the | ||
| # network connection broke down. | ||
| # If you want to have a way to retry, e.g., inserts while making sure they aren't duplicated, | ||
| # you need to use `request_id` for that purpose. | ||
| # In our case, we don't care about retries. And the delete is idempotent anyway. | ||
| # Hence, we simply use a randomly generated request id. | ||
| request_id = str(uuid.uuid4()) | ||
|
|
||
| # This action will delete all rows with `Region=Europe` from the published data source. | ||
| # Other actions (inserts, updates, ...) are also available. For more information see | ||
| # https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_how_to_update_data_to_hyper.htm | ||
| actions = [ | ||
| { | ||
| "action": "delete", | ||
| "target-table": "Extract", | ||
| "target-schema": "Extract", | ||
| "condition": {"op": "eq", "target-col": "Region", "const": {"type": "string", "v": "Europe"}} | ||
| } | ||
| ] | ||
|
|
||
| job = server.datasources.update_data(args.datasource_id, request_id=request_id, actions=actions) | ||
|
|
||
| # TODO: Add a flag that will poll and wait for the returned job to be done | ||
| print(job) | ||
|
|
||
| if __name__ == '__main__': | ||
| main() |
This file contains hidden or 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 hidden or 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 hidden or 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,9 @@ | ||
| <?xml version='1.0' encoding='UTF-8'?> | ||
| <tsResponse xmlns="http://tableau.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api https://help.tableau.com/samples/en-us/rest_api/ts-api_3_14.xsd"> | ||
| <job id="5c0ba560-c959-424e-b08a-f32ef0bfb737" mode="Asynchronous" type="UpdateUploadedFile" createdAt="2021-09-18T09:40:12Z"> | ||
| <updateUploadedFileJob> | ||
| <datasource id="9dbd2263-16b5-46e1-9c43-a76bb8ab65fb" name="test datasource"/> | ||
| <connectionLuid>7ecaccd8-39b0-4875-a77d-094f6e930019</connectionLuid> | ||
| </updateUploadedFileJob> | ||
| </job> | ||
| </tsResponse> |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some documentation about the parameters and what this method does + links to the documentation of the API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #893
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this work? Do we split the documentation from the code or is this somehow merged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for TSC, documentation and code are separated.
Not sure why, but that's how it is...
(Personally, I would prefer if functions would be documented in the source code itself, and the docs were generated from the source code, but that's not how TSC is currently handling its documentation)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this use BackgroundJobItem instead of JobItem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure what the difference between
JobItemandBackgroundJobItemis.@t8y8, @bcantoni which one should I use here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been trying to work out if the update_data method should wait for complete or return the jobitem and it looks like returning the jobitem is more consistent as this matches the other async method here (refresh).
To make this easier to use would you be open to adding a convenience method to the Jobs endpoint to wait for job completion - (e.g.
`
@api(version="3.13")
def wait_for_async_job(self, async_job_id, timeout=None):
`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think that the need to write the json for the "actions" parameter makes this harder to use than it needs to be? - I think we should keep this method so that you have the flexibility of writing your own 'actions' json but also create some convenience methods to pass the options as parameters - e.g.
i.e. hide some of the internals and allow an update by just calling:
server.datasources.update_datasource(datasource_id, path_to_database,[[keycol1,keycol1],[keycol2,keycol2]])There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented a proposal in #903. Please provide feedback on the proposed
wait_for_jobin that other PR.I would prefer not to do so. We have a documented and powerful "actions" language, i.e. the JSON structures. We shouldn't invent yet another "wrapper mini-language" here in this Python library.
Common cases (such as a short-hand notation for
matching_columnswhich doesn't need explicitop: eqelements) should rather be added on the server-side. That way, all clients (also JavaScript clients, etc.) can benefit from it.(actually, there is a proposal for a
matching_columsshort-hand syntax. It's just that we never implemented it... @jonas-eckhardt do you think we should re-prioritize that convenience feature on the server-side?)