window_rule_test.go 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405
  1. package topotest
  2. import (
  3. "github.com/emqx/kuiper/xstream"
  4. "github.com/emqx/kuiper/xstream/api"
  5. "testing"
  6. )
  7. func TestWindow(t *testing.T) {
  8. //Reset
  9. streamList := []string{"demo", "demoError", "demo1", "sessionDemo", "table1"}
  10. HandleStream(false, streamList, t)
  11. var tests = []RuleTest{
  12. {
  13. Name: `TestWindowRule1`,
  14. Sql: `SELECT * FROM demo GROUP BY HOPPINGWINDOW(ss, 2, 1)`,
  15. R: [][]map[string]interface{}{
  16. {{
  17. "color": "red",
  18. "size": float64(3),
  19. "ts": float64(1541152486013),
  20. }, {
  21. "color": "blue",
  22. "size": float64(6),
  23. "ts": float64(1541152486822),
  24. }},
  25. {{
  26. "color": "red",
  27. "size": float64(3),
  28. "ts": float64(1541152486013),
  29. }, {
  30. "color": "blue",
  31. "size": float64(6),
  32. "ts": float64(1541152486822),
  33. }, {
  34. "color": "blue",
  35. "size": float64(2),
  36. "ts": float64(1541152487632),
  37. }},
  38. {{
  39. "color": "blue",
  40. "size": float64(2),
  41. "ts": float64(1541152487632),
  42. }, {
  43. "color": "yellow",
  44. "size": float64(4),
  45. "ts": float64(1541152488442),
  46. }},
  47. {{
  48. "color": "yellow",
  49. "size": float64(4),
  50. "ts": float64(1541152488442),
  51. }, {
  52. "color": "red",
  53. "size": float64(1),
  54. "ts": float64(1541152489252),
  55. }},
  56. },
  57. M: map[string]interface{}{
  58. "op_1_preprocessor_demo_0_exceptions_total": int64(0),
  59. "op_1_preprocessor_demo_0_process_latency_us": int64(0),
  60. "op_1_preprocessor_demo_0_records_in_total": int64(5),
  61. "op_1_preprocessor_demo_0_records_out_total": int64(5),
  62. "op_3_project_0_exceptions_total": int64(0),
  63. "op_3_project_0_process_latency_us": int64(0),
  64. "op_3_project_0_records_in_total": int64(4),
  65. "op_3_project_0_records_out_total": int64(4),
  66. "sink_mockSink_0_exceptions_total": int64(0),
  67. "sink_mockSink_0_records_in_total": int64(4),
  68. "sink_mockSink_0_records_out_total": int64(4),
  69. "source_demo_0_exceptions_total": int64(0),
  70. "source_demo_0_records_in_total": int64(5),
  71. "source_demo_0_records_out_total": int64(5),
  72. "op_2_window_0_exceptions_total": int64(0),
  73. "op_2_window_0_process_latency_us": int64(0),
  74. "op_2_window_0_records_in_total": int64(5),
  75. "op_2_window_0_records_out_total": int64(4),
  76. },
  77. }, {
  78. Name: `TestWindowRule2`,
  79. Sql: `SELECT color, ts FROM demo where size > 2 GROUP BY tumblingwindow(ss, 1)`,
  80. R: [][]map[string]interface{}{
  81. {{
  82. "color": "red",
  83. "ts": float64(1541152486013),
  84. }, {
  85. "color": "blue",
  86. "ts": float64(1541152486822),
  87. }},
  88. {{
  89. "color": "yellow",
  90. "ts": float64(1541152488442),
  91. }},
  92. },
  93. M: map[string]interface{}{
  94. "op_1_preprocessor_demo_0_exceptions_total": int64(0),
  95. "op_1_preprocessor_demo_0_process_latency_us": int64(0),
  96. "op_1_preprocessor_demo_0_records_in_total": int64(5),
  97. "op_1_preprocessor_demo_0_records_out_total": int64(5),
  98. "op_4_project_0_exceptions_total": int64(0),
  99. "op_4_project_0_process_latency_us": int64(0),
  100. "op_4_project_0_records_in_total": int64(2),
  101. "op_4_project_0_records_out_total": int64(2),
  102. "sink_mockSink_0_exceptions_total": int64(0),
  103. "sink_mockSink_0_records_in_total": int64(2),
  104. "sink_mockSink_0_records_out_total": int64(2),
  105. "source_demo_0_exceptions_total": int64(0),
  106. "source_demo_0_records_in_total": int64(5),
  107. "source_demo_0_records_out_total": int64(5),
  108. "op_3_window_0_exceptions_total": int64(0),
  109. "op_3_window_0_process_latency_us": int64(0),
  110. "op_3_window_0_records_in_total": int64(3),
  111. "op_3_window_0_records_out_total": int64(2),
  112. "op_2_filter_0_exceptions_total": int64(0),
  113. "op_2_filter_0_process_latency_us": int64(0),
  114. "op_2_filter_0_records_in_total": int64(5),
  115. "op_2_filter_0_records_out_total": int64(3),
  116. },
  117. }, {
  118. Name: `TestWindowRule3`,
  119. Sql: `SELECT color, temp, ts FROM demo INNER JOIN demo1 ON demo.ts = demo1.ts GROUP BY SlidingWindow(ss, 1)`,
  120. R: [][]map[string]interface{}{
  121. {{
  122. "color": "red",
  123. "temp": 25.5,
  124. "ts": float64(1541152486013),
  125. }}, {{
  126. "color": "red",
  127. "temp": 25.5,
  128. "ts": float64(1541152486013),
  129. }}, {{
  130. "color": "red",
  131. "temp": 25.5,
  132. "ts": float64(1541152486013),
  133. }}, {{
  134. "color": "blue",
  135. "temp": 28.1,
  136. "ts": float64(1541152487632),
  137. }}, {{
  138. "color": "blue",
  139. "temp": 28.1,
  140. "ts": float64(1541152487632),
  141. }}, {{
  142. "color": "blue",
  143. "temp": 28.1,
  144. "ts": float64(1541152487632),
  145. }, {
  146. "color": "yellow",
  147. "temp": 27.4,
  148. "ts": float64(1541152488442),
  149. }}, {{
  150. "color": "yellow",
  151. "temp": 27.4,
  152. "ts": float64(1541152488442),
  153. }}, {{
  154. "color": "yellow",
  155. "temp": 27.4,
  156. "ts": float64(1541152488442),
  157. }, {
  158. "color": "red",
  159. "temp": 25.5,
  160. "ts": float64(1541152489252),
  161. }},
  162. },
  163. M: map[string]interface{}{
  164. "op_1_preprocessor_demo_0_exceptions_total": int64(0),
  165. "op_1_preprocessor_demo_0_process_latency_us": int64(0),
  166. "op_1_preprocessor_demo_0_records_in_total": int64(5),
  167. "op_1_preprocessor_demo_0_records_out_total": int64(5),
  168. "op_2_preprocessor_demo1_0_exceptions_total": int64(0),
  169. "op_2_preprocessor_demo1_0_process_latency_us": int64(0),
  170. "op_2_preprocessor_demo1_0_records_in_total": int64(5),
  171. "op_2_preprocessor_demo1_0_records_out_total": int64(5),
  172. "op_5_project_0_exceptions_total": int64(0),
  173. "op_5_project_0_process_latency_us": int64(0),
  174. "op_5_project_0_records_in_total": int64(8),
  175. "op_5_project_0_records_out_total": int64(8),
  176. "sink_mockSink_0_exceptions_total": int64(0),
  177. "sink_mockSink_0_records_in_total": int64(8),
  178. "sink_mockSink_0_records_out_total": int64(8),
  179. "source_demo_0_exceptions_total": int64(0),
  180. "source_demo_0_records_in_total": int64(5),
  181. "source_demo_0_records_out_total": int64(5),
  182. "source_demo1_0_exceptions_total": int64(0),
  183. "source_demo1_0_records_in_total": int64(5),
  184. "source_demo1_0_records_out_total": int64(5),
  185. "op_3_window_0_exceptions_total": int64(0),
  186. "op_3_window_0_process_latency_us": int64(0),
  187. "op_3_window_0_records_in_total": int64(10),
  188. "op_3_window_0_records_out_total": int64(10),
  189. "op_4_join_0_exceptions_total": int64(0),
  190. "op_4_join_0_process_latency_us": int64(0),
  191. "op_4_join_0_records_in_total": int64(10),
  192. "op_4_join_0_records_out_total": int64(8),
  193. },
  194. T: &xstream.PrintableTopo{
  195. Sources: []string{"source_demo", "source_demo1"},
  196. Edges: map[string][]string{
  197. "source_demo": {"op_1_preprocessor_demo"},
  198. "source_demo1": {"op_2_preprocessor_demo1"},
  199. "op_1_preprocessor_demo": {"op_3_window"},
  200. "op_2_preprocessor_demo1": {"op_3_window"},
  201. "op_3_window": {"op_4_join"},
  202. "op_4_join": {"op_5_project"},
  203. "op_5_project": {"sink_mockSink"},
  204. },
  205. },
  206. }, {
  207. Name: `TestWindowRule4`,
  208. Sql: `SELECT color FROM demo GROUP BY SlidingWindow(ss, 2), color ORDER BY color`,
  209. R: [][]map[string]interface{}{
  210. {{
  211. "color": "red",
  212. }}, {{
  213. "color": "blue",
  214. }, {
  215. "color": "red",
  216. }}, {{
  217. "color": "blue",
  218. }, {
  219. "color": "red",
  220. }}, {{
  221. "color": "blue",
  222. }, {
  223. "color": "yellow",
  224. }}, {{
  225. "color": "blue",
  226. }, {
  227. "color": "red",
  228. }, {
  229. "color": "yellow",
  230. }},
  231. },
  232. M: map[string]interface{}{
  233. "op_1_preprocessor_demo_0_exceptions_total": int64(0),
  234. "op_1_preprocessor_demo_0_process_latency_us": int64(0),
  235. "op_1_preprocessor_demo_0_records_in_total": int64(5),
  236. "op_1_preprocessor_demo_0_records_out_total": int64(5),
  237. "op_5_project_0_exceptions_total": int64(0),
  238. "op_5_project_0_process_latency_us": int64(0),
  239. "op_5_project_0_records_in_total": int64(5),
  240. "op_5_project_0_records_out_total": int64(5),
  241. "sink_mockSink_0_exceptions_total": int64(0),
  242. "sink_mockSink_0_records_in_total": int64(5),
  243. "sink_mockSink_0_records_out_total": int64(5),
  244. "source_demo_0_exceptions_total": int64(0),
  245. "source_demo_0_records_in_total": int64(5),
  246. "source_demo_0_records_out_total": int64(5),
  247. "op_2_window_0_exceptions_total": int64(0),
  248. "op_2_window_0_process_latency_us": int64(0),
  249. "op_2_window_0_records_in_total": int64(5),
  250. "op_2_window_0_records_out_total": int64(5),
  251. "op_3_aggregate_0_exceptions_total": int64(0),
  252. "op_3_aggregate_0_process_latency_us": int64(0),
  253. "op_3_aggregate_0_records_in_total": int64(5),
  254. "op_3_aggregate_0_records_out_total": int64(5),
  255. "op_4_order_0_exceptions_total": int64(0),
  256. "op_4_order_0_process_latency_us": int64(0),
  257. "op_4_order_0_records_in_total": int64(5),
  258. "op_4_order_0_records_out_total": int64(5),
  259. },
  260. }, {
  261. Name: `TestWindowRule5`,
  262. Sql: `SELECT temp FROM sessionDemo GROUP BY SessionWindow(ss, 2, 1) `,
  263. R: [][]map[string]interface{}{
  264. {{
  265. "temp": 25.5,
  266. }, {
  267. "temp": 27.5,
  268. }}, {{
  269. "temp": 28.1,
  270. }, {
  271. "temp": 27.4,
  272. }, {
  273. "temp": 25.5,
  274. }}, {{
  275. "temp": 26.2,
  276. }, {
  277. "temp": 26.8,
  278. }, {
  279. "temp": 28.9,
  280. }, {
  281. "temp": 29.1,
  282. }, {
  283. "temp": 32.2,
  284. }}, {{
  285. "temp": 30.9,
  286. }},
  287. },
  288. M: map[string]interface{}{
  289. "op_1_preprocessor_sessionDemo_0_exceptions_total": int64(0),
  290. "op_1_preprocessor_sessionDemo_0_process_latency_us": int64(0),
  291. "op_1_preprocessor_sessionDemo_0_records_in_total": int64(11),
  292. "op_1_preprocessor_sessionDemo_0_records_out_total": int64(11),
  293. "op_3_project_0_exceptions_total": int64(0),
  294. "op_3_project_0_process_latency_us": int64(0),
  295. "op_3_project_0_records_in_total": int64(4),
  296. "op_3_project_0_records_out_total": int64(4),
  297. "sink_mockSink_0_exceptions_total": int64(0),
  298. "sink_mockSink_0_records_in_total": int64(4),
  299. "sink_mockSink_0_records_out_total": int64(4),
  300. "source_sessionDemo_0_exceptions_total": int64(0),
  301. "source_sessionDemo_0_records_in_total": int64(11),
  302. "source_sessionDemo_0_records_out_total": int64(11),
  303. "op_2_window_0_exceptions_total": int64(0),
  304. "op_2_window_0_process_latency_us": int64(0),
  305. "op_2_window_0_records_in_total": int64(11),
  306. "op_2_window_0_records_out_total": int64(4),
  307. },
  308. }, {
  309. Name: `TestWindowRule6`,
  310. Sql: `SELECT max(temp) as m, count(color) as c FROM demo INNER JOIN demo1 ON demo.ts = demo1.ts GROUP BY SlidingWindow(ss, 1)`,
  311. R: [][]map[string]interface{}{
  312. {{
  313. "m": 25.5,
  314. "c": float64(1),
  315. }}, {{
  316. "m": 25.5,
  317. "c": float64(1),
  318. }}, {{
  319. "m": 25.5,
  320. "c": float64(1),
  321. }}, {{
  322. "m": 28.1,
  323. "c": float64(1),
  324. }}, {{
  325. "m": 28.1,
  326. "c": float64(1),
  327. }}, {{
  328. "m": 28.1,
  329. "c": float64(2),
  330. }}, {{
  331. "m": 27.4,
  332. "c": float64(1),
  333. }}, {{
  334. "m": 27.4,
  335. "c": float64(2),
  336. }},
  337. },
  338. M: map[string]interface{}{
  339. "op_1_preprocessor_demo_0_exceptions_total": int64(0),
  340. "op_1_preprocessor_demo_0_process_latency_us": int64(0),
  341. "op_1_preprocessor_demo_0_records_in_total": int64(5),
  342. "op_1_preprocessor_demo_0_records_out_total": int64(5),
  343. "op_2_preprocessor_demo1_0_exceptions_total": int64(0),
  344. "op_2_preprocessor_demo1_0_process_latency_us": int64(0),
  345. "op_2_preprocessor_demo1_0_records_in_total": int64(5),
  346. "op_2_preprocessor_demo1_0_records_out_total": int64(5),
  347. "op_6_project_0_exceptions_total": int64(0),
  348. "op_6_project_0_process_latency_us": int64(0),
  349. "op_6_project_0_records_in_total": int64(8),
  350. "op_6_project_0_records_out_total": int64(8),
  351. "sink_mockSink_0_exceptions_total": int64(0),
  352. "sink_mockSink_0_records_in_total": int64(8),
  353. "sink_mockSink_0_records_out_total": int64(8),
  354. "source_demo_0_exceptions_total": int64(0),
  355. "source_demo_0_records_in_total": int64(5),
  356. "source_demo_0_records_out_total": int64(5),
  357. "source_demo1_0_exceptions_total": int64(0),
  358. "source_demo1_0_records_in_total": int64(5),
  359. "source_demo1_0_records_out_total": int64(5),
  360. "op_3_window_0_exceptions_total": int64(0),
  361. "op_3_window_0_process_latency_us": int64(0),
  362. "op_3_window_0_records_in_total": int64(10),
  363. "op_3_window_0_records_out_total": int64(10),
  364. "op_4_join_0_exceptions_total": int64(0),
  365. "op_4_join_0_process_latency_us": int64(0),
  366. "op_4_join_0_records_in_total": int64(10),
  367. "op_4_join_0_records_out_total": int64(8),
  368. },
  369. }, {
  370. Name: `TestWindowRule7`,
  371. Sql: `SELECT * FROM demoError GROUP BY HOPPINGWINDOW(ss, 2, 1)`,
  372. R: [][]map[string]interface{}{
  373. {{
  374. "error": "error in preprocessor: invalid data type for color, expect string but found int(3)",
  375. }},
  376. {{
  377. "color": "blue",
  378. "size": float64(6),
  379. "ts": float64(1541152486822),
  380. }},
  381. {{
  382. "color": "blue",
  383. "size": float64(6),
  384. "ts": float64(1541152486822),
  385. }, {
  386. "color": "blue",
  387. "size": float64(2),
  388. "ts": float64(1541152487632),
  389. }},
  390. {{
  391. "error": "error in preprocessor: invalid data type for color, expect string but found int(7)",
  392. }},
  393. {{
  394. "color": "blue",
  395. "size": float64(2),
  396. "ts": float64(1541152487632),
  397. }},
  398. {{
  399. "error": "error in preprocessor: invalid data type for size, expect bigint but found string(blue)",
  400. }},
  401. },
  402. M: map[string]interface{}{
  403. "op_1_preprocessor_demoError_0_exceptions_total": int64(3),
  404. "op_1_preprocessor_demoError_0_process_latency_us": int64(0),
  405. "op_1_preprocessor_demoError_0_records_in_total": int64(5),
  406. "op_1_preprocessor_demoError_0_records_out_total": int64(2),
  407. "op_3_project_0_exceptions_total": int64(3),
  408. "op_3_project_0_process_latency_us": int64(0),
  409. "op_3_project_0_records_in_total": int64(6),
  410. "op_3_project_0_records_out_total": int64(3),
  411. "sink_mockSink_0_exceptions_total": int64(0),
  412. "sink_mockSink_0_records_in_total": int64(6),
  413. "sink_mockSink_0_records_out_total": int64(6),
  414. "source_demoError_0_exceptions_total": int64(0),
  415. "source_demoError_0_records_in_total": int64(5),
  416. "source_demoError_0_records_out_total": int64(5),
  417. "op_2_window_0_exceptions_total": int64(3),
  418. "op_2_window_0_process_latency_us": int64(0),
  419. "op_2_window_0_records_in_total": int64(5),
  420. "op_2_window_0_records_out_total": int64(3),
  421. },
  422. }, {
  423. Name: `TestWindowRule8`,
  424. Sql: `SELECT color, ts, count(*) as c FROM demo where size > 2 GROUP BY tumblingwindow(ss, 1) having c > 1`,
  425. R: [][]map[string]interface{}{
  426. {{
  427. "color": "red",
  428. "ts": float64(1541152486013),
  429. "c": float64(2),
  430. }},
  431. },
  432. M: map[string]interface{}{
  433. "op_1_preprocessor_demo_0_exceptions_total": int64(0),
  434. "op_1_preprocessor_demo_0_process_latency_us": int64(0),
  435. "op_1_preprocessor_demo_0_records_in_total": int64(5),
  436. "op_1_preprocessor_demo_0_records_out_total": int64(5),
  437. "op_6_project_0_exceptions_total": int64(0),
  438. "op_6_project_0_process_latency_us": int64(0),
  439. "op_6_project_0_records_in_total": int64(1),
  440. "op_6_project_0_records_out_total": int64(1),
  441. "sink_mockSink_0_exceptions_total": int64(0),
  442. "sink_mockSink_0_records_in_total": int64(1),
  443. "sink_mockSink_0_records_out_total": int64(1),
  444. "source_demo_0_exceptions_total": int64(0),
  445. "source_demo_0_records_in_total": int64(5),
  446. "source_demo_0_records_out_total": int64(5),
  447. "op_3_window_0_exceptions_total": int64(0),
  448. "op_3_window_0_process_latency_us": int64(0),
  449. "op_3_window_0_records_in_total": int64(3),
  450. "op_3_window_0_records_out_total": int64(2),
  451. "op_2_filter_0_exceptions_total": int64(0),
  452. "op_2_filter_0_process_latency_us": int64(0),
  453. "op_2_filter_0_records_in_total": int64(5),
  454. "op_2_filter_0_records_out_total": int64(3),
  455. "op_4_aggregate_0_exceptions_total": int64(0),
  456. "op_4_aggregate_0_process_latency_us": int64(0),
  457. "op_4_aggregate_0_records_in_total": int64(2),
  458. "op_4_aggregate_0_records_out_total": int64(2),
  459. "op_5_having_0_exceptions_total": int64(0),
  460. "op_5_having_0_process_latency_us": int64(0),
  461. "op_5_having_0_records_in_total": int64(2),
  462. "op_5_having_0_records_out_total": int64(1),
  463. },
  464. }, {
  465. Name: `TestWindowRule9`,
  466. Sql: `SELECT * FROM demo GROUP BY HOPPINGWINDOW(ss, 2, 1) FILTER( WHERE size > 2)`,
  467. R: [][]map[string]interface{}{
  468. {{
  469. "color": "red",
  470. "size": float64(3),
  471. "ts": float64(1541152486013),
  472. }, {
  473. "color": "blue",
  474. "size": float64(6),
  475. "ts": float64(1541152486822),
  476. }},
  477. {{
  478. "color": "red",
  479. "size": float64(3),
  480. "ts": float64(1541152486013),
  481. }, {
  482. "color": "blue",
  483. "size": float64(6),
  484. "ts": float64(1541152486822),
  485. }},
  486. {{
  487. "color": "yellow",
  488. "size": float64(4),
  489. "ts": float64(1541152488442),
  490. }},
  491. {{
  492. "color": "yellow",
  493. "size": float64(4),
  494. "ts": float64(1541152488442),
  495. }},
  496. },
  497. M: map[string]interface{}{
  498. "op_1_preprocessor_demo_0_exceptions_total": int64(0),
  499. "op_1_preprocessor_demo_0_process_latency_us": int64(0),
  500. "op_1_preprocessor_demo_0_records_in_total": int64(5),
  501. "op_1_preprocessor_demo_0_records_out_total": int64(5),
  502. "op_4_project_0_exceptions_total": int64(0),
  503. "op_4_project_0_process_latency_us": int64(0),
  504. "op_4_project_0_records_in_total": int64(4),
  505. "op_4_project_0_records_out_total": int64(4),
  506. "sink_mockSink_0_exceptions_total": int64(0),
  507. "sink_mockSink_0_records_in_total": int64(4),
  508. "sink_mockSink_0_records_out_total": int64(4),
  509. "source_demo_0_exceptions_total": int64(0),
  510. "source_demo_0_records_in_total": int64(5),
  511. "source_demo_0_records_out_total": int64(5),
  512. "op_3_window_0_exceptions_total": int64(0),
  513. "op_3_window_0_process_latency_us": int64(0),
  514. "op_3_window_0_records_in_total": int64(3),
  515. "op_3_window_0_records_out_total": int64(4),
  516. },
  517. }, {
  518. Name: `TestCountWindowRule1`,
  519. Sql: `SELECT collect(*)[0]->color as c FROM demo GROUP BY COUNTWINDOW(3)`,
  520. R: [][]map[string]interface{}{
  521. {{
  522. "c": "red",
  523. }},
  524. },
  525. M: map[string]interface{}{
  526. "op_1_preprocessor_demo_0_exceptions_total": int64(0),
  527. "op_1_preprocessor_demo_0_process_latency_us": int64(0),
  528. "op_1_preprocessor_demo_0_records_in_total": int64(5),
  529. "op_1_preprocessor_demo_0_records_out_total": int64(5),
  530. "op_4_project_0_exceptions_total": int64(0),
  531. "op_4_project_0_process_latency_us": int64(0),
  532. "op_4_project_0_records_in_total": int64(1),
  533. "op_4_project_0_records_out_total": int64(1),
  534. "sink_mockSink_0_exceptions_total": int64(0),
  535. "sink_mockSink_0_records_in_total": int64(1),
  536. "sink_mockSink_0_records_out_total": int64(1),
  537. "source_demo_0_exceptions_total": int64(0),
  538. "source_demo_0_records_in_total": int64(5),
  539. "source_demo_0_records_out_total": int64(5),
  540. "op_2_window_0_exceptions_total": int64(0),
  541. "op_2_window_0_process_latency_us": int64(0),
  542. "op_2_window_0_records_in_total": int64(5),
  543. "op_2_window_0_records_out_total": int64(1),
  544. },
  545. }, {
  546. Name: `TestWindowRule10`,
  547. Sql: `SELECT deduplicate(color, false)->color as c FROM demo GROUP BY SlidingWindow(hh, 1)`,
  548. R: [][]map[string]interface{}{
  549. {{
  550. "c": "red",
  551. }}, {{
  552. "c": "blue",
  553. }}, {{}}, {{
  554. "c": "yellow",
  555. }}, {{}},
  556. },
  557. M: map[string]interface{}{
  558. "op_1_preprocessor_demo_0_exceptions_total": int64(0),
  559. "op_1_preprocessor_demo_0_process_latency_us": int64(0),
  560. "op_1_preprocessor_demo_0_records_in_total": int64(5),
  561. "op_1_preprocessor_demo_0_records_out_total": int64(5),
  562. "op_4_project_0_exceptions_total": int64(0),
  563. "op_4_project_0_process_latency_us": int64(0),
  564. "op_4_project_0_records_in_total": int64(5),
  565. "op_4_project_0_records_out_total": int64(5),
  566. "sink_mockSink_0_exceptions_total": int64(0),
  567. "sink_mockSink_0_records_in_total": int64(5),
  568. "sink_mockSink_0_records_out_total": int64(5),
  569. "source_demo_0_exceptions_total": int64(0),
  570. "source_demo_0_records_in_total": int64(5),
  571. "source_demo_0_records_out_total": int64(5),
  572. "op_2_window_0_exceptions_total": int64(0),
  573. "op_2_window_0_process_latency_us": int64(0),
  574. "op_2_window_0_records_in_total": int64(5),
  575. "op_2_window_0_records_out_total": int64(5),
  576. },
  577. }, {
  578. Name: `TestWindowRule11`,
  579. Sql: `SELECT color, name FROM demo INNER JOIN table1 on demo.ts = table1.id where demo.size > 2 and table1.size > 1 GROUP BY tumblingwindow(ss, 1)`,
  580. R: [][]map[string]interface{}{
  581. {{
  582. "color": "red",
  583. "name": "name1",
  584. }},
  585. },
  586. M: map[string]interface{}{
  587. //"op_4_project_0_exceptions_total": int64(0),
  588. //"op_4_project_0_process_latency_us": int64(0),
  589. //"op_4_project_0_records_in_total": int64(2),
  590. //"op_4_project_0_records_out_total": int64(2),
  591. "op_3_window_0_exceptions_total": int64(0),
  592. "op_3_window_0_process_latency_us": int64(0),
  593. "op_3_window_0_records_in_total": int64(3),
  594. "op_3_window_0_records_out_total": int64(2),
  595. "op_2_filter_0_exceptions_total": int64(0),
  596. "op_2_filter_0_process_latency_us": int64(0),
  597. "op_2_filter_0_records_in_total": int64(5),
  598. "op_2_filter_0_records_out_total": int64(3),
  599. "op_1_preprocessor_demo_0_exceptions_total": int64(0),
  600. "op_1_preprocessor_demo_0_records_in_total": int64(5),
  601. "op_1_preprocessor_demo_0_records_out_total": int64(5),
  602. "op_4_tableprocessor_table1_0_exceptions_total": int64(0),
  603. "op_4_tableprocessor_table1_0_records_in_total": int64(4),
  604. "op_4_tableprocessor_table1_0_records_out_total": int64(1),
  605. "op_5_filter_0_exceptions_total": int64(0),
  606. "op_5_filter_0_records_in_total": int64(1),
  607. "op_5_filter_0_records_out_total": int64(1),
  608. "op_6_join_aligner_0_records_in_total": int64(3),
  609. "op_6_join_aligner_0_records_out_total": int64(2),
  610. "op_7_join_0_exceptions_total": int64(0),
  611. "op_7_join_0_records_in_total": int64(2),
  612. "op_7_join_0_records_out_total": int64(1),
  613. "op_8_project_0_exceptions_total": int64(0),
  614. "op_8_project_0_records_in_total": int64(1),
  615. "op_8_project_0_records_out_total": int64(1),
  616. "sink_mockSink_0_exceptions_total": int64(0),
  617. "sink_mockSink_0_records_in_total": int64(1),
  618. "sink_mockSink_0_records_out_total": int64(1),
  619. "source_demo_0_exceptions_total": int64(0),
  620. "source_demo_0_records_in_total": int64(5),
  621. "source_demo_0_records_out_total": int64(5),
  622. "source_table1_0_exceptions_total": int64(0),
  623. "source_table1_0_records_in_total": int64(4),
  624. "source_table1_0_records_out_total": int64(4),
  625. },
  626. },
  627. }
  628. HandleStream(true, streamList, t)
  629. options := []*api.RuleOption{
  630. {
  631. BufferLength: 100,
  632. SendError: true,
  633. }, {
  634. BufferLength: 100,
  635. SendError: true,
  636. Qos: api.AtLeastOnce,
  637. CheckpointInterval: 5000,
  638. }, {
  639. BufferLength: 100,
  640. SendError: true,
  641. Qos: api.ExactlyOnce,
  642. CheckpointInterval: 5000,
  643. },
  644. }
  645. for j, opt := range options {
  646. DoRuleTest(t, tests, j, opt, 15)
  647. }
  648. }
  649. func TestEventWindow(t *testing.T) {
  650. //Reset
  651. streamList := []string{"demoE", "demoErr", "demo1E", "sessionDemoE"}
  652. HandleStream(false, streamList, t)
  653. var tests = []RuleTest{
  654. {
  655. Name: `TestEventWindowRule1`,
  656. Sql: `SELECT * FROM demoE GROUP BY HOPPINGWINDOW(ss, 2, 1)`,
  657. R: [][]map[string]interface{}{
  658. {{
  659. "color": "red",
  660. "size": float64(3),
  661. "ts": float64(1541152486013),
  662. }},
  663. {{
  664. "color": "red",
  665. "size": float64(3),
  666. "ts": float64(1541152486013),
  667. }, {
  668. "color": "blue",
  669. "size": float64(2),
  670. "ts": float64(1541152487632),
  671. }},
  672. {{
  673. "color": "blue",
  674. "size": float64(2),
  675. "ts": float64(1541152487632),
  676. }, {
  677. "color": "yellow",
  678. "size": float64(4),
  679. "ts": float64(1541152488442),
  680. }}, {{
  681. "color": "yellow",
  682. "size": float64(4),
  683. "ts": float64(1541152488442),
  684. }, {
  685. "color": "red",
  686. "size": float64(1),
  687. "ts": float64(1541152489252),
  688. }}, {{
  689. "color": "red",
  690. "size": float64(1),
  691. "ts": float64(1541152489252),
  692. }},
  693. },
  694. M: map[string]interface{}{
  695. "op_1_preprocessor_demoE_0_exceptions_total": int64(0),
  696. "op_1_preprocessor_demoE_0_process_latency_us": int64(0),
  697. "op_1_preprocessor_demoE_0_records_in_total": int64(6),
  698. "op_1_preprocessor_demoE_0_records_out_total": int64(6),
  699. "op_3_project_0_exceptions_total": int64(0),
  700. "op_3_project_0_process_latency_us": int64(0),
  701. "op_3_project_0_records_in_total": int64(5),
  702. "op_3_project_0_records_out_total": int64(5),
  703. "sink_mockSink_0_exceptions_total": int64(0),
  704. "sink_mockSink_0_records_in_total": int64(5),
  705. "sink_mockSink_0_records_out_total": int64(5),
  706. "source_demoE_0_exceptions_total": int64(0),
  707. "source_demoE_0_records_in_total": int64(6),
  708. "source_demoE_0_records_out_total": int64(6),
  709. "op_2_window_0_exceptions_total": int64(0),
  710. "op_2_window_0_process_latency_us": int64(0),
  711. "op_2_window_0_records_in_total": int64(6),
  712. "op_2_window_0_records_out_total": int64(5),
  713. },
  714. }, {
  715. Name: `TestEventWindowRule2`,
  716. Sql: `SELECT color, ts FROM demoE where size > 2 GROUP BY tumblingwindow(ss, 1)`,
  717. R: [][]map[string]interface{}{
  718. {{
  719. "color": "red",
  720. "ts": float64(1541152486013),
  721. }},
  722. {{
  723. "color": "yellow",
  724. "ts": float64(1541152488442),
  725. }},
  726. },
  727. M: map[string]interface{}{
  728. "op_1_preprocessor_demoE_0_exceptions_total": int64(0),
  729. "op_1_preprocessor_demoE_0_process_latency_us": int64(0),
  730. "op_1_preprocessor_demoE_0_records_in_total": int64(6),
  731. "op_1_preprocessor_demoE_0_records_out_total": int64(6),
  732. "op_4_project_0_exceptions_total": int64(0),
  733. "op_4_project_0_process_latency_us": int64(0),
  734. "op_4_project_0_records_in_total": int64(2),
  735. "op_4_project_0_records_out_total": int64(2),
  736. "sink_mockSink_0_exceptions_total": int64(0),
  737. "sink_mockSink_0_records_in_total": int64(2),
  738. "sink_mockSink_0_records_out_total": int64(2),
  739. "source_demoE_0_exceptions_total": int64(0),
  740. "source_demoE_0_records_in_total": int64(6),
  741. "source_demoE_0_records_out_total": int64(6),
  742. "op_2_window_0_exceptions_total": int64(0),
  743. "op_2_window_0_process_latency_us": int64(0),
  744. "op_2_window_0_records_in_total": int64(6),
  745. "op_2_window_0_records_out_total": int64(4),
  746. "op_3_filter_0_exceptions_total": int64(0),
  747. "op_3_filter_0_process_latency_us": int64(0),
  748. "op_3_filter_0_records_in_total": int64(4),
  749. "op_3_filter_0_records_out_total": int64(2),
  750. },
  751. }, {
  752. Name: `TestEventWindowRule3`,
  753. Sql: `SELECT color, temp, ts FROM demoE INNER JOIN demo1E ON demoE.ts = demo1E.ts GROUP BY SlidingWindow(ss, 1)`,
  754. R: [][]map[string]interface{}{
  755. {{
  756. "color": "red",
  757. "temp": 25.5,
  758. "ts": float64(1541152486013),
  759. }}, {{
  760. "color": "red",
  761. "temp": 25.5,
  762. "ts": float64(1541152486013),
  763. }}, {{
  764. "color": "blue",
  765. "temp": 28.1,
  766. "ts": float64(1541152487632),
  767. }}, {{
  768. "color": "blue",
  769. "temp": 28.1,
  770. "ts": float64(1541152487632),
  771. }, {
  772. "color": "yellow",
  773. "temp": 27.4,
  774. "ts": float64(1541152488442),
  775. }}, {{
  776. "color": "yellow",
  777. "temp": 27.4,
  778. "ts": float64(1541152488442),
  779. }, {
  780. "color": "red",
  781. "temp": 25.5,
  782. "ts": float64(1541152489252),
  783. }},
  784. },
  785. M: map[string]interface{}{
  786. "op_1_preprocessor_demoE_0_exceptions_total": int64(0),
  787. "op_1_preprocessor_demoE_0_process_latency_us": int64(0),
  788. "op_1_preprocessor_demoE_0_records_in_total": int64(6),
  789. "op_1_preprocessor_demoE_0_records_out_total": int64(6),
  790. "op_2_preprocessor_demo1E_0_exceptions_total": int64(0),
  791. "op_2_preprocessor_demo1E_0_process_latency_us": int64(0),
  792. "op_2_preprocessor_demo1E_0_records_in_total": int64(6),
  793. "op_2_preprocessor_demo1E_0_records_out_total": int64(6),
  794. "op_5_project_0_exceptions_total": int64(0),
  795. "op_5_project_0_process_latency_us": int64(0),
  796. "op_5_project_0_records_in_total": int64(5),
  797. "op_5_project_0_records_out_total": int64(5),
  798. "sink_mockSink_0_exceptions_total": int64(0),
  799. "sink_mockSink_0_records_in_total": int64(5),
  800. "sink_mockSink_0_records_out_total": int64(5),
  801. "source_demoE_0_exceptions_total": int64(0),
  802. "source_demoE_0_records_in_total": int64(6),
  803. "source_demoE_0_records_out_total": int64(6),
  804. "source_demo1E_0_exceptions_total": int64(0),
  805. "source_demo1E_0_records_in_total": int64(6),
  806. "source_demo1E_0_records_out_total": int64(6),
  807. "op_3_window_0_exceptions_total": int64(0),
  808. "op_3_window_0_process_latency_us": int64(0),
  809. "op_3_window_0_records_in_total": int64(12),
  810. "op_3_window_0_records_out_total": int64(5),
  811. "op_4_join_0_exceptions_total": int64(0),
  812. "op_4_join_0_process_latency_us": int64(0),
  813. "op_4_join_0_records_in_total": int64(5),
  814. "op_4_join_0_records_out_total": int64(5),
  815. },
  816. }, {
  817. Name: `TestEventWindowRule4`,
  818. Sql: `SELECT color FROM demoE GROUP BY SlidingWindow(ss, 2), color ORDER BY color`,
  819. R: [][]map[string]interface{}{
  820. {{
  821. "color": "red",
  822. }}, {{
  823. "color": "blue",
  824. }, {
  825. "color": "red",
  826. }}, {{
  827. "color": "blue",
  828. }, {
  829. "color": "yellow",
  830. }}, {{
  831. "color": "blue",
  832. }, {
  833. "color": "red",
  834. }, {
  835. "color": "yellow",
  836. }},
  837. },
  838. M: map[string]interface{}{
  839. "op_1_preprocessor_demoE_0_exceptions_total": int64(0),
  840. "op_1_preprocessor_demoE_0_process_latency_us": int64(0),
  841. "op_1_preprocessor_demoE_0_records_in_total": int64(6),
  842. "op_1_preprocessor_demoE_0_records_out_total": int64(6),
  843. "op_5_project_0_exceptions_total": int64(0),
  844. "op_5_project_0_process_latency_us": int64(0),
  845. "op_5_project_0_records_in_total": int64(4),
  846. "op_5_project_0_records_out_total": int64(4),
  847. "sink_mockSink_0_exceptions_total": int64(0),
  848. "sink_mockSink_0_records_in_total": int64(4),
  849. "sink_mockSink_0_records_out_total": int64(4),
  850. "source_demoE_0_exceptions_total": int64(0),
  851. "source_demoE_0_records_in_total": int64(6),
  852. "source_demoE_0_records_out_total": int64(6),
  853. "op_2_window_0_exceptions_total": int64(0),
  854. "op_2_window_0_process_latency_us": int64(0),
  855. "op_2_window_0_records_in_total": int64(6),
  856. "op_2_window_0_records_out_total": int64(4),
  857. "op_3_aggregate_0_exceptions_total": int64(0),
  858. "op_3_aggregate_0_process_latency_us": int64(0),
  859. "op_3_aggregate_0_records_in_total": int64(4),
  860. "op_3_aggregate_0_records_out_total": int64(4),
  861. "op_4_order_0_exceptions_total": int64(0),
  862. "op_4_order_0_process_latency_us": int64(0),
  863. "op_4_order_0_records_in_total": int64(4),
  864. "op_4_order_0_records_out_total": int64(4),
  865. },
  866. }, {
  867. Name: `TestEventWindowRule5`,
  868. Sql: `SELECT temp FROM sessionDemoE GROUP BY SessionWindow(ss, 2, 1) `,
  869. R: [][]map[string]interface{}{
  870. {{
  871. "temp": 25.5,
  872. }}, {{
  873. "temp": 28.1,
  874. }, {
  875. "temp": 27.4,
  876. }, {
  877. "temp": 25.5,
  878. }}, {{
  879. "temp": 26.2,
  880. }, {
  881. "temp": 26.8,
  882. }, {
  883. "temp": 28.9,
  884. }, {
  885. "temp": 29.1,
  886. }, {
  887. "temp": 32.2,
  888. }}, {{
  889. "temp": 30.9,
  890. }},
  891. },
  892. M: map[string]interface{}{
  893. "op_1_preprocessor_sessionDemoE_0_exceptions_total": int64(0),
  894. "op_1_preprocessor_sessionDemoE_0_process_latency_us": int64(0),
  895. "op_1_preprocessor_sessionDemoE_0_records_in_total": int64(12),
  896. "op_1_preprocessor_sessionDemoE_0_records_out_total": int64(12),
  897. "op_3_project_0_exceptions_total": int64(0),
  898. "op_3_project_0_process_latency_us": int64(0),
  899. "op_3_project_0_records_in_total": int64(4),
  900. "op_3_project_0_records_out_total": int64(4),
  901. "sink_mockSink_0_exceptions_total": int64(0),
  902. "sink_mockSink_0_records_in_total": int64(4),
  903. "sink_mockSink_0_records_out_total": int64(4),
  904. "source_sessionDemoE_0_exceptions_total": int64(0),
  905. "source_sessionDemoE_0_records_in_total": int64(12),
  906. "source_sessionDemoE_0_records_out_total": int64(12),
  907. "op_2_window_0_exceptions_total": int64(0),
  908. "op_2_window_0_process_latency_us": int64(0),
  909. "op_2_window_0_records_in_total": int64(12),
  910. "op_2_window_0_records_out_total": int64(4),
  911. },
  912. }, {
  913. Name: `TestEventWindowRule6`,
  914. Sql: `SELECT max(temp) as m, count(color) as c FROM demoE INNER JOIN demo1E ON demoE.ts = demo1E.ts GROUP BY SlidingWindow(ss, 1)`,
  915. R: [][]map[string]interface{}{
  916. {{
  917. "m": 25.5,
  918. "c": float64(1),
  919. }}, {{
  920. "m": 25.5,
  921. "c": float64(1),
  922. }}, {{
  923. "m": 28.1,
  924. "c": float64(1),
  925. }}, {{
  926. "m": 28.1,
  927. "c": float64(2),
  928. }}, {{
  929. "m": 27.4,
  930. "c": float64(2),
  931. }},
  932. },
  933. M: map[string]interface{}{
  934. "op_1_preprocessor_demoE_0_exceptions_total": int64(0),
  935. "op_1_preprocessor_demoE_0_process_latency_us": int64(0),
  936. "op_1_preprocessor_demoE_0_records_in_total": int64(6),
  937. "op_1_preprocessor_demoE_0_records_out_total": int64(6),
  938. "op_2_preprocessor_demo1E_0_exceptions_total": int64(0),
  939. "op_2_preprocessor_demo1E_0_process_latency_us": int64(0),
  940. "op_2_preprocessor_demo1E_0_records_in_total": int64(6),
  941. "op_2_preprocessor_demo1E_0_records_out_total": int64(6),
  942. "op_6_project_0_exceptions_total": int64(0),
  943. "op_6_project_0_process_latency_us": int64(0),
  944. "op_6_project_0_records_in_total": int64(5),
  945. "op_6_project_0_records_out_total": int64(5),
  946. "sink_mockSink_0_exceptions_total": int64(0),
  947. "sink_mockSink_0_records_in_total": int64(5),
  948. "sink_mockSink_0_records_out_total": int64(5),
  949. "source_demoE_0_exceptions_total": int64(0),
  950. "source_demoE_0_records_in_total": int64(6),
  951. "source_demoE_0_records_out_total": int64(6),
  952. "source_demo1E_0_exceptions_total": int64(0),
  953. "source_demo1E_0_records_in_total": int64(6),
  954. "source_demo1E_0_records_out_total": int64(6),
  955. "op_3_window_0_exceptions_total": int64(0),
  956. "op_3_window_0_records_in_total": int64(12),
  957. "op_3_window_0_records_out_total": int64(5),
  958. "op_4_join_0_exceptions_total": int64(0),
  959. "op_4_join_0_process_latency_us": int64(0),
  960. "op_4_join_0_records_in_total": int64(5),
  961. "op_4_join_0_records_out_total": int64(5),
  962. },
  963. }, {
  964. Name: `TestEventWindowRule7`,
  965. Sql: `SELECT * FROM demoErr GROUP BY HOPPINGWINDOW(ss, 2, 1)`,
  966. R: [][]map[string]interface{}{
  967. {{
  968. "error": "error in preprocessor: invalid data type for color, expect string but found int(2)",
  969. }},
  970. {{
  971. "color": "red",
  972. "size": float64(3),
  973. "ts": float64(1541152486013),
  974. }},
  975. {{
  976. "color": "red",
  977. "size": float64(3),
  978. "ts": float64(1541152486013),
  979. }},
  980. {{
  981. "color": "yellow",
  982. "size": float64(4),
  983. "ts": float64(1541152488442),
  984. }}, {{
  985. "color": "yellow",
  986. "size": float64(4),
  987. "ts": float64(1541152488442),
  988. }, {
  989. "color": "red",
  990. "size": float64(1),
  991. "ts": float64(1541152489252),
  992. }}, {{
  993. "color": "red",
  994. "size": float64(1),
  995. "ts": float64(1541152489252),
  996. }},
  997. },
  998. M: map[string]interface{}{
  999. "op_1_preprocessor_demoErr_0_exceptions_total": int64(1),
  1000. "op_1_preprocessor_demoErr_0_process_latency_us": int64(0),
  1001. "op_1_preprocessor_demoErr_0_records_in_total": int64(6),
  1002. "op_1_preprocessor_demoErr_0_records_out_total": int64(5),
  1003. "op_3_project_0_exceptions_total": int64(1),
  1004. "op_3_project_0_process_latency_us": int64(0),
  1005. "op_3_project_0_records_in_total": int64(6),
  1006. "op_3_project_0_records_out_total": int64(5),
  1007. "sink_mockSink_0_exceptions_total": int64(0),
  1008. "sink_mockSink_0_records_in_total": int64(6),
  1009. "sink_mockSink_0_records_out_total": int64(6),
  1010. "source_demoErr_0_exceptions_total": int64(0),
  1011. "source_demoErr_0_records_in_total": int64(6),
  1012. "source_demoErr_0_records_out_total": int64(6),
  1013. "op_2_window_0_exceptions_total": int64(1),
  1014. "op_2_window_0_process_latency_us": int64(0),
  1015. "op_2_window_0_records_in_total": int64(6),
  1016. "op_2_window_0_records_out_total": int64(5),
  1017. },
  1018. },
  1019. }
  1020. HandleStream(true, streamList, t)
  1021. options := []*api.RuleOption{
  1022. {
  1023. BufferLength: 100,
  1024. SendError: true,
  1025. IsEventTime: true,
  1026. LateTol: 1000,
  1027. }, {
  1028. BufferLength: 100,
  1029. SendError: true,
  1030. Qos: api.AtLeastOnce,
  1031. CheckpointInterval: 5000,
  1032. IsEventTime: true,
  1033. LateTol: 1000,
  1034. }, {
  1035. BufferLength: 100,
  1036. SendError: true,
  1037. Qos: api.ExactlyOnce,
  1038. CheckpointInterval: 5000,
  1039. IsEventTime: true,
  1040. LateTol: 1000,
  1041. },
  1042. }
  1043. for j, opt := range options {
  1044. DoRuleTest(t, tests, j, opt, 10)
  1045. }
  1046. }
  1047. func TestWindowError(t *testing.T) {
  1048. //Reset
  1049. streamList := []string{"ldemo", "ldemo1"}
  1050. HandleStream(false, streamList, t)
  1051. var tests = []RuleTest{
  1052. {
  1053. Name: `TestWindowErrorRule1`,
  1054. Sql: `SELECT size * 3 FROM ldemo GROUP BY TUMBLINGWINDOW(ss, 2)`,
  1055. R: [][]map[string]interface{}{
  1056. {{
  1057. "error": "run Select error: invalid operation string(string) * int64(3)",
  1058. }}, {{
  1059. "kuiper_field_0": float64(6),
  1060. }, {}},
  1061. },
  1062. M: map[string]interface{}{
  1063. "op_1_preprocessor_ldemo_0_exceptions_total": int64(0),
  1064. "op_1_preprocessor_ldemo_0_process_latency_us": int64(0),
  1065. "op_1_preprocessor_ldemo_0_records_in_total": int64(5),
  1066. "op_1_preprocessor_ldemo_0_records_out_total": int64(5),
  1067. "op_3_project_0_exceptions_total": int64(1),
  1068. "op_3_project_0_process_latency_us": int64(0),
  1069. "op_3_project_0_records_in_total": int64(2),
  1070. "op_3_project_0_records_out_total": int64(1),
  1071. "sink_mockSink_0_exceptions_total": int64(0),
  1072. "sink_mockSink_0_records_in_total": int64(2),
  1073. "sink_mockSink_0_records_out_total": int64(2),
  1074. "source_ldemo_0_exceptions_total": int64(0),
  1075. "source_ldemo_0_records_in_total": int64(5),
  1076. "source_ldemo_0_records_out_total": int64(5),
  1077. "op_2_window_0_exceptions_total": int64(0),
  1078. "op_2_window_0_process_latency_us": int64(0),
  1079. "op_2_window_0_records_in_total": int64(5),
  1080. "op_2_window_0_records_out_total": int64(2),
  1081. },
  1082. }, {
  1083. Name: `TestWindowErrorRule2`,
  1084. Sql: `SELECT color, ts FROM ldemo where size > 2 GROUP BY tumblingwindow(ss, 1)`,
  1085. R: [][]map[string]interface{}{
  1086. {{
  1087. "error": "run Where error: invalid operation string(string) > int64(2)",
  1088. }}, {{
  1089. "color": "red",
  1090. "ts": float64(1541152486013),
  1091. }}, {{
  1092. "ts": float64(1541152487632),
  1093. }},
  1094. },
  1095. M: map[string]interface{}{
  1096. "op_1_preprocessor_ldemo_0_exceptions_total": int64(0),
  1097. "op_1_preprocessor_ldemo_0_process_latency_us": int64(0),
  1098. "op_1_preprocessor_ldemo_0_records_in_total": int64(5),
  1099. "op_1_preprocessor_ldemo_0_records_out_total": int64(5),
  1100. "op_4_project_0_exceptions_total": int64(1),
  1101. "op_4_project_0_process_latency_us": int64(0),
  1102. "op_4_project_0_records_in_total": int64(3),
  1103. "op_4_project_0_records_out_total": int64(2),
  1104. "sink_mockSink_0_exceptions_total": int64(0),
  1105. "sink_mockSink_0_records_in_total": int64(3),
  1106. "sink_mockSink_0_records_out_total": int64(3),
  1107. "source_ldemo_0_exceptions_total": int64(0),
  1108. "source_ldemo_0_records_in_total": int64(5),
  1109. "source_ldemo_0_records_out_total": int64(5),
  1110. "op_3_window_0_exceptions_total": int64(1),
  1111. "op_3_window_0_process_latency_us": int64(0),
  1112. "op_3_window_0_records_in_total": int64(3),
  1113. "op_3_window_0_records_out_total": int64(2),
  1114. "op_2_filter_0_exceptions_total": int64(1),
  1115. "op_2_filter_0_process_latency_us": int64(0),
  1116. "op_2_filter_0_records_in_total": int64(5),
  1117. "op_2_filter_0_records_out_total": int64(2),
  1118. },
  1119. }, {
  1120. Name: `TestWindowErrorRule3`,
  1121. Sql: `SELECT color, temp, ts FROM ldemo INNER JOIN ldemo1 ON ldemo.ts = ldemo1.ts GROUP BY SlidingWindow(ss, 1)`,
  1122. R: [][]map[string]interface{}{
  1123. {{
  1124. "color": "red",
  1125. "temp": 25.5,
  1126. "ts": float64(1541152486013),
  1127. }}, {{
  1128. "color": "red",
  1129. "temp": 25.5,
  1130. "ts": float64(1541152486013),
  1131. }}, {{
  1132. "color": "red",
  1133. "temp": 25.5,
  1134. "ts": float64(1541152486013),
  1135. }}, {{
  1136. "temp": 28.1,
  1137. "ts": float64(1541152487632),
  1138. }}, {{
  1139. "temp": 28.1,
  1140. "ts": float64(1541152487632),
  1141. }}, {{
  1142. "error": "run Join error: invalid operation int64(1541152487632) = string(1541152488442)",
  1143. }}, {{
  1144. "error": "run Join error: invalid operation int64(1541152488442) = string(1541152488442)",
  1145. }}, {{
  1146. "error": "run Join error: invalid operation int64(1541152488442) = string(1541152488442)",
  1147. }},
  1148. },
  1149. M: map[string]interface{}{
  1150. "op_1_preprocessor_ldemo_0_exceptions_total": int64(0),
  1151. "op_1_preprocessor_ldemo_0_process_latency_us": int64(0),
  1152. "op_1_preprocessor_ldemo_0_records_in_total": int64(5),
  1153. "op_1_preprocessor_ldemo_0_records_out_total": int64(5),
  1154. "op_2_preprocessor_ldemo1_0_exceptions_total": int64(0),
  1155. "op_2_preprocessor_ldemo1_0_process_latency_us": int64(0),
  1156. "op_2_preprocessor_ldemo1_0_records_in_total": int64(5),
  1157. "op_2_preprocessor_ldemo1_0_records_out_total": int64(5),
  1158. "op_5_project_0_exceptions_total": int64(3),
  1159. "op_5_project_0_process_latency_us": int64(0),
  1160. "op_5_project_0_records_in_total": int64(8),
  1161. "op_5_project_0_records_out_total": int64(5),
  1162. "sink_mockSink_0_exceptions_total": int64(0),
  1163. "sink_mockSink_0_records_in_total": int64(8),
  1164. "sink_mockSink_0_records_out_total": int64(8),
  1165. "source_ldemo_0_exceptions_total": int64(0),
  1166. "source_ldemo_0_records_in_total": int64(5),
  1167. "source_ldemo_0_records_out_total": int64(5),
  1168. "source_ldemo1_0_exceptions_total": int64(0),
  1169. "source_ldemo1_0_records_in_total": int64(5),
  1170. "source_ldemo1_0_records_out_total": int64(5),
  1171. "op_3_window_0_exceptions_total": int64(0),
  1172. "op_3_window_0_process_latency_us": int64(0),
  1173. "op_3_window_0_records_in_total": int64(10),
  1174. "op_3_window_0_records_out_total": int64(10),
  1175. "op_4_join_0_exceptions_total": int64(3),
  1176. "op_4_join_0_process_latency_us": int64(0),
  1177. "op_4_join_0_records_in_total": int64(10),
  1178. "op_4_join_0_records_out_total": int64(5),
  1179. },
  1180. }, {
  1181. Name: `TestWindowErrorRule4`,
  1182. Sql: `SELECT color FROM ldemo GROUP BY SlidingWindow(ss, 2), color having size >= 2 order by color`,
  1183. R: [][]map[string]interface{}{
  1184. {{
  1185. "color": "red",
  1186. }}, {{
  1187. "error": "run Having error: invalid operation string(string) >= int64(2)",
  1188. }}, {{
  1189. "error": "run Having error: invalid operation string(string) >= int64(2)",
  1190. }}, {{
  1191. "error": "run Having error: invalid operation string(string) >= int64(2)",
  1192. }}, {{
  1193. "color": float64(49),
  1194. }, {}},
  1195. },
  1196. M: map[string]interface{}{
  1197. "op_1_preprocessor_ldemo_0_exceptions_total": int64(0),
  1198. "op_1_preprocessor_ldemo_0_process_latency_us": int64(0),
  1199. "op_1_preprocessor_ldemo_0_records_in_total": int64(5),
  1200. "op_1_preprocessor_ldemo_0_records_out_total": int64(5),
  1201. "op_6_project_0_exceptions_total": int64(3),
  1202. "op_6_project_0_process_latency_us": int64(0),
  1203. "op_6_project_0_records_in_total": int64(5),
  1204. "op_6_project_0_records_out_total": int64(2),
  1205. "sink_mockSink_0_exceptions_total": int64(0),
  1206. "sink_mockSink_0_records_in_total": int64(5),
  1207. "sink_mockSink_0_records_out_total": int64(5),
  1208. "source_ldemo_0_exceptions_total": int64(0),
  1209. "source_ldemo_0_records_in_total": int64(5),
  1210. "source_ldemo_0_records_out_total": int64(5),
  1211. "op_2_window_0_exceptions_total": int64(0),
  1212. "op_2_window_0_process_latency_us": int64(0),
  1213. "op_2_window_0_records_in_total": int64(5),
  1214. "op_2_window_0_records_out_total": int64(5),
  1215. "op_3_aggregate_0_exceptions_total": int64(0),
  1216. "op_3_aggregate_0_process_latency_us": int64(0),
  1217. "op_3_aggregate_0_records_in_total": int64(5),
  1218. "op_3_aggregate_0_records_out_total": int64(5),
  1219. "op_4_having_0_exceptions_total": int64(3),
  1220. "op_4_having_0_process_latency_us": int64(0),
  1221. "op_4_having_0_records_in_total": int64(5),
  1222. "op_4_having_0_records_out_total": int64(2),
  1223. },
  1224. }, {
  1225. Name: `TestWindowErrorRule5`,
  1226. Sql: `SELECT color, size FROM ldemo GROUP BY tumblingwindow(ss, 1) ORDER BY size`,
  1227. R: [][]map[string]interface{}{
  1228. {{
  1229. "error": "run Order By error: incompatible types for comparison: int and string",
  1230. }}, {{
  1231. "size": float64(3),
  1232. }}, {{
  1233. "color": float64(49),
  1234. "size": float64(2),
  1235. }}, {{
  1236. "color": "red",
  1237. }},
  1238. },
  1239. M: map[string]interface{}{
  1240. "op_1_preprocessor_ldemo_0_exceptions_total": int64(0),
  1241. "op_1_preprocessor_ldemo_0_process_latency_us": int64(0),
  1242. "op_1_preprocessor_ldemo_0_records_in_total": int64(5),
  1243. "op_1_preprocessor_ldemo_0_records_out_total": int64(5),
  1244. "op_4_project_0_exceptions_total": int64(1),
  1245. "op_4_project_0_process_latency_us": int64(0),
  1246. "op_4_project_0_records_in_total": int64(4),
  1247. "op_4_project_0_records_out_total": int64(3),
  1248. "sink_mockSink_0_exceptions_total": int64(0),
  1249. "sink_mockSink_0_records_in_total": int64(4),
  1250. "sink_mockSink_0_records_out_total": int64(4),
  1251. "source_ldemo_0_exceptions_total": int64(0),
  1252. "source_ldemo_0_records_in_total": int64(5),
  1253. "source_ldemo_0_records_out_total": int64(5),
  1254. "op_2_window_0_exceptions_total": int64(0),
  1255. "op_2_window_0_process_latency_us": int64(0),
  1256. "op_2_window_0_records_in_total": int64(5),
  1257. "op_2_window_0_records_out_total": int64(4),
  1258. "op_3_order_0_exceptions_total": int64(1),
  1259. "op_3_order_0_process_latency_us": int64(0),
  1260. "op_3_order_0_records_in_total": int64(4),
  1261. "op_3_order_0_records_out_total": int64(3),
  1262. },
  1263. },
  1264. }
  1265. HandleStream(true, streamList, t)
  1266. DoRuleTest(t, tests, 0, &api.RuleOption{
  1267. BufferLength: 100,
  1268. SendError: true,
  1269. }, 0)
  1270. }