perfomance_olap_mart.sql 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. select
  2. Db ,
  3. Suite,
  4. Test,
  5. Next_Run_start_timestamp ,
  6. Run_start_timestamp,
  7. Run_number_in_version,
  8. Run_number_in_branch_desc,
  9. MaxDuration ,
  10. MeanDuration ,
  11. MedianDuration ,
  12. MinDuration ,
  13. YdbSumMax ,
  14. YdbSumMeans ,
  15. YdbSumMin ,
  16. Version,
  17. Branch,
  18. diff_response ,
  19. Timestamp,
  20. COALESCE(Success ,0) as Success ,
  21. max(Kind) OVER (PARTITION by Db , Run_start_timestamp, Suite) as Kind,
  22. max(Report) OVER (PARTITION by Db , Run_start_timestamp, Suite) as Report,
  23. max(RunId) OVER (PARTITION by Db , Run_start_timestamp, Suite) as RunId,
  24. max(RunTs) OVER (PARTITION by Db , Run_start_timestamp, Suite) as RunTs,
  25. CASE
  26. WHEN YdbSumMeans IS NULL THEN true
  27. ELSE false
  28. END AS errors,
  29. CASE
  30. WHEN max(Report) OVER (PARTITION by Db , Run_start_timestamp, Suite) IS NULL THEN true
  31. ELSE false
  32. END AS Suite_not_runned
  33. from (
  34. SELECT
  35. null_template.Db AS Db, --only from null_template
  36. COALESCE(real_data.Kind, null_template.Kind) AS Kind,
  37. COALESCE(real_data.MaxDuration, null_template.MaxDuration) AS MaxDuration,
  38. COALESCE(real_data.MeanDuration, null_template.MeanDuration) AS MeanDuration,
  39. COALESCE(real_data.MedianDuration, null_template.MedianDuration) AS MedianDuration,
  40. COALESCE(real_data.MinDuration, null_template.MinDuration) AS MinDuration,
  41. null_template.Next_Run_start_timestamp AS Next_Run_start_timestamp, --only from null_template
  42. COALESCE(real_data.Report, null_template.Report) AS Report,
  43. COALESCE(real_data.Branch, null_template.Branch) AS Branch,
  44. COALESCE(real_data.RunId, null_template.RunId) AS RunId,
  45. COALESCE(real_data.RunTs, null_template.RunTs) AS RunTs,
  46. null_template.Run_number_in_version AS Run_number_in_version, --only from null_template
  47. null_template.Run_start_timestamp AS Run_start_timestamp, --only from null_template
  48. COALESCE(real_data.Run_number_in_branch_desc, null_template.Run_number_in_branch_desc) AS Run_number_in_branch_desc,
  49. COALESCE(real_data.Success, null_template.Success) AS Success,
  50. null_template.Suite AS Suite, --only from null_template
  51. null_template.Test AS Test, --only from null_template
  52. COALESCE(real_data.Timestamp, null_template.Timestamp) AS Timestamp,
  53. COALESCE(real_data.Version, null_template.Version) AS Version,
  54. COALESCE(real_data.YdbSumMax, null_template.YdbSumMax) AS YdbSumMax,
  55. COALESCE(real_data.YdbSumMeans, null_template.YdbSumMeans) AS YdbSumMeans,
  56. COALESCE(real_data.YdbSumMin, null_template.YdbSumMin) AS YdbSumMin,
  57. COALESCE(real_data.diff_response, null_template.diff_response) AS diff_response
  58. FROM (
  59. SELECT
  60. all_tests.*,
  61. launch_times.*
  62. FROM (
  63. SELECT
  64. launch_times.*,
  65. all_suites.*
  66. FROM (
  67. SELECT DISTINCT
  68. Db,
  69. Version,
  70. Branch,
  71. Run_start_timestamp,
  72. Run_number_in_version,
  73. Next_Run_start_timestamp,
  74. ROW_NUMBER() OVER (PARTITION BY Db, Branch ORDER BY Run_start_timestamp DESC) AS Run_number_in_branch_desc
  75. FROM (
  76. SELECT
  77. Db,
  78. Version,
  79. Run_start_timestamp,
  80. Next_Run_start_timestamp,
  81. ROW_NUMBER() OVER (PARTITION BY t1.Db, t1.Version ORDER BY t1.Run_start_timestamp ASC) AS Run_number_in_version,
  82. Unicode::SplitToList(Version, '.')[0] AS Branch
  83. FROM (
  84. SELECT
  85. runs.Db AS Db,
  86. runs.Version AS Version,
  87. run_start.Run_start_timestamp AS Run_start_timestamp,
  88. run_start.Next_Run_start_timestamp AS Next_Run_start_timestamp
  89. FROM (
  90. SELECT DISTINCT
  91. Db,
  92. Timestamp,
  93. JSON_VALUE(Info, "$.cluster.version") AS Version,
  94. CAST(RunId / 1000 AS Timestamp) AS RunTs
  95. FROM `perfomance/olap/tests_results`
  96. WHere Timestamp >= CurrentUtcDate() - 30*Interval("P1D")
  97. ) AS runs
  98. LEFT JOIN (
  99. SELECT
  100. Db,
  101. JSON_VALUE(Info, "$.cluster.version") AS Version,
  102. Timestamp AS Run_start_timestamp,
  103. LEAD(Timestamp) OVER (PARTITION BY Db, JSON_VALUE(Info, "$.cluster.version") ORDER BY Timestamp) AS Next_Run_start_timestamp
  104. FROM `perfomance/olap/tests_results`
  105. WHERE Suite = 'Clickbench' AND Test = '_Verification'
  106. And Timestamp >= CurrentUtcDate() - 30*Interval("P1D")
  107. ORDER BY Db, Run_start_timestamp DESC, Version
  108. ) AS run_start
  109. ON runs.Db = run_start.Db AND runs.Version = run_start.Version
  110. WHERE (
  111. (runs.Timestamp >= run_start.Run_start_timestamp AND runs.Timestamp < run_start.Next_Run_start_timestamp) OR
  112. (runs.Timestamp >= run_start.Run_start_timestamp AND run_start.Next_Run_start_timestamp IS NULL)
  113. )
  114. ) AS t1
  115. GROUP BY Db, Version, Run_start_timestamp, Next_Run_start_timestamp
  116. ) AS run_start
  117. GROUP BY Db, Branch, Version, Run_start_timestamp, Run_number_in_version, Next_Run_start_timestamp
  118. ) AS launch_times
  119. CROSS JOIN (
  120. SELECT
  121. Suite, Test
  122. FROM (
  123. SELECT
  124. Suite,
  125. ListSort(AGG_LIST_DISTINCT(Test)) AS Tests
  126. FROM `perfomance/olap/tests_results`
  127. WHere Timestamp >= CurrentUtcDate() - 30*Interval("P1D")
  128. GROUP BY Suite
  129. ORDER BY Suite
  130. )
  131. FLATTEN LIST BY Tests AS Test
  132. ORDER BY Suite, Test
  133. ) AS all_suites
  134. ) AS launch_times
  135. LEFT JOIN (
  136. SELECT
  137. all_tests.*,
  138. JSON_VALUE(Info, "$.report_url") AS Report,
  139. JSON_VALUE(all_tests.Info, "$.cluster.version") AS Version_n,
  140. CAST(JSON_VALUE(Stats, '$.DiffsCount') AS INT) AS diff_response,
  141. IF(Success > 0, MeanDuration / 1000) AS YdbSumMeans,
  142. IF(Success > 0, MaxDuration / 1000) AS YdbSumMax,
  143. IF(Success > 0, MinDuration / 1000) AS YdbSumMin,
  144. CAST(RunId / 1000 AS Timestamp) AS RunTs
  145. FROM `perfomance/olap/tests_results` AS all_tests
  146. Where JSON_VALUE(all_tests.Info, "$.cluster.version") is Null --and Test != '_Verification'
  147. and Timestamp >= CurrentUtcDate() - 30*Interval("P1D")
  148. ) AS all_tests
  149. ON all_tests.Db = launch_times.Db
  150. AND all_tests.Suite = launch_times.Suite
  151. AND all_tests.Test = launch_times.Test
  152. -- WHERE ( all_tests.Version_n is Null)
  153. ORDER BY Run_start_timestamp DESC, Db, launch_times.Version, RunId
  154. ) AS null_template
  155. Full OUTER join
  156. (SELECT
  157. real_data.Db AS Db,
  158. real_data.Kind AS Kind,
  159. real_data.MaxDuration AS MaxDuration,
  160. real_data.MeanDuration AS MeanDuration,
  161. real_data.MedianDuration AS MedianDuration,
  162. real_data.MinDuration AS MinDuration,
  163. real_data.Next_Run_start_timestamp AS Next_Run_start_timestamp,
  164. real_data.Report AS Report,
  165. real_data.Branch AS Branch,
  166. real_data.RunId AS RunId,
  167. real_data.RunTs AS RunTs,
  168. real_data.Run_number_in_version AS Run_number_in_version,
  169. real_data.Run_start_timestamp AS Run_start_timestamp,
  170. real_data.Run_number_in_branch_desc AS Run_number_in_branch_desc,
  171. --real_data.Stats AS Stats,
  172. real_data.Success AS Success,
  173. real_data.Suite AS Suite,
  174. real_data.Test AS Test,
  175. real_data.Timestamp AS Timestamp,
  176. real_data.Version AS Version,
  177. real_data.YdbSumMax AS YdbSumMax,
  178. real_data.YdbSumMeans AS YdbSumMeans,
  179. real_data.YdbSumMin AS YdbSumMin,
  180. real_data.diff_response AS diff_response,
  181. FROM (
  182. SELECT
  183. all_tests.*,
  184. launch_times.*,
  185. FROM (
  186. SELECT
  187. launch_times.*,
  188. all_suites.*
  189. FROM (
  190. SELECT DISTINCT
  191. Db,
  192. Version,
  193. Branch,
  194. Run_start_timestamp,
  195. Run_number_in_version,
  196. Next_Run_start_timestamp,
  197. ROW_NUMBER() OVER (PARTITION BY Db, Branch ORDER BY Run_start_timestamp DESC) AS Run_number_in_branch_desc
  198. FROM (
  199. SELECT
  200. Db,
  201. Version,
  202. Run_start_timestamp,
  203. Next_Run_start_timestamp,
  204. ROW_NUMBER() OVER (PARTITION BY t1.Db, t1.Version ORDER BY t1.Run_start_timestamp ASC) AS Run_number_in_version,
  205. Unicode::SplitToList(Version, '.')[0] AS Branch
  206. FROM (
  207. SELECT
  208. runs.Db AS Db,
  209. runs.Version AS Version,
  210. run_start.Run_start_timestamp AS Run_start_timestamp,
  211. run_start.Next_Run_start_timestamp AS Next_Run_start_timestamp
  212. FROM (
  213. SELECT DISTINCT
  214. Db,
  215. Timestamp,
  216. JSON_VALUE(Info, "$.cluster.version") AS Version,
  217. CAST(RunId / 1000 AS Timestamp) AS RunTs
  218. FROM `perfomance/olap/tests_results`
  219. WHere Timestamp >= CurrentUtcDate() - 30*Interval("P1D")
  220. ) AS runs
  221. LEFT JOIN (
  222. SELECT
  223. Db,
  224. JSON_VALUE(Info, "$.cluster.version") AS Version,
  225. Timestamp AS Run_start_timestamp,
  226. LEAD(Timestamp) OVER (PARTITION BY Db, JSON_VALUE(Info, "$.cluster.version") ORDER BY Timestamp) AS Next_Run_start_timestamp
  227. FROM `perfomance/olap/tests_results`
  228. WHERE Suite = 'Clickbench' AND Test = '_Verification'
  229. And Timestamp >= CurrentUtcDate() - 30*Interval("P1D")
  230. ORDER BY Db, Run_start_timestamp DESC, Version
  231. ) AS run_start
  232. ON runs.Db = run_start.Db AND runs.Version = run_start.Version
  233. WHERE (
  234. (runs.Timestamp >= run_start.Run_start_timestamp AND runs.Timestamp < run_start.Next_Run_start_timestamp) OR
  235. (runs.Timestamp >= run_start.Run_start_timestamp AND run_start.Next_Run_start_timestamp IS NULL)
  236. )
  237. ) AS t1
  238. GROUP BY Db, Version, Run_start_timestamp, Next_Run_start_timestamp
  239. ) AS run_start
  240. GROUP BY Db, Branch, Version, Run_start_timestamp, Run_number_in_version, Next_Run_start_timestamp
  241. ) AS launch_times
  242. CROSS JOIN (
  243. SELECT
  244. Suite, Test
  245. FROM (
  246. SELECT
  247. Suite,
  248. ListSort(AGG_LIST_DISTINCT(Test)) AS Tests
  249. FROM `perfomance/olap/tests_results`
  250. WHere Timestamp >= CurrentUtcDate() - 30*Interval("P1D")
  251. GROUP BY Suite
  252. ORDER BY Suite
  253. )
  254. FLATTEN LIST BY Tests AS Test
  255. ORDER BY Suite, Test
  256. ) AS all_suites
  257. ) AS launch_times
  258. LEFT JOIN (
  259. SELECT
  260. all_tests.*,
  261. JSON_VALUE(Info, "$.report_url") AS Report,
  262. JSON_VALUE(all_tests.Info, "$.cluster.version") AS Version_n,
  263. CAST(JSON_VALUE(Stats, '$.DiffsCount') AS INT) AS diff_response,
  264. IF(Success > 0, MeanDuration / 1000) AS YdbSumMeans,
  265. IF(Success > 0, MaxDuration / 1000) AS YdbSumMax,
  266. IF(Success > 0, MinDuration / 1000) AS YdbSumMin,
  267. CAST(RunId / 1000 AS Timestamp) AS RunTs
  268. FROM `perfomance/olap/tests_results` AS all_tests
  269. WHere Timestamp >= CurrentUtcDate() - 30*Interval("P1D")
  270. ) AS all_tests
  271. ON all_tests.Db = launch_times.Db
  272. AND all_tests.Suite = launch_times.Suite
  273. AND all_tests.Test = launch_times.Test
  274. AND all_tests.Version_n = launch_times.Version
  275. WHERE (
  276. (all_tests.Timestamp >= launch_times.Run_start_timestamp AND all_tests.Timestamp < launch_times.Next_Run_start_timestamp) OR
  277. (all_tests.Timestamp >= launch_times.Run_start_timestamp AND launch_times.Next_Run_start_timestamp IS NULL)
  278. OR all_tests.RunId IS NULL
  279. )
  280. ORDER BY Run_start_timestamp DESC, Db, Version, RunId
  281. ) AS real_data
  282. ) as real_data
  283. on null_template.Db = real_data.Db
  284. and null_template.Run_start_timestamp = real_data.Run_start_timestamp
  285. and null_template.Suite = real_data.Suite
  286. and null_template.Test = real_data.Test
  287. )