window_rule_test.go 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612
  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. "color": "blue",
  525. "window_start": float64(1541152485000),
  526. "window_end": float64(1541152487000),
  527. }},
  528. {{
  529. "color": "red",
  530. "window_start": float64(1541152486000),
  531. "window_end": float64(1541152488000),
  532. }, {
  533. "color": "blue",
  534. "window_start": float64(1541152486000),
  535. "window_end": float64(1541152488000),
  536. }},
  537. {{
  538. "color": "yellow",
  539. "window_start": float64(1541152487000),
  540. "window_end": float64(1541152489000),
  541. }},
  542. {{
  543. "color": "yellow",
  544. "window_start": float64(1541152488000),
  545. "window_end": float64(1541152490000),
  546. }},
  547. },
  548. M: map[string]interface{}{
  549. "op_1_preprocessor_demo_0_exceptions_total": int64(0),
  550. "op_1_preprocessor_demo_0_process_latency_us": int64(0),
  551. "op_1_preprocessor_demo_0_records_in_total": int64(5),
  552. "op_1_preprocessor_demo_0_records_out_total": int64(5),
  553. "op_4_project_0_exceptions_total": int64(0),
  554. "op_4_project_0_process_latency_us": int64(0),
  555. "op_4_project_0_records_in_total": int64(4),
  556. "op_4_project_0_records_out_total": int64(4),
  557. "sink_mockSink_0_exceptions_total": int64(0),
  558. "sink_mockSink_0_records_in_total": int64(4),
  559. "sink_mockSink_0_records_out_total": int64(4),
  560. "source_demo_0_exceptions_total": int64(0),
  561. "source_demo_0_records_in_total": int64(5),
  562. "source_demo_0_records_out_total": int64(5),
  563. "op_3_window_0_exceptions_total": int64(0),
  564. "op_3_window_0_process_latency_us": int64(0),
  565. "op_3_window_0_records_in_total": int64(3),
  566. "op_3_window_0_records_out_total": int64(4),
  567. },
  568. }, {
  569. Name: `TestCountWindowRule1`,
  570. Sql: `SELECT collect(*)[0]->color as c FROM demo GROUP BY COUNTWINDOW(3)`,
  571. R: [][]map[string]interface{}{
  572. {{
  573. "c": "red",
  574. }},
  575. },
  576. M: map[string]interface{}{
  577. "op_1_preprocessor_demo_0_exceptions_total": int64(0),
  578. "op_1_preprocessor_demo_0_process_latency_us": int64(0),
  579. "op_1_preprocessor_demo_0_records_in_total": int64(5),
  580. "op_1_preprocessor_demo_0_records_out_total": int64(5),
  581. "op_3_project_0_exceptions_total": int64(0),
  582. "op_3_project_0_process_latency_us": int64(0),
  583. "op_3_project_0_records_in_total": int64(1),
  584. "op_3_project_0_records_out_total": int64(1),
  585. "sink_mockSink_0_exceptions_total": int64(0),
  586. "sink_mockSink_0_records_in_total": int64(1),
  587. "sink_mockSink_0_records_out_total": int64(1),
  588. "source_demo_0_exceptions_total": int64(0),
  589. "source_demo_0_records_in_total": int64(5),
  590. "source_demo_0_records_out_total": int64(5),
  591. "op_2_window_0_exceptions_total": int64(0),
  592. "op_2_window_0_process_latency_us": int64(0),
  593. "op_2_window_0_records_in_total": int64(5),
  594. "op_2_window_0_records_out_total": int64(1),
  595. },
  596. }, {
  597. Name: `TestWindowRule10`,
  598. Sql: `SELECT deduplicate(color, false)->color as c FROM demo GROUP BY SlidingWindow(hh, 1)`,
  599. R: [][]map[string]interface{}{
  600. {{
  601. "c": "red",
  602. }}, {{
  603. "c": "blue",
  604. }}, {{}}, {{
  605. "c": "yellow",
  606. }}, {{}},
  607. },
  608. M: map[string]interface{}{
  609. "op_1_preprocessor_demo_0_exceptions_total": int64(0),
  610. "op_1_preprocessor_demo_0_process_latency_us": int64(0),
  611. "op_1_preprocessor_demo_0_records_in_total": int64(5),
  612. "op_1_preprocessor_demo_0_records_out_total": int64(5),
  613. "op_3_project_0_exceptions_total": int64(0),
  614. "op_3_project_0_process_latency_us": int64(0),
  615. "op_3_project_0_records_in_total": int64(5),
  616. "op_3_project_0_records_out_total": int64(5),
  617. "sink_mockSink_0_exceptions_total": int64(0),
  618. "sink_mockSink_0_records_in_total": int64(5),
  619. "sink_mockSink_0_records_out_total": int64(5),
  620. "source_demo_0_exceptions_total": int64(0),
  621. "source_demo_0_records_in_total": int64(5),
  622. "source_demo_0_records_out_total": int64(5),
  623. "op_2_window_0_exceptions_total": int64(0),
  624. "op_2_window_0_process_latency_us": int64(0),
  625. "op_2_window_0_records_in_total": int64(5),
  626. "op_2_window_0_records_out_total": int64(5),
  627. },
  628. }, {
  629. Name: `TestWindowRule11`,
  630. 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)`,
  631. R: [][]map[string]interface{}{
  632. {{
  633. "color": "red",
  634. "name": "name1",
  635. "window_start": float64(1541152486000),
  636. "window_end": float64(1541152487000),
  637. }},
  638. },
  639. M: map[string]interface{}{
  640. //"op_4_project_0_exceptions_total": int64(0),
  641. //"op_4_project_0_process_latency_us": int64(0),
  642. //"op_4_project_0_records_in_total": int64(2),
  643. //"op_4_project_0_records_out_total": int64(2),
  644. "op_3_window_0_exceptions_total": int64(0),
  645. "op_3_window_0_process_latency_us": int64(0),
  646. "op_3_window_0_records_in_total": int64(3),
  647. "op_3_window_0_records_out_total": int64(2),
  648. "op_2_filter_0_exceptions_total": int64(0),
  649. "op_2_filter_0_process_latency_us": int64(0),
  650. "op_2_filter_0_records_in_total": int64(5),
  651. "op_2_filter_0_records_out_total": int64(3),
  652. "op_1_preprocessor_demo_0_exceptions_total": int64(0),
  653. "op_1_preprocessor_demo_0_records_in_total": int64(5),
  654. "op_1_preprocessor_demo_0_records_out_total": int64(5),
  655. "op_4_tableprocessor_table1_0_exceptions_total": int64(0),
  656. "op_4_tableprocessor_table1_0_records_in_total": int64(4),
  657. "op_4_tableprocessor_table1_0_records_out_total": int64(1),
  658. "op_5_filter_0_exceptions_total": int64(0),
  659. "op_5_filter_0_records_in_total": int64(1),
  660. "op_5_filter_0_records_out_total": int64(1),
  661. "op_6_join_aligner_0_records_in_total": int64(3),
  662. "op_6_join_aligner_0_records_out_total": int64(2),
  663. "op_7_join_0_exceptions_total": int64(0),
  664. "op_7_join_0_records_in_total": int64(2),
  665. "op_7_join_0_records_out_total": int64(1),
  666. "op_8_project_0_exceptions_total": int64(0),
  667. "op_8_project_0_records_in_total": int64(1),
  668. "op_8_project_0_records_out_total": int64(1),
  669. "sink_mockSink_0_exceptions_total": int64(0),
  670. "sink_mockSink_0_records_in_total": int64(1),
  671. "sink_mockSink_0_records_out_total": int64(1),
  672. "source_demo_0_exceptions_total": int64(0),
  673. "source_demo_0_records_in_total": int64(5),
  674. "source_demo_0_records_out_total": int64(5),
  675. "source_table1_0_exceptions_total": int64(0),
  676. "source_table1_0_records_in_total": int64(4),
  677. "source_table1_0_records_out_total": int64(4),
  678. },
  679. },
  680. }
  681. HandleStream(true, streamList, t)
  682. options := []*api.RuleOption{
  683. {
  684. BufferLength: 100,
  685. SendError: true,
  686. }, {
  687. BufferLength: 100,
  688. SendError: true,
  689. Qos: api.AtLeastOnce,
  690. CheckpointInterval: 5000,
  691. }, {
  692. BufferLength: 100,
  693. SendError: true,
  694. Qos: api.ExactlyOnce,
  695. CheckpointInterval: 5000,
  696. },
  697. }
  698. for j, opt := range options {
  699. DoRuleTest(t, tests, j, opt, 15)
  700. }
  701. }
  702. func TestEventWindow(t *testing.T) {
  703. //Reset
  704. streamList := []string{"demoE", "demoErr", "demo1E", "sessionDemoE"}
  705. HandleStream(false, streamList, t)
  706. var tests = []RuleTest{
  707. {
  708. Name: `TestEventWindowRule1`,
  709. Sql: `SELECT * FROM demoE GROUP BY HOPPINGWINDOW(ss, 2, 1)`,
  710. R: [][]map[string]interface{}{
  711. {{
  712. "color": "red",
  713. "size": float64(3),
  714. "ts": float64(1541152486013),
  715. }},
  716. {{
  717. "color": "red",
  718. "size": float64(3),
  719. "ts": float64(1541152486013),
  720. }, {
  721. "color": "blue",
  722. "size": float64(2),
  723. "ts": float64(1541152487632),
  724. }},
  725. {{
  726. "color": "blue",
  727. "size": float64(2),
  728. "ts": float64(1541152487632),
  729. }, {
  730. "color": "yellow",
  731. "size": float64(4),
  732. "ts": float64(1541152488442),
  733. }}, {{
  734. "color": "yellow",
  735. "size": float64(4),
  736. "ts": float64(1541152488442),
  737. }, {
  738. "color": "red",
  739. "size": float64(1),
  740. "ts": float64(1541152489252),
  741. }}, {{
  742. "color": "red",
  743. "size": float64(1),
  744. "ts": float64(1541152489252),
  745. }},
  746. },
  747. M: map[string]interface{}{
  748. "op_1_preprocessor_demoE_0_exceptions_total": int64(0),
  749. "op_1_preprocessor_demoE_0_process_latency_us": int64(0),
  750. "op_1_preprocessor_demoE_0_records_in_total": int64(6),
  751. "op_1_preprocessor_demoE_0_records_out_total": int64(6),
  752. "op_3_project_0_exceptions_total": int64(0),
  753. "op_3_project_0_process_latency_us": int64(0),
  754. "op_3_project_0_records_in_total": int64(5),
  755. "op_3_project_0_records_out_total": int64(5),
  756. "sink_mockSink_0_exceptions_total": int64(0),
  757. "sink_mockSink_0_records_in_total": int64(5),
  758. "sink_mockSink_0_records_out_total": int64(5),
  759. "source_demoE_0_exceptions_total": int64(0),
  760. "source_demoE_0_records_in_total": int64(6),
  761. "source_demoE_0_records_out_total": int64(6),
  762. "op_2_window_0_exceptions_total": int64(0),
  763. "op_2_window_0_process_latency_us": int64(0),
  764. "op_2_window_0_records_in_total": int64(6),
  765. "op_2_window_0_records_out_total": int64(5),
  766. },
  767. }, {
  768. Name: `TestEventWindowRule2`,
  769. Sql: `SELECT window_start(), window_end(), color, ts FROM demoE where size > 2 GROUP BY tumblingwindow(ss, 1)`,
  770. R: [][]map[string]interface{}{
  771. {{
  772. "window_start": float64(1541152486000),
  773. "window_end": float64(1541152487000),
  774. "color": "red",
  775. "ts": float64(1541152486013),
  776. }},
  777. {{
  778. "window_start": float64(1541152488000),
  779. "window_end": float64(1541152489000),
  780. "color": "yellow",
  781. "ts": float64(1541152488442),
  782. }},
  783. },
  784. M: map[string]interface{}{
  785. "op_1_preprocessor_demoE_0_exceptions_total": int64(0),
  786. "op_1_preprocessor_demoE_0_process_latency_us": int64(0),
  787. "op_1_preprocessor_demoE_0_records_in_total": int64(6),
  788. "op_1_preprocessor_demoE_0_records_out_total": int64(6),
  789. "op_4_project_0_exceptions_total": int64(0),
  790. "op_4_project_0_process_latency_us": int64(0),
  791. "op_4_project_0_records_in_total": int64(2),
  792. "op_4_project_0_records_out_total": int64(2),
  793. "sink_mockSink_0_exceptions_total": int64(0),
  794. "sink_mockSink_0_records_in_total": int64(2),
  795. "sink_mockSink_0_records_out_total": int64(2),
  796. "source_demoE_0_exceptions_total": int64(0),
  797. "source_demoE_0_records_in_total": int64(6),
  798. "source_demoE_0_records_out_total": int64(6),
  799. "op_2_window_0_exceptions_total": int64(0),
  800. "op_2_window_0_process_latency_us": int64(0),
  801. "op_2_window_0_records_in_total": int64(6),
  802. "op_2_window_0_records_out_total": int64(4),
  803. "op_3_filter_0_exceptions_total": int64(0),
  804. "op_3_filter_0_process_latency_us": int64(0),
  805. "op_3_filter_0_records_in_total": int64(4),
  806. "op_3_filter_0_records_out_total": int64(2),
  807. },
  808. }, {
  809. Name: `TestEventWindowRule3`,
  810. Sql: `SELECT color, temp, demoE.ts FROM demoE INNER JOIN demo1E ON demoE.ts = demo1E.ts GROUP BY SlidingWindow(ss, 1)`,
  811. R: [][]map[string]interface{}{
  812. {{
  813. "color": "red",
  814. "temp": 25.5,
  815. "ts": float64(1541152486013),
  816. }}, {{
  817. "color": "red",
  818. "temp": 25.5,
  819. "ts": float64(1541152486013),
  820. }}, {{
  821. "color": "blue",
  822. "temp": 28.1,
  823. "ts": float64(1541152487632),
  824. }}, {{
  825. "color": "blue",
  826. "temp": 28.1,
  827. "ts": float64(1541152487632),
  828. }, {
  829. "color": "yellow",
  830. "temp": 27.4,
  831. "ts": float64(1541152488442),
  832. }}, {{
  833. "color": "yellow",
  834. "temp": 27.4,
  835. "ts": float64(1541152488442),
  836. }, {
  837. "color": "red",
  838. "temp": 25.5,
  839. "ts": float64(1541152489252),
  840. }},
  841. },
  842. M: map[string]interface{}{
  843. "op_1_preprocessor_demoE_0_exceptions_total": int64(0),
  844. "op_1_preprocessor_demoE_0_process_latency_us": int64(0),
  845. "op_1_preprocessor_demoE_0_records_in_total": int64(6),
  846. "op_1_preprocessor_demoE_0_records_out_total": int64(6),
  847. "op_2_preprocessor_demo1E_0_exceptions_total": int64(0),
  848. "op_2_preprocessor_demo1E_0_process_latency_us": int64(0),
  849. "op_2_preprocessor_demo1E_0_records_in_total": int64(6),
  850. "op_2_preprocessor_demo1E_0_records_out_total": int64(6),
  851. "op_5_project_0_exceptions_total": int64(0),
  852. "op_5_project_0_process_latency_us": int64(0),
  853. "op_5_project_0_records_in_total": int64(5),
  854. "op_5_project_0_records_out_total": int64(5),
  855. "sink_mockSink_0_exceptions_total": int64(0),
  856. "sink_mockSink_0_records_in_total": int64(5),
  857. "sink_mockSink_0_records_out_total": int64(5),
  858. "source_demoE_0_exceptions_total": int64(0),
  859. "source_demoE_0_records_in_total": int64(6),
  860. "source_demoE_0_records_out_total": int64(6),
  861. "source_demo1E_0_exceptions_total": int64(0),
  862. "source_demo1E_0_records_in_total": int64(6),
  863. "source_demo1E_0_records_out_total": int64(6),
  864. "op_3_window_0_exceptions_total": int64(0),
  865. "op_3_window_0_process_latency_us": int64(0),
  866. "op_3_window_0_records_in_total": int64(12),
  867. "op_3_window_0_records_out_total": int64(5),
  868. "op_4_join_0_exceptions_total": int64(0),
  869. "op_4_join_0_process_latency_us": int64(0),
  870. "op_4_join_0_records_in_total": int64(5),
  871. "op_4_join_0_records_out_total": int64(5),
  872. },
  873. }, {
  874. Name: `TestEventWindowRule4`,
  875. Sql: `SELECT window_start() as ws, color, window_end() as we FROM demoE GROUP BY SlidingWindow(ss, 2), color ORDER BY color`,
  876. R: [][]map[string]interface{}{
  877. {{
  878. "color": "red",
  879. "ws": float64(1541152484013),
  880. "we": float64(1541152486013),
  881. }}, {{
  882. "color": "blue",
  883. "ws": float64(1541152485632),
  884. "we": float64(1541152487632),
  885. }, {
  886. "color": "red",
  887. "ws": float64(1541152485632),
  888. "we": float64(1541152487632),
  889. }}, {{
  890. "color": "blue",
  891. "ws": float64(1541152486442),
  892. "we": float64(1541152488442),
  893. }, {
  894. "color": "yellow",
  895. "ws": float64(1541152486442),
  896. "we": float64(1541152488442),
  897. }}, {{
  898. "color": "blue",
  899. "ws": float64(1541152487252),
  900. "we": float64(1541152489252),
  901. }, {
  902. "color": "red",
  903. "ws": float64(1541152487252),
  904. "we": float64(1541152489252),
  905. }, {
  906. "color": "yellow",
  907. "ws": float64(1541152487252),
  908. "we": float64(1541152489252),
  909. }},
  910. },
  911. M: map[string]interface{}{
  912. "op_1_preprocessor_demoE_0_exceptions_total": int64(0),
  913. "op_1_preprocessor_demoE_0_process_latency_us": int64(0),
  914. "op_1_preprocessor_demoE_0_records_in_total": int64(6),
  915. "op_1_preprocessor_demoE_0_records_out_total": int64(6),
  916. "op_5_project_0_exceptions_total": int64(0),
  917. "op_5_project_0_process_latency_us": int64(0),
  918. "op_5_project_0_records_in_total": int64(4),
  919. "op_5_project_0_records_out_total": int64(4),
  920. "sink_mockSink_0_exceptions_total": int64(0),
  921. "sink_mockSink_0_records_in_total": int64(4),
  922. "sink_mockSink_0_records_out_total": int64(4),
  923. "source_demoE_0_exceptions_total": int64(0),
  924. "source_demoE_0_records_in_total": int64(6),
  925. "source_demoE_0_records_out_total": int64(6),
  926. "op_2_window_0_exceptions_total": int64(0),
  927. "op_2_window_0_process_latency_us": int64(0),
  928. "op_2_window_0_records_in_total": int64(6),
  929. "op_2_window_0_records_out_total": int64(4),
  930. "op_3_aggregate_0_exceptions_total": int64(0),
  931. "op_3_aggregate_0_process_latency_us": int64(0),
  932. "op_3_aggregate_0_records_in_total": int64(4),
  933. "op_3_aggregate_0_records_out_total": int64(4),
  934. "op_4_order_0_exceptions_total": int64(0),
  935. "op_4_order_0_process_latency_us": int64(0),
  936. "op_4_order_0_records_in_total": int64(4),
  937. "op_4_order_0_records_out_total": int64(4),
  938. },
  939. }, {
  940. Name: `TestEventWindowRule5`,
  941. Sql: `SELECT temp FROM sessionDemoE GROUP BY SessionWindow(ss, 2, 1) `,
  942. R: [][]map[string]interface{}{
  943. {{
  944. "temp": 25.5,
  945. }}, {{
  946. "temp": 28.1,
  947. }, {
  948. "temp": 27.4,
  949. }, {
  950. "temp": 25.5,
  951. }}, {{
  952. "temp": 26.2,
  953. }, {
  954. "temp": 26.8,
  955. }, {
  956. "temp": 28.9,
  957. }, {
  958. "temp": 29.1,
  959. }, {
  960. "temp": 32.2,
  961. }}, {{
  962. "temp": 30.9,
  963. }},
  964. },
  965. M: map[string]interface{}{
  966. "op_1_preprocessor_sessionDemoE_0_exceptions_total": int64(0),
  967. "op_1_preprocessor_sessionDemoE_0_process_latency_us": int64(0),
  968. "op_1_preprocessor_sessionDemoE_0_records_in_total": int64(12),
  969. "op_1_preprocessor_sessionDemoE_0_records_out_total": int64(12),
  970. "op_3_project_0_exceptions_total": int64(0),
  971. "op_3_project_0_process_latency_us": int64(0),
  972. "op_3_project_0_records_in_total": int64(4),
  973. "op_3_project_0_records_out_total": int64(4),
  974. "sink_mockSink_0_exceptions_total": int64(0),
  975. "sink_mockSink_0_records_in_total": int64(4),
  976. "sink_mockSink_0_records_out_total": int64(4),
  977. "source_sessionDemoE_0_exceptions_total": int64(0),
  978. "source_sessionDemoE_0_records_in_total": int64(12),
  979. "source_sessionDemoE_0_records_out_total": int64(12),
  980. "op_2_window_0_exceptions_total": int64(0),
  981. "op_2_window_0_process_latency_us": int64(0),
  982. "op_2_window_0_records_in_total": int64(12),
  983. "op_2_window_0_records_out_total": int64(4),
  984. },
  985. }, {
  986. Name: `TestEventWindowRule6`,
  987. 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)`,
  988. R: [][]map[string]interface{}{
  989. {{
  990. "m": 25.5,
  991. "c": float64(1),
  992. }}, {{
  993. "m": 25.5,
  994. "c": float64(1),
  995. }}, {{
  996. "m": 28.1,
  997. "c": float64(1),
  998. }}, {{
  999. "m": 28.1,
  1000. "c": float64(2),
  1001. }}, {{
  1002. "m": 27.4,
  1003. "c": float64(2),
  1004. }},
  1005. },
  1006. M: map[string]interface{}{
  1007. "op_1_preprocessor_demoE_0_exceptions_total": int64(0),
  1008. "op_1_preprocessor_demoE_0_process_latency_us": int64(0),
  1009. "op_1_preprocessor_demoE_0_records_in_total": int64(6),
  1010. "op_1_preprocessor_demoE_0_records_out_total": int64(6),
  1011. "op_2_preprocessor_demo1E_0_exceptions_total": int64(0),
  1012. "op_2_preprocessor_demo1E_0_process_latency_us": int64(0),
  1013. "op_2_preprocessor_demo1E_0_records_in_total": int64(6),
  1014. "op_2_preprocessor_demo1E_0_records_out_total": int64(6),
  1015. "op_5_project_0_exceptions_total": int64(0),
  1016. "op_5_project_0_process_latency_us": int64(0),
  1017. "op_5_project_0_records_in_total": int64(5),
  1018. "op_5_project_0_records_out_total": int64(5),
  1019. "sink_mockSink_0_exceptions_total": int64(0),
  1020. "sink_mockSink_0_records_in_total": int64(5),
  1021. "sink_mockSink_0_records_out_total": int64(5),
  1022. "source_demoE_0_exceptions_total": int64(0),
  1023. "source_demoE_0_records_in_total": int64(6),
  1024. "source_demoE_0_records_out_total": int64(6),
  1025. "source_demo1E_0_exceptions_total": int64(0),
  1026. "source_demo1E_0_records_in_total": int64(6),
  1027. "source_demo1E_0_records_out_total": int64(6),
  1028. "op_3_window_0_exceptions_total": int64(0),
  1029. "op_3_window_0_records_in_total": int64(12),
  1030. "op_3_window_0_records_out_total": int64(5),
  1031. "op_4_join_0_exceptions_total": int64(0),
  1032. "op_4_join_0_process_latency_us": int64(0),
  1033. "op_4_join_0_records_in_total": int64(5),
  1034. "op_4_join_0_records_out_total": int64(5),
  1035. },
  1036. }, {
  1037. Name: `TestEventWindowRule7`,
  1038. Sql: `SELECT * FROM demoErr GROUP BY HOPPINGWINDOW(ss, 2, 1)`,
  1039. R: [][]map[string]interface{}{
  1040. {{
  1041. "error": "error in preprocessor: invalid data type for color, expect string but found int(2)",
  1042. }},
  1043. {{
  1044. "color": "red",
  1045. "size": float64(3),
  1046. "ts": float64(1541152486013),
  1047. }},
  1048. {{
  1049. "color": "red",
  1050. "size": float64(3),
  1051. "ts": float64(1541152486013),
  1052. }},
  1053. {{
  1054. "color": "yellow",
  1055. "size": float64(4),
  1056. "ts": float64(1541152488442),
  1057. }}, {{
  1058. "color": "yellow",
  1059. "size": float64(4),
  1060. "ts": float64(1541152488442),
  1061. }, {
  1062. "color": "red",
  1063. "size": float64(1),
  1064. "ts": float64(1541152489252),
  1065. }}, {{
  1066. "color": "red",
  1067. "size": float64(1),
  1068. "ts": float64(1541152489252),
  1069. }},
  1070. },
  1071. M: map[string]interface{}{
  1072. "op_1_preprocessor_demoErr_0_exceptions_total": int64(1),
  1073. "op_1_preprocessor_demoErr_0_process_latency_us": int64(0),
  1074. "op_1_preprocessor_demoErr_0_records_in_total": int64(6),
  1075. "op_1_preprocessor_demoErr_0_records_out_total": int64(5),
  1076. "op_3_project_0_exceptions_total": int64(1),
  1077. "op_3_project_0_process_latency_us": int64(0),
  1078. "op_3_project_0_records_in_total": int64(6),
  1079. "op_3_project_0_records_out_total": int64(5),
  1080. "sink_mockSink_0_exceptions_total": int64(0),
  1081. "sink_mockSink_0_records_in_total": int64(6),
  1082. "sink_mockSink_0_records_out_total": int64(6),
  1083. "source_demoErr_0_exceptions_total": int64(0),
  1084. "source_demoErr_0_records_in_total": int64(6),
  1085. "source_demoErr_0_records_out_total": int64(6),
  1086. "op_2_window_0_exceptions_total": int64(1),
  1087. "op_2_window_0_process_latency_us": int64(0),
  1088. "op_2_window_0_records_in_total": int64(6),
  1089. "op_2_window_0_records_out_total": int64(5),
  1090. },
  1091. }, {
  1092. Name: `TestEventWindowRule8`,
  1093. Sql: `SELECT temp, window_start(), window_end() FROM sessionDemoE GROUP BY SessionWindow(ss, 2, 1) `,
  1094. R: [][]map[string]interface{}{
  1095. {{
  1096. "temp": 25.5,
  1097. "window_start": float64(1541152486013),
  1098. "window_end": float64(1541152487013),
  1099. }}, {{
  1100. "temp": 28.1,
  1101. "window_start": float64(1541152487932),
  1102. "window_end": float64(1541152490000),
  1103. }, {
  1104. "temp": 27.4,
  1105. "window_start": float64(1541152487932),
  1106. "window_end": float64(1541152490000),
  1107. }, {
  1108. "temp": 25.5,
  1109. "window_start": float64(1541152487932),
  1110. "window_end": float64(1541152490000),
  1111. }}, {{
  1112. "temp": 26.2,
  1113. "window_start": float64(1541152490000),
  1114. "window_end": float64(1541152494000),
  1115. }, {
  1116. "temp": 26.8,
  1117. "window_start": float64(1541152490000),
  1118. "window_end": float64(1541152494000),
  1119. }, {
  1120. "temp": 28.9,
  1121. "window_start": float64(1541152490000),
  1122. "window_end": float64(1541152494000),
  1123. }, {
  1124. "temp": 29.1,
  1125. "window_start": float64(1541152490000),
  1126. "window_end": float64(1541152494000),
  1127. }, {
  1128. "temp": 32.2,
  1129. "window_start": float64(1541152490000),
  1130. "window_end": float64(1541152494000),
  1131. }}, {{
  1132. "temp": 30.9,
  1133. "window_start": float64(1541152494000),
  1134. "window_end": float64(1541152495112),
  1135. }},
  1136. },
  1137. M: map[string]interface{}{
  1138. "op_1_preprocessor_sessionDemoE_0_exceptions_total": int64(0),
  1139. "op_1_preprocessor_sessionDemoE_0_process_latency_us": int64(0),
  1140. "op_1_preprocessor_sessionDemoE_0_records_in_total": int64(12),
  1141. "op_1_preprocessor_sessionDemoE_0_records_out_total": int64(12),
  1142. "op_3_project_0_exceptions_total": int64(0),
  1143. "op_3_project_0_process_latency_us": int64(0),
  1144. "op_3_project_0_records_in_total": int64(4),
  1145. "op_3_project_0_records_out_total": int64(4),
  1146. "sink_mockSink_0_exceptions_total": int64(0),
  1147. "sink_mockSink_0_records_in_total": int64(4),
  1148. "sink_mockSink_0_records_out_total": int64(4),
  1149. "source_sessionDemoE_0_exceptions_total": int64(0),
  1150. "source_sessionDemoE_0_records_in_total": int64(12),
  1151. "source_sessionDemoE_0_records_out_total": int64(12),
  1152. "op_2_window_0_exceptions_total": int64(0),
  1153. "op_2_window_0_process_latency_us": int64(0),
  1154. "op_2_window_0_records_in_total": int64(12),
  1155. "op_2_window_0_records_out_total": int64(4),
  1156. },
  1157. }, {
  1158. Name: `TestEventWindowRule9`,
  1159. Sql: `SELECT window_end(), color, window_start() FROM demoE GROUP BY HOPPINGWINDOW(ss, 2, 1)`,
  1160. R: [][]map[string]interface{}{
  1161. {{
  1162. "color": "red",
  1163. "window_start": float64(1541152485000),
  1164. "window_end": float64(1541152487000),
  1165. }},
  1166. {{
  1167. "color": "red",
  1168. "window_start": float64(1541152486000),
  1169. "window_end": float64(1541152488000),
  1170. }, {
  1171. "color": "blue",
  1172. "window_start": float64(1541152486000),
  1173. "window_end": float64(1541152488000),
  1174. }},
  1175. {{
  1176. "color": "blue",
  1177. "window_start": float64(1541152487000),
  1178. "window_end": float64(1541152489000),
  1179. }, {
  1180. "color": "yellow",
  1181. "window_start": float64(1541152487000),
  1182. "window_end": float64(1541152489000),
  1183. }}, {{
  1184. "color": "yellow",
  1185. "window_start": float64(1541152488000),
  1186. "window_end": float64(1541152490000),
  1187. }, {
  1188. "color": "red",
  1189. "window_start": float64(1541152488000),
  1190. "window_end": float64(1541152490000),
  1191. }}, {{
  1192. "color": "red",
  1193. "window_start": float64(1541152489000),
  1194. "window_end": float64(1541152491000),
  1195. }},
  1196. },
  1197. M: map[string]interface{}{
  1198. "op_1_preprocessor_demoE_0_exceptions_total": int64(0),
  1199. "op_1_preprocessor_demoE_0_process_latency_us": int64(0),
  1200. "op_1_preprocessor_demoE_0_records_in_total": int64(6),
  1201. "op_1_preprocessor_demoE_0_records_out_total": int64(6),
  1202. "op_3_project_0_exceptions_total": int64(0),
  1203. "op_3_project_0_process_latency_us": int64(0),
  1204. "op_3_project_0_records_in_total": int64(5),
  1205. "op_3_project_0_records_out_total": int64(5),
  1206. "sink_mockSink_0_exceptions_total": int64(0),
  1207. "sink_mockSink_0_records_in_total": int64(5),
  1208. "sink_mockSink_0_records_out_total": int64(5),
  1209. "source_demoE_0_exceptions_total": int64(0),
  1210. "source_demoE_0_records_in_total": int64(6),
  1211. "source_demoE_0_records_out_total": int64(6),
  1212. "op_2_window_0_exceptions_total": int64(0),
  1213. "op_2_window_0_process_latency_us": int64(0),
  1214. "op_2_window_0_records_in_total": int64(6),
  1215. "op_2_window_0_records_out_total": int64(5),
  1216. },
  1217. },
  1218. }
  1219. HandleStream(true, streamList, t)
  1220. options := []*api.RuleOption{
  1221. {
  1222. BufferLength: 100,
  1223. SendError: true,
  1224. IsEventTime: true,
  1225. LateTol: 1000,
  1226. }, {
  1227. BufferLength: 100,
  1228. SendError: true,
  1229. Qos: api.AtLeastOnce,
  1230. CheckpointInterval: 5000,
  1231. IsEventTime: true,
  1232. LateTol: 1000,
  1233. }, {
  1234. BufferLength: 100,
  1235. SendError: true,
  1236. Qos: api.ExactlyOnce,
  1237. CheckpointInterval: 5000,
  1238. IsEventTime: true,
  1239. LateTol: 1000,
  1240. },
  1241. }
  1242. for j, opt := range options {
  1243. DoRuleTest(t, tests, j, opt, 10)
  1244. }
  1245. }
  1246. func TestWindowError(t *testing.T) {
  1247. //Reset
  1248. streamList := []string{"ldemo", "ldemo1"}
  1249. HandleStream(false, streamList, t)
  1250. var tests = []RuleTest{
  1251. {
  1252. Name: `TestWindowErrorRule1`,
  1253. Sql: `SELECT size * 3 FROM ldemo GROUP BY TUMBLINGWINDOW(ss, 2)`,
  1254. R: [][]map[string]interface{}{
  1255. {{
  1256. "error": "run Select error: invalid operation string(string) * int64(3)",
  1257. }}, {{
  1258. "kuiper_field_0": float64(6),
  1259. }, {}},
  1260. },
  1261. M: map[string]interface{}{
  1262. "op_1_preprocessor_ldemo_0_exceptions_total": int64(0),
  1263. "op_1_preprocessor_ldemo_0_process_latency_us": int64(0),
  1264. "op_1_preprocessor_ldemo_0_records_in_total": int64(5),
  1265. "op_1_preprocessor_ldemo_0_records_out_total": int64(5),
  1266. "op_3_project_0_exceptions_total": int64(1),
  1267. "op_3_project_0_process_latency_us": int64(0),
  1268. "op_3_project_0_records_in_total": int64(2),
  1269. "op_3_project_0_records_out_total": int64(1),
  1270. "sink_mockSink_0_exceptions_total": int64(0),
  1271. "sink_mockSink_0_records_in_total": int64(2),
  1272. "sink_mockSink_0_records_out_total": int64(2),
  1273. "source_ldemo_0_exceptions_total": int64(0),
  1274. "source_ldemo_0_records_in_total": int64(5),
  1275. "source_ldemo_0_records_out_total": int64(5),
  1276. "op_2_window_0_exceptions_total": int64(0),
  1277. "op_2_window_0_process_latency_us": int64(0),
  1278. "op_2_window_0_records_in_total": int64(5),
  1279. "op_2_window_0_records_out_total": int64(2),
  1280. },
  1281. }, {
  1282. Name: `TestWindowErrorRule2`,
  1283. Sql: `SELECT color, ts FROM ldemo where size > 2 GROUP BY tumblingwindow(ss, 1)`,
  1284. R: [][]map[string]interface{}{
  1285. {{
  1286. "error": "run Where error: invalid operation string(string) > int64(2)",
  1287. }}, {{
  1288. "color": "red",
  1289. "ts": float64(1541152486013),
  1290. }}, {{
  1291. "ts": float64(1541152487632),
  1292. }},
  1293. },
  1294. M: map[string]interface{}{
  1295. "op_1_preprocessor_ldemo_0_exceptions_total": int64(0),
  1296. "op_1_preprocessor_ldemo_0_process_latency_us": int64(0),
  1297. "op_1_preprocessor_ldemo_0_records_in_total": int64(5),
  1298. "op_1_preprocessor_ldemo_0_records_out_total": int64(5),
  1299. "op_4_project_0_exceptions_total": int64(1),
  1300. "op_4_project_0_process_latency_us": int64(0),
  1301. "op_4_project_0_records_in_total": int64(3),
  1302. "op_4_project_0_records_out_total": int64(2),
  1303. "sink_mockSink_0_exceptions_total": int64(0),
  1304. "sink_mockSink_0_records_in_total": int64(3),
  1305. "sink_mockSink_0_records_out_total": int64(3),
  1306. "source_ldemo_0_exceptions_total": int64(0),
  1307. "source_ldemo_0_records_in_total": int64(5),
  1308. "source_ldemo_0_records_out_total": int64(5),
  1309. "op_3_window_0_exceptions_total": int64(1),
  1310. "op_3_window_0_process_latency_us": int64(0),
  1311. "op_3_window_0_records_in_total": int64(3),
  1312. "op_3_window_0_records_out_total": int64(2),
  1313. "op_2_filter_0_exceptions_total": int64(1),
  1314. "op_2_filter_0_process_latency_us": int64(0),
  1315. "op_2_filter_0_records_in_total": int64(5),
  1316. "op_2_filter_0_records_out_total": int64(2),
  1317. },
  1318. }, {
  1319. Name: `TestWindowErrorRule3`,
  1320. Sql: `SELECT color, temp, ts FROM ldemo INNER JOIN ldemo1 ON ldemo.ts = ldemo1.ts GROUP BY SlidingWindow(ss, 1)`,
  1321. R: [][]map[string]interface{}{
  1322. {{
  1323. "color": "red",
  1324. "temp": 25.5,
  1325. "ts": float64(1541152486013),
  1326. }}, {{
  1327. "color": "red",
  1328. "temp": 25.5,
  1329. "ts": float64(1541152486013),
  1330. }}, {{
  1331. "color": "red",
  1332. "temp": 25.5,
  1333. "ts": float64(1541152486013),
  1334. }}, {{
  1335. "temp": 28.1,
  1336. "ts": float64(1541152487632),
  1337. }}, {{
  1338. "temp": 28.1,
  1339. "ts": float64(1541152487632),
  1340. }}, {{
  1341. "error": "run Join error: invalid operation int64(1541152487632) = string(1541152488442)",
  1342. }}, {{
  1343. "error": "run Join error: invalid operation int64(1541152488442) = string(1541152488442)",
  1344. }}, {{
  1345. "error": "run Join error: invalid operation int64(1541152488442) = string(1541152488442)",
  1346. }},
  1347. },
  1348. M: map[string]interface{}{
  1349. "op_1_preprocessor_ldemo_0_exceptions_total": int64(0),
  1350. "op_1_preprocessor_ldemo_0_process_latency_us": int64(0),
  1351. "op_1_preprocessor_ldemo_0_records_in_total": int64(5),
  1352. "op_1_preprocessor_ldemo_0_records_out_total": int64(5),
  1353. "op_2_preprocessor_ldemo1_0_exceptions_total": int64(0),
  1354. "op_2_preprocessor_ldemo1_0_process_latency_us": int64(0),
  1355. "op_2_preprocessor_ldemo1_0_records_in_total": int64(5),
  1356. "op_2_preprocessor_ldemo1_0_records_out_total": int64(5),
  1357. "op_5_project_0_exceptions_total": int64(3),
  1358. "op_5_project_0_process_latency_us": int64(0),
  1359. "op_5_project_0_records_in_total": int64(8),
  1360. "op_5_project_0_records_out_total": int64(5),
  1361. "sink_mockSink_0_exceptions_total": int64(0),
  1362. "sink_mockSink_0_records_in_total": int64(8),
  1363. "sink_mockSink_0_records_out_total": int64(8),
  1364. "source_ldemo_0_exceptions_total": int64(0),
  1365. "source_ldemo_0_records_in_total": int64(5),
  1366. "source_ldemo_0_records_out_total": int64(5),
  1367. "source_ldemo1_0_exceptions_total": int64(0),
  1368. "source_ldemo1_0_records_in_total": int64(5),
  1369. "source_ldemo1_0_records_out_total": int64(5),
  1370. "op_3_window_0_exceptions_total": int64(0),
  1371. "op_3_window_0_process_latency_us": int64(0),
  1372. "op_3_window_0_records_in_total": int64(10),
  1373. "op_3_window_0_records_out_total": int64(10),
  1374. "op_4_join_0_exceptions_total": int64(3),
  1375. "op_4_join_0_process_latency_us": int64(0),
  1376. "op_4_join_0_records_in_total": int64(10),
  1377. "op_4_join_0_records_out_total": int64(5),
  1378. },
  1379. }, {
  1380. Name: `TestWindowErrorRule4`,
  1381. Sql: `SELECT color FROM ldemo GROUP BY SlidingWindow(ss, 2), color having collect(size)[0] >= 2 order by color`,
  1382. R: [][]map[string]interface{}{
  1383. {{
  1384. "color": "red",
  1385. }}, {{
  1386. "error": "run Having error: invalid operation string(string) >= int64(2)",
  1387. }}, {{
  1388. "error": "run Having error: invalid operation string(string) >= int64(2)",
  1389. }}, {{
  1390. "error": "run Having error: invalid operation string(string) >= int64(2)",
  1391. }}, {{
  1392. "color": float64(49),
  1393. }, {}},
  1394. },
  1395. M: map[string]interface{}{
  1396. "op_1_preprocessor_ldemo_0_exceptions_total": int64(0),
  1397. "op_1_preprocessor_ldemo_0_process_latency_us": int64(0),
  1398. "op_1_preprocessor_ldemo_0_records_in_total": int64(5),
  1399. "op_1_preprocessor_ldemo_0_records_out_total": int64(5),
  1400. "op_6_project_0_exceptions_total": int64(3),
  1401. "op_6_project_0_process_latency_us": int64(0),
  1402. "op_6_project_0_records_in_total": int64(5),
  1403. "op_6_project_0_records_out_total": int64(2),
  1404. "sink_mockSink_0_exceptions_total": int64(0),
  1405. "sink_mockSink_0_records_in_total": int64(5),
  1406. "sink_mockSink_0_records_out_total": int64(5),
  1407. "source_ldemo_0_exceptions_total": int64(0),
  1408. "source_ldemo_0_records_in_total": int64(5),
  1409. "source_ldemo_0_records_out_total": int64(5),
  1410. "op_2_window_0_exceptions_total": int64(0),
  1411. "op_2_window_0_process_latency_us": int64(0),
  1412. "op_2_window_0_records_in_total": int64(5),
  1413. "op_2_window_0_records_out_total": int64(5),
  1414. "op_3_aggregate_0_exceptions_total": int64(0),
  1415. "op_3_aggregate_0_process_latency_us": int64(0),
  1416. "op_3_aggregate_0_records_in_total": int64(5),
  1417. "op_3_aggregate_0_records_out_total": int64(5),
  1418. "op_4_having_0_exceptions_total": int64(3),
  1419. "op_4_having_0_process_latency_us": int64(0),
  1420. "op_4_having_0_records_in_total": int64(5),
  1421. "op_4_having_0_records_out_total": int64(2),
  1422. },
  1423. }, {
  1424. Name: `TestWindowErrorRule5`,
  1425. Sql: `SELECT color, size FROM ldemo GROUP BY tumblingwindow(ss, 1) ORDER BY size`,
  1426. R: [][]map[string]interface{}{
  1427. {{
  1428. "error": "run Order By error: incompatible types for comparison: int and string",
  1429. }}, {{
  1430. "size": float64(3),
  1431. }}, {{
  1432. "color": float64(49),
  1433. "size": float64(2),
  1434. }}, {{
  1435. "color": "red",
  1436. }},
  1437. },
  1438. M: map[string]interface{}{
  1439. "op_1_preprocessor_ldemo_0_exceptions_total": int64(0),
  1440. "op_1_preprocessor_ldemo_0_process_latency_us": int64(0),
  1441. "op_1_preprocessor_ldemo_0_records_in_total": int64(5),
  1442. "op_1_preprocessor_ldemo_0_records_out_total": int64(5),
  1443. "op_4_project_0_exceptions_total": int64(1),
  1444. "op_4_project_0_process_latency_us": int64(0),
  1445. "op_4_project_0_records_in_total": int64(4),
  1446. "op_4_project_0_records_out_total": int64(3),
  1447. "sink_mockSink_0_exceptions_total": int64(0),
  1448. "sink_mockSink_0_records_in_total": int64(4),
  1449. "sink_mockSink_0_records_out_total": int64(4),
  1450. "source_ldemo_0_exceptions_total": int64(0),
  1451. "source_ldemo_0_records_in_total": int64(5),
  1452. "source_ldemo_0_records_out_total": int64(5),
  1453. "op_2_window_0_exceptions_total": int64(0),
  1454. "op_2_window_0_process_latency_us": int64(0),
  1455. "op_2_window_0_records_in_total": int64(5),
  1456. "op_2_window_0_records_out_total": int64(4),
  1457. "op_3_order_0_exceptions_total": int64(1),
  1458. "op_3_order_0_process_latency_us": int64(0),
  1459. "op_3_order_0_records_in_total": int64(4),
  1460. "op_3_order_0_records_out_total": int64(3),
  1461. },
  1462. },
  1463. }
  1464. HandleStream(true, streamList, t)
  1465. DoRuleTest(t, tests, 0, &api.RuleOption{
  1466. BufferLength: 100,
  1467. SendError: true,
  1468. }, 0)
  1469. }