Skip to content

Instantly share code, notes, and snippets.

@martijnlentink
Created September 17, 2019 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martijnlentink/b69092630f2cce6c3a92762600e200f5 to your computer and use it in GitHub Desktop.
Save martijnlentink/b69092630f2cce6c3a92762600e200f5 to your computer and use it in GitHub Desktop.
// 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