planner_graph_test.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  1. // Copyright 2022-2023 EMQ Technologies Co., Ltd.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package planner
  15. import (
  16. "encoding/json"
  17. "fmt"
  18. "reflect"
  19. "testing"
  20. "github.com/lf-edge/ekuiper/internal/pkg/store"
  21. "github.com/lf-edge/ekuiper/internal/testx"
  22. "github.com/lf-edge/ekuiper/internal/xsql"
  23. "github.com/lf-edge/ekuiper/pkg/api"
  24. "github.com/lf-edge/ekuiper/pkg/ast"
  25. )
  26. func TestPlannerGraphValidate(t *testing.T) {
  27. tests := []struct {
  28. graph string
  29. err string
  30. }{
  31. {
  32. graph: `{
  33. "nodes": {
  34. "abc": {
  35. "type": "source",
  36. "nodeType": "mqtt",
  37. "props": {
  38. "datasource": "demo"
  39. }
  40. },
  41. "myfilter": {
  42. "type": "operator",
  43. "nodeType": "filter",
  44. "props": {
  45. "expr": "temperature > 20"
  46. }
  47. },
  48. "logfunc": {
  49. "type": "operator",
  50. "nodeType": "function",
  51. "props": {
  52. "expr": "log(temperature) as log_temperature"
  53. }
  54. },
  55. "sinfunc": {
  56. "type": "operator",
  57. "nodeType": "function",
  58. "props": {
  59. "expr": "sin(temperature) as sin_temperature"
  60. }
  61. },
  62. "pick": {
  63. "type": "operator",
  64. "nodeType": "pick",
  65. "props": {
  66. "fields": [
  67. "log_temperature",
  68. "humidity"
  69. ]
  70. }
  71. },
  72. "mqttpv": {
  73. "type": "sink",
  74. "nodeType": "mqtt",
  75. "props": {
  76. "server": "tcp://syno.home:1883",
  77. "topic": "result",
  78. "sendSingle": true
  79. }
  80. },
  81. "mqtt2": {
  82. "type": "sink",
  83. "nodeType": "mqtt",
  84. "props": {
  85. "server": "tcp://syno.home:1883",
  86. "topic": "result2",
  87. "sendSingle": true
  88. }
  89. }
  90. },
  91. "topo": {
  92. "sources": [
  93. "abc"
  94. ],
  95. "edges": {
  96. "abc": [
  97. "myfilter",
  98. "sinfunc"
  99. ],
  100. "myfilter": [
  101. "logfunc"
  102. ],
  103. "logfunc": [
  104. "pick"
  105. ],
  106. "pick": [
  107. "mqttpv"
  108. ],
  109. "sinfunc": [
  110. "mqtt2"
  111. ]
  112. }
  113. }
  114. }`,
  115. err: "",
  116. },
  117. {
  118. graph: `{
  119. "nodes": {
  120. "abc": {
  121. "type": "source",
  122. "nodeType": "mqtt",
  123. "props": {
  124. "datasource": "demo"
  125. }
  126. },
  127. "mqtt2": {
  128. "type": "sink",
  129. "nodeType": "mqtt",
  130. "props": {
  131. "server": "tcp://syno.home:1883",
  132. "topic": "result2",
  133. "sendSingle": true
  134. }
  135. }
  136. },
  137. "topo": {
  138. "sources": [
  139. "abc"
  140. ],
  141. "edges": {
  142. "abc": [
  143. "myfilter"
  144. ]
  145. }
  146. }
  147. }`,
  148. err: "node myfilter is not defined",
  149. },
  150. {
  151. graph: `{
  152. "nodes": {
  153. "abc": {
  154. "type": "source",
  155. "nodeType": "mqtt",
  156. "props": {
  157. "datasource": "demo"
  158. }
  159. },
  160. "mqtt2": {
  161. "type": "sink",
  162. "nodeType": "mqtt",
  163. "props": {
  164. "server": "tcp://syno.home:1883",
  165. "topic": "result2",
  166. "sendSingle": true
  167. }
  168. }
  169. },
  170. "topo": {
  171. "sources": [
  172. "abc"
  173. ],
  174. "edges": {
  175. }
  176. }
  177. }`,
  178. err: "no edge defined for source node abc",
  179. },
  180. {
  181. graph: `{
  182. "nodes": {
  183. "abc": {
  184. "type": "source",
  185. "nodeType": "mqtt",
  186. "props": {
  187. "datasource": "demo"
  188. }
  189. },
  190. "aggfunc": {
  191. "type": "operator",
  192. "nodeType": "aggfunc",
  193. "props": {
  194. "expr": "avg(temperature) as avg_temperature"
  195. }
  196. },
  197. "mqtt2": {
  198. "type": "sink",
  199. "nodeType": "mqtt",
  200. "props": {
  201. "server": "tcp://syno.home:1883",
  202. "topic": "result2",
  203. "sendSingle": true
  204. }
  205. }
  206. },
  207. "topo": {
  208. "sources": [
  209. "abc"
  210. ],
  211. "edges": {
  212. "abc": ["aggfunc"],
  213. "aggfunc": ["mqtt2"]
  214. }
  215. }
  216. }`,
  217. err: "node abc output does not match node aggfunc input: input type mismatch, expect collection, got row",
  218. },
  219. {
  220. graph: `{
  221. "nodes": {
  222. "abc": {
  223. "type": "source",
  224. "nodeType": "mqtt",
  225. "props": {
  226. "datasource": "demo"
  227. }
  228. },
  229. "abc2": {
  230. "type": "source",
  231. "nodeType": "mqtt",
  232. "props": {
  233. "datasource": "demo1"
  234. }
  235. },
  236. "joinop": {
  237. "type": "operator",
  238. "nodeType": "join",
  239. "props": {
  240. "from": "abc",
  241. "joins": [
  242. {
  243. "name": "abc2",
  244. "type": "inner",
  245. "on": "abc.id = abc2.id"
  246. }
  247. ]
  248. }
  249. },
  250. "mqtt2": {
  251. "type": "sink",
  252. "nodeType": "mqtt",
  253. "props": {
  254. "server": "tcp://syno.home:1883",
  255. "topic": "result2",
  256. "sendSingle": true
  257. }
  258. }
  259. },
  260. "topo": {
  261. "sources": [
  262. "abc","abc2"
  263. ],
  264. "edges": {
  265. "abc": ["joinop"],
  266. "abc2": ["joinop"],
  267. "joinop": ["mqtt2"]
  268. }
  269. }
  270. }`,
  271. err: "join node joinop does not allow multiple stream inputs",
  272. },
  273. {
  274. graph: `{
  275. "nodes": {
  276. "abc": {
  277. "type": "source",
  278. "nodeType": "mqtt",
  279. "props": {
  280. "datasource": "demo"
  281. }
  282. },
  283. "abc2": {
  284. "type": "source",
  285. "nodeType": "mqtt",
  286. "props": {
  287. "datasource": "demo1"
  288. }
  289. },
  290. "windowop": {
  291. "type": "operator",
  292. "nodeType": "window",
  293. "props": {
  294. "type": "hoppingwindow",
  295. "unit": "ss",
  296. "size": 10,
  297. "interval": 5
  298. }
  299. },
  300. "joinop": {
  301. "type": "operator",
  302. "nodeType": "join",
  303. "props": {
  304. "from": "abc",
  305. "joins": [
  306. {
  307. "name": "abc2",
  308. "type": "inner",
  309. "on": "abc.id = abc2.id"
  310. }
  311. ]
  312. }
  313. },
  314. "groupop": {
  315. "type": "operator",
  316. "nodeType": "groupby",
  317. "props": {
  318. "dimensions": ["id","userId"]
  319. }
  320. },
  321. "mqtt2": {
  322. "type": "sink",
  323. "nodeType": "mqtt",
  324. "props": {
  325. "server": "tcp://syno.home:1883",
  326. "topic": "result2",
  327. "sendSingle": true
  328. }
  329. }
  330. },
  331. "topo": {
  332. "sources": [
  333. "abc","abc2"
  334. ],
  335. "edges": {
  336. "abc": ["windowop"],
  337. "abc2": ["windowop"],
  338. "windowop": ["joinop"],
  339. "joinop": ["groupop"],
  340. "groupop": ["mqtt2"]
  341. }
  342. }
  343. }`,
  344. err: "",
  345. },
  346. {
  347. graph: `{
  348. "nodes": {
  349. "abc": {
  350. "type": "source",
  351. "nodeType": "mqtt",
  352. "props": {
  353. "datasource": "demo"
  354. }
  355. },
  356. "abc2": {
  357. "type": "source",
  358. "nodeType": "mqtt",
  359. "props": {
  360. "datasource": "demo1"
  361. }
  362. },
  363. "windowop": {
  364. "type": "operator",
  365. "nodeType": "window",
  366. "props": {
  367. "type": "hoppingwindow",
  368. "unit": "ss",
  369. "size": 10,
  370. "interval": 5
  371. }
  372. },
  373. "joinop": {
  374. "type": "operator",
  375. "nodeType": "join",
  376. "props": {
  377. "from": "abc",
  378. "joins": [
  379. {
  380. "name": "abc2",
  381. "type": "inner",
  382. "on": "abc.id = abc2.id"
  383. }
  384. ]
  385. }
  386. },
  387. "groupop": {
  388. "type": "operator",
  389. "nodeType": "groupby",
  390. "props": {
  391. "dimensions": ["id","userId"]
  392. }
  393. },
  394. "mqtt2": {
  395. "type": "sink",
  396. "nodeType": "mqtt",
  397. "props": {
  398. "server": "tcp://syno.home:1883",
  399. "topic": "result2",
  400. "sendSingle": true
  401. }
  402. }
  403. },
  404. "topo": {
  405. "sources": [
  406. "abc","abc2"
  407. ],
  408. "edges": {
  409. "abc": ["windowop"],
  410. "abc2": ["windowop"],
  411. "windowop": ["groupop"],
  412. "joinop": ["mqtt2"],
  413. "groupop": ["joinop"]
  414. }
  415. }
  416. }`,
  417. err: "node groupop output does not match node joinop input: collection type mismatch, expect non-grouped collection, got grouped collection",
  418. },
  419. {
  420. graph: `{
  421. "nodes": {
  422. "abc": {
  423. "type": "source",
  424. "nodeType": "mqtt",
  425. "props": {
  426. "datasource": "demo"
  427. }
  428. },
  429. "abc2": {
  430. "type": "source",
  431. "nodeType": "mqtt",
  432. "props": {
  433. "datasource": "demo1"
  434. }
  435. },
  436. "windowop": {
  437. "type": "operator",
  438. "nodeType": "window",
  439. "props": {
  440. "type": "hoppingwindow",
  441. "unit": "ss",
  442. "size": 10,
  443. "interval": 5
  444. }
  445. },
  446. "joinop": {
  447. "type": "operator",
  448. "nodeType": "join",
  449. "props": {
  450. "from": "abc",
  451. "joins": [
  452. {
  453. "name": "abc2",
  454. "type": "inner",
  455. "on": "abc.id = abc2.id"
  456. }
  457. ]
  458. }
  459. },
  460. "groupop": {
  461. "type": "operator",
  462. "nodeType": "groupby",
  463. "props": {
  464. "dimensions": ["id","userId"]
  465. }
  466. },
  467. "aggfunc": {
  468. "type": "operator",
  469. "nodeType": "aggFunc",
  470. "props": {
  471. "expr": "avg(temperature) as avg_temperature"
  472. }
  473. },
  474. "mqtt2": {
  475. "type": "sink",
  476. "nodeType": "mqtt",
  477. "props": {
  478. "server": "tcp://syno.home:1883",
  479. "topic": "result2",
  480. "sendSingle": true
  481. }
  482. }
  483. },
  484. "topo": {
  485. "sources": [
  486. "abc","abc2"
  487. ],
  488. "edges": {
  489. "abc": ["windowop"],
  490. "abc2": ["windowop"],
  491. "windowop": ["groupop"],
  492. "joinop": ["mqtt2"],
  493. "groupop": ["aggfunc"],
  494. "aggfunc": ["joinop"]
  495. }
  496. }
  497. }`,
  498. err: "node aggfunc output does not match node joinop input: collection type mismatch, expect non-grouped collection, got grouped collection",
  499. },
  500. {
  501. graph: `{
  502. "nodes": {
  503. "abc": {
  504. "type": "source",
  505. "nodeType": "mqtt",
  506. "props": {
  507. "datasource": "demo"
  508. }
  509. },
  510. "aggfunc": {
  511. "type": "operator",
  512. "nodeType": "aggfunc",
  513. "props": {
  514. "expr": "avg(,temperature) as avg_temperature"
  515. }
  516. },
  517. "mqtt2": {
  518. "type": "sink",
  519. "nodeType": "mqtt",
  520. "props": {
  521. "server": "tcp://syno.home:1883",
  522. "topic": "result2",
  523. "sendSingle": true
  524. }
  525. }
  526. },
  527. "topo": {
  528. "sources": [
  529. "abc"
  530. ],
  531. "edges": {
  532. "abc": ["aggfunc"],
  533. "aggfunc": ["mqtt2"]
  534. }
  535. }
  536. }`,
  537. err: "parse aggfunc aggfunc with map[expr:avg(,temperature) as avg_temperature] error: found \",\", expected expression.",
  538. },
  539. }
  540. t.Logf("The test bucket size is %d.\n\n", len(tests))
  541. for i, tt := range tests {
  542. rg := &api.RuleGraph{}
  543. err := json.Unmarshal([]byte(tt.graph), rg)
  544. if err != nil {
  545. t.Error(err)
  546. continue
  547. }
  548. _, err = PlanByGraph(&api.Rule{
  549. Triggered: false,
  550. Id: fmt.Sprintf("rule%d", i),
  551. Name: fmt.Sprintf("rule%d", i),
  552. Graph: rg,
  553. Options: &api.RuleOption{
  554. IsEventTime: false,
  555. LateTol: 1000,
  556. Concurrency: 1,
  557. BufferLength: 1024,
  558. SendMetaToSink: false,
  559. SendError: true,
  560. Qos: api.AtMostOnce,
  561. CheckpointInterval: 300000,
  562. },
  563. })
  564. if !reflect.DeepEqual(tt.err, testx.Errstring(err)) {
  565. t.Errorf("%d: error mismatch:\n exp=%s\n got=%s\n\n", i, tt.err, err)
  566. }
  567. }
  568. }
  569. func TestPlannerGraphWithStream(t *testing.T) {
  570. store, err := store.GetKV("stream")
  571. if err != nil {
  572. t.Error(err)
  573. return
  574. }
  575. streamSqls := map[string]string{
  576. "src1": `CREATE STREAM src1 (
  577. id1 BIGINT,
  578. temp BIGINT,
  579. name string,
  580. myarray array(string)
  581. ) WITH (DATASOURCE="src1", FORMAT="json", KEY="ts");`,
  582. "src2": `CREATE STREAM src2 (
  583. id2 BIGINT,
  584. hum BIGINT
  585. ) WITH (DATASOURCE="src2", FORMAT="json", KEY="ts", TIMESTAMP_FORMAT="YYYY-MM-dd HH:mm:ss");`,
  586. "tableInPlanner": `CREATE TABLE tableInPlanner (
  587. id BIGINT,
  588. name STRING,
  589. value STRING,
  590. hum BIGINT
  591. ) WITH (TYPE="file");`,
  592. "lookupT": `CREATE TABLE lookupT () WITH (DATASOURCE="alertVal", TYPE="memory", KIND="lookup", KEY="id");`,
  593. }
  594. types := map[string]ast.StreamType{
  595. "src1": ast.TypeStream,
  596. "src2": ast.TypeStream,
  597. "tableInPlanner": ast.TypeTable,
  598. "lookupT": ast.TypeTable,
  599. }
  600. for name, sql := range streamSqls {
  601. s, err := json.Marshal(&xsql.StreamInfo{
  602. StreamType: types[name],
  603. Statement: sql,
  604. })
  605. if err != nil {
  606. t.Error(err)
  607. t.Fail()
  608. }
  609. err = store.Set(name, string(s))
  610. if err != nil {
  611. t.Error(err)
  612. t.Fail()
  613. }
  614. }
  615. testCases := []struct {
  616. name string
  617. graph string
  618. err error
  619. }{
  620. {
  621. name: "test stream",
  622. graph: `{
  623. "nodes": {
  624. "demo": {
  625. "type": "source",
  626. "nodeType": "mqtt",
  627. "props": {
  628. "sourceType": "stream",
  629. "sourceName": "src1"
  630. }
  631. },
  632. "log": {
  633. "type": "sink",
  634. "nodeType": "log",
  635. "props": {}
  636. }
  637. },
  638. "topo": {
  639. "sources": ["demo"],
  640. "edges": {
  641. "demo": ["log"]
  642. }
  643. }
  644. }`,
  645. err: nil,
  646. },
  647. {
  648. name: "stream type wrong",
  649. graph: `{
  650. "nodes": {
  651. "demo": {
  652. "type": "source",
  653. "nodeType": "file",
  654. "props": {
  655. "sourceType": "stream",
  656. "sourceName": "src1"
  657. }
  658. },
  659. "log": {
  660. "type": "sink",
  661. "nodeType": "log",
  662. "props": {}
  663. }
  664. },
  665. "topo": {
  666. "sources": ["demo"],
  667. "edges": {
  668. "demo": ["log"]
  669. }
  670. }
  671. }`,
  672. err: fmt.Errorf("parse source demo with map[sourceName:src1 sourceType:stream] error: source type file does not match the stream type mqtt"),
  673. },
  674. {
  675. name: "non exist stream",
  676. graph: `{
  677. "nodes": {
  678. "demo": {
  679. "type": "source",
  680. "nodeType": "mqtt",
  681. "props": {
  682. "sourceType": "stream",
  683. "sourceName": "unknown"
  684. }
  685. },
  686. "log": {
  687. "type": "sink",
  688. "nodeType": "log",
  689. "props": {}
  690. }
  691. },
  692. "topo": {
  693. "sources": ["demo"],
  694. "edges": {
  695. "demo": ["log"]
  696. }
  697. }
  698. }`,
  699. err: fmt.Errorf("parse source demo with map[sourceName:unknown sourceType:stream] error: fail to get stream unknown, please check if stream is created"),
  700. },
  701. {
  702. name: "wrong source type",
  703. graph: `{
  704. "nodes": {
  705. "demo": {
  706. "type": "source",
  707. "nodeType": "mqtt",
  708. "props": {
  709. "sourceType": "stream",
  710. "sourceName": "tableInPlanner"
  711. }
  712. },
  713. "log": {
  714. "type": "sink",
  715. "nodeType": "log",
  716. "props": {}
  717. }
  718. },
  719. "topo": {
  720. "sources": ["demo"],
  721. "edges": {
  722. "demo": ["log"]
  723. }
  724. }
  725. }`,
  726. err: fmt.Errorf("parse source demo with map[sourceName:tableInPlanner sourceType:stream] error: table tableInPlanner is not a stream"),
  727. },
  728. {
  729. name: "stream and table",
  730. graph: `{
  731. "nodes": {
  732. "demo": {
  733. "type": "source",
  734. "nodeType": "mqtt",
  735. "props": {
  736. "sourceType": "stream",
  737. "sourceName": "src1"
  738. }
  739. },
  740. "lookupT":{
  741. "type": "source",
  742. "nodeType": "memory",
  743. "props": {
  744. "sourceType": "table",
  745. "sourceName": "lookupT"
  746. }
  747. },
  748. "joinop": {
  749. "type": "operator",
  750. "nodeType": "join",
  751. "props": {
  752. "from": "src1",
  753. "joins": [
  754. {
  755. "name": "lookupT",
  756. "type": "inner",
  757. "on": "src1.deviceKind = lookupT.id"
  758. }
  759. ]
  760. }
  761. },
  762. "log": {
  763. "type": "sink",
  764. "nodeType": "log",
  765. "props": {}
  766. }
  767. },
  768. "topo": {
  769. "sources": ["demo", "lookupT"],
  770. "edges": {
  771. "demo": ["joinop"],
  772. "lookupT": ["joinop"],
  773. "joinop": ["log"]
  774. }
  775. }
  776. }`,
  777. err: nil,
  778. },
  779. {
  780. name: "wrong join stream name",
  781. graph: `{
  782. "nodes": {
  783. "demo": {
  784. "type": "source",
  785. "nodeType": "mqtt",
  786. "props": {
  787. "sourceType": "stream",
  788. "sourceName": "src1"
  789. }
  790. },
  791. "lookupT":{
  792. "type": "source",
  793. "nodeType": "memory",
  794. "props": {
  795. "sourceType": "table",
  796. "sourceName": "lookupT"
  797. }
  798. },
  799. "joinop": {
  800. "type": "operator",
  801. "nodeType": "join",
  802. "props": {
  803. "from": "demo",
  804. "joins": [
  805. {
  806. "name": "lookupT",
  807. "type": "inner",
  808. "on": "demo.deviceKind = lookupT.id"
  809. }
  810. ]
  811. }
  812. },
  813. "log": {
  814. "type": "sink",
  815. "nodeType": "log",
  816. "props": {}
  817. }
  818. },
  819. "topo": {
  820. "sources": ["demo", "lookupT"],
  821. "edges": {
  822. "demo": ["joinop"],
  823. "lookupT": ["joinop"],
  824. "joinop": ["log"]
  825. }
  826. }
  827. }`,
  828. err: fmt.Errorf("parse join joinop with map[from:demo joins:[map[name:lookupT on:demo.deviceKind = lookupT.id type:inner]]] error: join source demo is not a stream"),
  829. },
  830. {
  831. name: "stream and scan table",
  832. graph: `{
  833. "nodes": {
  834. "demo": {
  835. "type": "source",
  836. "nodeType": "mqtt",
  837. "props": {
  838. "sourceType": "stream",
  839. "sourceName": "src1"
  840. }
  841. },
  842. "lookupT":{
  843. "type": "source",
  844. "nodeType": "file",
  845. "props": {
  846. "sourceType": "table",
  847. "sourceName": "tableInPlanner"
  848. }
  849. },
  850. "joinop": {
  851. "type": "operator",
  852. "nodeType": "join",
  853. "props": {
  854. "from": "src1",
  855. "joins": [
  856. {
  857. "name": "lookupT",
  858. "type": "inner",
  859. "on": "demo.deviceKind = lookupT.id"
  860. }
  861. ]
  862. }
  863. },
  864. "log": {
  865. "type": "sink",
  866. "nodeType": "log",
  867. "props": {}
  868. }
  869. },
  870. "topo": {
  871. "sources": ["demo", "lookupT"],
  872. "edges": {
  873. "demo": ["joinop"],
  874. "lookupT": ["joinop"],
  875. "joinop": ["log"]
  876. }
  877. }
  878. }`,
  879. err: fmt.Errorf("parse join joinop with map[from:src1 joins:[map[name:lookupT on:demo.deviceKind = lookupT.id type:inner]]] error: do not support scan table [tableInPlanner] yet"),
  880. },
  881. }
  882. for _, tc := range testCases {
  883. t.Run(tc.name, func(t *testing.T) {
  884. rg := &api.RuleGraph{}
  885. err := json.Unmarshal([]byte(tc.graph), rg)
  886. if err != nil {
  887. t.Error(err)
  888. return
  889. }
  890. _, err = PlanByGraph(&api.Rule{
  891. Triggered: false,
  892. Id: "test",
  893. Graph: rg,
  894. Options: &api.RuleOption{
  895. IsEventTime: false,
  896. LateTol: 1000,
  897. Concurrency: 1,
  898. BufferLength: 1024,
  899. SendMetaToSink: false,
  900. SendError: true,
  901. Qos: api.AtMostOnce,
  902. CheckpointInterval: 300000,
  903. },
  904. })
  905. if tc.err == nil {
  906. if err != nil {
  907. t.Errorf("error mismatch:\n exp=%s\n got=%s\n\n", tc.err, err)
  908. }
  909. return
  910. }
  911. if !reflect.DeepEqual(tc.err.Error(), err.Error()) {
  912. t.Errorf("error mismatch:\n exp=%s\n got=%s\n\n", tc.err, err)
  913. }
  914. })
  915. }
  916. }