@@ -34,7 +34,7 @@ def main(ctx, base_url, tenant_name, client_id, client_secret, refresh_token):
34
34
"""CLI for interacting with Workday’s Prism API"""
35
35
36
36
# initialize the prism class with your credentials
37
- p = prism .Prism (base_url , tenant_name , client_id , client_secret , refresh_token )
37
+ p = prism .Prism (base_url , tenant_name , client_id , client_secret , refresh_token , version = "v2" )
38
38
39
39
# create the bearer token
40
40
p .create_bearer_token ()
@@ -44,64 +44,89 @@ def main(ctx, base_url, tenant_name, client_id, client_secret, refresh_token):
44
44
45
45
46
46
@main .command ()
47
- @click .option ("--id " , default = None , type = str , help = "The ID of the dataset to obtain details about" )
47
+ @click .option ("--name " , default = None , type = str , help = "The name of the table to obtain details about" )
48
48
@click .pass_context
49
- def list (ctx , id ):
50
- """List all datasets of type API"""
49
+ def list (ctx , name ):
50
+ """List all tables of type API"""
51
51
52
52
# get the initialized prism class
53
53
p = ctx .obj ["p" ]
54
54
55
- # list the datasets
56
- status = p .list_dataset ( dataset_id = id )
55
+ # list the tables
56
+ status = p .list_table ( table_name = name )
57
57
58
58
# print message
59
59
if id is None :
60
- click .echo ("There are {} API datasets " .format (status ["total" ]))
60
+ click .echo ("There are {} API tables " .format (status ["total" ]))
61
61
click .echo (json .dumps (status ["data" ], indent = 2 , sort_keys = True ))
62
62
else :
63
63
click .echo (json .dumps (status , indent = 2 , sort_keys = True ))
64
64
65
65
66
66
@main .command ()
67
+ @click .argument ("table_name" , type = str )
68
+ @click .argument ("schema_path" , type = click .Path ())
69
+ @click .pass_context
70
+ def create (ctx , table_name , schema_path ):
71
+ """Create a new Prism table TABLE_NAME with schema from SCHEMA_PATH
72
+
73
+ Example: prism create my_table /home/data/schema.json
74
+ """
75
+
76
+ # get the initialized prism class
77
+ p = ctx .obj ["p" ]
78
+
79
+ # read in your table schema
80
+ schema = prism .load_schema (schema_path )
81
+
82
+ # clean up the table name
83
+ table_name = table_name .replace (" " , "_" )
84
+
85
+ # create an empty API table
86
+ table = p .create_table (table_name , schema = schema ["fields" ])
87
+
88
+ # print message
89
+ click .echo (json .dumps (table , indent = 2 , sort_keys = True ))
90
+
91
+
92
+ @main .command ()
93
+ @click .argument ("gzip_file" , type = click .Path ())
94
+ @click .argument ("table_id" , type = str )
67
95
@click .option (
68
- "--dataset_name " ,
69
- type = str ,
70
- required = True ,
71
- help = "The dataset name. The name must be unique and conform to the name validation rules " ,
96
+ "--operation " ,
97
+ type = click . Choice ([ "TruncateandInsert" , "Insert" , "Update" , "Upsert" , "Delete" ]) ,
98
+ default = "TruncateandInsert" ,
99
+ help = "The Table load operation " ,
72
100
)
73
- @click .option ("--schema_path" , type = click .Path (), required = True , help = "The path to your schema file" )
74
- @click .option ("--data_path" , type = click .Path (), required = True , help = "The path to your gzip compressed data file" )
75
101
@click .pass_context
76
- def upload (ctx , dataset_name , schema_path , data_path ):
77
- """Upload a gzip CSV file"""
102
+ def upload (ctx , gzip_file , table_id , operation ):
103
+ """Upload GZIP_FILE to TABLE_ID
104
+
105
+ Example: prism upload /home/data/file.csv.gz bbab30e3018b01a723524ce18010811b
106
+ """
78
107
79
108
# get the initialized prism class
80
109
p = ctx .obj ["p" ]
81
110
82
- # clean up the dataset name
83
- dataset_name = dataset_name . replace ( " " , "_" )
111
+ # get the details about the newly created table
112
+ details = p . describe_table ( table_id )
84
113
85
- # create an empty API dataset
86
- dataset = p .create_dataset (dataset_name )
87
-
88
- # read in your dataset schema
89
- schema = prism .load_schema (schema_path )
114
+ # convert the details to a bucket schema
115
+ bucket_schema = p .convert_describe_schema_to_bucket_schema (details )
90
116
91
117
# create a new bucket to hold your file
92
- bucket = p .create_bucket (schema , dataset [ "id" ] )
118
+ bucket = p .create_bucket (bucket_schema , table_id , operation = operation )
93
119
94
- # add your file the bucket you just created
95
- p .upload_file_to_bucket (bucket ["id" ], data_path )
120
+ # add your file to the bucket you just created
121
+ p .upload_file_to_bucket (bucket ["id" ], gzip_file )
96
122
97
123
# complete the bucket and upload your file
98
124
p .complete_bucket (bucket ["id" ])
99
125
100
- # check the status of the dataset you just created
101
- status = p .list_dataset ( dataset [ "id" ] )
126
+ # check the status of the table you just created
127
+ status = p .list_table ( table_id )
102
128
103
129
# print message
104
- click .echo ("{} has successfully uploaded" .format (dataset_name ))
105
130
click .echo (json .dumps (status ["data" ], indent = 2 , sort_keys = True ))
106
131
107
132
0 commit comments