FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
server-client-python/samples/update_datasource_data.py at development · tableau/server-client-python · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
tableau
/
server-client-python
Public
Notifications
You must be signed in to change notification settings
Fork
447
Star
714
Code
Issues
84
Pull requests
25
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
server-client-python
/
samples
/
update_datasource_data.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
83 lines (71 loc) · 3.55 KB
Breadcrumbs
server-client-python
/
samples
/
update_datasource_data.py
Copy path
File metadata and controls
83 lines (71 loc) · 3.55 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
####
# 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"
,
help
=
"server address"
)
parser
.
add_argument
(
"--site"
,
"-S"
,
help
=
"site name"
)
parser
.
add_argument
(
"--token-name"
,
"-p"
,
help
=
"name of the personal access token used to sign into the server"
)
parser
.
add_argument
(
"--token-value"
,
"-v"
,
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_hyper_data
(
args
.
datasource_id
,
request_id
=
request_id
,
actions
=
actions
)
print
(
f"Update job posted (ID:
{
job
.
id
}
)"
)
print
(
"Waiting for job..."
)
# `wait_for_job` will throw if the job isn't executed successfully
job
=
server
.
jobs
.
wait_for_job
(
job
)
print
(
"Job finished successfully"
)
if
__name__
==
"__main__"
:
main
()
Back
|
FazBrowse Home
|
New Git URL