-
Notifications
You must be signed in to change notification settings - Fork 251
Expand file tree
/
Copy pathtest_import_sql_oracle.py
More file actions
245 lines (234 loc) · 6.92 KB
/
Copy pathtest_import_sql_oracle.py
File metadata and controls
245 lines (234 loc) · 6.92 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
import yaml
from typer.testing import CliRunner
from datacontract.cli import app
from datacontract.data_contract import DataContract
# logging.basicConfig(level=logging.DEBUG, force=True)
data_definition_file = "fixtures/oracle/import/ddl.sql"
def test_cli():
runner = CliRunner()
result = runner.invoke(
app,
[
"import",
"sql",
"--source",
data_definition_file,
],
)
assert result.exit_code == 0
def test_import_sql_oracle():
result = DataContract.import_from_source("sql", data_definition_file, dialect="oracle")
expected = """
apiVersion: v3.1.0
kind: DataContract
id: my-data-contract
name: My Data Contract
version: 1.0.0
status: draft
servers:
- server: oracle
type: oracle
host: my_host
port: 1521
database: my_database
schema: my_schema
schema:
- name: field_showcase
physicalType: table
logicalType: object
physicalName: field_showcase
properties:
- name: field_primary_key
logicalType: integer
physicalType: INT
primaryKey: true
primaryKeyPosition: 1
description: Primary key
- name: field_not_null
logicalType: integer
physicalType: INT
required: true
description: Not null
- name: field_varchar
logicalType: string
physicalType: VARCHAR2
description: Variable-length string
- name: field_nvarchar
logicalType: string
physicalType: NVARCHAR2
description: Variable-length Unicode string
- name: field_number
logicalType: number
physicalType: NUMBER
description: Number
- name: field_float
logicalType: number
physicalType: FLOAT
description: Float
- name: field_date
logicalType: date
physicalType: DATE
description: Date and Time down to second precision
- name: field_binary_float
logicalType: number
physicalType: FLOAT
description: 32-bit floating point number
- name: field_binary_double
logicalType: number
physicalType: DOUBLE PRECISION
description: 64-bit floating point number
- name: field_timestamp
logicalType: timestamp
physicalType: TIMESTAMP
description: Timestamp with fractional second precision of 6, no timezones
- name: field_timestamp_tz
logicalType: timestamp
physicalType: TIMESTAMP WITH TIME ZONE
description: Timestamp with fractional second precision of 6, with timezones (TZ)
- name: field_timestamp_ltz
logicalType: timestamp
physicalType: TIMESTAMPLTZ
description: Timestamp with fractional second precision of 6, with local timezone (LTZ)
- name: field_interval_year
logicalType: object
physicalType: INTERVAL YEAR TO MONTH
description: Interval of time in years and months with default (2) precision
- name: field_interval_day
logicalType: object
physicalType: INTERVAL DAY TO SECOND
description: Interval of time in days, hours, minutes and seconds with default (2 / 6) precision
- name: field_raw
logicalType: string
logicalTypeOptions:
format: binary
physicalType: RAW
description: Large raw binary data
- name: field_rowid
logicalType: object
physicalType: ROWID
description: Base 64 string representing a unique row address
- name: field_urowid
logicalType: object
physicalType: UROWID
description: Base 64 string representing the logical address
- name: field_char
logicalType: string
logicalTypeOptions:
maxLength: 10
physicalType: CHAR(10)
description: Fixed-length string
- name: field_nchar
logicalType: string
logicalTypeOptions:
maxLength: 10
physicalType: NCHAR(10)
description: Fixed-length Unicode string
- name: field_clob
logicalType: string
physicalType: CLOB
description: Character large object
- name: field_nclob
logicalType: string
physicalType: NCLOB
description: National character large object
- name: field_blob
logicalType: string
logicalTypeOptions:
format: binary
physicalType: BLOB
description: Binary large object
- name: field_bfile
logicalType: string
logicalTypeOptions:
format: binary
physicalType: BFILE
"""
print("Result", result.to_yaml())
assert yaml.safe_load(result.to_yaml()) == yaml.safe_load(expected)
def test_import_sql_constraints():
result = DataContract.import_from_source("sql", "fixtures/postgres/data/data_constraints.sql", dialect="postgres")
expected = """
apiVersion: v3.1.0
kind: DataContract
id: my-data-contract
name: My Data Contract
version: 1.0.0
status: draft
servers:
- server: postgres
type: postgres
host: my_host
port: 5432
database: my_database
schema: public
schema:
- name: customer_location
physicalType: table
logicalType: object
physicalName: customer_location
properties:
- name: id
physicalType: DECIMAL
primaryKey: true
primaryKeyPosition: 1
logicalType: number
required: true
- name: created_by
logicalType: string
logicalTypeOptions:
maxLength: 30
physicalType: VARCHAR(30)
required: true
- name: create_date
logicalType: timestamp
physicalType: TIMESTAMP
required: true
- name: changed_by
logicalType: string
logicalTypeOptions:
maxLength: 30
physicalType: VARCHAR(30)
- name: change_date
logicalType: timestamp
physicalType: TIMESTAMP
- name: name
logicalType: string
logicalTypeOptions:
maxLength: 120
physicalType: VARCHAR(120)
required: true
- name: short_name
logicalType: string
logicalTypeOptions:
maxLength: 60
physicalType: VARCHAR(60)
- name: display_name
logicalType: string
logicalTypeOptions:
maxLength: 120
physicalType: VARCHAR(120)
required: true
- name: code
logicalType: string
logicalTypeOptions:
maxLength: 30
physicalType: VARCHAR(30)
required: true
- name: description
logicalType: string
logicalTypeOptions:
maxLength: 4000
physicalType: VARCHAR(4000)
- name: language_id
logicalType: number
physicalType: DECIMAL
required: true
- name: status
logicalType: string
logicalTypeOptions:
maxLength: 2
physicalType: VARCHAR(2)
required: true
"""
print("Result", result.to_yaml())
assert yaml.safe_load(result.to_yaml()) == yaml.safe_load(expected)