|
6 | 6 | import great_expectations as gx |
7 | 7 | import great_expectations.expectations as gxe |
8 | 8 |
|
| 9 | + |
| 10 | +class ExpectContactTypeColumnValuesToBeInSet(gxe.ExpectColumnValuesToBeInSet): |
| 11 | + column: str = 'contacttype' |
| 12 | + value_set: list = ['email', 'address', 'phone'] |
| 13 | + description: str = "Expect Contact Type to be one of email, address or phone" |
| 14 | + |
| 15 | + |
| 16 | +class ExpectSubTypeColumnValuesToBeInSet(gxe.ExpectColumnValuesToBeInSet): |
| 17 | + column: str = 'subtype' |
| 18 | + value_set: list = ['mainNumber', 'emergencyContact', 'carer', 'wife', 'husband', 'spouse', 'child', 'sibling', |
| 19 | + 'relative', |
| 20 | + 'neighbour', 'doctor', 'socialWorker', 'other'] |
| 21 | + description: str = "Expect Subtype values to be within set" |
| 22 | + |
| 23 | + |
| 24 | +class ExpectTargetTypeColumnValuesToBeInSet(gxe.ExpectColumnValuesToBeInSet): |
| 25 | + column: str = 'targettype' |
| 26 | + value_set: list = ['person', 'organisation'] |
| 27 | + description: str = "Expect Target Type values to be one of person or organisation" |
| 28 | + |
| 29 | + |
| 30 | +class ExpectContactValueColumnValuesToBeUnique(gxe.ExpectColumnValuesToBeUnique): |
| 31 | + column: str = 'value' |
| 32 | + description: str = "Expect Value field to be unique for a contact type" |
| 33 | + |
| 34 | + |
| 35 | +class ExpectTargetIDAndValueColumnValuesToBeUniqueWithinRecord(gxe.ExpectSelectColumnValuesToBeUniqueWithinRecord): |
| 36 | + column_list: list = ['target_id', 'value'] |
| 37 | + description: str = "Expect Target ID and Value field to be unique for a record" |
| 38 | + |
| 39 | + |
| 40 | +class ExpectTargetIDColumnValuesToNotBeNull(gxe.ExpectColumnValuesToNotBeNull): |
| 41 | + column = 'target_id' |
| 42 | + description: str = "Expect Target ID column to be complete with no nulls" |
| 43 | + |
| 44 | + |
| 45 | +class ExpectContactValueColumnValuesToNotBeNull(gxe.ExpectColumnValuesToNotBeNull): |
| 46 | + column = 'value' |
| 47 | + description: str = "Expect Value column to be complete with no nulls" |
| 48 | + |
| 49 | + |
| 50 | +class ExpectContactTypeColumnValuesToNotBeNull(gxe.ExpectColumnValuesToNotBeNull): |
| 51 | + column = 'contacttype' |
| 52 | + description: str = "Expect Contact Type column to be complete with no nulls" |
| 53 | + |
| 54 | + |
| 55 | +class ExpectSubTypeColumnValuesToNotBeNull(gxe.ExpectColumnValuesToNotBeNull): |
| 56 | + column = 'subtype' |
| 57 | + description: str = "Expect Subtype column to be complete with no nulls" |
| 58 | + |
| 59 | + |
9 | 60 | arg_key = ['s3_target_location'] |
10 | 61 | args = getResolvedOptions(sys.argv, arg_key) |
11 | 62 | locals().update(args) |
|
14 | 65 | context = gx.get_context(mode="file", project_root_dir=s3_target_location) |
15 | 66 |
|
16 | 67 | suite = gx.ExpectationSuite(name='contacts_reshape_suite') |
17 | | -suite.add_expectation( |
18 | | - gxe.ExpectColumnValuesToBeInSet( |
19 | | - column='contacttype', |
20 | | - value_set=['email', 'address', 'phone']) |
21 | | -) |
22 | | -suite.add_expectation( |
23 | | - gxe.ExpectColumnValuesToBeInSet( |
24 | | - column='subtype', |
25 | | - value_set=['mainNumber', 'emergencyContact', 'carer', 'wife', 'husband', 'spouse', 'child', 'sibling', |
26 | | - 'relative', 'neighbour', 'doctor', 'socialWorker', 'other']) |
27 | | -) |
28 | | -suite.add_expectation( |
29 | | - gxe.ExpectColumnValuesToBeInSet( |
30 | | - column='targettype', |
31 | | - value_set=['person', 'organisation']) |
32 | | -) |
33 | | -suite.add_expectation( |
34 | | - gxe.ExpectColumnValuesToBeUnique( |
35 | | - column='value') |
36 | | -) |
37 | | -suite.add_expectation( |
38 | | - gxe.ExpectSelectColumnValuesToBeUniqueWithinRecord( |
39 | | - column_list=['target_id', 'value']) |
40 | | -) |
41 | | -suite.add_expectation( |
42 | | - gxe.ExpectColumnValuesToNotBeNull( |
43 | | - column='target_id') |
44 | | -) |
45 | | -suite.add_expectation( |
46 | | - gxe.ExpectColumnValuesToNotBeNull( |
47 | | - column='value') |
48 | | -) |
49 | | -suite.add_expectation( |
50 | | - gxe.ExpectColumnValuesToNotBeNull( |
51 | | - column='contacttype') |
52 | | -) |
53 | | -suite.add_expectation( |
54 | | - gxe.ExpectColumnValuesToNotBeNull( |
55 | | - column='subtype') |
56 | | -) |
| 68 | + |
| 69 | +suite.add_expectation(ExpectContactTypeColumnValuesToBeInSet()) |
| 70 | +suite.add_expectation(ExpectSubTypeColumnValuesToBeInSet()) |
| 71 | +suite.add_expectation(ExpectTargetTypeColumnValuesToBeInSet()) |
| 72 | +suite.add_expectation(ExpectContactValueColumnValuesToBeUnique()) |
| 73 | +suite.add_expectation(ExpectTargetIDAndValueColumnValuesToBeUniqueWithinRecord()) |
| 74 | +suite.add_expectation(ExpectTargetIDColumnValuesToNotBeNull()) |
| 75 | +suite.add_expectation(ExpectContactValueColumnValuesToNotBeNull()) |
| 76 | +suite.add_expectation(ExpectContactTypeColumnValuesToNotBeNull()) |
| 77 | +suite.add_expectation(ExpectSubTypeColumnValuesToNotBeNull()) |
57 | 78 |
|
58 | 79 | suite = context.suites.add(suite) |
0 commit comments