-
Notifications
You must be signed in to change notification settings - Fork 5
/
realistic.yml
284 lines (249 loc) · 9.75 KB
/
realistic.yml
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
---
version: '0.1'
description: |
Realistic - A more realistic example of a test spec that highlights most of the features of dtspec.
Includes multiple, sources, targets, scenarios, factories, and slightly more
complex transformations.
In this example, we have 4 source tables (raw_students, raw_schools,
raw_classes, and dim_date), which get combined and aggregated into
two target tables (student_classes and students_per_school).
identifiers:
- identifier: students
attributes:
# The id attribute corresponds to a backend auto-generated number.
# It has not meaning to business users and would not show up in any reports.
- field: id
generator: unique_integer
# The external_id attribute is like the id printed on a student id card and has some
# real world meaning. It's string-like.
- field: external_id
generator: unique_string
- identifier: schools
attributes:
- field: id
generator: unique_integer
- field: name
generator: unique_string
prefix: "school" # Optional argument for unique_string can help troubleshoot testing issues
sources:
- source: raw_students
description: This is the main source for student data
identifier_map:
- column: id
identifier:
name: students
attribute: id
- column: external_id
identifier:
name: students
attribute: external_id
# raw_students.school_id is a foreign key to lookup the school record
# These identifiers need to be translated as well.
- column: school_id
identifier:
name: schools
attribute: id
- source: raw_schools
identifier_map:
- column: id
identifier:
name: schools
attribute: id
- column: name
identifier:
name: schools
attribute: name
- source: raw_classes
# We don't actually require a separate "classes" identifier.
# The identifier doesn't even need to be unique within rows because
# identifiers are only used to group records into classes.
# This may not be realistic for data generated through standard MVC frameworks, but
# is definitely a situation that can happen with some data sources.
identifier_map:
- column: student_id
identifier:
name: students
attribute: id
# source columns can be given defaults. This can be useful when a source field shouldn't be
# blank and needs some sensible default.
defaults:
- column: start_date
value: '2002-06-01'
# For some sources, it doesn't make sense to associate them with identifiers.
# This is true when the source data does not change from one case to the next.
# A perfect example of this is a list of dates, like this.
- source: dim_date
targets:
- target: student_classes
description: Denormalized table with one record per student per class
identifier_map:
# The transformation will map the source field "external_id" to the target field "card_id"
- column: card_id
identifier:
name: students
attribute: external_id
# Additionally, we've said that raw_schools.name is an identifier, which also appears on this target
- column: school_name
identifier:
name: schools
attribute: name
- target: students_per_school
identifier_map:
- column: school_name
identifier:
name: schools
attribute: name
factories:
- factory: SomeStudents
description: A few example students. Yes, I am mixing geek universes. So what?
data:
- source: raw_students
table: |
| id | external_id | school_id | name |
| - | - | - | - |
| stu1 | stu1 | sch1 | Buffy |
| stu2 | stu2 | sch1 | Willow |
| stu3 | stu3 | sch2 | Bill |
| stu4 | stu4 | sch2 | Ted |
# Every student will always be associated with a school, so we'll include it in the
# the same factory
- source: raw_schools
table: |
| id | name |
| - | - |
| sch1 | Sunnydale |
| sch2 | San Dimas |
# Build another factory that starts from the one we build, but combines it with some
# additional data.
- factory: StudentsWithClasses
parents:
- SomeStudents
data:
- source: raw_classes
table: |
| student_id | name | start_date |
| - | - | - |
| stu1 | Applied Stabby | 2001-09-08 |
| stu2 | Good Spells | 2002-01-09 |
| stu3 | Station | 2002-09-07 |
| stu4 | Being Excellent | 2002-09-07 |
- factory: DateDimension
data:
- source: dim_date
table: |
| date | season |
| - | - |
| 2001-09-08 | Fall 2001 |
| 2002-01-09 | Spring 2002 |
| 2002-06-01 | Summer 2002 |
| 2002-09-07 | Fall 2002 |
scenarios:
- scenario: DenormalizingStudentClasses
description: |
Shows how we take all our raw data and denormalize it
and how we handle some common edge cases.
# All cases will inherit from this factory
factory:
parents:
- StudentsWithClasses
- DateDimension
cases:
- case: BasicDenormalization
description: This is what happens when everything works normally
expected:
data:
- target: student_classes
table: |
| card_id | name | school_name | class_name | season |
| - | - | - | - | - |
| stu1 | Buffy | Sunnydale | Applied Stabby | Fall 2001 |
| stu2 | Willow | Sunnydale | Good Spells | Spring 2002 |
| stu3 | Bill | San Dimas | Station | Fall 2002 |
| stu4 | Ted | San Dimas | Being Excellent | Fall 2002 |
# Order may not always predictable. Use the by clause to order prior to comparison
by:
- card_id
- case: MissingClasses
description: Students without classes are excluded from denormalized table
factory:
data:
- source: raw_classes
table: |
| student_id | name |
| - | - |
| stu1 | Applied Stabby |
| stu2 | Good Spells |
expected:
data:
- target: student_classes
table: |
| card_id | name | class_name |
| - | - | - |
| stu1 | Buffy | Applied Stabby |
| stu2 | Willow | Good Spells |
# Can also specify column values that are constant over all records in case
values:
- column: school_name
value: Sunnydale
by:
- card_id
- case: MultipleClasses
description: Students with multiple classes have multiple records
factory:
data:
- source: raw_classes
table: |
| student_id | name |
| - | - |
| stu1 | Applied Stabby |
| stu2 | Good Spells |
| stu2 | Season 6 Spells |
| stu3 | Station |
| stu4 | Being Excellent |
| stu4 | Station |
expected:
data:
- target: student_classes
table: |
| card_id | name | school_name | class_name |
| - | - | - | - |
| stu1 | Buffy | Sunnydale | Applied Stabby |
| stu2 | Willow | Sunnydale | Good Spells |
| stu2 | Willow | Sunnydale | Season 6 Spells |
| stu3 | Bill | San Dimas | Station |
| stu4 | Ted | San Dimas | Being Excellent |
| stu4 | Ted | San Dimas | Station |
by:
- card_id
- class_name
- case: IdConcatenation
description: Identifiers can be embedded as strings in expectations
expected:
data:
- target: student_classes
table: |
| card_id | class_name | student_class_id |
| - | - | - |
| stu1 | Applied Stabby | {students.external_id[stu1]}-Applied Stabby |
| stu2 | Good Spells | {students.external_id[stu2]}-Good Spells |
| stu3 | Station | {students.external_id[stu3]}-Station |
| stu4 | Being Excellent | {students.external_id[stu4]}-Being Excellent |
by:
- card_id
- scenario: StudentAggregation
description: Counts students per school
factory:
parents:
- SomeStudents
cases:
- case: StudentAggregation
expected:
data:
- target: students_per_school
table: |
| school_name | number_of_students |
| - | - |
| Sunnydale | 2 |
| San Dimas | 2 |
by:
- school_name