-
Notifications
You must be signed in to change notification settings - Fork 4
/
Assert.ColumnsExist.pq
58 lines (54 loc) · 2.34 KB
/
Assert.ColumnsExist.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
let
// This function is WIP
Assert.ColumnsExist = (source as table, requiredNames as list) as any => [ // as logical => [
// refactor and export this func to shared
config = [
// DetailedOutput = true,
// CaseSensitiveCompare = true
// CultureComparer = null
],
// details = [// ],
actualCols = List.Buffer( Table.ColumnNames( source ) ),
missingCols = List.RemoveItems( requiredNames, actualCols ),
extraCols = List.RemoveItems( actualCols, requiredNames ),
conditionsUsingSchema = [
Source = Table.Schema( source ),
SortedRows = Table.Sort(Source,{ { "TypeName", Order.Ascending } } ),
FindTypeAnyRows = Table.SelectRows(SortedRows, each ( [Kind] = "any" ))
],
// todo future: make names case insensitive using config
shouldThrow = List.Count( missingCols ) > 0,
FinalAssertStatement =
if not shouldThrow then true
else error [
Message.Format = Text.Combine({
"Assert: ColumnsExist failed! Target: #[Source], To find: #[ToFind]",
"ActualCols: #[ActualCols]",
"MissingCols: #[MissingCols]",
"ExtraCols: #[ExtraCols]"
}, "#(cr,lf)" ),
Message.Parameters = [
ToFind = requiredNames,
Source = source,
ActualCols = actualCols,
MissingCols = missingCols,
ExtraCols = extraCols
] ],
// return = FinalAssertStatement,
return = [
WipNotes = error "NYI",
FinalAssertStatement = FinalAssertStatement,
MissingCols = missingCols,
ExtraCols = extraCols,
ActualCols = actualCols
]
// if config[DetailedOutput] then details
// else FinalAssertStatement
// error "NYI, successfull stand alone bool"
// Table.SelectColumns( Source, ExpectCols, MissingField.Error ),
// finalCondCondition =
// try a catch (e) =>
// error e
// ][return],
][return]
in Assert.ColumnsExist