window_rule_test.go 45 KB

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