Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let tablePrefix = "TimeseriesTable";
- let partitions = 2;
- //
- let partitionTables = materialize(
- range i from 0 to partitions - 1 step 1
- | extend t = strcat(tablePrefix, "_", i)
- );
- //
- let dropTables = toscalar(
- partitionTables
- | summarize makelist(t)
- | project strcat(".drop tables (\n", strcat_array(list_t, ",\n"), "\n) ifexists")
- );
- //
- let createTables = toscalar(
- partitionTables
- | project t = strcat(" ", t, " (Sensor:string, Timestamp:datetime, Value:real)")
- | summarize makelist(t)
- | project strcat(".create tables\n", strcat_array(list_t, ",\n"))
- );
- //
- let alterFolder = toscalar(
- partitionTables
- | project t = strcat(".alter table ", t, " folder \"Partitioned Tables\"")
- | summarize makelist(t)
- | project strcat_array(list_t, "\n\n")
- );
- //
- let updatePolicy = toscalar(
- partitionTables
- | project t = strcat(".alter-merge table ", t, " policy update @'[{\"IsEnabled\": true, \"Source\": \"", tablePrefix, "_Staging\", \"Query\": \"", tablePrefix, "_UpdateFunction(", i, ")\", \"IsTransactional\": true, \"PropagateIngestionProperties\": true}]'")
- | summarize makelist(t)
- | project strcat_array(list_t, "\n\n")
- );
- //
- let unionFunction = toscalar(
- partitionTables
- | project t = strcat(" (", t, " | where hash(Sensor, 100) == ", i, ")")
- | summarize makelist(t)
- | project strcat(".create-or-alter function f", tablePrefix, "()", "\n{\n union\n", strcat_array(list_t, ",\n"), "\n}")
- );
- //
- let scriptArray=pack_array(
- dropTables,
- createTables,
- alterFolder,
- updatePolicy,
- unionFunction);
- //
- print strcat_array(scriptArray, "\n\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement