window_rule_test.go 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335
  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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": 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_us": int64(0),
  542. "op_window_0_records_in_total": int64(5),
  543. "op_window_0_records_out_total": int64(1),
  544. },
  545. }, {
  546. name: `TestWindowRule10`,
  547. sql: `SELECT deduplicate(color, false)->color as c FROM demo GROUP BY SlidingWindow(hh, 1)`,
  548. r: [][]map[string]interface{}{
  549. {{
  550. "c": "red",
  551. }}, {{
  552. "c": "blue",
  553. }}, {{}}, {{
  554. "c": "yellow",
  555. }}, {{}},
  556. },
  557. m: map[string]interface{}{
  558. "op_preprocessor_demo_0_exceptions_total": int64(0),
  559. "op_preprocessor_demo_0_process_latency_us": int64(0),
  560. "op_preprocessor_demo_0_records_in_total": int64(5),
  561. "op_preprocessor_demo_0_records_out_total": int64(5),
  562. "op_project_0_exceptions_total": int64(0),
  563. "op_project_0_process_latency_us": int64(0),
  564. "op_project_0_records_in_total": int64(5),
  565. "op_project_0_records_out_total": int64(5),
  566. "sink_mockSink_0_exceptions_total": int64(0),
  567. "sink_mockSink_0_records_in_total": int64(5),
  568. "sink_mockSink_0_records_out_total": int64(5),
  569. "source_demo_0_exceptions_total": int64(0),
  570. "source_demo_0_records_in_total": int64(5),
  571. "source_demo_0_records_out_total": int64(5),
  572. "op_window_0_exceptions_total": int64(0),
  573. "op_window_0_process_latency_us": int64(0),
  574. "op_window_0_records_in_total": int64(5),
  575. "op_window_0_records_out_total": int64(5),
  576. },
  577. },
  578. }
  579. handleStream(true, streamList, t)
  580. options := []*api.RuleOption{
  581. {
  582. BufferLength: 100,
  583. }, {
  584. BufferLength: 100,
  585. Qos: api.AtLeastOnce,
  586. CheckpointInterval: 5000,
  587. }, {
  588. BufferLength: 100,
  589. Qos: api.ExactlyOnce,
  590. CheckpointInterval: 5000,
  591. },
  592. }
  593. for j, opt := range options {
  594. doRuleTest(t, tests, j, opt)
  595. }
  596. }
  597. func TestEventWindow(t *testing.T) {
  598. //Reset
  599. streamList := []string{"demoE", "demoErr", "demo1E", "sessionDemoE"}
  600. handleStream(false, streamList, t)
  601. var tests = []ruleTest{
  602. {
  603. name: `TestEventWindowRule1`,
  604. sql: `SELECT * FROM demoE GROUP BY HOPPINGWINDOW(ss, 2, 1)`,
  605. r: [][]map[string]interface{}{
  606. {{
  607. "color": "red",
  608. "size": float64(3),
  609. "ts": float64(1541152486013),
  610. }},
  611. {{
  612. "color": "red",
  613. "size": float64(3),
  614. "ts": float64(1541152486013),
  615. }, {
  616. "color": "blue",
  617. "size": float64(2),
  618. "ts": float64(1541152487632),
  619. }},
  620. {{
  621. "color": "blue",
  622. "size": float64(2),
  623. "ts": float64(1541152487632),
  624. }, {
  625. "color": "yellow",
  626. "size": float64(4),
  627. "ts": float64(1541152488442),
  628. }}, {{
  629. "color": "yellow",
  630. "size": float64(4),
  631. "ts": float64(1541152488442),
  632. }, {
  633. "color": "red",
  634. "size": float64(1),
  635. "ts": float64(1541152489252),
  636. }}, {{
  637. "color": "red",
  638. "size": float64(1),
  639. "ts": float64(1541152489252),
  640. }},
  641. },
  642. m: map[string]interface{}{
  643. "op_preprocessor_demoE_0_exceptions_total": int64(0),
  644. "op_preprocessor_demoE_0_process_latency_us": int64(0),
  645. "op_preprocessor_demoE_0_records_in_total": int64(6),
  646. "op_preprocessor_demoE_0_records_out_total": int64(6),
  647. "op_project_0_exceptions_total": int64(0),
  648. "op_project_0_process_latency_us": int64(0),
  649. "op_project_0_records_in_total": int64(5),
  650. "op_project_0_records_out_total": int64(5),
  651. "sink_mockSink_0_exceptions_total": int64(0),
  652. "sink_mockSink_0_records_in_total": int64(5),
  653. "sink_mockSink_0_records_out_total": int64(5),
  654. "source_demoE_0_exceptions_total": int64(0),
  655. "source_demoE_0_records_in_total": int64(6),
  656. "source_demoE_0_records_out_total": int64(6),
  657. "op_window_0_exceptions_total": int64(0),
  658. "op_window_0_process_latency_us": int64(0),
  659. "op_window_0_records_in_total": int64(6),
  660. "op_window_0_records_out_total": int64(5),
  661. },
  662. }, {
  663. name: `TestEventWindowRule2`,
  664. sql: `SELECT color, ts FROM demoE where size > 2 GROUP BY tumblingwindow(ss, 1)`,
  665. r: [][]map[string]interface{}{
  666. {{
  667. "color": "red",
  668. "ts": float64(1541152486013),
  669. }},
  670. {{
  671. "color": "yellow",
  672. "ts": float64(1541152488442),
  673. }},
  674. },
  675. m: map[string]interface{}{
  676. "op_preprocessor_demoE_0_exceptions_total": int64(0),
  677. "op_preprocessor_demoE_0_process_latency_us": int64(0),
  678. "op_preprocessor_demoE_0_records_in_total": int64(6),
  679. "op_preprocessor_demoE_0_records_out_total": int64(6),
  680. "op_project_0_exceptions_total": int64(0),
  681. "op_project_0_process_latency_us": int64(0),
  682. "op_project_0_records_in_total": int64(2),
  683. "op_project_0_records_out_total": int64(2),
  684. "sink_mockSink_0_exceptions_total": int64(0),
  685. "sink_mockSink_0_records_in_total": int64(2),
  686. "sink_mockSink_0_records_out_total": int64(2),
  687. "source_demoE_0_exceptions_total": int64(0),
  688. "source_demoE_0_records_in_total": int64(6),
  689. "source_demoE_0_records_out_total": int64(6),
  690. "op_window_0_exceptions_total": int64(0),
  691. "op_window_0_process_latency_us": int64(0),
  692. "op_window_0_records_in_total": int64(6),
  693. "op_window_0_records_out_total": int64(4),
  694. "op_filter_0_exceptions_total": int64(0),
  695. "op_filter_0_process_latency_us": int64(0),
  696. "op_filter_0_records_in_total": int64(4),
  697. "op_filter_0_records_out_total": int64(2),
  698. },
  699. }, {
  700. name: `TestEventWindowRule3`,
  701. sql: `SELECT color, temp, ts FROM demoE INNER JOIN demo1E ON demoE.ts = demo1E.ts GROUP BY SlidingWindow(ss, 1)`,
  702. r: [][]map[string]interface{}{
  703. {{
  704. "color": "red",
  705. "temp": 25.5,
  706. "ts": float64(1541152486013),
  707. }}, {{
  708. "color": "red",
  709. "temp": 25.5,
  710. "ts": float64(1541152486013),
  711. }}, {{
  712. "color": "blue",
  713. "temp": 28.1,
  714. "ts": float64(1541152487632),
  715. }}, {{
  716. "color": "blue",
  717. "temp": 28.1,
  718. "ts": float64(1541152487632),
  719. }, {
  720. "color": "yellow",
  721. "temp": 27.4,
  722. "ts": float64(1541152488442),
  723. }}, {{
  724. "color": "yellow",
  725. "temp": 27.4,
  726. "ts": float64(1541152488442),
  727. }, {
  728. "color": "red",
  729. "temp": 25.5,
  730. "ts": float64(1541152489252),
  731. }},
  732. },
  733. m: map[string]interface{}{
  734. "op_preprocessor_demoE_0_exceptions_total": int64(0),
  735. "op_preprocessor_demoE_0_process_latency_us": int64(0),
  736. "op_preprocessor_demoE_0_records_in_total": int64(6),
  737. "op_preprocessor_demoE_0_records_out_total": int64(6),
  738. "op_preprocessor_demo1E_0_exceptions_total": int64(0),
  739. "op_preprocessor_demo1E_0_process_latency_us": int64(0),
  740. "op_preprocessor_demo1E_0_records_in_total": int64(6),
  741. "op_preprocessor_demo1E_0_records_out_total": int64(6),
  742. "op_project_0_exceptions_total": int64(0),
  743. "op_project_0_process_latency_us": int64(0),
  744. "op_project_0_records_in_total": int64(5),
  745. "op_project_0_records_out_total": int64(5),
  746. "sink_mockSink_0_exceptions_total": int64(0),
  747. "sink_mockSink_0_records_in_total": int64(5),
  748. "sink_mockSink_0_records_out_total": int64(5),
  749. "source_demoE_0_exceptions_total": int64(0),
  750. "source_demoE_0_records_in_total": int64(6),
  751. "source_demoE_0_records_out_total": int64(6),
  752. "source_demo1E_0_exceptions_total": int64(0),
  753. "source_demo1E_0_records_in_total": int64(6),
  754. "source_demo1E_0_records_out_total": int64(6),
  755. "op_window_0_exceptions_total": int64(0),
  756. "op_window_0_process_latency_us": int64(0),
  757. "op_window_0_records_in_total": int64(12),
  758. "op_window_0_records_out_total": int64(5),
  759. "op_join_0_exceptions_total": int64(0),
  760. "op_join_0_process_latency_us": int64(0),
  761. "op_join_0_records_in_total": int64(5),
  762. "op_join_0_records_out_total": int64(5),
  763. },
  764. }, {
  765. name: `TestEventWindowRule4`,
  766. sql: `SELECT color FROM demoE GROUP BY SlidingWindow(ss, 2), color ORDER BY color`,
  767. r: [][]map[string]interface{}{
  768. {{
  769. "color": "red",
  770. }}, {{
  771. "color": "blue",
  772. }, {
  773. "color": "red",
  774. }}, {{
  775. "color": "blue",
  776. }, {
  777. "color": "yellow",
  778. }}, {{
  779. "color": "blue",
  780. }, {
  781. "color": "red",
  782. }, {
  783. "color": "yellow",
  784. }},
  785. },
  786. m: map[string]interface{}{
  787. "op_preprocessor_demoE_0_exceptions_total": int64(0),
  788. "op_preprocessor_demoE_0_process_latency_us": int64(0),
  789. "op_preprocessor_demoE_0_records_in_total": int64(6),
  790. "op_preprocessor_demoE_0_records_out_total": int64(6),
  791. "op_project_0_exceptions_total": int64(0),
  792. "op_project_0_process_latency_us": int64(0),
  793. "op_project_0_records_in_total": int64(4),
  794. "op_project_0_records_out_total": int64(4),
  795. "sink_mockSink_0_exceptions_total": int64(0),
  796. "sink_mockSink_0_records_in_total": int64(4),
  797. "sink_mockSink_0_records_out_total": int64(4),
  798. "source_demoE_0_exceptions_total": int64(0),
  799. "source_demoE_0_records_in_total": int64(6),
  800. "source_demoE_0_records_out_total": int64(6),
  801. "op_window_0_exceptions_total": int64(0),
  802. "op_window_0_process_latency_us": int64(0),
  803. "op_window_0_records_in_total": int64(6),
  804. "op_window_0_records_out_total": int64(4),
  805. "op_aggregate_0_exceptions_total": int64(0),
  806. "op_aggregate_0_process_latency_us": int64(0),
  807. "op_aggregate_0_records_in_total": int64(4),
  808. "op_aggregate_0_records_out_total": int64(4),
  809. "op_order_0_exceptions_total": int64(0),
  810. "op_order_0_process_latency_us": int64(0),
  811. "op_order_0_records_in_total": int64(4),
  812. "op_order_0_records_out_total": int64(4),
  813. },
  814. }, {
  815. name: `TestEventWindowRule5`,
  816. sql: `SELECT temp FROM sessionDemoE GROUP BY SessionWindow(ss, 2, 1) `,
  817. r: [][]map[string]interface{}{
  818. {{
  819. "temp": 25.5,
  820. }}, {{
  821. "temp": 28.1,
  822. }, {
  823. "temp": 27.4,
  824. }, {
  825. "temp": 25.5,
  826. }}, {{
  827. "temp": 26.2,
  828. }, {
  829. "temp": 26.8,
  830. }, {
  831. "temp": 28.9,
  832. }, {
  833. "temp": 29.1,
  834. }, {
  835. "temp": 32.2,
  836. }}, {{
  837. "temp": 30.9,
  838. }},
  839. },
  840. m: map[string]interface{}{
  841. "op_preprocessor_sessionDemoE_0_exceptions_total": int64(0),
  842. "op_preprocessor_sessionDemoE_0_process_latency_us": int64(0),
  843. "op_preprocessor_sessionDemoE_0_records_in_total": int64(12),
  844. "op_preprocessor_sessionDemoE_0_records_out_total": int64(12),
  845. "op_project_0_exceptions_total": int64(0),
  846. "op_project_0_process_latency_us": int64(0),
  847. "op_project_0_records_in_total": int64(4),
  848. "op_project_0_records_out_total": int64(4),
  849. "sink_mockSink_0_exceptions_total": int64(0),
  850. "sink_mockSink_0_records_in_total": int64(4),
  851. "sink_mockSink_0_records_out_total": int64(4),
  852. "source_sessionDemoE_0_exceptions_total": int64(0),
  853. "source_sessionDemoE_0_records_in_total": int64(12),
  854. "source_sessionDemoE_0_records_out_total": int64(12),
  855. "op_window_0_exceptions_total": int64(0),
  856. "op_window_0_process_latency_us": int64(0),
  857. "op_window_0_records_in_total": int64(12),
  858. "op_window_0_records_out_total": int64(4),
  859. },
  860. }, {
  861. name: `TestEventWindowRule6`,
  862. 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)`,
  863. r: [][]map[string]interface{}{
  864. {{
  865. "m": 25.5,
  866. "c": float64(1),
  867. }}, {{
  868. "m": 25.5,
  869. "c": float64(1),
  870. }}, {{
  871. "m": 28.1,
  872. "c": float64(1),
  873. }}, {{
  874. "m": 28.1,
  875. "c": float64(2),
  876. }}, {{
  877. "m": 27.4,
  878. "c": float64(2),
  879. }},
  880. },
  881. m: map[string]interface{}{
  882. "op_preprocessor_demoE_0_exceptions_total": int64(0),
  883. "op_preprocessor_demoE_0_process_latency_us": int64(0),
  884. "op_preprocessor_demoE_0_records_in_total": int64(6),
  885. "op_preprocessor_demoE_0_records_out_total": int64(6),
  886. "op_preprocessor_demo1E_0_exceptions_total": int64(0),
  887. "op_preprocessor_demo1E_0_process_latency_us": int64(0),
  888. "op_preprocessor_demo1E_0_records_in_total": int64(6),
  889. "op_preprocessor_demo1E_0_records_out_total": int64(6),
  890. "op_project_0_exceptions_total": int64(0),
  891. "op_project_0_process_latency_us": int64(0),
  892. "op_project_0_records_in_total": int64(5),
  893. "op_project_0_records_out_total": int64(5),
  894. "sink_mockSink_0_exceptions_total": int64(0),
  895. "sink_mockSink_0_records_in_total": int64(5),
  896. "sink_mockSink_0_records_out_total": int64(5),
  897. "source_demoE_0_exceptions_total": int64(0),
  898. "source_demoE_0_records_in_total": int64(6),
  899. "source_demoE_0_records_out_total": int64(6),
  900. "source_demo1E_0_exceptions_total": int64(0),
  901. "source_demo1E_0_records_in_total": int64(6),
  902. "source_demo1E_0_records_out_total": int64(6),
  903. "op_window_0_exceptions_total": int64(0),
  904. "op_window_0_records_in_total": int64(12),
  905. "op_window_0_records_out_total": int64(5),
  906. "op_join_0_exceptions_total": int64(0),
  907. "op_join_0_process_latency_us": int64(0),
  908. "op_join_0_records_in_total": int64(5),
  909. "op_join_0_records_out_total": int64(5),
  910. },
  911. }, {
  912. name: `TestEventWindowRule7`,
  913. sql: `SELECT * FROM demoErr GROUP BY HOPPINGWINDOW(ss, 2, 1)`,
  914. r: [][]map[string]interface{}{
  915. {{
  916. "error": "error in preprocessor: invalid data type for color, expect string but found int(2)",
  917. }},
  918. {{
  919. "color": "red",
  920. "size": float64(3),
  921. "ts": float64(1541152486013),
  922. }},
  923. {{
  924. "color": "red",
  925. "size": float64(3),
  926. "ts": float64(1541152486013),
  927. }},
  928. {{
  929. "color": "yellow",
  930. "size": float64(4),
  931. "ts": float64(1541152488442),
  932. }}, {{
  933. "color": "yellow",
  934. "size": float64(4),
  935. "ts": float64(1541152488442),
  936. }, {
  937. "color": "red",
  938. "size": float64(1),
  939. "ts": float64(1541152489252),
  940. }}, {{
  941. "color": "red",
  942. "size": float64(1),
  943. "ts": float64(1541152489252),
  944. }},
  945. },
  946. m: map[string]interface{}{
  947. "op_preprocessor_demoErr_0_exceptions_total": int64(1),
  948. "op_preprocessor_demoErr_0_process_latency_us": int64(0),
  949. "op_preprocessor_demoErr_0_records_in_total": int64(6),
  950. "op_preprocessor_demoErr_0_records_out_total": int64(5),
  951. "op_project_0_exceptions_total": int64(1),
  952. "op_project_0_process_latency_us": int64(0),
  953. "op_project_0_records_in_total": int64(6),
  954. "op_project_0_records_out_total": int64(5),
  955. "sink_mockSink_0_exceptions_total": int64(0),
  956. "sink_mockSink_0_records_in_total": int64(6),
  957. "sink_mockSink_0_records_out_total": int64(6),
  958. "source_demoErr_0_exceptions_total": int64(0),
  959. "source_demoErr_0_records_in_total": int64(6),
  960. "source_demoErr_0_records_out_total": int64(6),
  961. "op_window_0_exceptions_total": int64(1),
  962. "op_window_0_process_latency_us": int64(0),
  963. "op_window_0_records_in_total": int64(6),
  964. "op_window_0_records_out_total": int64(5),
  965. },
  966. },
  967. }
  968. handleStream(true, streamList, t)
  969. options := []*api.RuleOption{
  970. {
  971. BufferLength: 100,
  972. IsEventTime: true,
  973. LateTol: 1000,
  974. }, {
  975. BufferLength: 100,
  976. Qos: api.AtLeastOnce,
  977. CheckpointInterval: 5000,
  978. IsEventTime: true,
  979. LateTol: 1000,
  980. }, {
  981. BufferLength: 100,
  982. Qos: api.ExactlyOnce,
  983. CheckpointInterval: 5000,
  984. IsEventTime: true,
  985. LateTol: 1000,
  986. },
  987. }
  988. for j, opt := range options {
  989. doRuleTest(t, tests, j, opt)
  990. }
  991. }
  992. func TestWindowError(t *testing.T) {
  993. //Reset
  994. streamList := []string{"ldemo", "ldemo1"}
  995. handleStream(false, streamList, t)
  996. var tests = []ruleTest{
  997. {
  998. name: `TestWindowErrorRule1`,
  999. sql: `SELECT size * 3 FROM ldemo GROUP BY TUMBLINGWINDOW(ss, 2)`,
  1000. r: [][]map[string]interface{}{
  1001. {{
  1002. "error": "run Select error: invalid operation string(string) * int64(3)",
  1003. }}, {{
  1004. "rengine_field_0": float64(6),
  1005. }, {}},
  1006. },
  1007. m: map[string]interface{}{
  1008. "op_preprocessor_ldemo_0_exceptions_total": int64(0),
  1009. "op_preprocessor_ldemo_0_process_latency_us": int64(0),
  1010. "op_preprocessor_ldemo_0_records_in_total": int64(5),
  1011. "op_preprocessor_ldemo_0_records_out_total": int64(5),
  1012. "op_project_0_exceptions_total": int64(1),
  1013. "op_project_0_process_latency_us": int64(0),
  1014. "op_project_0_records_in_total": int64(2),
  1015. "op_project_0_records_out_total": int64(1),
  1016. "sink_mockSink_0_exceptions_total": int64(0),
  1017. "sink_mockSink_0_records_in_total": int64(2),
  1018. "sink_mockSink_0_records_out_total": int64(2),
  1019. "source_ldemo_0_exceptions_total": int64(0),
  1020. "source_ldemo_0_records_in_total": int64(5),
  1021. "source_ldemo_0_records_out_total": int64(5),
  1022. "op_window_0_exceptions_total": int64(0),
  1023. "op_window_0_process_latency_us": int64(0),
  1024. "op_window_0_records_in_total": int64(5),
  1025. "op_window_0_records_out_total": int64(2),
  1026. },
  1027. }, {
  1028. name: `TestWindowErrorRule2`,
  1029. sql: `SELECT color, ts FROM ldemo where size > 2 GROUP BY tumblingwindow(ss, 1)`,
  1030. r: [][]map[string]interface{}{
  1031. {{
  1032. "error": "run Where error: invalid operation string(string) > int64(2)",
  1033. }}, {{
  1034. "ts": float64(1541152487632),
  1035. }},
  1036. },
  1037. m: map[string]interface{}{
  1038. "op_preprocessor_ldemo_0_exceptions_total": int64(0),
  1039. "op_preprocessor_ldemo_0_process_latency_us": int64(0),
  1040. "op_preprocessor_ldemo_0_records_in_total": int64(5),
  1041. "op_preprocessor_ldemo_0_records_out_total": int64(5),
  1042. "op_project_0_exceptions_total": int64(1),
  1043. "op_project_0_process_latency_us": int64(0),
  1044. "op_project_0_records_in_total": int64(2),
  1045. "op_project_0_records_out_total": int64(1),
  1046. "sink_mockSink_0_exceptions_total": int64(0),
  1047. "sink_mockSink_0_records_in_total": int64(2),
  1048. "sink_mockSink_0_records_out_total": int64(2),
  1049. "source_ldemo_0_exceptions_total": int64(0),
  1050. "source_ldemo_0_records_in_total": int64(5),
  1051. "source_ldemo_0_records_out_total": int64(5),
  1052. "op_window_0_exceptions_total": int64(0),
  1053. "op_window_0_process_latency_us": int64(0),
  1054. "op_window_0_records_in_total": int64(5),
  1055. "op_window_0_records_out_total": int64(4),
  1056. "op_filter_0_exceptions_total": int64(1),
  1057. "op_filter_0_process_latency_us": int64(0),
  1058. "op_filter_0_records_in_total": int64(4),
  1059. "op_filter_0_records_out_total": int64(1),
  1060. },
  1061. }, {
  1062. name: `TestWindowErrorRule3`,
  1063. sql: `SELECT color, temp, ts FROM ldemo INNER JOIN ldemo1 ON ldemo.ts = ldemo1.ts GROUP BY SlidingWindow(ss, 1)`,
  1064. r: [][]map[string]interface{}{
  1065. {{
  1066. "color": "red",
  1067. "temp": 25.5,
  1068. "ts": float64(1541152486013),
  1069. }}, {{
  1070. "color": "red",
  1071. "temp": 25.5,
  1072. "ts": float64(1541152486013),
  1073. }}, {{
  1074. "color": "red",
  1075. "temp": 25.5,
  1076. "ts": float64(1541152486013),
  1077. }}, {{
  1078. "temp": 28.1,
  1079. "ts": float64(1541152487632),
  1080. }}, {{
  1081. "temp": 28.1,
  1082. "ts": float64(1541152487632),
  1083. }}, {{
  1084. "error": "run Join error: invalid operation int64(1541152487632) = string(1541152488442)",
  1085. }}, {{
  1086. "error": "run Join error: invalid operation int64(1541152488442) = string(1541152488442)",
  1087. }}, {{
  1088. "error": "run Join error: invalid operation int64(1541152488442) = string(1541152488442)",
  1089. }},
  1090. },
  1091. m: map[string]interface{}{
  1092. "op_preprocessor_ldemo_0_exceptions_total": int64(0),
  1093. "op_preprocessor_ldemo_0_process_latency_us": int64(0),
  1094. "op_preprocessor_ldemo_0_records_in_total": int64(5),
  1095. "op_preprocessor_ldemo_0_records_out_total": int64(5),
  1096. "op_preprocessor_ldemo1_0_exceptions_total": int64(0),
  1097. "op_preprocessor_ldemo1_0_process_latency_us": int64(0),
  1098. "op_preprocessor_ldemo1_0_records_in_total": int64(5),
  1099. "op_preprocessor_ldemo1_0_records_out_total": int64(5),
  1100. "op_project_0_exceptions_total": int64(3),
  1101. "op_project_0_process_latency_us": int64(0),
  1102. "op_project_0_records_in_total": int64(8),
  1103. "op_project_0_records_out_total": int64(5),
  1104. "sink_mockSink_0_exceptions_total": int64(0),
  1105. "sink_mockSink_0_records_in_total": int64(8),
  1106. "sink_mockSink_0_records_out_total": int64(8),
  1107. "source_ldemo_0_exceptions_total": int64(0),
  1108. "source_ldemo_0_records_in_total": int64(5),
  1109. "source_ldemo_0_records_out_total": int64(5),
  1110. "source_ldemo1_0_exceptions_total": int64(0),
  1111. "source_ldemo1_0_records_in_total": int64(5),
  1112. "source_ldemo1_0_records_out_total": int64(5),
  1113. "op_window_0_exceptions_total": int64(0),
  1114. "op_window_0_process_latency_us": int64(0),
  1115. "op_window_0_records_in_total": int64(10),
  1116. "op_window_0_records_out_total": int64(10),
  1117. "op_join_0_exceptions_total": int64(3),
  1118. "op_join_0_process_latency_us": int64(0),
  1119. "op_join_0_records_in_total": int64(10),
  1120. "op_join_0_records_out_total": int64(5),
  1121. },
  1122. }, {
  1123. name: `TestWindowErrorRule4`,
  1124. sql: `SELECT color FROM ldemo GROUP BY SlidingWindow(ss, 2), color having size >= 2 order by color`,
  1125. r: [][]map[string]interface{}{
  1126. {{
  1127. "color": "red",
  1128. }}, {{
  1129. "error": "run Having error: invalid operation string(string) >= int64(2)",
  1130. }}, {{
  1131. "error": "run Having error: invalid operation string(string) >= int64(2)",
  1132. }}, {{
  1133. "error": "run Having error: invalid operation string(string) >= int64(2)",
  1134. }}, {{
  1135. "color": float64(49),
  1136. }, {}},
  1137. },
  1138. m: map[string]interface{}{
  1139. "op_preprocessor_ldemo_0_exceptions_total": int64(0),
  1140. "op_preprocessor_ldemo_0_process_latency_us": int64(0),
  1141. "op_preprocessor_ldemo_0_records_in_total": int64(5),
  1142. "op_preprocessor_ldemo_0_records_out_total": int64(5),
  1143. "op_project_0_exceptions_total": int64(3),
  1144. "op_project_0_process_latency_us": int64(0),
  1145. "op_project_0_records_in_total": int64(5),
  1146. "op_project_0_records_out_total": int64(2),
  1147. "sink_mockSink_0_exceptions_total": int64(0),
  1148. "sink_mockSink_0_records_in_total": int64(5),
  1149. "sink_mockSink_0_records_out_total": int64(5),
  1150. "source_ldemo_0_exceptions_total": int64(0),
  1151. "source_ldemo_0_records_in_total": int64(5),
  1152. "source_ldemo_0_records_out_total": int64(5),
  1153. "op_window_0_exceptions_total": int64(0),
  1154. "op_window_0_process_latency_us": int64(0),
  1155. "op_window_0_records_in_total": int64(5),
  1156. "op_window_0_records_out_total": int64(5),
  1157. "op_aggregate_0_exceptions_total": int64(0),
  1158. "op_aggregate_0_process_latency_us": int64(0),
  1159. "op_aggregate_0_records_in_total": int64(5),
  1160. "op_aggregate_0_records_out_total": int64(5),
  1161. "op_having_0_exceptions_total": int64(3),
  1162. "op_having_0_process_latency_us": int64(0),
  1163. "op_having_0_records_in_total": int64(5),
  1164. "op_having_0_records_out_total": int64(2),
  1165. },
  1166. }, {
  1167. name: `TestWindowErrorRule5`,
  1168. sql: `SELECT color, size FROM ldemo GROUP BY tumblingwindow(ss, 1) ORDER BY size`,
  1169. r: [][]map[string]interface{}{
  1170. {{
  1171. "error": "run Order By error: incompatible types for comparison: int and string",
  1172. }}, {{
  1173. "size": float64(3),
  1174. }}, {{
  1175. "color": float64(49),
  1176. "size": float64(2),
  1177. }}, {{
  1178. "color": "red",
  1179. }},
  1180. },
  1181. m: map[string]interface{}{
  1182. "op_preprocessor_ldemo_0_exceptions_total": int64(0),
  1183. "op_preprocessor_ldemo_0_process_latency_us": int64(0),
  1184. "op_preprocessor_ldemo_0_records_in_total": int64(5),
  1185. "op_preprocessor_ldemo_0_records_out_total": int64(5),
  1186. "op_project_0_exceptions_total": int64(1),
  1187. "op_project_0_process_latency_us": int64(0),
  1188. "op_project_0_records_in_total": int64(4),
  1189. "op_project_0_records_out_total": int64(3),
  1190. "sink_mockSink_0_exceptions_total": int64(0),
  1191. "sink_mockSink_0_records_in_total": int64(4),
  1192. "sink_mockSink_0_records_out_total": int64(4),
  1193. "source_ldemo_0_exceptions_total": int64(0),
  1194. "source_ldemo_0_records_in_total": int64(5),
  1195. "source_ldemo_0_records_out_total": int64(5),
  1196. "op_window_0_exceptions_total": int64(0),
  1197. "op_window_0_process_latency_us": int64(0),
  1198. "op_window_0_records_in_total": int64(5),
  1199. "op_window_0_records_out_total": int64(4),
  1200. "op_order_0_exceptions_total": int64(1),
  1201. "op_order_0_process_latency_us": int64(0),
  1202. "op_order_0_records_in_total": int64(4),
  1203. "op_order_0_records_out_total": int64(3),
  1204. },
  1205. },
  1206. }
  1207. handleStream(true, streamList, t)
  1208. doRuleTest(t, tests, 0, &api.RuleOption{
  1209. BufferLength: 100,
  1210. })
  1211. }