window_rule_test.go 46 KB

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