Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
61 lines (59 sloc)
2.26 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(inputTable as table) as text => | |
let | |
source = Table.Schema(inputTable) | |
,sortRows = Table.Sort(source,{{"Position", Order.Ascending}}) | |
,simplifyTypeNameRec = | |
[#"Any.Type" = "any" | |
,#"Binary.Type" = "binary" | |
,#"Date.Type" = "date" | |
,#"DateTime.Type" = "datetime" | |
,#"DateTimeZone.Type" = "datetimezone" | |
,#"Duration.Type" = "duration" | |
,#"Function.Type" = "function" | |
,#"List.Type" = "list" | |
,#"Logical.Type" = "logical" | |
,#"None.Type" = "none" | |
,#"Null.Type" = "null" | |
,#"Number.Type" = "number" | |
,#"Record.Type" = "record" | |
,#"Table.Type" = "table" | |
,#"Text.Type" = "text" | |
,#"Time.Type" = "time" | |
,#"Type.Type" = "type"] | |
,simplifyTypeNames = Table.TransformColumns(sortRows,{{"TypeName", each Record.FieldOrDefault(simplifyTypeNameRec,_,_)}}) | |
,selectColumns = Table.SelectColumns(simplifyTypeNames,{"Name", "TypeName","IsNullable"}) | |
,addColOfTypeNames = | |
Table.AddColumn( | |
selectColumns | |
,"TypeNames" | |
,each | |
Expression.Identifier([Name]) | |
& " = " | |
& (if [IsNullable] then "nullable " else "") | |
& [TypeName] | |
) | |
,tableTypeRec = "[" & Text.Combine(addColOfTypeNames[TypeNames], ", ") & "]" | |
//Code above is based on a function by Chris Webb | |
,tableOfExpressions = Table.TransformColumns(inputTable,{},Expression.Constant) | |
,listOfCols = Table.ToColumns(tableOfExpressions) | |
,listOfColsOfPaddedText = | |
List.Transform( | |
listOfCols | |
,(col as list)=> | |
let | |
buf = List.Buffer(col), | |
maxTextLength = List.Max(List.Transform(buf,Text.Length)), | |
paddedText = List.Transform(buf,each Text.PadEnd(_,maxTextLength)) | |
in | |
paddedText | |
) | |
,listOfRowsOfPaddedText = List.Zip(listOfColsOfPaddedText) | |
,bodyAsList = List.Transform(listOfRowsOfPaddedText, (row as list)=> "{"&Text.Combine(row,",")&"}") | |
,bodyAsText = "{"&Text.Combine(bodyAsList,"#(lf),")&"#(lf)}" | |
,together = "#table(type table " | |
& tableTypeRec | |
& ",#(lf)" | |
& bodyAsText | |
& ")" | |
in | |
together |