-
Notifications
You must be signed in to change notification settings - Fork 4
/
Columns.ThatExist.pq
37 lines (31 loc) · 1.14 KB
/
Columns.ThatExist.pq
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
let
/*
Asserts if columns are valid, return their names as a list
otherwise throw
in: { "Name", "Id" }
out: good
{ "Name", "Id"}
out: bad
error Exception for missing columns
*/
Columns.ThatExist = (
source as table,
columnNames as list
) as any => [
actual_columnNames = Table.ColumnNames(source),
all_exist = List.ContainsAll( actual_columnNames, columnNames, Comparer.Ordinal ),
assert = all_exist,
valid_data = columnNames,
error_missingMandatory =
// The ErrorRecord from Err.InvalidColumnNames contains
// Message.Parameters, if you want to drill down into columnNames, and table
Err.InvalidColumnNames( source, columnNames )
meta [
NinAssertName = "Columns.ThatExist",
Activity = Diagnostics.ActivityId() ],
return =
if assert then valid_data
else error error_missingMandatory
][return]
in
Columns.ThatExist