Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// RecursiveTableStorage
let
Base64Encode = (str as text) => Binary.ToText(Text.ToBinary(str, BinaryEncoding.Base64)),
CreateContinuationTokens = (partitionkey as text, rowkey as text) =>
let
tokenPrefix = "1",
combineToken = "!",
encodedPartition = Base64Encode(partitionkey),
encodedRow = Base64Encode(rowkey),
nextPartKey = Text.Combine({tokenPrefix, Text.From(Text.Length(encodedPartition)), encodedPartition}, combineToken),
nextRowKey = Text.Combine({tokenPrefix, Text.From(Text.Length(encodedRow)), encodedRow}, combineToken),
result = [ NextPartitionKey = nextPartKey, NextRowKey = nextRowKey]
in
result,
Func = (query as record, optional continuationTokens as record) =>
let
queryCombine = if continuationTokens = null then query else Record.Combine({query, continuationTokens}),
result = Json.Document(Web.Contents("https://storagename.table.core.windows.net/tablename", [ Headers=[Accept="application/json;odata=nometadata"], Query = queryCombine ])),
resultAsList = result[value],
lastInList = List.Last(resultAsList),
tokens = CreateContinuationTokens(lastInList[PartitionKey], lastInList[RowKey]),
resultList = if List.Count(resultAsList) > 1 then List.Combine({resultAsList, RecursiveTableStorage(query, tokens)}) else resultAsList
in
resultList
in
Func
// CallQuery
let
queryParameters = [ st = "2019-08-20T10:00:00Z",
se = "2030-08-25T10:00:00Z",
sp = "r",
sv = "2018-05-30",
tn = "tablename",
sig = "abcdefghijklmnopqrstuvwxyz"
],
tabledata = Table.FromRecords(RecursiveTableStorage(queryParameters)),
distinctRows = Table.Distinct(tabledata, {"PartitionKey", "RowKey"}),
in
distinctRows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.