forked from hpcc-systems/DataPatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTests.ecl
403 lines (359 loc) · 18.5 KB
/
Tests.ecl
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
IMPORT DataPatterns;
IMPORT Std;
EXPORT Tests := MODULE
EXPORT Engine_Test := OUTPUT
(
IF
(
Std.System.Job.Platform() IN ['hthor', 'roxie'],
Std.System.Job.Platform(),
ERROR('This code must be run on hthor or roxie')
),
NAMED('Execution_Engine')
);
//--------------------------------------------------------------------------
// Useful functions
//--------------------------------------------------------------------------
SHARED ValueForAttr(ds, attrNameStr, f) := FUNCTIONMACRO
RETURN ds(attribute = attrNameStr)[1].f;
ENDMACRO;
//--------------------------------------------------------------------------
// Baseline string test
//--------------------------------------------------------------------------
SHARED Basic_String := DATASET
(
[
'Dan', 'Steve', '', 'Mike', 'Dan', 'Sebastian', 'Dan'
],
{STRING s}
);
SHARED Basic_String_Profile := DataPatterns.Profile(Basic_String);
EXPORT Test_Basic_String_Profile :=
[
ASSERT(Basic_String_Profile[1].attribute = 's'),
ASSERT(Basic_String_Profile[1].rec_count = 7),
ASSERT(Basic_String_Profile[1].given_attribute_type = 'string'),
ASSERT((DECIMAL9_6)Basic_String_Profile[1].fill_rate = (DECIMAL9_6)85.714286),
ASSERT(Basic_String_Profile[1].fill_count = 6),
ASSERT(Basic_String_Profile[1].cardinality = 4),
ASSERT(Basic_String_Profile[1].best_attribute_type = 'string9'),
ASSERT(COUNT(Basic_String_Profile[1].modes) = 1),
ASSERT(Basic_String_Profile[1].modes[1].value = 'Dan'),
ASSERT(Basic_String_Profile[1].modes[1].rec_count = 3),
ASSERT(Basic_String_Profile[1].min_length = 3),
ASSERT(Basic_String_Profile[1].max_length = 9),
ASSERT(Basic_String_Profile[1].ave_length = 5),
ASSERT(COUNT(Basic_String_Profile[1].popular_patterns) = 4),
ASSERT(Basic_String_Profile[1].popular_patterns[1].data_pattern = 'Aaa'),
ASSERT(Basic_String_Profile[1].popular_patterns[1].rec_count = 3),
ASSERT(Basic_String_Profile[1].popular_patterns[2].data_pattern = 'Aaaa'),
ASSERT(Basic_String_Profile[1].popular_patterns[2].rec_count = 1),
ASSERT(Basic_String_Profile[1].popular_patterns[3].data_pattern = 'Aaaaa'),
ASSERT(Basic_String_Profile[1].popular_patterns[3].rec_count = 1),
ASSERT(Basic_String_Profile[1].popular_patterns[4].data_pattern = 'Aaaaaaaaa'),
ASSERT(Basic_String_Profile[1].popular_patterns[4].rec_count = 1),
ASSERT(COUNT(Basic_String_Profile[1].rare_patterns) = 0),
ASSERT(Basic_String_Profile[1].is_numeric = FALSE),
ASSERT(Basic_String_Profile[1].numeric_min = 0),
ASSERT(Basic_String_Profile[1].numeric_max = 0),
ASSERT(Basic_String_Profile[1].numeric_mean = 0),
ASSERT(Basic_String_Profile[1].numeric_std_dev = 0),
ASSERT(Basic_String_Profile[1].numeric_lower_quartile = 0),
ASSERT(Basic_String_Profile[1].numeric_median = 0),
ASSERT(Basic_String_Profile[1].numeric_upper_quartile = 0),
ASSERT(COUNT(Basic_String_Profile[1].numeric_correlations) = 0),
ASSERT(TRUE)
];
//--------------------------------------------------------------------------
// Baseline numeric test
//--------------------------------------------------------------------------
SHARED Basic_Numeric := DATASET
(
[
-1000, 500, -250, 2000, 1500, -2000, 2000
],
{INTEGER n}
);
SHARED Basic_Numeric_Profile := DataPatterns.Profile(Basic_Numeric);
EXPORT Test_Basic_Numeric_Profile :=
[
ASSERT(Basic_Numeric_Profile[1].attribute = 'n'),
ASSERT(Basic_Numeric_Profile[1].rec_count = 7),
ASSERT(Basic_Numeric_Profile[1].given_attribute_type = 'integer8'),
ASSERT(Basic_Numeric_Profile[1].fill_rate = 100),
ASSERT(Basic_Numeric_Profile[1].fill_count = 7),
ASSERT(Basic_Numeric_Profile[1].cardinality = 6),
ASSERT(Basic_Numeric_Profile[1].best_attribute_type = 'integer3'),
ASSERT(COUNT(Basic_Numeric_Profile[1].modes) = 1),
ASSERT(Basic_Numeric_Profile[1].modes[1].value = '2000'),
ASSERT(Basic_Numeric_Profile[1].modes[1].rec_count = 2),
ASSERT(Basic_Numeric_Profile[1].min_length = 3),
ASSERT(Basic_Numeric_Profile[1].max_length = 5),
ASSERT(Basic_Numeric_Profile[1].ave_length = 4),
ASSERT(COUNT(Basic_Numeric_Profile[1].popular_patterns) = 4),
ASSERT(Basic_Numeric_Profile[1].popular_patterns[1].data_pattern = '9999'),
ASSERT(Basic_Numeric_Profile[1].popular_patterns[1].rec_count = 3),
ASSERT(Basic_Numeric_Profile[1].popular_patterns[2].data_pattern = '-9999'),
ASSERT(Basic_Numeric_Profile[1].popular_patterns[2].rec_count = 2),
ASSERT(Basic_Numeric_Profile[1].popular_patterns[3].data_pattern = '-999'),
ASSERT(Basic_Numeric_Profile[1].popular_patterns[3].rec_count = 1),
ASSERT(Basic_Numeric_Profile[1].popular_patterns[4].data_pattern = '999'),
ASSERT(Basic_Numeric_Profile[1].popular_patterns[4].rec_count = 1),
ASSERT(COUNT(Basic_Numeric_Profile[1].rare_patterns) = 0),
ASSERT(Basic_Numeric_Profile[1].is_numeric = TRUE),
ASSERT(Basic_Numeric_Profile[1].numeric_min = -2000),
ASSERT(Basic_Numeric_Profile[1].numeric_max = 2000),
ASSERT(Basic_Numeric_Profile[1].numeric_mean = 392.8571),
ASSERT(Basic_Numeric_Profile[1].numeric_std_dev = 1438.3593),
ASSERT(Basic_Numeric_Profile[1].numeric_lower_quartile = -1000),
ASSERT(Basic_Numeric_Profile[1].numeric_median = 500),
ASSERT(Basic_Numeric_Profile[1].numeric_upper_quartile = 2000),
ASSERT(COUNT(Basic_Numeric_Profile[1].numeric_correlations) = 0),
ASSERT(TRUE)
];
//--------------------------------------------------------------------------
// Empty data detection
//--------------------------------------------------------------------------
// Layout contains every ECL data type that Profile can deal with
SHARED EmptyDataLayout := RECORD
BOOLEAN f_boolean;
INTEGER f_integer;
UNSIGNED f_unsigned;
UNSIGNED INTEGER f_unsigned_integer;
BIG_ENDIAN INTEGER f_big_endian_integer;
BIG_ENDIAN UNSIGNED f_big_endian_unsigned;
BIG_ENDIAN UNSIGNED INTEGER f_big_endian_unsigned_integer;
LITTLE_ENDIAN INTEGER f_little_endian_integer;
LITTLE_ENDIAN UNSIGNED f_little_endian_unsigned;
LITTLE_ENDIAN UNSIGNED INTEGER f_little_endian_unsigned_integer;
REAL f_real;
DECIMAL32 f_decimal32;
DECIMAL32_6 f_decimal32_6;
UDECIMAL32 f_udecimal32;
UDECIMAL32_6 f_udecimal32_6;
UNSIGNED DECIMAL32 f_unsigned_decimal32;
UNSIGNED DECIMAL32_6 f_unsigned_decimal32_6;
STRING f_string;
STRING256 f_string256;
ASCII STRING f_ascii_string;
ASCII STRING256 f_ascii_string256;
EBCDIC STRING f_ebcdic_string;
EBCDIC STRING256 f_ebcdic_string256;
QSTRING f_qstring;
QSTRING256 f_qstring256;
UNICODE f_unicode;
UNICODE_de f_unicode_de;
UNICODE256 f_unicode256;
UNICODE_de256 f_unicode_de256;
UTF8 f_utf8;
UTF8_de f_utf8_de;
DATA f_data;
DATA16 f_data16;
VARSTRING f_varstring;
VARSTRING256 f_varstring256;
VARUNICODE f_varunicode;
VARUNICODE_de f_varunicode_de;
VARUNICODE256 f_varunicode256;
VARUNICODE_de256 f_varunicode_de256;
END;
SHARED Empty_Data := DATASET
(
1,
TRANSFORM
(
EmptyDataLayout,
SELF := []
)
);
SHARED Empty_Data_Profile := DataPatterns.Profile(Empty_Data, features := 'cardinality,best_ecl_types,lengths,modes,patterns');
// Convenience function for testing the same thing for several attributes
SHARED TestEmptyAttr(STRING attributeName) :=
[
ASSERT(ValueForAttr(Empty_Data_Profile, attributeName, cardinality) = 0),
ASSERT(ValueForAttr(Empty_Data_Profile, attributeName, best_attribute_type) = ValueForAttr(Empty_Data_Profile, attributeName, given_attribute_type)),
ASSERT(ValueForAttr(Empty_Data_Profile, attributeName, min_length) = 0),
ASSERT(ValueForAttr(Empty_Data_Profile, attributeName, max_length) = 0),
ASSERT(ValueForAttr(Empty_Data_Profile, attributeName, ave_length) = 0),
ASSERT(COUNT(ValueForAttr(Empty_Data_Profile, attributeName, popular_patterns)) = 0),
ASSERT(COUNT(ValueForAttr(Empty_Data_Profile, attributeName, rare_patterns)) = 0),
ASSERT(TRUE)
];
EXPORT Test_Empty_Data_Profile :=
[
TestEmptyAttr('f_ascii_string'),
TestEmptyAttr('f_ascii_string16'),
TestEmptyAttr('f_big_endian_integer'),
TestEmptyAttr('f_big_endian_unsigned'),
TestEmptyAttr('f_big_endian_unsigned_integer'),
TestEmptyAttr('f_data'),
TestEmptyAttr('f_decimal32'),
TestEmptyAttr('f_decimal32_6'),
TestEmptyAttr('f_ebcdic_string'),
TestEmptyAttr('f_ebcdic_string16'),
TestEmptyAttr('f_integer'),
TestEmptyAttr('f_little_endian_integer'),
TestEmptyAttr('f_little_endian_unsigned'),
TestEmptyAttr('f_little_endian_unsigned_integer'),
TestEmptyAttr('f_qstring'),
TestEmptyAttr('f_qstring16'),
TestEmptyAttr('f_real'),
TestEmptyAttr('f_string'),
TestEmptyAttr('f_string16'),
TestEmptyAttr('f_udecimal32'),
TestEmptyAttr('f_udecimal32_6'),
TestEmptyAttr('f_unicode'),
TestEmptyAttr('f_unicode16'),
TestEmptyAttr('f_unicode_de'),
TestEmptyAttr('f_unicode_de16'),
TestEmptyAttr('f_unsigned'),
TestEmptyAttr('f_unsigned_decimal32'),
TestEmptyAttr('f_unsigned_decimal32_6'),
TestEmptyAttr('f_unsigned_integer'),
TestEmptyAttr('f_utf8'),
TestEmptyAttr('f_utf8_de'),
TestEmptyAttr('f_varstring'),
TestEmptyAttr('f_varstring16'),
TestEmptyAttr('f_varunicode'),
TestEmptyAttr('f_varunicode16'),
TestEmptyAttr('f_varunicode_de'),
TestEmptyAttr('f_varunicode_de16'),
// Handle BOOLEAN special because it is not truly empty
ASSERT(ValueForAttr(Empty_Data_Profile, 'f_boolean', cardinality) = 1),
ASSERT(ValueForAttr(Empty_Data_Profile, 'f_boolean', best_attribute_type) = ValueForAttr(Empty_Data_Profile, 'f_boolean', given_attribute_type)),
ASSERT(ValueForAttr(Empty_Data_Profile, 'f_boolean', min_length) = 1),
ASSERT(ValueForAttr(Empty_Data_Profile, 'f_boolean', max_length) = 1),
ASSERT(ValueForAttr(Empty_Data_Profile, 'f_boolean', ave_length) = 1),
ASSERT(COUNT(ValueForAttr(Empty_Data_Profile, 'f_boolean', popular_patterns)) = 1),
ASSERT(COUNT(ValueForAttr(Empty_Data_Profile, 'f_boolean', rare_patterns)) = 0),
// Handle fixed-length DATA special because it is not truly empty
ASSERT(ValueForAttr(Empty_Data_Profile, 'f_data16', cardinality) = 1),
ASSERT(ValueForAttr(Empty_Data_Profile, 'f_data16', best_attribute_type) = ValueForAttr(Empty_Data_Profile, 'f_data16', given_attribute_type)),
ASSERT(ValueForAttr(Empty_Data_Profile, 'f_data16', min_length) = 16),
ASSERT(ValueForAttr(Empty_Data_Profile, 'f_data16', max_length) = 16),
ASSERT(ValueForAttr(Empty_Data_Profile, 'f_data16', ave_length) = 16),
ASSERT(COUNT(ValueForAttr(Empty_Data_Profile, 'f_data16', popular_patterns)) = 1),
ASSERT(COUNT(ValueForAttr(Empty_Data_Profile, 'f_data16', rare_patterns)) = 0),
ASSERT(TRUE)
];
//--------------------------------------------------------------------------
// Unicode pattern detection
//--------------------------------------------------------------------------
SHARED Pattern_Unicode := DATASET
(
[
U'abcd\353', U'ABCDË'
],
{UNICODE_de5 s}
);
SHARED Pattern_Unicode_Profile := DataPatterns.Profile(Pattern_Unicode, features := 'patterns');
EXPORT Test_Pattern_Unicode_Profile :=
[
ASSERT(Pattern_Unicode_Profile[1].given_attribute_type = 'unicode_de5'),
ASSERT(COUNT(Pattern_Unicode_Profile[1].popular_patterns) = 2),
ASSERT(Pattern_Unicode_Profile[1].popular_patterns[1].data_pattern = 'AAAAA'),
ASSERT(Pattern_Unicode_Profile[1].popular_patterns[1].rec_count = 1),
ASSERT(Pattern_Unicode_Profile[1].popular_patterns[2].data_pattern = 'aaaaa'),
ASSERT(Pattern_Unicode_Profile[1].popular_patterns[2].rec_count = 1),
ASSERT(TRUE)
];
//--------------------------------------------------------------------------
// Punctuation pattern test
//--------------------------------------------------------------------------
SHARED Pattern_Punctuation := DATASET
(
[
'This! Is- Not. Helpful?'
],
{STRING s}
);
SHARED Pattern_Punctuation_Profile := DataPatterns.Profile(Pattern_Punctuation, features := 'patterns');
EXPORT Test_Pattern_Punctuation_Profile :=
[
ASSERT(Pattern_Punctuation_Profile[1].attribute = 's'),
ASSERT(COUNT(Pattern_Punctuation_Profile[1].popular_patterns) = 1),
ASSERT(Pattern_Punctuation_Profile[1].popular_patterns[1].data_pattern = 'Aaaa! Aa- Aaa. Aaaaaaa?'),
ASSERT(Pattern_Punctuation_Profile[1].popular_patterns[1].rec_count = 1),
ASSERT(TRUE)
];
//--------------------------------------------------------------------------
// Finding integers within strings test
//--------------------------------------------------------------------------
SHARED Best_Integer := DATASET
(
[
{'-100', '-100', '-1000', '-10000', '-100000'},
{'100', '100', '1000', '10000', '100000'}
],
{STRING s1, STRING s2, STRING s3, STRING s4, STRING s5}
);
SHARED Best_Integer_Profile := DataPatterns.Profile(Best_Integer, features := 'best_ecl_types');
EXPORT Test_Best_Integer_Profile :=
[
ASSERT(ValueForAttr(Best_Integer_Profile, 's1', best_attribute_type) = 'integer2'),
ASSERT(ValueForAttr(Best_Integer_Profile, 's2', best_attribute_type) = 'integer2'),
ASSERT(ValueForAttr(Best_Integer_Profile, 's3', best_attribute_type) = 'integer3'),
ASSERT(ValueForAttr(Best_Integer_Profile, 's4', best_attribute_type) = 'integer3'),
ASSERT(ValueForAttr(Best_Integer_Profile, 's5', best_attribute_type) = 'integer4'),
ASSERT(TRUE)
];
//--------------------------------------------------------------------------
// Finding unsigned integers within strings test
//--------------------------------------------------------------------------
SHARED Best_Unsigned := DATASET
(
[
{'100', '100', '1000', '10000', '100000'}
],
{STRING s1, STRING s2, STRING s3, STRING s4, STRING s5}
);
SHARED Best_Unsigned_Profile := DataPatterns.Profile(Best_Unsigned, features := 'best_ecl_types');
EXPORT Test_Best_Unsigned_Profile :=
[
ASSERT(ValueForAttr(Best_Unsigned_Profile, 's1', best_attribute_type) = 'unsigned2'),
ASSERT(ValueForAttr(Best_Unsigned_Profile, 's2', best_attribute_type) = 'unsigned2'),
ASSERT(ValueForAttr(Best_Unsigned_Profile, 's3', best_attribute_type) = 'unsigned2'),
ASSERT(ValueForAttr(Best_Unsigned_Profile, 's4', best_attribute_type) = 'unsigned3'),
ASSERT(ValueForAttr(Best_Unsigned_Profile, 's5', best_attribute_type) = 'unsigned3'),
ASSERT(TRUE)
];
//--------------------------------------------------------------------------
// Finding reals within strings test
//--------------------------------------------------------------------------
SHARED Best_Real := DATASET
(
[
{'99.99', '-99.99', '9.1234e-10', '.123', '99.0'}
],
{STRING s1, STRING s2, STRING s3, STRING s4, STRING s5}
);
SHARED Best_Real_Profile := DataPatterns.Profile(Best_Real, features := 'best_ecl_types');
EXPORT Test_Best_Real_Profile :=
[
ASSERT(ValueForAttr(Best_Real_Profile, 's1', best_attribute_type) = 'real4'),
ASSERT(ValueForAttr(Best_Real_Profile, 's2', best_attribute_type) = 'real4'),
ASSERT(ValueForAttr(Best_Real_Profile, 's3', best_attribute_type) = 'real8'),
ASSERT(ValueForAttr(Best_Real_Profile, 's4', best_attribute_type) = 'real4'),
ASSERT(ValueForAttr(Best_Real_Profile, 's5', best_attribute_type) = 'real4'),
ASSERT(TRUE)
];
//--------------------------------------------------------------------------
// Not actually numbers test
//--------------------------------------------------------------------------
SHARED Best_NaN := DATASET
(
[
{'123456789012345678901', '-12345678901234567890', '9.1234e-1000', '99.1234567890123456', '123456789012345678901.0'}
],
{STRING s1, STRING s2, STRING s3, STRING s4, STRING s5}
);
SHARED Best_NaN_Profile := DataPatterns.Profile(Best_NaN, features := 'best_ecl_types');
EXPORT Test_Best_NaN_Profile :=
[
ASSERT(ValueForAttr(Best_NaN_Profile, 's1', best_attribute_type) = 'string21'),
ASSERT(ValueForAttr(Best_NaN_Profile, 's2', best_attribute_type) = 'string21'),
ASSERT(ValueForAttr(Best_NaN_Profile, 's3', best_attribute_type) = 'string12'),
ASSERT(ValueForAttr(Best_NaN_Profile, 's4', best_attribute_type) = 'string19'),
ASSERT(ValueForAttr(Best_NaN_Profile, 's5', best_attribute_type) = 'string23'),
ASSERT(TRUE)
];
END;