window_rule_test.go 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345
  1. package processors
  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"}
  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. }
  579. handleStream(true, streamList, t)
  580. options := []*api.RuleOption{
  581. {
  582. BufferLength: 100,
  583. SendError: true,
  584. }, {
  585. BufferLength: 100,
  586. SendError: true,
  587. Qos: api.AtLeastOnce,
  588. CheckpointInterval: 5000,
  589. }, {
  590. BufferLength: 100,
  591. SendError: true,
  592. Qos: api.ExactlyOnce,
  593. CheckpointInterval: 5000,
  594. },
  595. }
  596. for j, opt := range options {
  597. doRuleTest(t, tests, j, opt)
  598. }
  599. }
  600. func TestEventWindow(t *testing.T) {
  601. //Reset
  602. streamList := []string{"demoE", "demoErr", "demo1E", "sessionDemoE"}
  603. handleStream(false, streamList, t)
  604. var tests = []ruleTest{
  605. {
  606. name: `TestEventWindowRule1`,
  607. sql: `SELECT * FROM demoE GROUP BY HOPPINGWINDOW(ss, 2, 1)`,
  608. r: [][]map[string]interface{}{
  609. {{
  610. "color": "red",
  611. "size": float64(3),
  612. "ts": float64(1541152486013),
  613. }},
  614. {{
  615. "color": "red",
  616. "size": float64(3),
  617. "ts": float64(1541152486013),
  618. }, {
  619. "color": "blue",
  620. "size": float64(2),
  621. "ts": float64(1541152487632),
  622. }},
  623. {{
  624. "color": "blue",
  625. "size": float64(2),
  626. "ts": float64(1541152487632),
  627. }, {
  628. "color": "yellow",
  629. "size": float64(4),
  630. "ts": float64(1541152488442),
  631. }}, {{
  632. "color": "yellow",
  633. "size": float64(4),
  634. "ts": float64(1541152488442),
  635. }, {
  636. "color": "red",
  637. "size": float64(1),
  638. "ts": float64(1541152489252),
  639. }}, {{
  640. "color": "red",
  641. "size": float64(1),
  642. "ts": float64(1541152489252),
  643. }},
  644. },
  645. m: map[string]interface{}{
  646. "op_1_preprocessor_demoE_0_exceptions_total": int64(0),
  647. "op_1_preprocessor_demoE_0_process_latency_us": int64(0),
  648. "op_1_preprocessor_demoE_0_records_in_total": int64(6),
  649. "op_1_preprocessor_demoE_0_records_out_total": int64(6),
  650. "op_3_project_0_exceptions_total": int64(0),
  651. "op_3_project_0_process_latency_us": int64(0),
  652. "op_3_project_0_records_in_total": int64(5),
  653. "op_3_project_0_records_out_total": int64(5),
  654. "sink_mockSink_0_exceptions_total": int64(0),
  655. "sink_mockSink_0_records_in_total": int64(5),
  656. "sink_mockSink_0_records_out_total": int64(5),
  657. "source_demoE_0_exceptions_total": int64(0),
  658. "source_demoE_0_records_in_total": int64(6),
  659. "source_demoE_0_records_out_total": int64(6),
  660. "op_2_window_0_exceptions_total": int64(0),
  661. "op_2_window_0_process_latency_us": int64(0),
  662. "op_2_window_0_records_in_total": int64(6),
  663. "op_2_window_0_records_out_total": int64(5),
  664. },
  665. }, {
  666. name: `TestEventWindowRule2`,
  667. sql: `SELECT color, ts FROM demoE where size > 2 GROUP BY tumblingwindow(ss, 1)`,
  668. r: [][]map[string]interface{}{
  669. {{
  670. "color": "red",
  671. "ts": float64(1541152486013),
  672. }},
  673. {{
  674. "color": "yellow",
  675. "ts": float64(1541152488442),
  676. }},
  677. },
  678. m: map[string]interface{}{
  679. "op_1_preprocessor_demoE_0_exceptions_total": int64(0),
  680. "op_1_preprocessor_demoE_0_process_latency_us": int64(0),
  681. "op_1_preprocessor_demoE_0_records_in_total": int64(6),
  682. "op_1_preprocessor_demoE_0_records_out_total": int64(6),
  683. "op_4_project_0_exceptions_total": int64(0),
  684. "op_4_project_0_process_latency_us": int64(0),
  685. "op_4_project_0_records_in_total": int64(2),
  686. "op_4_project_0_records_out_total": int64(2),
  687. "sink_mockSink_0_exceptions_total": int64(0),
  688. "sink_mockSink_0_records_in_total": int64(2),
  689. "sink_mockSink_0_records_out_total": int64(2),
  690. "source_demoE_0_exceptions_total": int64(0),
  691. "source_demoE_0_records_in_total": int64(6),
  692. "source_demoE_0_records_out_total": int64(6),
  693. "op_2_window_0_exceptions_total": int64(0),
  694. "op_2_window_0_process_latency_us": int64(0),
  695. "op_2_window_0_records_in_total": int64(6),
  696. "op_2_window_0_records_out_total": int64(4),
  697. "op_3_filter_0_exceptions_total": int64(0),
  698. "op_3_filter_0_process_latency_us": int64(0),
  699. "op_3_filter_0_records_in_total": int64(4),
  700. "op_3_filter_0_records_out_total": int64(2),
  701. },
  702. }, {
  703. name: `TestEventWindowRule3`,
  704. sql: `SELECT color, temp, ts FROM demoE INNER JOIN demo1E ON demoE.ts = demo1E.ts GROUP BY SlidingWindow(ss, 1)`,
  705. r: [][]map[string]interface{}{
  706. {{
  707. "color": "red",
  708. "temp": 25.5,
  709. "ts": float64(1541152486013),
  710. }}, {{
  711. "color": "red",
  712. "temp": 25.5,
  713. "ts": float64(1541152486013),
  714. }}, {{
  715. "color": "blue",
  716. "temp": 28.1,
  717. "ts": float64(1541152487632),
  718. }}, {{
  719. "color": "blue",
  720. "temp": 28.1,
  721. "ts": float64(1541152487632),
  722. }, {
  723. "color": "yellow",
  724. "temp": 27.4,
  725. "ts": float64(1541152488442),
  726. }}, {{
  727. "color": "yellow",
  728. "temp": 27.4,
  729. "ts": float64(1541152488442),
  730. }, {
  731. "color": "red",
  732. "temp": 25.5,
  733. "ts": float64(1541152489252),
  734. }},
  735. },
  736. m: map[string]interface{}{
  737. "op_1_preprocessor_demoE_0_exceptions_total": int64(0),
  738. "op_1_preprocessor_demoE_0_process_latency_us": int64(0),
  739. "op_1_preprocessor_demoE_0_records_in_total": int64(6),
  740. "op_1_preprocessor_demoE_0_records_out_total": int64(6),
  741. "op_2_preprocessor_demo1E_0_exceptions_total": int64(0),
  742. "op_2_preprocessor_demo1E_0_process_latency_us": int64(0),
  743. "op_2_preprocessor_demo1E_0_records_in_total": int64(6),
  744. "op_2_preprocessor_demo1E_0_records_out_total": int64(6),
  745. "op_5_project_0_exceptions_total": int64(0),
  746. "op_5_project_0_process_latency_us": int64(0),
  747. "op_5_project_0_records_in_total": int64(5),
  748. "op_5_project_0_records_out_total": int64(5),
  749. "sink_mockSink_0_exceptions_total": int64(0),
  750. "sink_mockSink_0_records_in_total": int64(5),
  751. "sink_mockSink_0_records_out_total": int64(5),
  752. "source_demoE_0_exceptions_total": int64(0),
  753. "source_demoE_0_records_in_total": int64(6),
  754. "source_demoE_0_records_out_total": int64(6),
  755. "source_demo1E_0_exceptions_total": int64(0),
  756. "source_demo1E_0_records_in_total": int64(6),
  757. "source_demo1E_0_records_out_total": int64(6),
  758. "op_3_window_0_exceptions_total": int64(0),
  759. "op_3_window_0_process_latency_us": int64(0),
  760. "op_3_window_0_records_in_total": int64(12),
  761. "op_3_window_0_records_out_total": int64(5),
  762. "op_4_join_0_exceptions_total": int64(0),
  763. "op_4_join_0_process_latency_us": int64(0),
  764. "op_4_join_0_records_in_total": int64(5),
  765. "op_4_join_0_records_out_total": int64(5),
  766. },
  767. }, {
  768. name: `TestEventWindowRule4`,
  769. sql: `SELECT color FROM demoE GROUP BY SlidingWindow(ss, 2), color ORDER BY color`,
  770. r: [][]map[string]interface{}{
  771. {{
  772. "color": "red",
  773. }}, {{
  774. "color": "blue",
  775. }, {
  776. "color": "red",
  777. }}, {{
  778. "color": "blue",
  779. }, {
  780. "color": "yellow",
  781. }}, {{
  782. "color": "blue",
  783. }, {
  784. "color": "red",
  785. }, {
  786. "color": "yellow",
  787. }},
  788. },
  789. m: map[string]interface{}{
  790. "op_1_preprocessor_demoE_0_exceptions_total": int64(0),
  791. "op_1_preprocessor_demoE_0_process_latency_us": int64(0),
  792. "op_1_preprocessor_demoE_0_records_in_total": int64(6),
  793. "op_1_preprocessor_demoE_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(4),
  797. "op_5_project_0_records_out_total": int64(4),
  798. "sink_mockSink_0_exceptions_total": int64(0),
  799. "sink_mockSink_0_records_in_total": int64(4),
  800. "sink_mockSink_0_records_out_total": int64(4),
  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. "op_2_window_0_exceptions_total": int64(0),
  805. "op_2_window_0_process_latency_us": int64(0),
  806. "op_2_window_0_records_in_total": int64(6),
  807. "op_2_window_0_records_out_total": int64(4),
  808. "op_3_aggregate_0_exceptions_total": int64(0),
  809. "op_3_aggregate_0_process_latency_us": int64(0),
  810. "op_3_aggregate_0_records_in_total": int64(4),
  811. "op_3_aggregate_0_records_out_total": int64(4),
  812. "op_4_order_0_exceptions_total": int64(0),
  813. "op_4_order_0_process_latency_us": int64(0),
  814. "op_4_order_0_records_in_total": int64(4),
  815. "op_4_order_0_records_out_total": int64(4),
  816. },
  817. }, {
  818. name: `TestEventWindowRule5`,
  819. sql: `SELECT temp FROM sessionDemoE GROUP BY SessionWindow(ss, 2, 1) `,
  820. r: [][]map[string]interface{}{
  821. {{
  822. "temp": 25.5,
  823. }}, {{
  824. "temp": 28.1,
  825. }, {
  826. "temp": 27.4,
  827. }, {
  828. "temp": 25.5,
  829. }}, {{
  830. "temp": 26.2,
  831. }, {
  832. "temp": 26.8,
  833. }, {
  834. "temp": 28.9,
  835. }, {
  836. "temp": 29.1,
  837. }, {
  838. "temp": 32.2,
  839. }}, {{
  840. "temp": 30.9,
  841. }},
  842. },
  843. m: map[string]interface{}{
  844. "op_1_preprocessor_sessionDemoE_0_exceptions_total": int64(0),
  845. "op_1_preprocessor_sessionDemoE_0_process_latency_us": int64(0),
  846. "op_1_preprocessor_sessionDemoE_0_records_in_total": int64(12),
  847. "op_1_preprocessor_sessionDemoE_0_records_out_total": int64(12),
  848. "op_3_project_0_exceptions_total": int64(0),
  849. "op_3_project_0_process_latency_us": int64(0),
  850. "op_3_project_0_records_in_total": int64(4),
  851. "op_3_project_0_records_out_total": int64(4),
  852. "sink_mockSink_0_exceptions_total": int64(0),
  853. "sink_mockSink_0_records_in_total": int64(4),
  854. "sink_mockSink_0_records_out_total": int64(4),
  855. "source_sessionDemoE_0_exceptions_total": int64(0),
  856. "source_sessionDemoE_0_records_in_total": int64(12),
  857. "source_sessionDemoE_0_records_out_total": int64(12),
  858. "op_2_window_0_exceptions_total": int64(0),
  859. "op_2_window_0_process_latency_us": int64(0),
  860. "op_2_window_0_records_in_total": int64(12),
  861. "op_2_window_0_records_out_total": int64(4),
  862. },
  863. }, {
  864. name: `TestEventWindowRule6`,
  865. 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)`,
  866. r: [][]map[string]interface{}{
  867. {{
  868. "m": 25.5,
  869. "c": float64(1),
  870. }}, {{
  871. "m": 25.5,
  872. "c": float64(1),
  873. }}, {{
  874. "m": 28.1,
  875. "c": float64(1),
  876. }}, {{
  877. "m": 28.1,
  878. "c": float64(2),
  879. }}, {{
  880. "m": 27.4,
  881. "c": float64(2),
  882. }},
  883. },
  884. m: map[string]interface{}{
  885. "op_1_preprocessor_demoE_0_exceptions_total": int64(0),
  886. "op_1_preprocessor_demoE_0_process_latency_us": int64(0),
  887. "op_1_preprocessor_demoE_0_records_in_total": int64(6),
  888. "op_1_preprocessor_demoE_0_records_out_total": int64(6),
  889. "op_2_preprocessor_demo1E_0_exceptions_total": int64(0),
  890. "op_2_preprocessor_demo1E_0_process_latency_us": int64(0),
  891. "op_2_preprocessor_demo1E_0_records_in_total": int64(6),
  892. "op_2_preprocessor_demo1E_0_records_out_total": int64(6),
  893. "op_6_project_0_exceptions_total": int64(0),
  894. "op_6_project_0_process_latency_us": int64(0),
  895. "op_6_project_0_records_in_total": int64(5),
  896. "op_6_project_0_records_out_total": int64(5),
  897. "sink_mockSink_0_exceptions_total": int64(0),
  898. "sink_mockSink_0_records_in_total": int64(5),
  899. "sink_mockSink_0_records_out_total": int64(5),
  900. "source_demoE_0_exceptions_total": int64(0),
  901. "source_demoE_0_records_in_total": int64(6),
  902. "source_demoE_0_records_out_total": int64(6),
  903. "source_demo1E_0_exceptions_total": int64(0),
  904. "source_demo1E_0_records_in_total": int64(6),
  905. "source_demo1E_0_records_out_total": int64(6),
  906. "op_3_window_0_exceptions_total": int64(0),
  907. "op_3_window_0_records_in_total": int64(12),
  908. "op_3_window_0_records_out_total": int64(5),
  909. "op_4_join_0_exceptions_total": int64(0),
  910. "op_4_join_0_process_latency_us": int64(0),
  911. "op_4_join_0_records_in_total": int64(5),
  912. "op_4_join_0_records_out_total": int64(5),
  913. },
  914. }, {
  915. name: `TestEventWindowRule7`,
  916. sql: `SELECT * FROM demoErr GROUP BY HOPPINGWINDOW(ss, 2, 1)`,
  917. r: [][]map[string]interface{}{
  918. {{
  919. "error": "error in preprocessor: invalid data type for color, expect string but found int(2)",
  920. }},
  921. {{
  922. "color": "red",
  923. "size": float64(3),
  924. "ts": float64(1541152486013),
  925. }},
  926. {{
  927. "color": "red",
  928. "size": float64(3),
  929. "ts": float64(1541152486013),
  930. }},
  931. {{
  932. "color": "yellow",
  933. "size": float64(4),
  934. "ts": float64(1541152488442),
  935. }}, {{
  936. "color": "yellow",
  937. "size": float64(4),
  938. "ts": float64(1541152488442),
  939. }, {
  940. "color": "red",
  941. "size": float64(1),
  942. "ts": float64(1541152489252),
  943. }}, {{
  944. "color": "red",
  945. "size": float64(1),
  946. "ts": float64(1541152489252),
  947. }},
  948. },
  949. m: map[string]interface{}{
  950. "op_1_preprocessor_demoErr_0_exceptions_total": int64(1),
  951. "op_1_preprocessor_demoErr_0_process_latency_us": int64(0),
  952. "op_1_preprocessor_demoErr_0_records_in_total": int64(6),
  953. "op_1_preprocessor_demoErr_0_records_out_total": int64(5),
  954. "op_3_project_0_exceptions_total": int64(1),
  955. "op_3_project_0_process_latency_us": int64(0),
  956. "op_3_project_0_records_in_total": int64(6),
  957. "op_3_project_0_records_out_total": int64(5),
  958. "sink_mockSink_0_exceptions_total": int64(0),
  959. "sink_mockSink_0_records_in_total": int64(6),
  960. "sink_mockSink_0_records_out_total": int64(6),
  961. "source_demoErr_0_exceptions_total": int64(0),
  962. "source_demoErr_0_records_in_total": int64(6),
  963. "source_demoErr_0_records_out_total": int64(6),
  964. "op_2_window_0_exceptions_total": int64(1),
  965. "op_2_window_0_process_latency_us": int64(0),
  966. "op_2_window_0_records_in_total": int64(6),
  967. "op_2_window_0_records_out_total": int64(5),
  968. },
  969. },
  970. }
  971. handleStream(true, streamList, t)
  972. options := []*api.RuleOption{
  973. {
  974. BufferLength: 100,
  975. SendError: true,
  976. IsEventTime: true,
  977. LateTol: 1000,
  978. }, {
  979. BufferLength: 100,
  980. SendError: true,
  981. Qos: api.AtLeastOnce,
  982. CheckpointInterval: 5000,
  983. IsEventTime: true,
  984. LateTol: 1000,
  985. }, {
  986. BufferLength: 100,
  987. SendError: true,
  988. Qos: api.ExactlyOnce,
  989. CheckpointInterval: 5000,
  990. IsEventTime: true,
  991. LateTol: 1000,
  992. },
  993. }
  994. for j, opt := range options {
  995. doRuleTest(t, tests, j, opt)
  996. }
  997. }
  998. func TestWindowError(t *testing.T) {
  999. //Reset
  1000. streamList := []string{"ldemo", "ldemo1"}
  1001. handleStream(false, streamList, t)
  1002. var tests = []ruleTest{
  1003. {
  1004. name: `TestWindowErrorRule1`,
  1005. sql: `SELECT size * 3 FROM ldemo GROUP BY TUMBLINGWINDOW(ss, 2)`,
  1006. r: [][]map[string]interface{}{
  1007. {{
  1008. "error": "run Select error: invalid operation string(string) * int64(3)",
  1009. }}, {{
  1010. "rengine_field_0": float64(6),
  1011. }, {}},
  1012. },
  1013. m: map[string]interface{}{
  1014. "op_1_preprocessor_ldemo_0_exceptions_total": int64(0),
  1015. "op_1_preprocessor_ldemo_0_process_latency_us": int64(0),
  1016. "op_1_preprocessor_ldemo_0_records_in_total": int64(5),
  1017. "op_1_preprocessor_ldemo_0_records_out_total": int64(5),
  1018. "op_3_project_0_exceptions_total": int64(1),
  1019. "op_3_project_0_process_latency_us": int64(0),
  1020. "op_3_project_0_records_in_total": int64(2),
  1021. "op_3_project_0_records_out_total": int64(1),
  1022. "sink_mockSink_0_exceptions_total": int64(0),
  1023. "sink_mockSink_0_records_in_total": int64(2),
  1024. "sink_mockSink_0_records_out_total": int64(2),
  1025. "source_ldemo_0_exceptions_total": int64(0),
  1026. "source_ldemo_0_records_in_total": int64(5),
  1027. "source_ldemo_0_records_out_total": int64(5),
  1028. "op_2_window_0_exceptions_total": int64(0),
  1029. "op_2_window_0_process_latency_us": int64(0),
  1030. "op_2_window_0_records_in_total": int64(5),
  1031. "op_2_window_0_records_out_total": int64(2),
  1032. },
  1033. }, {
  1034. name: `TestWindowErrorRule2`,
  1035. sql: `SELECT color, ts FROM ldemo where size > 2 GROUP BY tumblingwindow(ss, 1)`,
  1036. r: [][]map[string]interface{}{
  1037. {{
  1038. "error": "run Where error: invalid operation string(string) > int64(2)",
  1039. }}, {{
  1040. "color": "red",
  1041. "ts": float64(1541152486013),
  1042. }}, {{
  1043. "ts": float64(1541152487632),
  1044. }},
  1045. },
  1046. m: map[string]interface{}{
  1047. "op_1_preprocessor_ldemo_0_exceptions_total": int64(0),
  1048. "op_1_preprocessor_ldemo_0_process_latency_us": int64(0),
  1049. "op_1_preprocessor_ldemo_0_records_in_total": int64(5),
  1050. "op_1_preprocessor_ldemo_0_records_out_total": int64(5),
  1051. "op_4_project_0_exceptions_total": int64(1),
  1052. "op_4_project_0_process_latency_us": int64(0),
  1053. "op_4_project_0_records_in_total": int64(3),
  1054. "op_4_project_0_records_out_total": int64(2),
  1055. "sink_mockSink_0_exceptions_total": int64(0),
  1056. "sink_mockSink_0_records_in_total": int64(3),
  1057. "sink_mockSink_0_records_out_total": int64(3),
  1058. "source_ldemo_0_exceptions_total": int64(0),
  1059. "source_ldemo_0_records_in_total": int64(5),
  1060. "source_ldemo_0_records_out_total": int64(5),
  1061. "op_3_window_0_exceptions_total": int64(1),
  1062. "op_3_window_0_process_latency_us": int64(0),
  1063. "op_3_window_0_records_in_total": int64(3),
  1064. "op_3_window_0_records_out_total": int64(2),
  1065. "op_2_filter_0_exceptions_total": int64(1),
  1066. "op_2_filter_0_process_latency_us": int64(0),
  1067. "op_2_filter_0_records_in_total": int64(5),
  1068. "op_2_filter_0_records_out_total": int64(2),
  1069. },
  1070. }, {
  1071. name: `TestWindowErrorRule3`,
  1072. sql: `SELECT color, temp, ts FROM ldemo INNER JOIN ldemo1 ON ldemo.ts = ldemo1.ts GROUP BY SlidingWindow(ss, 1)`,
  1073. r: [][]map[string]interface{}{
  1074. {{
  1075. "color": "red",
  1076. "temp": 25.5,
  1077. "ts": float64(1541152486013),
  1078. }}, {{
  1079. "color": "red",
  1080. "temp": 25.5,
  1081. "ts": float64(1541152486013),
  1082. }}, {{
  1083. "color": "red",
  1084. "temp": 25.5,
  1085. "ts": float64(1541152486013),
  1086. }}, {{
  1087. "temp": 28.1,
  1088. "ts": float64(1541152487632),
  1089. }}, {{
  1090. "temp": 28.1,
  1091. "ts": float64(1541152487632),
  1092. }}, {{
  1093. "error": "run Join error: invalid operation int64(1541152487632) = string(1541152488442)",
  1094. }}, {{
  1095. "error": "run Join error: invalid operation int64(1541152488442) = string(1541152488442)",
  1096. }}, {{
  1097. "error": "run Join error: invalid operation int64(1541152488442) = string(1541152488442)",
  1098. }},
  1099. },
  1100. m: map[string]interface{}{
  1101. "op_1_preprocessor_ldemo_0_exceptions_total": int64(0),
  1102. "op_1_preprocessor_ldemo_0_process_latency_us": int64(0),
  1103. "op_1_preprocessor_ldemo_0_records_in_total": int64(5),
  1104. "op_1_preprocessor_ldemo_0_records_out_total": int64(5),
  1105. "op_2_preprocessor_ldemo1_0_exceptions_total": int64(0),
  1106. "op_2_preprocessor_ldemo1_0_process_latency_us": int64(0),
  1107. "op_2_preprocessor_ldemo1_0_records_in_total": int64(5),
  1108. "op_2_preprocessor_ldemo1_0_records_out_total": int64(5),
  1109. "op_5_project_0_exceptions_total": int64(3),
  1110. "op_5_project_0_process_latency_us": int64(0),
  1111. "op_5_project_0_records_in_total": int64(8),
  1112. "op_5_project_0_records_out_total": int64(5),
  1113. "sink_mockSink_0_exceptions_total": int64(0),
  1114. "sink_mockSink_0_records_in_total": int64(8),
  1115. "sink_mockSink_0_records_out_total": int64(8),
  1116. "source_ldemo_0_exceptions_total": int64(0),
  1117. "source_ldemo_0_records_in_total": int64(5),
  1118. "source_ldemo_0_records_out_total": int64(5),
  1119. "source_ldemo1_0_exceptions_total": int64(0),
  1120. "source_ldemo1_0_records_in_total": int64(5),
  1121. "source_ldemo1_0_records_out_total": int64(5),
  1122. "op_3_window_0_exceptions_total": int64(0),
  1123. "op_3_window_0_process_latency_us": int64(0),
  1124. "op_3_window_0_records_in_total": int64(10),
  1125. "op_3_window_0_records_out_total": int64(10),
  1126. "op_4_join_0_exceptions_total": int64(3),
  1127. "op_4_join_0_process_latency_us": int64(0),
  1128. "op_4_join_0_records_in_total": int64(10),
  1129. "op_4_join_0_records_out_total": int64(5),
  1130. },
  1131. }, {
  1132. name: `TestWindowErrorRule4`,
  1133. sql: `SELECT color FROM ldemo GROUP BY SlidingWindow(ss, 2), color having size >= 2 order by color`,
  1134. r: [][]map[string]interface{}{
  1135. {{
  1136. "color": "red",
  1137. }}, {{
  1138. "error": "run Having error: invalid operation string(string) >= int64(2)",
  1139. }}, {{
  1140. "error": "run Having error: invalid operation string(string) >= int64(2)",
  1141. }}, {{
  1142. "error": "run Having error: invalid operation string(string) >= int64(2)",
  1143. }}, {{
  1144. "color": float64(49),
  1145. }, {}},
  1146. },
  1147. m: map[string]interface{}{
  1148. "op_1_preprocessor_ldemo_0_exceptions_total": int64(0),
  1149. "op_1_preprocessor_ldemo_0_process_latency_us": int64(0),
  1150. "op_1_preprocessor_ldemo_0_records_in_total": int64(5),
  1151. "op_1_preprocessor_ldemo_0_records_out_total": int64(5),
  1152. "op_6_project_0_exceptions_total": int64(3),
  1153. "op_6_project_0_process_latency_us": int64(0),
  1154. "op_6_project_0_records_in_total": int64(5),
  1155. "op_6_project_0_records_out_total": int64(2),
  1156. "sink_mockSink_0_exceptions_total": int64(0),
  1157. "sink_mockSink_0_records_in_total": int64(5),
  1158. "sink_mockSink_0_records_out_total": int64(5),
  1159. "source_ldemo_0_exceptions_total": int64(0),
  1160. "source_ldemo_0_records_in_total": int64(5),
  1161. "source_ldemo_0_records_out_total": int64(5),
  1162. "op_2_window_0_exceptions_total": int64(0),
  1163. "op_2_window_0_process_latency_us": int64(0),
  1164. "op_2_window_0_records_in_total": int64(5),
  1165. "op_2_window_0_records_out_total": int64(5),
  1166. "op_3_aggregate_0_exceptions_total": int64(0),
  1167. "op_3_aggregate_0_process_latency_us": int64(0),
  1168. "op_3_aggregate_0_records_in_total": int64(5),
  1169. "op_3_aggregate_0_records_out_total": int64(5),
  1170. "op_4_having_0_exceptions_total": int64(3),
  1171. "op_4_having_0_process_latency_us": int64(0),
  1172. "op_4_having_0_records_in_total": int64(5),
  1173. "op_4_having_0_records_out_total": int64(2),
  1174. },
  1175. }, {
  1176. name: `TestWindowErrorRule5`,
  1177. sql: `SELECT color, size FROM ldemo GROUP BY tumblingwindow(ss, 1) ORDER BY size`,
  1178. r: [][]map[string]interface{}{
  1179. {{
  1180. "error": "run Order By error: incompatible types for comparison: int and string",
  1181. }}, {{
  1182. "size": float64(3),
  1183. }}, {{
  1184. "color": float64(49),
  1185. "size": float64(2),
  1186. }}, {{
  1187. "color": "red",
  1188. }},
  1189. },
  1190. m: map[string]interface{}{
  1191. "op_1_preprocessor_ldemo_0_exceptions_total": int64(0),
  1192. "op_1_preprocessor_ldemo_0_process_latency_us": int64(0),
  1193. "op_1_preprocessor_ldemo_0_records_in_total": int64(5),
  1194. "op_1_preprocessor_ldemo_0_records_out_total": int64(5),
  1195. "op_4_project_0_exceptions_total": int64(1),
  1196. "op_4_project_0_process_latency_us": int64(0),
  1197. "op_4_project_0_records_in_total": int64(4),
  1198. "op_4_project_0_records_out_total": int64(3),
  1199. "sink_mockSink_0_exceptions_total": int64(0),
  1200. "sink_mockSink_0_records_in_total": int64(4),
  1201. "sink_mockSink_0_records_out_total": int64(4),
  1202. "source_ldemo_0_exceptions_total": int64(0),
  1203. "source_ldemo_0_records_in_total": int64(5),
  1204. "source_ldemo_0_records_out_total": int64(5),
  1205. "op_2_window_0_exceptions_total": int64(0),
  1206. "op_2_window_0_process_latency_us": int64(0),
  1207. "op_2_window_0_records_in_total": int64(5),
  1208. "op_2_window_0_records_out_total": int64(4),
  1209. "op_3_order_0_exceptions_total": int64(1),
  1210. "op_3_order_0_process_latency_us": int64(0),
  1211. "op_3_order_0_records_in_total": int64(4),
  1212. "op_3_order_0_records_out_total": int64(3),
  1213. },
  1214. },
  1215. }
  1216. handleStream(true, streamList, t)
  1217. doRuleTest(t, tests, 0, &api.RuleOption{
  1218. BufferLength: 100,
  1219. SendError: true,
  1220. })
  1221. }