-
Notifications
You must be signed in to change notification settings - Fork 4
/
Query.Summarize.pq
82 lines (75 loc) · 3.07 KB
/
Query.Summarize.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
let
/*
future code
get: Number of Table Rows
test: Table.IsDistinct()
additional metadata of table
which primary keys are set
generate record of table schema, then ToString()
*/
options = [
IgnoreQueries = {"Lib", "Listing of Queries"},
HideNonTables = false
],
Query.Summarize = (optional options as nullable record) =>
let
options = [
IgnoreQueries = {"Lib", "Listing Of Queries"},
HideNonTables = false
] & options,
Source = Record.RemoveFields( #sections[Section1], options[IgnoreQueries] ),
base = Record.ToTable( Source ),
renamed_columns = Table.RenameColumns(base,
{ {"Name", "Query Name"} }),
add_QueryType = Table.AddColumn(
renamed_columns, "Query Type",
(row) => Type.ToText( row[Value] ),
type text
),
optional_removeNonTables =
if not options[HideNonTables] then add_QueryType
else Table.SelectRows( add_QueryType, each ([Query Type] = "Table" or [Value] is table)),
add_Schema = Table.AddColumn(
optional_removeNonTables, "Schema",
(row) =>
if not (row[Value] is table) then null
else
try Table.Schema( row[Value] )
catch (e) => error Error.Record(
"InnerException", "Table.Schema() failed",
e),
type table
),
add_Profile = Table.AddColumn(
add_Schema, "Profile",
(row) =>
if not (row[Value] is table) then null
else
try Table.Profile( row[Value] )
catch (e) => error Error.Record(
"InnerException", "Table.Profile() failed",
e),
type table
),
sort_type = Table.Sort( add_Profile, {
{"Query Type", Order.Descending}} ),
final = sort_type,
// converts values to typenames as text
Type.ToText = (typeInfo as any) as text =>
let
name =
if typeInfo is null then "Null"
else if typeInfo is type then "Type"
else if typeInfo is binary then "Binary"
else if typeInfo is number then "Number"
else if typeInfo is function then "Function"
else if typeInfo is list then "List"
else if typeInfo is table then "Table"
else if typeInfo is record then "Record"
else "Other" meta [ ValueType = typeInfo ]
in
name
in
final
in
Query.Summarize