-
Notifications
You must be signed in to change notification settings - Fork 4
/
import.yaml
115 lines (111 loc) · 3.09 KB
/
import.yaml
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
main:
steps:
- assignStep:
assign:
- bucket: "<YOUR BUCKET>"
- projectid: "<YOUR PROJECT ID>"
- prefix: "<YOUR FILE PREFIX>"
- query: "<YOUR BIGQUERY QUERY>"
- instance: "<YOUR CLOUD SQL INSTANCE NAME>"
- databaseschema: "<YOUR CLOUD SQL DATABASE NAME>"
- importtable: "<YOUR CLOUD SQL TABLE NAME>"
- listResult:
nextPageToken: ""
- export-query:
call: googleapis.bigquery.v2.jobs.query
args:
projectId: ${projectid}
body:
query: ${"EXPORT DATA OPTIONS( uri='gs://" + bucket + "/" + prefix + "*.csv', format='CSV', overwrite=true,header=false) AS " + query}
useLegacySql: false
- importfiles:
call: list_file_to_import
args:
pagetoken: ${listResult.nextPageToken}
bucket: ${bucket}
prefix: ${prefix}
projectid: ${projectid}
instance: ${instance}
databaseschema: ${databaseschema}
importtable: ${importtable}
result: listResult
- missing-files:
switch:
- condition: ${"nextPageToken" in listResult}
next: importfiles
list_file_to_import:
params:
- pagetoken
- bucket
- prefix
- projectid
- instance
- databaseschema
- importtable
steps:
- list-files:
call: googleapis.storage.v1.objects.list
args:
bucket: ${bucket}
pageToken: ${pagetoken}
prefix: ${prefix}
result: listResult
- process-files:
for:
value: file
in: ${listResult.items}
steps:
- wait-import:
call: import_file
args:
projectid: ${projectid}
instance: ${instance}
databaseschema: ${databaseschema}
importtable: ${importtable}
file: ${"gs://" + bucket + "/" + file.name}
- return-step:
return: ${listResult}
import_file:
params:
- projectid
- instance
- databaseschema
- importtable
- file
steps:
- callImport:
try:
call: http.post
args:
url: ${"https://sqladmin.googleapis.com/v1/projects/" + projectid + "/instances/" + instance + "/import"}
auth:
type: OAuth2
body:
importContext:
uri: ${file}
database: ${databaseschema}
fileType: CSV
csvImportOptions:
table: ${importtable}
result: operation
retry: ${http.default_retry}
- chekoperation:
switch:
- condition: ${operation.body.status != "DONE"}
next: wait
next: completed
- completed:
return: "done"
- wait:
call: sys.sleep
args:
seconds: 1
next: getoperation
- getoperation:
call: http.get
args:
url: ${operation.body.selfLink}
auth:
type: OAuth2
result: operation
next: chekoperation