window_rule_test.go 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  1. package processors
  2. import (
  3. "github.com/emqx/kuiper/xstream"
  4. "github.com/emqx/kuiper/xstream/api"
  5. "testing"
  6. )
  7. func TestWindow(t *testing.T) {
  8. //Reset
  9. streamList := []string{"demo", "demoError", "demo1", "sessionDemo"}
  10. handleStream(false, streamList, t)
  11. var tests = []ruleTest{
  12. {
  13. name: `TestWindowRule1`,
  14. sql: `SELECT * FROM demo GROUP BY HOPPINGWINDOW(ss, 2, 1)`,
  15. r: [][]map[string]interface{}{
  16. {{
  17. "color": "red",
  18. "size": float64(3),
  19. "ts": float64(1541152486013),
  20. }, {
  21. "color": "blue",
  22. "size": float64(6),
  23. "ts": float64(1541152486822),
  24. }},
  25. {{
  26. "color": "red",
  27. "size": float64(3),
  28. "ts": float64(1541152486013),
  29. }, {
  30. "color": "blue",
  31. "size": float64(6),
  32. "ts": float64(1541152486822),
  33. }, {
  34. "color": "blue",
  35. "size": float64(2),
  36. "ts": float64(1541152487632),
  37. }},
  38. {{
  39. "color": "blue",
  40. "size": float64(2),
  41. "ts": float64(1541152487632),
  42. }, {
  43. "color": "yellow",
  44. "size": float64(4),
  45. "ts": float64(1541152488442),
  46. }},
  47. {{
  48. "color": "yellow",
  49. "size": float64(4),
  50. "ts": float64(1541152488442),
  51. }, {
  52. "color": "red",
  53. "size": float64(1),
  54. "ts": float64(1541152489252),
  55. }},
  56. },
  57. m: map[string]interface{}{
  58. "op_preprocessor_demo_0_exceptions_total": int64(0),
  59. "op_preprocessor_demo_0_process_latency_ms": int64(0),
  60. "op_preprocessor_demo_0_records_in_total": int64(5),
  61. "op_preprocessor_demo_0_records_out_total": int64(5),
  62. "op_project_0_exceptions_total": int64(0),
  63. "op_project_0_process_latency_ms": int64(0),
  64. "op_project_0_records_in_total": int64(4),
  65. "op_project_0_records_out_total": int64(4),
  66. "sink_mockSink_0_exceptions_total": int64(0),
  67. "sink_mockSink_0_records_in_total": int64(4),
  68. "sink_mockSink_0_records_out_total": int64(4),
  69. "source_demo_0_exceptions_total": int64(0),
  70. "source_demo_0_records_in_total": int64(5),
  71. "source_demo_0_records_out_total": int64(5),
  72. "op_window_0_exceptions_total": int64(0),
  73. "op_window_0_process_latency_ms": int64(0),
  74. "op_window_0_records_in_total": int64(5),
  75. "op_window_0_records_out_total": int64(4),
  76. },
  77. }, {
  78. name: `TestWindowRule2`,
  79. sql: `SELECT color, ts FROM demo where size > 2 GROUP BY tumblingwindow(ss, 1)`,
  80. r: [][]map[string]interface{}{
  81. {{
  82. "color": "red",
  83. "ts": float64(1541152486013),
  84. }, {
  85. "color": "blue",
  86. "ts": float64(1541152486822),
  87. }},
  88. {{
  89. "color": "yellow",
  90. "ts": float64(1541152488442),
  91. }},
  92. },
  93. m: map[string]interface{}{
  94. "op_preprocessor_demo_0_exceptions_total": int64(0),
  95. "op_preprocessor_demo_0_process_latency_ms": int64(0),
  96. "op_preprocessor_demo_0_records_in_total": int64(5),
  97. "op_preprocessor_demo_0_records_out_total": int64(5),
  98. "op_project_0_exceptions_total": int64(0),
  99. "op_project_0_process_latency_ms": int64(0),
  100. "op_project_0_records_in_total": int64(2),
  101. "op_project_0_records_out_total": int64(2),
  102. "sink_mockSink_0_exceptions_total": int64(0),
  103. "sink_mockSink_0_records_in_total": int64(2),
  104. "sink_mockSink_0_records_out_total": int64(2),
  105. "source_demo_0_exceptions_total": int64(0),
  106. "source_demo_0_records_in_total": int64(5),
  107. "source_demo_0_records_out_total": int64(5),
  108. "op_window_0_exceptions_total": int64(0),
  109. "op_window_0_process_latency_ms": int64(0),
  110. "op_window_0_records_in_total": int64(5),
  111. "op_window_0_records_out_total": int64(4),
  112. "op_filter_0_exceptions_total": int64(0),
  113. "op_filter_0_process_latency_ms": int64(0),
  114. "op_filter_0_records_in_total": int64(4),
  115. "op_filter_0_records_out_total": int64(2),
  116. },
  117. }, {
  118. name: `TestWindowRule3`,
  119. sql: `SELECT color, temp, ts FROM demo INNER JOIN demo1 ON demo.ts = demo1.ts GROUP BY SlidingWindow(ss, 1)`,
  120. r: [][]map[string]interface{}{
  121. {{
  122. "color": "red",
  123. "temp": 25.5,
  124. "ts": float64(1541152486013),
  125. }}, {{
  126. "color": "red",
  127. "temp": 25.5,
  128. "ts": float64(1541152486013),
  129. }}, {{
  130. "color": "red",
  131. "temp": 25.5,
  132. "ts": float64(1541152486013),
  133. }}, {{
  134. "color": "blue",
  135. "temp": 28.1,
  136. "ts": float64(1541152487632),
  137. }}, {{
  138. "color": "blue",
  139. "temp": 28.1,
  140. "ts": float64(1541152487632),
  141. }}, {{
  142. "color": "blue",
  143. "temp": 28.1,
  144. "ts": float64(1541152487632),
  145. }, {
  146. "color": "yellow",
  147. "temp": 27.4,
  148. "ts": float64(1541152488442),
  149. }}, {{
  150. "color": "yellow",
  151. "temp": 27.4,
  152. "ts": float64(1541152488442),
  153. }}, {{
  154. "color": "yellow",
  155. "temp": 27.4,
  156. "ts": float64(1541152488442),
  157. }, {
  158. "color": "red",
  159. "temp": 25.5,
  160. "ts": float64(1541152489252),
  161. }},
  162. },
  163. m: map[string]interface{}{
  164. "op_preprocessor_demo_0_exceptions_total": int64(0),
  165. "op_preprocessor_demo_0_process_latency_ms": int64(0),
  166. "op_preprocessor_demo_0_records_in_total": int64(5),
  167. "op_preprocessor_demo_0_records_out_total": int64(5),
  168. "op_preprocessor_demo1_0_exceptions_total": int64(0),
  169. "op_preprocessor_demo1_0_process_latency_ms": int64(0),
  170. "op_preprocessor_demo1_0_records_in_total": int64(5),
  171. "op_preprocessor_demo1_0_records_out_total": int64(5),
  172. "op_project_0_exceptions_total": int64(0),
  173. "op_project_0_process_latency_ms": int64(0),
  174. "op_project_0_records_in_total": int64(8),
  175. "op_project_0_records_out_total": int64(8),
  176. "sink_mockSink_0_exceptions_total": int64(0),
  177. "sink_mockSink_0_records_in_total": int64(8),
  178. "sink_mockSink_0_records_out_total": int64(8),
  179. "source_demo_0_exceptions_total": int64(0),
  180. "source_demo_0_records_in_total": int64(5),
  181. "source_demo_0_records_out_total": int64(5),
  182. "source_demo1_0_exceptions_total": int64(0),
  183. "source_demo1_0_records_in_total": int64(5),
  184. "source_demo1_0_records_out_total": int64(5),
  185. "op_window_0_exceptions_total": int64(0),
  186. "op_window_0_process_latency_ms": int64(0),
  187. "op_window_0_records_in_total": int64(10),
  188. "op_window_0_records_out_total": int64(10),
  189. "op_join_0_exceptions_total": int64(0),
  190. "op_join_0_process_latency_ms": int64(0),
  191. "op_join_0_records_in_total": int64(10),
  192. "op_join_0_records_out_total": int64(8),
  193. },
  194. t: &xstream.PrintableTopo{
  195. Sources: []string{"source_demo", "source_demo1"},
  196. Edges: map[string][]string{
  197. "source_demo": {"op_preprocessor_demo"},
  198. "source_demo1": {"op_preprocessor_demo1"},
  199. "op_preprocessor_demo": {"op_window"},
  200. "op_preprocessor_demo1": {"op_window"},
  201. "op_window": {"op_join"},
  202. "op_join": {"op_project"},
  203. "op_project": {"sink_mockSink"},
  204. },
  205. },
  206. }, {
  207. name: `TestWindowRule4`,
  208. sql: `SELECT color FROM demo GROUP BY SlidingWindow(ss, 2), color ORDER BY color`,
  209. r: [][]map[string]interface{}{
  210. {{
  211. "color": "red",
  212. }}, {{
  213. "color": "blue",
  214. }, {
  215. "color": "red",
  216. }}, {{
  217. "color": "blue",
  218. }, {
  219. "color": "red",
  220. }}, {{
  221. "color": "blue",
  222. }, {
  223. "color": "yellow",
  224. }}, {{
  225. "color": "blue",
  226. }, {
  227. "color": "red",
  228. }, {
  229. "color": "yellow",
  230. }},
  231. },
  232. m: map[string]interface{}{
  233. "op_preprocessor_demo_0_exceptions_total": int64(0),
  234. "op_preprocessor_demo_0_process_latency_ms": int64(0),
  235. "op_preprocessor_demo_0_records_in_total": int64(5),
  236. "op_preprocessor_demo_0_records_out_total": int64(5),
  237. "op_project_0_exceptions_total": int64(0),
  238. "op_project_0_process_latency_ms": int64(0),
  239. "op_project_0_records_in_total": int64(5),
  240. "op_project_0_records_out_total": int64(5),
  241. "sink_mockSink_0_exceptions_total": int64(0),
  242. "sink_mockSink_0_records_in_total": int64(5),
  243. "sink_mockSink_0_records_out_total": int64(5),
  244. "source_demo_0_exceptions_total": int64(0),
  245. "source_demo_0_records_in_total": int64(5),
  246. "source_demo_0_records_out_total": int64(5),
  247. "op_window_0_exceptions_total": int64(0),
  248. "op_window_0_process_latency_ms": int64(0),
  249. "op_window_0_records_in_total": int64(5),
  250. "op_window_0_records_out_total": int64(5),
  251. "op_aggregate_0_exceptions_total": int64(0),
  252. "op_aggregate_0_process_latency_ms": int64(0),
  253. "op_aggregate_0_records_in_total": int64(5),
  254. "op_aggregate_0_records_out_total": int64(5),
  255. "op_order_0_exceptions_total": int64(0),
  256. "op_order_0_process_latency_ms": int64(0),
  257. "op_order_0_records_in_total": int64(5),
  258. "op_order_0_records_out_total": int64(5),
  259. },
  260. }, {
  261. name: `TestWindowRule5`,
  262. sql: `SELECT temp FROM sessionDemo GROUP BY SessionWindow(ss, 2, 1) `,
  263. r: [][]map[string]interface{}{
  264. {{
  265. "temp": 25.5,
  266. }, {
  267. "temp": 27.5,
  268. }}, {{
  269. "temp": 28.1,
  270. }, {
  271. "temp": 27.4,
  272. }, {
  273. "temp": 25.5,
  274. }}, {{
  275. "temp": 26.2,
  276. }, {
  277. "temp": 26.8,
  278. }, {
  279. "temp": 28.9,
  280. }, {
  281. "temp": 29.1,
  282. }, {
  283. "temp": 32.2,
  284. }}, {{
  285. "temp": 30.9,
  286. }},
  287. },
  288. m: map[string]interface{}{
  289. "op_preprocessor_sessionDemo_0_exceptions_total": int64(0),
  290. "op_preprocessor_sessionDemo_0_process_latency_ms": int64(0),
  291. "op_preprocessor_sessionDemo_0_records_in_total": int64(11),
  292. "op_preprocessor_sessionDemo_0_records_out_total": int64(11),
  293. "op_project_0_exceptions_total": int64(0),
  294. "op_project_0_process_latency_ms": int64(0),
  295. "op_project_0_records_in_total": int64(4),
  296. "op_project_0_records_out_total": int64(4),
  297. "sink_mockSink_0_exceptions_total": int64(0),
  298. "sink_mockSink_0_records_in_total": int64(4),
  299. "sink_mockSink_0_records_out_total": int64(4),
  300. "source_sessionDemo_0_exceptions_total": int64(0),
  301. "source_sessionDemo_0_records_in_total": int64(11),
  302. "source_sessionDemo_0_records_out_total": int64(11),
  303. "op_window_0_exceptions_total": int64(0),
  304. "op_window_0_process_latency_ms": int64(0),
  305. "op_window_0_records_in_total": int64(11),
  306. "op_window_0_records_out_total": int64(4),
  307. },
  308. }, {
  309. name: `TestWindowRule6`,
  310. sql: `SELECT max(temp) as m, count(color) as c FROM demo INNER JOIN demo1 ON demo.ts = demo1.ts GROUP BY SlidingWindow(ss, 1)`,
  311. r: [][]map[string]interface{}{
  312. {{
  313. "m": 25.5,
  314. "c": float64(1),
  315. }}, {{
  316. "m": 25.5,
  317. "c": float64(1),
  318. }}, {{
  319. "m": 25.5,
  320. "c": float64(1),
  321. }}, {{
  322. "m": 28.1,
  323. "c": float64(1),
  324. }}, {{
  325. "m": 28.1,
  326. "c": float64(1),
  327. }}, {{
  328. "m": 28.1,
  329. "c": float64(2),
  330. }}, {{
  331. "m": 27.4,
  332. "c": float64(1),
  333. }}, {{
  334. "m": 27.4,
  335. "c": float64(2),
  336. }},
  337. },
  338. m: map[string]interface{}{
  339. "op_preprocessor_demo_0_exceptions_total": int64(0),
  340. "op_preprocessor_demo_0_process_latency_ms": int64(0),
  341. "op_preprocessor_demo_0_records_in_total": int64(5),
  342. "op_preprocessor_demo_0_records_out_total": int64(5),
  343. "op_preprocessor_demo1_0_exceptions_total": int64(0),
  344. "op_preprocessor_demo1_0_process_latency_ms": int64(0),
  345. "op_preprocessor_demo1_0_records_in_total": int64(5),
  346. "op_preprocessor_demo1_0_records_out_total": int64(5),
  347. "op_project_0_exceptions_total": int64(0),
  348. "op_project_0_process_latency_ms": int64(0),
  349. "op_project_0_records_in_total": int64(8),
  350. "op_project_0_records_out_total": int64(8),
  351. "sink_mockSink_0_exceptions_total": int64(0),
  352. "sink_mockSink_0_records_in_total": int64(8),
  353. "sink_mockSink_0_records_out_total": int64(8),
  354. "source_demo_0_exceptions_total": int64(0),
  355. "source_demo_0_records_in_total": int64(5),
  356. "source_demo_0_records_out_total": int64(5),
  357. "source_demo1_0_exceptions_total": int64(0),
  358. "source_demo1_0_records_in_total": int64(5),
  359. "source_demo1_0_records_out_total": int64(5),
  360. "op_window_0_exceptions_total": int64(0),
  361. "op_window_0_process_latency_ms": int64(0),
  362. "op_window_0_records_in_total": int64(10),
  363. "op_window_0_records_out_total": int64(10),
  364. "op_join_0_exceptions_total": int64(0),
  365. "op_join_0_process_latency_ms": int64(0),
  366. "op_join_0_records_in_total": int64(10),
  367. "op_join_0_records_out_total": int64(8),
  368. },
  369. }, {
  370. name: `TestWindowRule7`,
  371. sql: `SELECT * FROM demoError GROUP BY HOPPINGWINDOW(ss, 2, 1)`,
  372. r: [][]map[string]interface{}{
  373. {{
  374. "error": "error in preprocessor: invalid data type for color, expect string but found int(3)",
  375. }},
  376. {{
  377. "color": "blue",
  378. "size": float64(6),
  379. "ts": float64(1541152486822),
  380. }},
  381. {{
  382. "color": "blue",
  383. "size": float64(6),
  384. "ts": float64(1541152486822),
  385. }, {
  386. "color": "blue",
  387. "size": float64(2),
  388. "ts": float64(1541152487632),
  389. }},
  390. {{
  391. "error": "error in preprocessor: invalid data type for color, expect string but found int(7)",
  392. }},
  393. {{
  394. "color": "blue",
  395. "size": float64(2),
  396. "ts": float64(1541152487632),
  397. }},
  398. {{
  399. "error": "error in preprocessor: invalid data type for size, expect bigint but found string(blue)",
  400. }},
  401. },
  402. m: map[string]interface{}{
  403. "op_preprocessor_demoError_0_exceptions_total": int64(3),
  404. "op_preprocessor_demoError_0_process_latency_ms": int64(0),
  405. "op_preprocessor_demoError_0_records_in_total": int64(5),
  406. "op_preprocessor_demoError_0_records_out_total": int64(2),
  407. "op_project_0_exceptions_total": int64(3),
  408. "op_project_0_process_latency_ms": int64(0),
  409. "op_project_0_records_in_total": int64(6),
  410. "op_project_0_records_out_total": int64(3),
  411. "sink_mockSink_0_exceptions_total": int64(0),
  412. "sink_mockSink_0_records_in_total": int64(6),
  413. "sink_mockSink_0_records_out_total": int64(6),
  414. "source_demoError_0_exceptions_total": int64(0),
  415. "source_demoError_0_records_in_total": int64(5),
  416. "source_demoError_0_records_out_total": int64(5),
  417. "op_window_0_exceptions_total": int64(3),
  418. "op_window_0_process_latency_ms": int64(0),
  419. "op_window_0_records_in_total": int64(5),
  420. "op_window_0_records_out_total": int64(3),
  421. },
  422. }, {
  423. name: `TestWindowRule8`,
  424. sql: `SELECT color, ts, count(*) as c FROM demo where size > 2 GROUP BY tumblingwindow(ss, 1) having c > 1`,
  425. r: [][]map[string]interface{}{
  426. {{
  427. "color": "red",
  428. "ts": float64(1541152486013),
  429. "c": float64(2),
  430. }},
  431. },
  432. m: map[string]interface{}{
  433. "op_preprocessor_demo_0_exceptions_total": int64(0),
  434. "op_preprocessor_demo_0_process_latency_ms": int64(0),
  435. "op_preprocessor_demo_0_records_in_total": int64(5),
  436. "op_preprocessor_demo_0_records_out_total": int64(5),
  437. "op_project_0_exceptions_total": int64(0),
  438. "op_project_0_process_latency_ms": int64(0),
  439. "op_project_0_records_in_total": int64(1),
  440. "op_project_0_records_out_total": int64(1),
  441. "sink_mockSink_0_exceptions_total": int64(0),
  442. "sink_mockSink_0_records_in_total": int64(1),
  443. "sink_mockSink_0_records_out_total": int64(1),
  444. "source_demo_0_exceptions_total": int64(0),
  445. "source_demo_0_records_in_total": int64(5),
  446. "source_demo_0_records_out_total": int64(5),
  447. "op_window_0_exceptions_total": int64(0),
  448. "op_window_0_process_latency_ms": int64(0),
  449. "op_window_0_records_in_total": int64(5),
  450. "op_window_0_records_out_total": int64(4),
  451. "op_filter_0_exceptions_total": int64(0),
  452. "op_filter_0_process_latency_ms": int64(0),
  453. "op_filter_0_records_in_total": int64(4),
  454. "op_filter_0_records_out_total": int64(2),
  455. "op_aggregate_0_exceptions_total": int64(0),
  456. "op_aggregate_0_process_latency_ms": int64(0),
  457. "op_aggregate_0_records_in_total": int64(2),
  458. "op_aggregate_0_records_out_total": int64(2),
  459. "op_having_0_exceptions_total": int64(0),
  460. "op_having_0_process_latency_ms": int64(0),
  461. "op_having_0_records_in_total": int64(2),
  462. "op_having_0_records_out_total": int64(1),
  463. },
  464. }, {
  465. name: `TestWindowRule9`,
  466. sql: `SELECT * FROM demo GROUP BY HOPPINGWINDOW(ss, 2, 1) FILTER( WHERE size > 2)`,
  467. r: [][]map[string]interface{}{
  468. {{
  469. "color": "red",
  470. "size": float64(3),
  471. "ts": float64(1541152486013),
  472. }, {
  473. "color": "blue",
  474. "size": float64(6),
  475. "ts": float64(1541152486822),
  476. }},
  477. {{
  478. "color": "red",
  479. "size": float64(3),
  480. "ts": float64(1541152486013),
  481. }, {
  482. "color": "blue",
  483. "size": float64(6),
  484. "ts": float64(1541152486822),
  485. }},
  486. {{
  487. "color": "yellow",
  488. "size": float64(4),
  489. "ts": float64(1541152488442),
  490. }},
  491. {{
  492. "color": "yellow",
  493. "size": float64(4),
  494. "ts": float64(1541152488442),
  495. }},
  496. },
  497. m: map[string]interface{}{
  498. "op_preprocessor_demo_0_exceptions_total": int64(0),
  499. "op_preprocessor_demo_0_process_latency_ms": int64(0),
  500. "op_preprocessor_demo_0_records_in_total": int64(5),
  501. "op_preprocessor_demo_0_records_out_total": int64(5),
  502. "op_project_0_exceptions_total": int64(0),
  503. "op_project_0_process_latency_ms": int64(0),
  504. "op_project_0_records_in_total": int64(4),
  505. "op_project_0_records_out_total": int64(4),
  506. "sink_mockSink_0_exceptions_total": int64(0),
  507. "sink_mockSink_0_records_in_total": int64(4),
  508. "sink_mockSink_0_records_out_total": int64(4),
  509. "source_demo_0_exceptions_total": int64(0),
  510. "source_demo_0_records_in_total": int64(5),
  511. "source_demo_0_records_out_total": int64(5),
  512. "op_window_0_exceptions_total": int64(0),
  513. "op_window_0_process_latency_ms": int64(0),
  514. "op_window_0_records_in_total": int64(3),
  515. "op_window_0_records_out_total": int64(4),
  516. },
  517. }, {
  518. name: `TestCountWindowRule1`,
  519. sql: `SELECT collect(*)[0]->color as c FROM demo GROUP BY COUNTWINDOW(3)`,
  520. r: [][]map[string]interface{}{
  521. {{
  522. "c": "red",
  523. }},
  524. },
  525. m: map[string]interface{}{
  526. "op_preprocessor_demo_0_exceptions_total": int64(0),
  527. "op_preprocessor_demo_0_process_latency_ms": int64(0),
  528. "op_preprocessor_demo_0_records_in_total": int64(5),
  529. "op_preprocessor_demo_0_records_out_total": int64(5),
  530. "op_project_0_exceptions_total": int64(0),
  531. "op_project_0_process_latency_ms": int64(0),
  532. "op_project_0_records_in_total": int64(1),
  533. "op_project_0_records_out_total": int64(1),
  534. "sink_mockSink_0_exceptions_total": int64(0),
  535. "sink_mockSink_0_records_in_total": int64(1),
  536. "sink_mockSink_0_records_out_total": int64(1),
  537. "source_demo_0_exceptions_total": int64(0),
  538. "source_demo_0_records_in_total": int64(5),
  539. "source_demo_0_records_out_total": int64(5),
  540. "op_window_0_exceptions_total": int64(0),
  541. "op_window_0_process_latency_ms": int64(0),
  542. "op_window_0_records_in_total": int64(5),
  543. "op_window_0_records_out_total": int64(1),
  544. },
  545. },
  546. }
  547. handleStream(true, streamList, t)
  548. options := []*api.RuleOption{
  549. {
  550. BufferLength: 100,
  551. }, {
  552. BufferLength: 100,
  553. Qos: api.AtLeastOnce,
  554. CheckpointInterval: 5000,
  555. }, {
  556. BufferLength: 100,
  557. Qos: api.ExactlyOnce,
  558. CheckpointInterval: 5000,
  559. },
  560. }
  561. for j, opt := range options {
  562. doRuleTest(t, tests, j, opt)
  563. }
  564. }
  565. func TestEventWindow(t *testing.T) {
  566. //Reset
  567. streamList := []string{"demoE", "demoErr", "demo1E", "sessionDemoE"}
  568. handleStream(false, streamList, t)
  569. var tests = []ruleTest{
  570. {
  571. name: `TestEventWindowRule1`,
  572. sql: `SELECT * FROM demoE GROUP BY HOPPINGWINDOW(ss, 2, 1)`,
  573. r: [][]map[string]interface{}{
  574. {{
  575. "color": "red",
  576. "size": float64(3),
  577. "ts": float64(1541152486013),
  578. }},
  579. {{
  580. "color": "red",
  581. "size": float64(3),
  582. "ts": float64(1541152486013),
  583. }, {
  584. "color": "blue",
  585. "size": float64(2),
  586. "ts": float64(1541152487632),
  587. }},
  588. {{
  589. "color": "blue",
  590. "size": float64(2),
  591. "ts": float64(1541152487632),
  592. }, {
  593. "color": "yellow",
  594. "size": float64(4),
  595. "ts": float64(1541152488442),
  596. }}, {{
  597. "color": "yellow",
  598. "size": float64(4),
  599. "ts": float64(1541152488442),
  600. }, {
  601. "color": "red",
  602. "size": float64(1),
  603. "ts": float64(1541152489252),
  604. }}, {{
  605. "color": "red",
  606. "size": float64(1),
  607. "ts": float64(1541152489252),
  608. }},
  609. },
  610. m: map[string]interface{}{
  611. "op_preprocessor_demoE_0_exceptions_total": int64(0),
  612. "op_preprocessor_demoE_0_process_latency_ms": int64(0),
  613. "op_preprocessor_demoE_0_records_in_total": int64(6),
  614. "op_preprocessor_demoE_0_records_out_total": int64(6),
  615. "op_project_0_exceptions_total": int64(0),
  616. "op_project_0_process_latency_ms": int64(0),
  617. "op_project_0_records_in_total": int64(5),
  618. "op_project_0_records_out_total": int64(5),
  619. "sink_mockSink_0_exceptions_total": int64(0),
  620. "sink_mockSink_0_records_in_total": int64(5),
  621. "sink_mockSink_0_records_out_total": int64(5),
  622. "source_demoE_0_exceptions_total": int64(0),
  623. "source_demoE_0_records_in_total": int64(6),
  624. "source_demoE_0_records_out_total": int64(6),
  625. "op_window_0_exceptions_total": int64(0),
  626. "op_window_0_process_latency_ms": int64(0),
  627. "op_window_0_records_in_total": int64(6),
  628. "op_window_0_records_out_total": int64(5),
  629. },
  630. }, {
  631. name: `TestEventWindowRule2`,
  632. sql: `SELECT color, ts FROM demoE where size > 2 GROUP BY tumblingwindow(ss, 1)`,
  633. r: [][]map[string]interface{}{
  634. {{
  635. "color": "red",
  636. "ts": float64(1541152486013),
  637. }},
  638. {{
  639. "color": "yellow",
  640. "ts": float64(1541152488442),
  641. }},
  642. },
  643. m: map[string]interface{}{
  644. "op_preprocessor_demoE_0_exceptions_total": int64(0),
  645. "op_preprocessor_demoE_0_process_latency_ms": int64(0),
  646. "op_preprocessor_demoE_0_records_in_total": int64(6),
  647. "op_preprocessor_demoE_0_records_out_total": int64(6),
  648. "op_project_0_exceptions_total": int64(0),
  649. "op_project_0_process_latency_ms": int64(0),
  650. "op_project_0_records_in_total": int64(2),
  651. "op_project_0_records_out_total": int64(2),
  652. "sink_mockSink_0_exceptions_total": int64(0),
  653. "sink_mockSink_0_records_in_total": int64(2),
  654. "sink_mockSink_0_records_out_total": int64(2),
  655. "source_demoE_0_exceptions_total": int64(0),
  656. "source_demoE_0_records_in_total": int64(6),
  657. "source_demoE_0_records_out_total": int64(6),
  658. "op_window_0_exceptions_total": int64(0),
  659. "op_window_0_process_latency_ms": int64(0),
  660. "op_window_0_records_in_total": int64(6),
  661. "op_window_0_records_out_total": int64(4),
  662. "op_filter_0_exceptions_total": int64(0),
  663. "op_filter_0_process_latency_ms": int64(0),
  664. "op_filter_0_records_in_total": int64(4),
  665. "op_filter_0_records_out_total": int64(2),
  666. },
  667. }, {
  668. name: `TestEventWindowRule3`,
  669. sql: `SELECT color, temp, ts FROM demoE INNER JOIN demo1E ON demoE.ts = demo1E.ts GROUP BY SlidingWindow(ss, 1)`,
  670. r: [][]map[string]interface{}{
  671. {{
  672. "color": "red",
  673. "temp": 25.5,
  674. "ts": float64(1541152486013),
  675. }}, {{
  676. "color": "red",
  677. "temp": 25.5,
  678. "ts": float64(1541152486013),
  679. }}, {{
  680. "color": "blue",
  681. "temp": 28.1,
  682. "ts": float64(1541152487632),
  683. }}, {{
  684. "color": "blue",
  685. "temp": 28.1,
  686. "ts": float64(1541152487632),
  687. }, {
  688. "color": "yellow",
  689. "temp": 27.4,
  690. "ts": float64(1541152488442),
  691. }}, {{
  692. "color": "yellow",
  693. "temp": 27.4,
  694. "ts": float64(1541152488442),
  695. }, {
  696. "color": "red",
  697. "temp": 25.5,
  698. "ts": float64(1541152489252),
  699. }},
  700. },
  701. m: map[string]interface{}{
  702. "op_preprocessor_demoE_0_exceptions_total": int64(0),
  703. "op_preprocessor_demoE_0_process_latency_ms": int64(0),
  704. "op_preprocessor_demoE_0_records_in_total": int64(6),
  705. "op_preprocessor_demoE_0_records_out_total": int64(6),
  706. "op_preprocessor_demo1E_0_exceptions_total": int64(0),
  707. "op_preprocessor_demo1E_0_process_latency_ms": int64(0),
  708. "op_preprocessor_demo1E_0_records_in_total": int64(6),
  709. "op_preprocessor_demo1E_0_records_out_total": int64(6),
  710. "op_project_0_exceptions_total": int64(0),
  711. "op_project_0_process_latency_ms": int64(0),
  712. "op_project_0_records_in_total": int64(5),
  713. "op_project_0_records_out_total": int64(5),
  714. "sink_mockSink_0_exceptions_total": int64(0),
  715. "sink_mockSink_0_records_in_total": int64(5),
  716. "sink_mockSink_0_records_out_total": int64(5),
  717. "source_demoE_0_exceptions_total": int64(0),
  718. "source_demoE_0_records_in_total": int64(6),
  719. "source_demoE_0_records_out_total": int64(6),
  720. "source_demo1E_0_exceptions_total": int64(0),
  721. "source_demo1E_0_records_in_total": int64(6),
  722. "source_demo1E_0_records_out_total": int64(6),
  723. "op_window_0_exceptions_total": int64(0),
  724. "op_window_0_process_latency_ms": int64(0),
  725. "op_window_0_records_in_total": int64(12),
  726. "op_window_0_records_out_total": int64(5),
  727. "op_join_0_exceptions_total": int64(0),
  728. "op_join_0_process_latency_ms": int64(0),
  729. "op_join_0_records_in_total": int64(5),
  730. "op_join_0_records_out_total": int64(5),
  731. },
  732. }, {
  733. name: `TestEventWindowRule4`,
  734. sql: `SELECT color FROM demoE GROUP BY SlidingWindow(ss, 2), color ORDER BY color`,
  735. r: [][]map[string]interface{}{
  736. {{
  737. "color": "red",
  738. }}, {{
  739. "color": "blue",
  740. }, {
  741. "color": "red",
  742. }}, {{
  743. "color": "blue",
  744. }, {
  745. "color": "yellow",
  746. }}, {{
  747. "color": "blue",
  748. }, {
  749. "color": "red",
  750. }, {
  751. "color": "yellow",
  752. }},
  753. },
  754. m: map[string]interface{}{
  755. "op_preprocessor_demoE_0_exceptions_total": int64(0),
  756. "op_preprocessor_demoE_0_process_latency_ms": int64(0),
  757. "op_preprocessor_demoE_0_records_in_total": int64(6),
  758. "op_preprocessor_demoE_0_records_out_total": int64(6),
  759. "op_project_0_exceptions_total": int64(0),
  760. "op_project_0_process_latency_ms": int64(0),
  761. "op_project_0_records_in_total": int64(4),
  762. "op_project_0_records_out_total": int64(4),
  763. "sink_mockSink_0_exceptions_total": int64(0),
  764. "sink_mockSink_0_records_in_total": int64(4),
  765. "sink_mockSink_0_records_out_total": int64(4),
  766. "source_demoE_0_exceptions_total": int64(0),
  767. "source_demoE_0_records_in_total": int64(6),
  768. "source_demoE_0_records_out_total": int64(6),
  769. "op_window_0_exceptions_total": int64(0),
  770. "op_window_0_process_latency_ms": int64(0),
  771. "op_window_0_records_in_total": int64(6),
  772. "op_window_0_records_out_total": int64(4),
  773. "op_aggregate_0_exceptions_total": int64(0),
  774. "op_aggregate_0_process_latency_ms": int64(0),
  775. "op_aggregate_0_records_in_total": int64(4),
  776. "op_aggregate_0_records_out_total": int64(4),
  777. "op_order_0_exceptions_total": int64(0),
  778. "op_order_0_process_latency_ms": int64(0),
  779. "op_order_0_records_in_total": int64(4),
  780. "op_order_0_records_out_total": int64(4),
  781. },
  782. }, {
  783. name: `TestEventWindowRule5`,
  784. sql: `SELECT temp FROM sessionDemoE GROUP BY SessionWindow(ss, 2, 1) `,
  785. r: [][]map[string]interface{}{
  786. {{
  787. "temp": 25.5,
  788. }}, {{
  789. "temp": 28.1,
  790. }, {
  791. "temp": 27.4,
  792. }, {
  793. "temp": 25.5,
  794. }}, {{
  795. "temp": 26.2,
  796. }, {
  797. "temp": 26.8,
  798. }, {
  799. "temp": 28.9,
  800. }, {
  801. "temp": 29.1,
  802. }, {
  803. "temp": 32.2,
  804. }}, {{
  805. "temp": 30.9,
  806. }},
  807. },
  808. m: map[string]interface{}{
  809. "op_preprocessor_sessionDemoE_0_exceptions_total": int64(0),
  810. "op_preprocessor_sessionDemoE_0_process_latency_ms": int64(0),
  811. "op_preprocessor_sessionDemoE_0_records_in_total": int64(12),
  812. "op_preprocessor_sessionDemoE_0_records_out_total": int64(12),
  813. "op_project_0_exceptions_total": int64(0),
  814. "op_project_0_process_latency_ms": int64(0),
  815. "op_project_0_records_in_total": int64(4),
  816. "op_project_0_records_out_total": int64(4),
  817. "sink_mockSink_0_exceptions_total": int64(0),
  818. "sink_mockSink_0_records_in_total": int64(4),
  819. "sink_mockSink_0_records_out_total": int64(4),
  820. "source_sessionDemoE_0_exceptions_total": int64(0),
  821. "source_sessionDemoE_0_records_in_total": int64(12),
  822. "source_sessionDemoE_0_records_out_total": int64(12),
  823. "op_window_0_exceptions_total": int64(0),
  824. "op_window_0_process_latency_ms": int64(0),
  825. "op_window_0_records_in_total": int64(12),
  826. "op_window_0_records_out_total": int64(4),
  827. },
  828. }, {
  829. name: `TestEventWindowRule6`,
  830. 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)`,
  831. r: [][]map[string]interface{}{
  832. {{
  833. "m": 25.5,
  834. "c": float64(1),
  835. }}, {{
  836. "m": 25.5,
  837. "c": float64(1),
  838. }}, {{
  839. "m": 28.1,
  840. "c": float64(1),
  841. }}, {{
  842. "m": 28.1,
  843. "c": float64(2),
  844. }}, {{
  845. "m": 27.4,
  846. "c": float64(2),
  847. }},
  848. },
  849. m: map[string]interface{}{
  850. "op_preprocessor_demoE_0_exceptions_total": int64(0),
  851. "op_preprocessor_demoE_0_process_latency_ms": int64(0),
  852. "op_preprocessor_demoE_0_records_in_total": int64(6),
  853. "op_preprocessor_demoE_0_records_out_total": int64(6),
  854. "op_preprocessor_demo1E_0_exceptions_total": int64(0),
  855. "op_preprocessor_demo1E_0_process_latency_ms": int64(0),
  856. "op_preprocessor_demo1E_0_records_in_total": int64(6),
  857. "op_preprocessor_demo1E_0_records_out_total": int64(6),
  858. "op_project_0_exceptions_total": int64(0),
  859. "op_project_0_process_latency_ms": int64(0),
  860. "op_project_0_records_in_total": int64(5),
  861. "op_project_0_records_out_total": int64(5),
  862. "sink_mockSink_0_exceptions_total": int64(0),
  863. "sink_mockSink_0_records_in_total": int64(5),
  864. "sink_mockSink_0_records_out_total": int64(5),
  865. "source_demoE_0_exceptions_total": int64(0),
  866. "source_demoE_0_records_in_total": int64(6),
  867. "source_demoE_0_records_out_total": int64(6),
  868. "source_demo1E_0_exceptions_total": int64(0),
  869. "source_demo1E_0_records_in_total": int64(6),
  870. "source_demo1E_0_records_out_total": int64(6),
  871. "op_window_0_exceptions_total": int64(0),
  872. "op_window_0_records_in_total": int64(12),
  873. "op_window_0_records_out_total": int64(5),
  874. "op_join_0_exceptions_total": int64(0),
  875. "op_join_0_process_latency_ms": int64(0),
  876. "op_join_0_records_in_total": int64(5),
  877. "op_join_0_records_out_total": int64(5),
  878. },
  879. }, {
  880. name: `TestEventWindowRule7`,
  881. sql: `SELECT * FROM demoErr GROUP BY HOPPINGWINDOW(ss, 2, 1)`,
  882. r: [][]map[string]interface{}{
  883. {{
  884. "error": "error in preprocessor: invalid data type for color, expect string but found int(2)",
  885. }},
  886. {{
  887. "color": "red",
  888. "size": float64(3),
  889. "ts": float64(1541152486013),
  890. }},
  891. {{
  892. "color": "red",
  893. "size": float64(3),
  894. "ts": float64(1541152486013),
  895. }},
  896. {{
  897. "color": "yellow",
  898. "size": float64(4),
  899. "ts": float64(1541152488442),
  900. }}, {{
  901. "color": "yellow",
  902. "size": float64(4),
  903. "ts": float64(1541152488442),
  904. }, {
  905. "color": "red",
  906. "size": float64(1),
  907. "ts": float64(1541152489252),
  908. }}, {{
  909. "color": "red",
  910. "size": float64(1),
  911. "ts": float64(1541152489252),
  912. }},
  913. },
  914. m: map[string]interface{}{
  915. "op_preprocessor_demoErr_0_exceptions_total": int64(1),
  916. "op_preprocessor_demoErr_0_process_latency_ms": int64(0),
  917. "op_preprocessor_demoErr_0_records_in_total": int64(6),
  918. "op_preprocessor_demoErr_0_records_out_total": int64(5),
  919. "op_project_0_exceptions_total": int64(1),
  920. "op_project_0_process_latency_ms": int64(0),
  921. "op_project_0_records_in_total": int64(6),
  922. "op_project_0_records_out_total": int64(5),
  923. "sink_mockSink_0_exceptions_total": int64(0),
  924. "sink_mockSink_0_records_in_total": int64(6),
  925. "sink_mockSink_0_records_out_total": int64(6),
  926. "source_demoErr_0_exceptions_total": int64(0),
  927. "source_demoErr_0_records_in_total": int64(6),
  928. "source_demoErr_0_records_out_total": int64(6),
  929. "op_window_0_exceptions_total": int64(1),
  930. "op_window_0_process_latency_ms": int64(0),
  931. "op_window_0_records_in_total": int64(6),
  932. "op_window_0_records_out_total": int64(5),
  933. },
  934. },
  935. }
  936. handleStream(true, streamList, t)
  937. options := []*api.RuleOption{
  938. {
  939. BufferLength: 100,
  940. IsEventTime: true,
  941. LateTol: 1000,
  942. }, {
  943. BufferLength: 100,
  944. Qos: api.AtLeastOnce,
  945. CheckpointInterval: 5000,
  946. IsEventTime: true,
  947. LateTol: 1000,
  948. }, {
  949. BufferLength: 100,
  950. Qos: api.ExactlyOnce,
  951. CheckpointInterval: 5000,
  952. IsEventTime: true,
  953. LateTol: 1000,
  954. },
  955. }
  956. for j, opt := range options {
  957. doRuleTest(t, tests, j, opt)
  958. }
  959. }
  960. func TestWindowError(t *testing.T) {
  961. //Reset
  962. streamList := []string{"ldemo", "ldemo1"}
  963. handleStream(false, streamList, t)
  964. var tests = []ruleTest{
  965. {
  966. name: `TestWindowErrorRule1`,
  967. sql: `SELECT size * 3 FROM ldemo GROUP BY TUMBLINGWINDOW(ss, 2)`,
  968. r: [][]map[string]interface{}{
  969. {{
  970. "error": "run Select error: invalid operation string(string) * int64(3)",
  971. }}, {{
  972. "rengine_field_0": float64(6),
  973. }, {}},
  974. },
  975. m: map[string]interface{}{
  976. "op_preprocessor_ldemo_0_exceptions_total": int64(0),
  977. "op_preprocessor_ldemo_0_process_latency_ms": int64(0),
  978. "op_preprocessor_ldemo_0_records_in_total": int64(5),
  979. "op_preprocessor_ldemo_0_records_out_total": int64(5),
  980. "op_project_0_exceptions_total": int64(1),
  981. "op_project_0_process_latency_ms": int64(0),
  982. "op_project_0_records_in_total": int64(2),
  983. "op_project_0_records_out_total": int64(1),
  984. "sink_mockSink_0_exceptions_total": int64(0),
  985. "sink_mockSink_0_records_in_total": int64(2),
  986. "sink_mockSink_0_records_out_total": int64(2),
  987. "source_ldemo_0_exceptions_total": int64(0),
  988. "source_ldemo_0_records_in_total": int64(5),
  989. "source_ldemo_0_records_out_total": int64(5),
  990. "op_window_0_exceptions_total": int64(0),
  991. "op_window_0_process_latency_ms": int64(0),
  992. "op_window_0_records_in_total": int64(5),
  993. "op_window_0_records_out_total": int64(2),
  994. },
  995. }, {
  996. name: `TestWindowErrorRule2`,
  997. sql: `SELECT color, ts FROM ldemo where size > 2 GROUP BY tumblingwindow(ss, 1)`,
  998. r: [][]map[string]interface{}{
  999. {{
  1000. "error": "run Where error: invalid operation string(string) > int64(2)",
  1001. }}, {{
  1002. "ts": float64(1541152487632),
  1003. }},
  1004. },
  1005. m: map[string]interface{}{
  1006. "op_preprocessor_ldemo_0_exceptions_total": int64(0),
  1007. "op_preprocessor_ldemo_0_process_latency_ms": int64(0),
  1008. "op_preprocessor_ldemo_0_records_in_total": int64(5),
  1009. "op_preprocessor_ldemo_0_records_out_total": int64(5),
  1010. "op_project_0_exceptions_total": int64(1),
  1011. "op_project_0_process_latency_ms": int64(0),
  1012. "op_project_0_records_in_total": int64(2),
  1013. "op_project_0_records_out_total": int64(1),
  1014. "sink_mockSink_0_exceptions_total": int64(0),
  1015. "sink_mockSink_0_records_in_total": int64(2),
  1016. "sink_mockSink_0_records_out_total": int64(2),
  1017. "source_ldemo_0_exceptions_total": int64(0),
  1018. "source_ldemo_0_records_in_total": int64(5),
  1019. "source_ldemo_0_records_out_total": int64(5),
  1020. "op_window_0_exceptions_total": int64(0),
  1021. "op_window_0_process_latency_ms": int64(0),
  1022. "op_window_0_records_in_total": int64(5),
  1023. "op_window_0_records_out_total": int64(4),
  1024. "op_filter_0_exceptions_total": int64(1),
  1025. "op_filter_0_process_latency_ms": int64(0),
  1026. "op_filter_0_records_in_total": int64(4),
  1027. "op_filter_0_records_out_total": int64(1),
  1028. },
  1029. }, {
  1030. name: `TestWindowErrorRule3`,
  1031. sql: `SELECT color, temp, ts FROM ldemo INNER JOIN ldemo1 ON ldemo.ts = ldemo1.ts GROUP BY SlidingWindow(ss, 1)`,
  1032. r: [][]map[string]interface{}{
  1033. {{
  1034. "color": "red",
  1035. "temp": 25.5,
  1036. "ts": float64(1541152486013),
  1037. }}, {{
  1038. "color": "red",
  1039. "temp": 25.5,
  1040. "ts": float64(1541152486013),
  1041. }}, {{
  1042. "color": "red",
  1043. "temp": 25.5,
  1044. "ts": float64(1541152486013),
  1045. }}, {{
  1046. "temp": 28.1,
  1047. "ts": float64(1541152487632),
  1048. }}, {{
  1049. "temp": 28.1,
  1050. "ts": float64(1541152487632),
  1051. }}, {{
  1052. "error": "run Join error: invalid operation int64(1541152487632) = string(1541152488442)",
  1053. }}, {{
  1054. "error": "run Join error: invalid operation int64(1541152488442) = string(1541152488442)",
  1055. }}, {{
  1056. "error": "run Join error: invalid operation int64(1541152488442) = string(1541152488442)",
  1057. }},
  1058. },
  1059. m: map[string]interface{}{
  1060. "op_preprocessor_ldemo_0_exceptions_total": int64(0),
  1061. "op_preprocessor_ldemo_0_process_latency_ms": int64(0),
  1062. "op_preprocessor_ldemo_0_records_in_total": int64(5),
  1063. "op_preprocessor_ldemo_0_records_out_total": int64(5),
  1064. "op_preprocessor_ldemo1_0_exceptions_total": int64(0),
  1065. "op_preprocessor_ldemo1_0_process_latency_ms": int64(0),
  1066. "op_preprocessor_ldemo1_0_records_in_total": int64(5),
  1067. "op_preprocessor_ldemo1_0_records_out_total": int64(5),
  1068. "op_project_0_exceptions_total": int64(3),
  1069. "op_project_0_process_latency_ms": int64(0),
  1070. "op_project_0_records_in_total": int64(8),
  1071. "op_project_0_records_out_total": int64(5),
  1072. "sink_mockSink_0_exceptions_total": int64(0),
  1073. "sink_mockSink_0_records_in_total": int64(8),
  1074. "sink_mockSink_0_records_out_total": int64(8),
  1075. "source_ldemo_0_exceptions_total": int64(0),
  1076. "source_ldemo_0_records_in_total": int64(5),
  1077. "source_ldemo_0_records_out_total": int64(5),
  1078. "source_ldemo1_0_exceptions_total": int64(0),
  1079. "source_ldemo1_0_records_in_total": int64(5),
  1080. "source_ldemo1_0_records_out_total": int64(5),
  1081. "op_window_0_exceptions_total": int64(0),
  1082. "op_window_0_process_latency_ms": int64(0),
  1083. "op_window_0_records_in_total": int64(10),
  1084. "op_window_0_records_out_total": int64(10),
  1085. "op_join_0_exceptions_total": int64(3),
  1086. "op_join_0_process_latency_ms": int64(0),
  1087. "op_join_0_records_in_total": int64(10),
  1088. "op_join_0_records_out_total": int64(5),
  1089. },
  1090. }, {
  1091. name: `TestWindowErrorRule4`,
  1092. sql: `SELECT color FROM ldemo GROUP BY SlidingWindow(ss, 2), color having size >= 2 order by color`,
  1093. r: [][]map[string]interface{}{
  1094. {{
  1095. "color": "red",
  1096. }}, {{
  1097. "error": "run Having error: invalid operation string(string) >= int64(2)",
  1098. }}, {{
  1099. "error": "run Having error: invalid operation string(string) >= int64(2)",
  1100. }}, {{
  1101. "error": "run Having error: invalid operation string(string) >= int64(2)",
  1102. }}, {{
  1103. "color": float64(49),
  1104. }, {}},
  1105. },
  1106. m: map[string]interface{}{
  1107. "op_preprocessor_ldemo_0_exceptions_total": int64(0),
  1108. "op_preprocessor_ldemo_0_process_latency_ms": int64(0),
  1109. "op_preprocessor_ldemo_0_records_in_total": int64(5),
  1110. "op_preprocessor_ldemo_0_records_out_total": int64(5),
  1111. "op_project_0_exceptions_total": int64(3),
  1112. "op_project_0_process_latency_ms": int64(0),
  1113. "op_project_0_records_in_total": int64(5),
  1114. "op_project_0_records_out_total": int64(2),
  1115. "sink_mockSink_0_exceptions_total": int64(0),
  1116. "sink_mockSink_0_records_in_total": int64(5),
  1117. "sink_mockSink_0_records_out_total": int64(5),
  1118. "source_ldemo_0_exceptions_total": int64(0),
  1119. "source_ldemo_0_records_in_total": int64(5),
  1120. "source_ldemo_0_records_out_total": int64(5),
  1121. "op_window_0_exceptions_total": int64(0),
  1122. "op_window_0_process_latency_ms": int64(0),
  1123. "op_window_0_records_in_total": int64(5),
  1124. "op_window_0_records_out_total": int64(5),
  1125. "op_aggregate_0_exceptions_total": int64(0),
  1126. "op_aggregate_0_process_latency_ms": int64(0),
  1127. "op_aggregate_0_records_in_total": int64(5),
  1128. "op_aggregate_0_records_out_total": int64(5),
  1129. "op_having_0_exceptions_total": int64(3),
  1130. "op_having_0_process_latency_ms": int64(0),
  1131. "op_having_0_records_in_total": int64(5),
  1132. "op_having_0_records_out_total": int64(2),
  1133. },
  1134. }, {
  1135. name: `TestWindowErrorRule5`,
  1136. sql: `SELECT color, size FROM ldemo GROUP BY tumblingwindow(ss, 1) ORDER BY size`,
  1137. r: [][]map[string]interface{}{
  1138. {{
  1139. "error": "run Order By error: incompatible types for comparison: int and string",
  1140. }}, {{
  1141. "size": float64(3),
  1142. }}, {{
  1143. "color": float64(49),
  1144. "size": float64(2),
  1145. }}, {{
  1146. "color": "red",
  1147. }},
  1148. },
  1149. m: map[string]interface{}{
  1150. "op_preprocessor_ldemo_0_exceptions_total": int64(0),
  1151. "op_preprocessor_ldemo_0_process_latency_ms": int64(0),
  1152. "op_preprocessor_ldemo_0_records_in_total": int64(5),
  1153. "op_preprocessor_ldemo_0_records_out_total": int64(5),
  1154. "op_project_0_exceptions_total": int64(1),
  1155. "op_project_0_process_latency_ms": int64(0),
  1156. "op_project_0_records_in_total": int64(4),
  1157. "op_project_0_records_out_total": int64(3),
  1158. "sink_mockSink_0_exceptions_total": int64(0),
  1159. "sink_mockSink_0_records_in_total": int64(4),
  1160. "sink_mockSink_0_records_out_total": int64(4),
  1161. "source_ldemo_0_exceptions_total": int64(0),
  1162. "source_ldemo_0_records_in_total": int64(5),
  1163. "source_ldemo_0_records_out_total": int64(5),
  1164. "op_window_0_exceptions_total": int64(0),
  1165. "op_window_0_process_latency_ms": int64(0),
  1166. "op_window_0_records_in_total": int64(5),
  1167. "op_window_0_records_out_total": int64(4),
  1168. "op_order_0_exceptions_total": int64(1),
  1169. "op_order_0_process_latency_ms": int64(0),
  1170. "op_order_0_records_in_total": int64(4),
  1171. "op_order_0_records_out_total": int64(3),
  1172. },
  1173. },
  1174. }
  1175. handleStream(true, streamList, t)
  1176. doRuleTest(t, tests, 0, &api.RuleOption{
  1177. BufferLength: 100,
  1178. })
  1179. }