window_rule_test.go 53 KB

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