Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. let tablePrefix = "TimeseriesTable";
  2. let partitions = 2;
  3. //
  4. let partitionTables = materialize(
  5. range i from 0 to partitions - 1 step 1
  6. | extend t = strcat(tablePrefix, "_", i)
  7. );
  8. //
  9. let dropTables = toscalar(
  10. partitionTables
  11. | summarize makelist(t)
  12. | project strcat(".drop tables (\n", strcat_array(list_t, ",\n"), "\n) ifexists")
  13. );
  14. //
  15. let createTables = toscalar(
  16. partitionTables
  17. | project t = strcat(" ", t, " (Sensor:string, Timestamp:datetime, Value:real)")
  18. | summarize makelist(t)
  19. | project strcat(".create tables\n", strcat_array(list_t, ",\n"))
  20. );
  21. //
  22. let alterFolder = toscalar(
  23. partitionTables
  24. | project t = strcat(".alter table ", t, " folder \"Partitioned Tables\"")
  25. | summarize makelist(t)
  26. | project strcat_array(list_t, "\n\n")
  27. );
  28. //
  29. let updatePolicy = toscalar(
  30. partitionTables
  31. | project t = strcat(".alter-merge table ", t, " policy update @'[{\"IsEnabled\": true, \"Source\": \"", tablePrefix, "_Staging\", \"Query\": \"", tablePrefix, "_UpdateFunction(", i, ")\", \"IsTransactional\": true, \"PropagateIngestionProperties\": true}]'")
  32. | summarize makelist(t)
  33. | project strcat_array(list_t, "\n\n")
  34. );
  35. //
  36. let unionFunction = toscalar(
  37. partitionTables
  38. | project t = strcat(" (", t, " | where hash(Sensor, 100) == ", i, ")")
  39. | summarize makelist(t)
  40. | project strcat(".create-or-alter function f", tablePrefix, "()", "\n{\n union\n", strcat_array(list_t, ",\n"), "\n}")
  41. );
  42. //
  43. let scriptArray=pack_array(
  44. dropTables,
  45. createTables,
  46. alterFolder,
  47. updatePolicy,
  48. unionFunction);
  49. //
  50. print strcat_array(scriptArray, "\n\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement