Azure Table: Save and Resume an Entity Query
See more Azure Table Service Examples
Fetches one page per invocation and saves private JSON plus a checkpoint bound to the account, collection path, filter, projection, page size and API version. Refuses to overwrite an unprocessed page. Process/archive qa_output/table-page.json before the next run; keep table-checkpoint.json until completion.
This demonstrates at-least-once processing, not an atomic transaction between output and checkpoint. A crash or failed checkpoint write can replay a page; deduplicate by entity identity/version. A malformed checkpoint stops instead of restarting. Use a single caller, protect files, and use transactional durable state for stronger guarantees. Table contents can change during enumeration.
Targets Azure Storage Table service in the public cloud, not Azure Cosmos DB for Table. Uses Chilkat 11.6.0 or later and an unlocked library. Direct data requests pin x-ms-version 2026-04-06 and OData 3.0. Shared Key examples read private qa_data/azure/storage.json with account and access_key string fields. Authentication examples explain their additional fields. Create private local directories before running; keep credentials, tokens, SAS, entity values, checkpoints and diagnostics outside public content and source control.
HTTPS certificates are verified. Transport completion and HTTP status are checked separately. Writes are not automatically retried after an uncertain outcome. Entity keys, ETags and continuation tokens remain strings. Examples operate on the existing ExampleCustomers table unless noted; review the targets before adapting them. Microsoft Entra ID with suitable Table data roles is preferred where available.
Chilkat Lua Downloads
local chilkat = require("chilkat")
-- StringBuilder compares text by value in every generated language.
local textCompare = chilkat.StringBuilder.new()
-- Assumes Chilkat is unlocked. See Global Unlock Sample.
local success = false
local config = chilkat.JsonObject.new()
config.strict = true
success = config:load_file("qa_data/azure/storage.json")
if not success then
print("Could not load private Azure configuration.")
return
end
textCompare:clear()
textCompare:set_string(config:string_of("account"))
local sameText1 = textCompare:contents_equal("", true)
if (config:json_type_of("account") ~= 1) or (sameText1) then
print("Supply the storage account name.")
return
end
-- access_key is the base64 account key, not a connection string or SAS.
textCompare:clear()
textCompare:set_string(config:string_of("access_key"))
local sameText2 = textCompare:contents_equal("", true)
if (config:json_type_of("access_key") ~= 1) or (sameText2) then
print("Supply the base64 account access key.")
return
end
local accountText = chilkat.StringBuilder.new()
success = accountText:append(config:string_of("account"))
if not success then
print("Could not prepare the request.")
return
end
if (accountText.length < 3) or (accountText.length > 24) then
print("Storage account names need 3-24 lowercase letters or digits.")
return
end
local allowedAccountChars = chilkat.StringBuilder.new()
success = allowedAccountChars:append("abcdefghijklmnopqrstuvwxyz0123456789")
if not success then
print("Could not prepare the request.")
return
end
local charIndex = 0
while charIndex < accountText.length do
if not allowedAccountChars:contains(accountText:get_range(charIndex, 1, false), true) then
print("Storage account names need lowercase letters or digits.")
return
end
charIndex = charIndex + 1
end
local endpoint = chilkat.StringBuilder.new()
success = endpoint:append(config:string_of("account"))
if not success then
print("Could not prepare the request.")
return
end
success = endpoint:append(".table.core.windows.net")
if not success then
print("Could not prepare the request.")
return
end
-- Table names contain only letters and digits and are case-insensitive.
-- Entity PartitionKey and RowKey values are case-sensitive.
local resourcePath = "/ExampleCustomers()"
local rest = chilkat.Rest.new()
rest.connect_timeout_ms = 20000
rest.idle_timeout_ms = 60000
local azAuth = chilkat.AuthAzureStorage.new()
azAuth.account = config:string_of("account")
azAuth.access_key = config:string_of("access_key")
azAuth.service = "Table"
azAuth.scheme = "SharedKey"
azAuth.xms_version = "2026-04-06"
success = rest:set_auth_azure_storage(azAuth)
if not success then
print("Could not configure Shared Key signing.")
return
end
local connection = chilkat.Socket.new()
connection.require_ssl_cert_verify = true
connection.max_read_idle_ms = 60000
connection.max_send_idle_ms = 60000
success = connection:connect(endpoint:get_as_string(), 443, true, 20000)
if not success then
print("TLS connection failed; inspect diagnostics privately.")
return
end
-- Do not replay a write automatically after losing its response.
success = rest:use_connection(connection, false)
if not success then
print("Could not prepare the request.")
return
end
local result = chilkat.JsonObject.new()
result.strict = true
success = rest:add_header("DataServiceVersion", "3.0;NetFx")
if not success then
print("Could not prepare the request.")
return
end
success = rest:add_header("MaxDataServiceVersion", "3.0;NetFx")
if not success then
print("Could not prepare the request.")
return
end
success = rest:add_header("Content-Type", "application/json")
if not success then
print("Could not prepare the request.")
return
end
success = rest:add_header("Accept", "application/json;odata=minimalmetadata")
if not success then
print("Could not prepare the request.")
return
end
-- Single-caller, one-page-per-run example. Archive table-page.json before the next run.
local files = chilkat.FileAccess.new()
if files:file_exists("qa_output/table-page.json") then
print("Previous page output exists; process and archive it before continuing.")
return
end
local checkpoint = chilkat.JsonObject.new()
checkpoint.strict = true
local nextPartition = ""
local nextRow = ""
if files:file_exists("qa_data/azure/table-checkpoint.json") then
success = checkpoint:load_file("qa_data/azure/table-checkpoint.json")
if not success then
print("Invalid checkpoint; do not silently restart.")
return
end
textCompare:clear()
textCompare:set_string(checkpoint:string_of("path"))
local sameText3 = textCompare:contents_equal(resourcePath, true)
textCompare:clear()
textCompare:set_string(checkpoint:string_of("filter"))
local sameText4 = textCompare:contents_equal("PartitionKey eq 'customers-west'", true)
textCompare:clear()
textCompare:set_string(checkpoint:string_of("select"))
local sameText5 = textCompare:contents_equal("PartitionKey,RowKey,Address,NumberOfOrders", true)
textCompare:clear()
textCompare:set_string(checkpoint:string_of("top"))
local sameText6 = textCompare:contents_equal("100", true)
textCompare:clear()
textCompare:set_string(checkpoint:string_of("version"))
local sameText7 = textCompare:contents_equal("2026-04-06", true)
if (checkpoint:string_of("account") ~= config:string_of("account")) or ((not sameText3) or ((not sameText4) or ((not sameText5) or ((not sameText6) or (not sameText7))))) then
print("Checkpoint belongs to a different account or query.")
return
end
if (checkpoint:json_type_of("complete") ~= 5) or ((checkpoint:json_type_of("partition") ~= 1) or (checkpoint:json_type_of("row") ~= 1)) then
print("Checkpoint fields are invalid.")
return
end
if checkpoint:bool_of("complete") then
print("Query already complete.")
return
end
nextPartition = checkpoint:string_of("partition")
nextRow = checkpoint:string_of("row")
textCompare:clear()
textCompare:set_string(nextPartition)
local sameText8 = textCompare:contents_equal("", true)
if sameText8 then
print("Incomplete checkpoint has no continuation token.")
return
end
end
success = rest:add_query_param("$filter", "PartitionKey eq 'customers-west'")
if not success then
print("Could not prepare the request.")
return
end
success = rest:add_query_param("$select", "PartitionKey,RowKey,Address,NumberOfOrders")
if not success then
print("Could not prepare the request.")
return
end
success = rest:add_query_param("$top", "100")
if not success then
print("Could not prepare the request.")
return
end
textCompare:clear()
textCompare:set_string(nextPartition)
local sameText9 = textCompare:contents_equal("", true)
if not sameText9 then
success = rest:add_query_param("NextPartitionKey", nextPartition)
if not success then
print("Could not prepare the request.")
return
end
end
textCompare:clear()
textCompare:set_string(nextRow)
local sameText10 = textCompare:contents_equal("", true)
if not sameText10 then
success = rest:add_query_param("NextRowKey", nextRow)
if not success then
print("Could not prepare the request.")
return
end
end
local responseText = rest:full_request_no_body("GET", resourcePath)
if not rest.last_method_success then
print("Request did not complete; inspect the target before retrying a write.")
return
end
if rest.response_status_code ~= 200 then
print("HTTP status: " .. rest.response_status_code)
print("Request ID: " .. rest:response_hdr_by_name("x-ms-request-id"))
-- 404 is missing, 409 is conflict, and 412 is a stale ETag: none are success.
-- Keep response bodies private. Reconcile uncertain writes before retrying.
return
end
success = result:load(responseText)
if not success then
print("Expected well-formed JSON.")
return
end
if result:json_type_of("value") ~= 4 then
print("Missing entity/table array.")
return
end
local followingPartition = rest:response_hdr_by_name("x-ms-continuation-NextPartitionKey")
local followingRow = rest:response_hdr_by_name("x-ms-continuation-NextRowKey")
textCompare:clear()
textCompare:set_string(followingPartition)
local sameText11 = textCompare:contents_equal("null", true)
if sameText11 then
followingPartition = ""
end
textCompare:clear()
textCompare:set_string(followingRow)
local sameText12 = textCompare:contents_equal("null", true)
if sameText12 then
followingRow = ""
end
textCompare:clear()
textCompare:set_string(followingPartition)
local sameText13 = textCompare:contents_equal("", true)
textCompare:clear()
textCompare:set_string(followingRow)
local sameText14 = textCompare:contents_equal("", true)
if (sameText13) and (not sameText14) then
print("Malformed continuation.")
return
end
textCompare:clear()
textCompare:set_string(followingPartition)
local sameText15 = textCompare:contents_equal("", true)
textCompare:clear()
textCompare:set_string(followingPartition)
local sameText16 = textCompare:contents_equal(nextPartition, true)
textCompare:clear()
textCompare:set_string(followingRow)
local sameText17 = textCompare:contents_equal(nextRow, true)
if (not sameText15) and ((sameText16) and (sameText17)) then
print("Service repeated the current checkpoint.")
return
end
-- Save the page before advancing its checkpoint. Failures can cause replay, never intentional skipping.
success = result:write_file("qa_output/table-page.json")
if not success then
print("Could not save private page output.")
return
end
success = checkpoint:update_string("account", config:string_of("account"))
if not success then
print("Could not prepare the request.")
return
end
success = checkpoint:update_string("path", resourcePath)
if not success then
print("Could not prepare the request.")
return
end
success = checkpoint:update_string("filter", "PartitionKey eq 'customers-west'")
if not success then
print("Could not prepare the request.")
return
end
success = checkpoint:update_string("select", "PartitionKey,RowKey,Address,NumberOfOrders")
if not success then
print("Could not prepare the request.")
return
end
success = checkpoint:update_string("top", "100")
if not success then
print("Could not prepare the request.")
return
end
success = checkpoint:update_string("version", "2026-04-06")
if not success then
print("Could not prepare the request.")
return
end
success = checkpoint:update_string("partition", followingPartition)
if not success then
print("Could not prepare the request.")
return
end
success = checkpoint:update_string("row", followingRow)
if not success then
print("Could not prepare the request.")
return
end
local completed = false
textCompare:clear()
textCompare:set_string(followingPartition)
local sameText18 = textCompare:contents_equal("", true)
if sameText18 then
completed = true
end
success = checkpoint:update_bool("complete", completed)
if not success then
print("Could not prepare the request.")
return
end
success = checkpoint:write_file("qa_data/azure/table-checkpoint.json")
if not success then
print("Page saved but checkpoint write failed. Preserve the page and reconcile before resuming.")
return
end
print("Page and continuation checkpoint saved privately.")