window_rule_test.go 39 KB

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