Hybrid rule engines (rulesfest 2010)

Geoffrey De Smet
Geoffrey De SmetSoftware developer at Red Hat
●
The SkyNet funding bill is passed.
●
The system goes online on August 4th, 1997.
●
Human decisions are removed from strategic defense.
●
SkyNet begins to learn at a geometric rate.
●
It becomes self-aware at 2:14am Eastern time, August
29th
●
In a panic, they try to pull the plug.
●
And, Skynet fights back
Mark Proctor
Co-Creator
Project Lead
2
Topics
 Rule engines suck
 Hybrid Rule Engines
● Reaction Rules
● Query Rules
● Functional Support
 Conccurrency and Parallization
3
Because Not Everyone
Is As Smart As He Is
4
Fact of Life
Fact of Life
5
Fact of Life
Rule Engines Suck
6
Problems
 Limitations of expressiveness
● Inability to cleanly say what you want declaratively
● Verbosity, Control/Semaphores, Emulation
 Execution flow and ordering
● Conflict Resolution is not easy
● Modules (Agenda Groups), RuleFlow Groups
● Concurrency
 Ambiguity
● Rule Recursion
● Unwanted rules
 Extensibility and Pluggability
 Transactions and isolation
 Design Patterns
7
Sequencing
select * from Light l where
seq(l.color) { start: "orange" ->
"red" -> end } )
(Light seq( (color, category)
(start: "orange", "x" ->
"green", “y” -> end ) ) )
8
Sequencing
select * from Light l where
seq(l.color, l.category) {
start: "red", "x" ->
("green", "x" ||
"yellow", "y") -> mid
start: "red", "y" -> mid
mid: "blue", "z" -> end} )
(Light seq( (color, category)
(start: "red", "x" ->
("green", "x" ||
"yellow", "y") -> mid
start: "red", "y" -> mid
mid: "blue", "z" -> end) ) )
9
Life Mission
Life Mission
10
Life Mission
HMS Suckage
Destroyer
11
Let Me Count the Ways
12
Let Me Count the Ways
13
Let Me Count the Ways
14
Let Me Count the Ways
15
Archaeology Expedition
16
The Future
 Full Hybrid Engine
● http://community.jboss.org/wiki/DroolsLanguageEnhancements
●Nested Objects
●Casting Nested Objects
●Positional Constraints
●POSL - Positional-Slotted
Language
●Method Calls
●Maps and Arrays
(Collections)
●Collections and XPath like
filtering
●Free form Expressions
●Managed Object Graphs
(MOGS)
●Nested Patterns and Queries
●Queries and Unification
●Ontologies and Relations via
●Query Based Backward
Chaining with POSL
●Triples with Hybrid POJO Graph
Notation.
●Escapes for Dialects
●Accumulate Improvements to
Support Haskell map/fold/filter
and MVEL projection/fold
● Otherwise
● Branch (Labelled Else)
● Rule Execution Groups
● Rule Dependency Meta-Rule
Language
●Parallel Meta-Rule Language
● Field Versioning
●Logical Closures/OnFalse
●Opportunistic Backward
Chaining, Lazy Field/Object
Values
●...
Hybrid Rule Engine
18
Hyrbid Rule Engine
 Rule Based Programming
● Reactive rules
● Forward Chaining
● Production Rules: Drools, Clips, OPSJ, Jess, JRules
● Query rules
● Backward Chaining
● Prolog: Prova, Open Prolog, SWI Prolog, Visual Prolog
 Functional Programming
● Haskell/Lisp
Reactive Rules
20
D a te d a te
d o u b le a m o u n t
in t ty p e
lo n g a c c o u n tN o
C a s h flo w
lo n g a c c o u n tN o
d o u b le b a la n c e
A c c o u n t
D a te s ta r t
D a te e n d
A c c o u n tin g P e r io d
Tables
21
Account
accountNo balance
1 0
increase balance for AccountPeriod Credits decrease balance for AccountPeriod Debits
AccountingPeriod
start end
01-Jan-07 31-Mar-07
trigger : acc.balance += cf.amount
Account
balance
1 -25
accountNo
Creating Views with Triggers
date amount type
12-Jan-07 100 CREDIT 1
2-Feb-07 200 DEBIT 1
18-May-07 50 CREDIT 1
9-Mar-07 75 CREDIT 1
CashFlow
accountNo
date amount type
12-Jan-07 100 CREDIT
9-Mar-07 75 CREDIT
CashFlow
date amount type
2-Feb-07 200 DEBIT
CashFlow
trigger : acc.balance -= cf.amounttrigger : acc.balance += cf.amount
select * from Account acc,
Cashflow cf, AccountPeriod ap
where acc.accountNo == cf.accountNo
and
cf.type == CREDIT
cf.date >= ap.start and
cf.date <= ap.end
trigger : acc.balance -= cf.amount
select * from Account acc,
Cashflow cf, AccountPeriod ap
where acc.accountNo == cf.accountNo
and
cf.type == DEBIT
cf.date >= ap.start and
cf.date <= ap.end
22
date amount type
12-Jan-07 100 CREDIT 1
2-Feb-07 200 DEBIT 1
18-May-07 50 CREDIT 1
9-Mar-07 75 CREDIT 1
CashFlow
accountNo
Account
accountNo balance
1 0
start end
01-Apr-07 30-Jun-07
AccountingPeriod
date amount type
18-May-07 50 CREDIT
CashFlow
date amount type
CashFlow
balance
1 25
accountNo
Creating Views with Triggers
increase balance for AccountPeriod Credits decrease balance for AccountPeriod Debits
trigger : acc.balance += cf.amount
select * from Account acc,
Cashflow cf, AccountPeriod ap
where acc.accountNo == cf.accountNo
and
cf.type == CREDIT
cf.date >= ap.start and
cf.date <= ap.end
trigger : acc.balance -= cf.amount
select * from Account acc,
Cashflow cf, AccountPeriod ap
where acc.accountNo == cf.accountNo
and
cf.type == DEBIT
cf.date >= ap.start and
cf.date <= ap.end
23
A c c o u n t A c c o u n tin g P e r io d C a s h flo w
v ie w 1 v ie w 2
m a in v ie w
T a b le s
V ie w s
V ie w
A c c o u n t A c c o u n tin g P e r io d C a s h flo w
r u le 1 r u le 2
a g e n d a
O b je c t T y p e s
R u le s
a g e n d a
Rules as Views
24
(rule “increase balance for AccountPeriod Credits”
?ap <- (AccountPeriod)
?acc <- (Account (?accountNo accountNo ) )
(CashFlow { type == CREDIT,
accountNo == ?accountNo,
date >= ?ap.start && <= ?ap.end }
(?amount amount ) )
->
(bind ?acc (balance (+ 1 ?amount) ) )
)
select * from Account acc,
Cashflow cf, AccountPeriod ap
where acc.accountNo == cf.accountNo and
cf.type == CREDIT
cf.date >= ap.start and
cf.date <= ap.end
trigger : acc.balance += cf.amount
SQL / S-Expression Rule
25
rule “increase balance for AccountPeriod Credits”
when
ap : AccountPeriod()
acc : Account( $accountNo : accountNo )
CashFlow( type == CREDIT,
accountNo == $accountNo,
date >= ap.start && date <= ap.end,
$amount : amount )
then
acc.balance += $amount;
end
DRL
26
rule “Print blance for AccountPeriod”
salience -50
when
ap : AccountPeriod()
acc : Account()
then
System.out.println( acc.accountNo + “ : “ acc.balance );
end
Salience
Agenda
1 increase balance
arbitrary2 decrease balance
3 increase balance
4 print balance
Conflict Resolution with Salience
Query Rules
28
Same Author Rule
rule sameAuthor
$i1 : Item( )
$i2 : Item( author == $i1.author )
end
select * from
Item i1, Item i2,
where
i1.author == i2.author
i1 != i2
create query(String author)
select * from
Item i1, Item i2,
where
i1.author == author
i1.author == i2.author
i1 != i2
29
Same Author Query
query sameAuthor (Item $i1, Item $i2)
$i1 : Item( )
$i2 : Item( this != $i1, author == $i1.author )
end
Book Author
Poems Tom
Songs Tom
Cars Bob
Largs Cars Jane
 sameAuthor( item1, item2 )
● both are output vars
● returns full cross product
 sameAuthor(new Item( new Book( Poems), item )
● Item1 is input var
● Item2 is output var
● Returns Songs by Tom
30
Recommendations
query sameSubject (Item $i1, Item $i2)
$i1 : Item( )
$i2 : Item( this != $i1 )
exists( $s1 : ItemSubject(item == $i1)
ItemSubject(item == $i2, subject == $s1.subject)
)
end
query recommended (Item $i1, Item $i2)
$i1 : Item( )
$p1 : Purchase( item == $i1 )
$c : Customer( this == $p.customer )
$p2 : Purchase( customer == $c, item != $i1 )
$i2 : Item( this == $p2.item )
( ?sameAuthor( $i1, $i2 ) or ?sameSubject( $i1, $i2 ) )
end
query sameAuthor (Item $i1, Item $i2)
$i1 : Item( )
$i2 : Item( this != $i1, author == $i1.author )
end
'?' incalls the query.
Bound vars are inputs.
Unbound vars are outputs.
Functional Programming
32
Functional Programming
Basic Haskel Groups
 List Processing
 Arithmetic, Higher Order Functions
 Tuples
Arithmatic
 Average
● avg [12, 4, 5, 9]
● 7.5
33
Functional Programming
Higher Order Functions
Map, Fold and Filter
 Fold
● Fold (+) 0 [1, 2, 3, 4]
● 10
 Map
● map (*2) [1, 2, 3]
● [2, 4, 6, 8]
 Filter
● Filter (>2) [3, 4, 5]
34
rule "init" when
then
insert( new Acc( "sum red buses",
STAGE.ACC_START ) );
end
rule "action" when
$b : Bus( colour == "red" )
$acc : Acc( name == "sum red buses",
stage == STAGE.ACC_START )
then
$acc.sum( $b.takings ); // do not notify the engine
end
Accumulate CE
35
Accumulate CE
rule "result" when
salience -5
$acc : Acc( name == "sum red buses",
stage == STAGE.ACC_START )
then
modify( $acc ) { stage = STAGE.ACC_END };
End
rule "evaluate result" when
$acc : Acc( sum > 100,
stage == STAGE.ACC_END )
then
print "sum is “ + $acc.sum;
end
36
Functional Support
select
c, sum(bi.price) t
from
Customer c, BaskteItem bi
where
bi.customer == c
group by
c
?c <- (Customer )
acc( ?bi <- (BasketItem {customer == ?c} )
?t <- (sum ?bi.price) )
37
Functional Support
select
c, bi.type type, sum(bi.price) t
from
Customer c, BaskteItem bi
where
bi.customer == c
group
by c , bi.type
?c <- (Customer)
acc( ?bi <- (BasketItem {customer == ?c} )
?type <- (distinct ?bi.price) )
acc( ?bi <- (BasketItem {customer == ?c,
type == ?type} )
?t <- (sum ?bi.price) )
38
DRL
select
c, sum(bi.price) t
from
Customer c, BaskteItem bi
where
bi.customer == c
group by
c
$c : Customer()
acc( $bi : BasketItem( customer == $c );
$t : sum( $bi.price) )
39
Nested
acc( acc( $c : Customer()
$bi : BasketItem( customer == $c );
$t : sum( $bi.price) );
$a : avg( $t ) )
 Average the summed expenditure for all customers
40
Nested
$c : Customer()
acc( $bi : BasketItem() from
acc( $bi : BasketItem( customer == $c );
filter( $bi, $bi.price > 100) );
$a : avg( $bi.price ) )
 Average price for all item with a price over 100
Patterns can also filter “from”
an acc result.
All Together Now
42
Shopping Basket
43
Discount Alert
rule "alert customer to potential band change"
$c : Customer()
acc( $bi : BasketItem(customer == $c )
$s : sum( $bi.price ) )
acc( $bi : BasketItem(customer == $c )
?recommended( $bi.item, $rec )
$rs : sum( $rec.price ) )
$b : Band( this != $c.band, min >= ($s + $rs),
max <= ($s + $rs) )
then
println( “If you buy all items and all recommendations,
you move up a band with a new
discount of “ + $b.discount );
end
'$rec' is unbound
and thusan output var
Concurrency and Parallelization
45
C : Customer
[John,
Sally]
B : BasketItem
b.customer == c
[John,
Sally]
Simple Rete Rule
46
Simple Rete Rule
 insert “sally”
● propagate to join
● Return as right memory is empty
 insert “john”
● propagate to join
● Return as right memory is empty
47
Simple Rete Rule
C : Customer
[John,
Sally]
[BasktItem( John, Book, Cars ),]
[John,
Sally]
[ [John,BasktItem( John, Book, Cars )] ]
B : BasketItem
b.customer == c
[BasktItem( John, Book, Cars )]
Token
Node node
Token leftParent
Token rightParent
List<Token> children
48
Simple Rete Rule
 Insert BasktItem( John, Book, Cars )
● propagate to join
● foreach( l-token : left-memory )
if ( r-token.customer == l-token )
create new Token and propagate
[John, BasktItem( John, Book, Cars )]
Token
Node node
Token leftParent
Token rightParent
List<Token> children
49
Simple Rete Rule
C : Customer
[John,
Sally]
[BasktItem( John, Book, Cars ),
BasktItem( John, Book, Poems ),
BasktItem( Sally, Book, Cinema )]
[John,
Sally]
[ [John,BasktItem( John, Book, Cars )],
[John, BasktItem( John, Book, Poems ) ],
[Sally, BasktItem( Sally, Book, Cinema ) ] ]
B : BasketItem
b.customer == c
[BasktItem( John, Book, Cars ),
BasktItem( John, Book, Poems ),
BasktItem( Sally, Book, Cinema )]
50
1 Rule 3 Joins
51
3 Rules 3 Joins
52
Gator Networks
53
Partitioning for Parellelization
54
Task Oriented
 Submit each Token propagation to Executor pool
● The join node is now an executable job
 Wins
● Only the node is locked, allowing a “pipeline”
● Possible to lock only the current index bucket
● Solves recursive query problem of large stack frames
 Loses
● Only a small amount of time in each node
● Each node repeatedly locked and scheduled, for a single WM
action, due to tree “to leaf” traversal
● Previous papers show increases for only some use cases
● Network thrashing for subnetworks on accumulate
55
Subnetwork Thrashing
$c : Customer()
acc( $b : BasketItem(customer == $c )
$d : Discount( type == $b.type);
$s : sum( $b.price * $d.multiplier ) )
Band( this != $c.band, min >= $s, max <= $s )
56
Set Oriented
 Propagate Collections instead of Tokens
● Left Input trigger
● Iterate right memory create a collection of all matching right
tokens
● Note multi-dimesional array of 1
● [[l1[r1, r2, r3]]]
● Right Input trigger
● Iterate left memory create a collection of all left joins
● Note multi-dimensional array for each left token
● [ [l1, r1],
[l2, r1]
[l3, r1] ]
Token
Node node
Token leftParent
Token rightParent
List<Token> children
57
Set Oriented
 Wins
● More work done in a node
● scalable task scheduling
● Less indirection so better statement execution
● All the work for that node done for that WM action in one task
● Single network pass, so nodes locked just once per WM action
● Avoids repeatedly creating and destroying method stack
frames
● Avoids sub network thrashing
 Loses
● More complex algorithm
● Especially on “collection” merging
58
MVCC
 Modifies
● Clone + new values and current transaction id
● Existing instance still there with older transaction id
● Node uses constraint to join with correct version
 Isolation
● Scoped to rule or rule-group
● Scoped rule(s) see new data, others old
● Non blocking so reads (joins) can still continue
 Fully Concurrent safe Queries
● Queries leave no state in join
● Node joins with correct instance, based on transaction id
59
Questions?Questions?
• Dave Bowman: All right, HAL; I'll go in
through the emergency airlock.
• HAL: Without your space helmet, Dave,
you're going to find that rather difficult.
• Dave Bowman: HAL, I won't argue with
you anymore! Open the doors!
• HAL: Dave, this conversation can serve
no purpose anymore. Goodbye.
Joshua: Greetings, Professor Falken.
Stephen Falken: Hello, Joshua.
Joshua: A strange game. The only
winning move is not to play. How
about a nice game of chess?
1 of 59

Recommended

2011-03-29 London - drools by
2011-03-29 London - drools2011-03-29 London - drools
2011-03-29 London - droolsGeoffrey De Smet
1.6K views87 slides
Developing applications with rules, workflow and event processing (it@cork 2010) by
Developing applications with rules, workflow and event processing (it@cork 2010)Developing applications with rules, workflow and event processing (it@cork 2010)
Developing applications with rules, workflow and event processing (it@cork 2010)Geoffrey De Smet
2.5K views100 slides
JBoss World 2011 - Drools by
JBoss World 2011 - DroolsJBoss World 2011 - Drools
JBoss World 2011 - DroolsGeoffrey De Smet
1.7K views89 slides
Drools Expert and Fusion Intro : London 2012 by
Drools Expert and Fusion Intro  : London 2012Drools Expert and Fusion Intro  : London 2012
Drools Expert and Fusion Intro : London 2012Mark Proctor
5.6K views57 slides
Pushing the rule engine to its limits with drools planner (parisjug 2010-11-09) by
Pushing the rule engine to its limits with drools planner (parisjug 2010-11-09)Pushing the rule engine to its limits with drools planner (parisjug 2010-11-09)
Pushing the rule engine to its limits with drools planner (parisjug 2010-11-09)Geoffrey De Smet
6.1K views49 slides
Buenos Aires Drools Expert Presentation by
Buenos Aires Drools Expert PresentationBuenos Aires Drools Expert Presentation
Buenos Aires Drools Expert PresentationMark Proctor
1.7K views63 slides

More Related Content

What's hot

Justjava 2007 Arquitetura Java EE Paulo Silveira, Phillip Calçado by
Justjava 2007 Arquitetura Java EE Paulo Silveira, Phillip CalçadoJustjava 2007 Arquitetura Java EE Paulo Silveira, Phillip Calçado
Justjava 2007 Arquitetura Java EE Paulo Silveira, Phillip CalçadoPaulo Silveira
1.3K views53 slides
Introduction to Drools by
Introduction to DroolsIntroduction to Drools
Introduction to Droolsgiurca
3.9K views22 slides
Design Patterns Reconsidered by
Design Patterns ReconsideredDesign Patterns Reconsidered
Design Patterns ReconsideredAlex Miller
1.7K views55 slides
T3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTR by
T3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTRT3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTR
T3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTRDavid Gómez García
1.3K views46 slides
Singletons in PHP - Why they are bad and how you can eliminate them from your... by
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...go_oh
43.5K views53 slides
OS_Ch8 by
OS_Ch8OS_Ch8
OS_Ch8Supriya Shrivastava
580 views41 slides

What's hot(20)

Justjava 2007 Arquitetura Java EE Paulo Silveira, Phillip Calçado by Paulo Silveira
Justjava 2007 Arquitetura Java EE Paulo Silveira, Phillip CalçadoJustjava 2007 Arquitetura Java EE Paulo Silveira, Phillip Calçado
Justjava 2007 Arquitetura Java EE Paulo Silveira, Phillip Calçado
Paulo Silveira1.3K views
Introduction to Drools by giurca
Introduction to DroolsIntroduction to Drools
Introduction to Drools
giurca3.9K views
Design Patterns Reconsidered by Alex Miller
Design Patterns ReconsideredDesign Patterns Reconsidered
Design Patterns Reconsidered
Alex Miller1.7K views
T3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTR by David Gómez García
T3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTRT3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTR
T3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTR
Singletons in PHP - Why they are bad and how you can eliminate them from your... by go_oh
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...
go_oh43.5K views
Webinar: Building Your First App in Node.js by MongoDB
Webinar: Building Your First App in Node.jsWebinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.js
MongoDB633 views
PostgreSQL Open SV 2018 by artgillespie
PostgreSQL Open SV 2018PostgreSQL Open SV 2018
PostgreSQL Open SV 2018
artgillespie166 views
MongoDB World 2016: Deciphering .explain() Output by MongoDB
MongoDB World 2016: Deciphering .explain() OutputMongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() Output
MongoDB2.3K views
Distributed Search in Riak - Integrating Search in a NoSQL Database: Presente... by Lucidworks
Distributed Search in Riak - Integrating Search in a NoSQL Database: Presente...Distributed Search in Riak - Integrating Search in a NoSQL Database: Presente...
Distributed Search in Riak - Integrating Search in a NoSQL Database: Presente...
Lucidworks819 views
V8 hidden class and inline cache by Fanis Prodromou
V8 hidden class and inline cacheV8 hidden class and inline cache
V8 hidden class and inline cache
Fanis Prodromou459 views

Similar to Hybrid rule engines (rulesfest 2010)

What's new in Drools 6 - London JBUG 2013 by
What's new in Drools 6 - London JBUG 2013What's new in Drools 6 - London JBUG 2013
What's new in Drools 6 - London JBUG 2013Mark Proctor
3.4K views104 slides
Drools 6.0 (Red Hat Summit) by
Drools 6.0 (Red Hat Summit)Drools 6.0 (Red Hat Summit)
Drools 6.0 (Red Hat Summit)Mark Proctor
37.4K views189 slides
Advanced SQL For Data Scientists by
Advanced SQL For Data ScientistsAdvanced SQL For Data Scientists
Advanced SQL For Data ScientistsDatabricks
412 views29 slides
Compose Async with RxJS by
Compose Async with RxJSCompose Async with RxJS
Compose Async with RxJSKyung Yeol Kim
5.7K views178 slides
Love Your Database Railsconf 2017 by
Love Your Database Railsconf 2017Love Your Database Railsconf 2017
Love Your Database Railsconf 2017gisborne
733 views88 slides
Drooling for drools (JBoss webex) by
Drooling for drools (JBoss webex)Drooling for drools (JBoss webex)
Drooling for drools (JBoss webex)Geoffrey De Smet
1.8K views88 slides

Similar to Hybrid rule engines (rulesfest 2010)(20)

What's new in Drools 6 - London JBUG 2013 by Mark Proctor
What's new in Drools 6 - London JBUG 2013What's new in Drools 6 - London JBUG 2013
What's new in Drools 6 - London JBUG 2013
Mark Proctor3.4K views
Drools 6.0 (Red Hat Summit) by Mark Proctor
Drools 6.0 (Red Hat Summit)Drools 6.0 (Red Hat Summit)
Drools 6.0 (Red Hat Summit)
Mark Proctor37.4K views
Advanced SQL For Data Scientists by Databricks
Advanced SQL For Data ScientistsAdvanced SQL For Data Scientists
Advanced SQL For Data Scientists
Databricks412 views
Love Your Database Railsconf 2017 by gisborne
Love Your Database Railsconf 2017Love Your Database Railsconf 2017
Love Your Database Railsconf 2017
gisborne733 views
Drooling for drools (JBoss webex) by Geoffrey De Smet
Drooling for drools (JBoss webex)Drooling for drools (JBoss webex)
Drooling for drools (JBoss webex)
Geoffrey De Smet1.8K views
Refactoring at Large by Danilo Sato
Refactoring at LargeRefactoring at Large
Refactoring at Large
Danilo Sato8.1K views
Query Optimization & How to interpret query execution plan by Amol Barewar
Query Optimization & How to interpret query  execution planQuery Optimization & How to interpret query  execution plan
Query Optimization & How to interpret query execution plan
Amol Barewar2K views
Performance measurement and tuning by AOE
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuning
AOE 1.4K views
Smarter Together - Bringing Relational Algebra, Powered by Apache Calcite, in... by Julian Hyde
Smarter Together - Bringing Relational Algebra, Powered by Apache Calcite, in...Smarter Together - Bringing Relational Algebra, Powered by Apache Calcite, in...
Smarter Together - Bringing Relational Algebra, Powered by Apache Calcite, in...
Julian Hyde1.6K views
Distributed Real-Time Stream Processing: Why and How 2.0 by Petr Zapletal
Distributed Real-Time Stream Processing:  Why and How 2.0Distributed Real-Time Stream Processing:  Why and How 2.0
Distributed Real-Time Stream Processing: Why and How 2.0
Petr Zapletal5.5K views
So S.O.L.I.D Fu - Designing Better Code by Neil Crookes
So S.O.L.I.D Fu - Designing Better CodeSo S.O.L.I.D Fu - Designing Better Code
So S.O.L.I.D Fu - Designing Better Code
Neil Crookes223 views
Drools 6.0 (CamelOne 2013) by Mark Proctor
Drools 6.0 (CamelOne 2013)Drools 6.0 (CamelOne 2013)
Drools 6.0 (CamelOne 2013)
Mark Proctor1.4K views
Digital analytics with R - Sydney Users of R Forum - May 2015 by Johann de Boer
Digital analytics with R - Sydney Users of R Forum - May 2015Digital analytics with R - Sydney Users of R Forum - May 2015
Digital analytics with R - Sydney Users of R Forum - May 2015
Johann de Boer1.5K views
Performance measurement and tuning by AOE
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuning
AOE2.3K views
Paper Reading: Pessimistic Cardinality Estimation by PingCAP
Paper Reading: Pessimistic Cardinality EstimationPaper Reading: Pessimistic Cardinality Estimation
Paper Reading: Pessimistic Cardinality Estimation
PingCAP222 views

More from Geoffrey De Smet

Drools planner - 2012-10-23 IntelliFest 2012 by
Drools planner - 2012-10-23 IntelliFest 2012Drools planner - 2012-10-23 IntelliFest 2012
Drools planner - 2012-10-23 IntelliFest 2012Geoffrey De Smet
1.4K views83 slides
What is Drools, Guvnor and Planner? 2012 02-17 Brno Dev Conference by
What is Drools, Guvnor and Planner? 2012 02-17 Brno Dev ConferenceWhat is Drools, Guvnor and Planner? 2012 02-17 Brno Dev Conference
What is Drools, Guvnor and Planner? 2012 02-17 Brno Dev ConferenceGeoffrey De Smet
2.6K views87 slides
2012 02-04 fosdem 2012 - drools planner by
2012 02-04 fosdem 2012 - drools planner2012 02-04 fosdem 2012 - drools planner
2012 02-04 fosdem 2012 - drools plannerGeoffrey De Smet
1.5K views99 slides
JUDCon London 2011 - Bin packing with drools planner by example by
JUDCon London 2011 - Bin packing with drools planner by exampleJUDCon London 2011 - Bin packing with drools planner by example
JUDCon London 2011 - Bin packing with drools planner by exampleGeoffrey De Smet
2.8K views93 slides
Drools Planner webinar (2011-06-15): Drools Planner optimizes automated planning by
Drools Planner webinar (2011-06-15): Drools Planner optimizes automated planningDrools Planner webinar (2011-06-15): Drools Planner optimizes automated planning
Drools Planner webinar (2011-06-15): Drools Planner optimizes automated planningGeoffrey De Smet
3.1K views53 slides
Applying CEP Drools Fusion - Drools jBPM Bootcamps 2011 by
Applying CEP Drools Fusion - Drools jBPM Bootcamps 2011Applying CEP Drools Fusion - Drools jBPM Bootcamps 2011
Applying CEP Drools Fusion - Drools jBPM Bootcamps 2011Geoffrey De Smet
5.1K views42 slides

More from Geoffrey De Smet(18)

Drools planner - 2012-10-23 IntelliFest 2012 by Geoffrey De Smet
Drools planner - 2012-10-23 IntelliFest 2012Drools planner - 2012-10-23 IntelliFest 2012
Drools planner - 2012-10-23 IntelliFest 2012
Geoffrey De Smet1.4K views
What is Drools, Guvnor and Planner? 2012 02-17 Brno Dev Conference by Geoffrey De Smet
What is Drools, Guvnor and Planner? 2012 02-17 Brno Dev ConferenceWhat is Drools, Guvnor and Planner? 2012 02-17 Brno Dev Conference
What is Drools, Guvnor and Planner? 2012 02-17 Brno Dev Conference
Geoffrey De Smet2.6K views
2012 02-04 fosdem 2012 - drools planner by Geoffrey De Smet
2012 02-04 fosdem 2012 - drools planner2012 02-04 fosdem 2012 - drools planner
2012 02-04 fosdem 2012 - drools planner
Geoffrey De Smet1.5K views
JUDCon London 2011 - Bin packing with drools planner by example by Geoffrey De Smet
JUDCon London 2011 - Bin packing with drools planner by exampleJUDCon London 2011 - Bin packing with drools planner by example
JUDCon London 2011 - Bin packing with drools planner by example
Geoffrey De Smet2.8K views
Drools Planner webinar (2011-06-15): Drools Planner optimizes automated planning by Geoffrey De Smet
Drools Planner webinar (2011-06-15): Drools Planner optimizes automated planningDrools Planner webinar (2011-06-15): Drools Planner optimizes automated planning
Drools Planner webinar (2011-06-15): Drools Planner optimizes automated planning
Geoffrey De Smet3.1K views
Applying CEP Drools Fusion - Drools jBPM Bootcamps 2011 by Geoffrey De Smet
Applying CEP Drools Fusion - Drools jBPM Bootcamps 2011Applying CEP Drools Fusion - Drools jBPM Bootcamps 2011
Applying CEP Drools Fusion - Drools jBPM Bootcamps 2011
Geoffrey De Smet5.1K views
Drools New York City workshop 2011 by Geoffrey De Smet
Drools New York City workshop 2011Drools New York City workshop 2011
Drools New York City workshop 2011
Geoffrey De Smet1.7K views
2011-03-29 London - Decision tables in depth (Michael Anstis) by Geoffrey De Smet
2011-03-29 London - Decision tables in depth (Michael Anstis)2011-03-29 London - Decision tables in depth (Michael Anstis)
2011-03-29 London - Decision tables in depth (Michael Anstis)
Geoffrey De Smet4K views
2011-03-29 London - Why do I need the guvnor BRMS? by Geoffrey De Smet
2011-03-29 London - Why do I need the guvnor BRMS?2011-03-29 London - Why do I need the guvnor BRMS?
2011-03-29 London - Why do I need the guvnor BRMS?
Geoffrey De Smet5.4K views
2011-03-09 London - Drools Planner in a nutshell by Geoffrey De Smet
2011-03-09 London - Drools Planner in a nutshell2011-03-09 London - Drools Planner in a nutshell
2011-03-09 London - Drools Planner in a nutshell
Geoffrey De Smet1.3K views
2011-03-24 IDC - Adaptive and flexible processes (Mark Proctor) by Geoffrey De Smet
2011-03-24 IDC - Adaptive and flexible processes (Mark Proctor)2011-03-24 IDC - Adaptive and flexible processes (Mark Proctor)
2011-03-24 IDC - Adaptive and flexible processes (Mark Proctor)
Geoffrey De Smet1.1K views
st - demystifying complext event processing by Geoffrey De Smet
st - demystifying complext event processingst - demystifying complext event processing
st - demystifying complext event processing
Geoffrey De Smet1.2K views
Applying complex event processing (2010-10-11) by Geoffrey De Smet
Applying complex event processing (2010-10-11)Applying complex event processing (2010-10-11)
Applying complex event processing (2010-10-11)
Geoffrey De Smet1.8K views
Towards unified knowledge management platform (rulefest 2010) by Geoffrey De Smet
Towards unified knowledge management platform (rulefest 2010)Towards unified knowledge management platform (rulefest 2010)
Towards unified knowledge management platform (rulefest 2010)
Geoffrey De Smet1K views
2010 04-20 san diego bootcamp - drools planner - use cases by Geoffrey De Smet
2010 04-20 san diego bootcamp - drools planner - use cases2010 04-20 san diego bootcamp - drools planner - use cases
2010 04-20 san diego bootcamp - drools planner - use cases
Geoffrey De Smet1K views

Recently uploaded

Data Integrity for Banking and Financial Services by
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial ServicesPrecisely
29 views26 slides
Scaling Knowledge Graph Architectures with AI by
Scaling Knowledge Graph Architectures with AIScaling Knowledge Graph Architectures with AI
Scaling Knowledge Graph Architectures with AIEnterprise Knowledge
50 views15 slides
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensorssugiuralab
23 views15 slides
"Running students' code in isolation. The hard way", Yurii Holiuk by
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk Fwdays
24 views34 slides
"Surviving highload with Node.js", Andrii Shumada by
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada Fwdays
33 views29 slides
Future of AR - Facebook Presentation by
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentationssuserb54b561
22 views27 slides

Recently uploaded(20)

Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely29 views
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab23 views
"Running students' code in isolation. The hard way", Yurii Holiuk by Fwdays
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk
Fwdays24 views
"Surviving highload with Node.js", Andrii Shumada by Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays33 views
Future of AR - Facebook Presentation by ssuserb54b561
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
ssuserb54b56122 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman38 views
"Node.js Development in 2024: trends and tools", Nikita Galkin by Fwdays
"Node.js Development in 2024: trends and tools", Nikita Galkin "Node.js Development in 2024: trends and tools", Nikita Galkin
"Node.js Development in 2024: trends and tools", Nikita Galkin
Fwdays17 views
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf by Dr. Jimmy Schwarzkopf
STKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdfSTKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdf
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading... by The Digital Insurer
Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading...
Piloting & Scaling Successfully With Microsoft Viva by Richard Harbridge
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft Viva
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker48 views
Case Study Copenhagen Energy and Business Central.pdf by Aitana
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdf
Aitana17 views

Hybrid rule engines (rulesfest 2010)

  • 1. ● The SkyNet funding bill is passed. ● The system goes online on August 4th, 1997. ● Human decisions are removed from strategic defense. ● SkyNet begins to learn at a geometric rate. ● It becomes self-aware at 2:14am Eastern time, August 29th ● In a panic, they try to pull the plug. ● And, Skynet fights back Mark Proctor Co-Creator Project Lead
  • 2. 2 Topics  Rule engines suck  Hybrid Rule Engines ● Reaction Rules ● Query Rules ● Functional Support  Conccurrency and Parallization
  • 3. 3 Because Not Everyone Is As Smart As He Is
  • 5. 5 Fact of Life Rule Engines Suck
  • 6. 6 Problems  Limitations of expressiveness ● Inability to cleanly say what you want declaratively ● Verbosity, Control/Semaphores, Emulation  Execution flow and ordering ● Conflict Resolution is not easy ● Modules (Agenda Groups), RuleFlow Groups ● Concurrency  Ambiguity ● Rule Recursion ● Unwanted rules  Extensibility and Pluggability  Transactions and isolation  Design Patterns
  • 7. 7 Sequencing select * from Light l where seq(l.color) { start: "orange" -> "red" -> end } ) (Light seq( (color, category) (start: "orange", "x" -> "green", “y” -> end ) ) )
  • 8. 8 Sequencing select * from Light l where seq(l.color, l.category) { start: "red", "x" -> ("green", "x" || "yellow", "y") -> mid start: "red", "y" -> mid mid: "blue", "z" -> end} ) (Light seq( (color, category) (start: "red", "x" -> ("green", "x" || "yellow", "y") -> mid start: "red", "y" -> mid mid: "blue", "z" -> end) ) )
  • 11. 11 Let Me Count the Ways
  • 12. 12 Let Me Count the Ways
  • 13. 13 Let Me Count the Ways
  • 14. 14 Let Me Count the Ways
  • 16. 16 The Future  Full Hybrid Engine ● http://community.jboss.org/wiki/DroolsLanguageEnhancements ●Nested Objects ●Casting Nested Objects ●Positional Constraints ●POSL - Positional-Slotted Language ●Method Calls ●Maps and Arrays (Collections) ●Collections and XPath like filtering ●Free form Expressions ●Managed Object Graphs (MOGS) ●Nested Patterns and Queries ●Queries and Unification ●Ontologies and Relations via ●Query Based Backward Chaining with POSL ●Triples with Hybrid POJO Graph Notation. ●Escapes for Dialects ●Accumulate Improvements to Support Haskell map/fold/filter and MVEL projection/fold ● Otherwise ● Branch (Labelled Else) ● Rule Execution Groups ● Rule Dependency Meta-Rule Language ●Parallel Meta-Rule Language ● Field Versioning ●Logical Closures/OnFalse ●Opportunistic Backward Chaining, Lazy Field/Object Values ●...
  • 18. 18 Hyrbid Rule Engine  Rule Based Programming ● Reactive rules ● Forward Chaining ● Production Rules: Drools, Clips, OPSJ, Jess, JRules ● Query rules ● Backward Chaining ● Prolog: Prova, Open Prolog, SWI Prolog, Visual Prolog  Functional Programming ● Haskell/Lisp
  • 20. 20 D a te d a te d o u b le a m o u n t in t ty p e lo n g a c c o u n tN o C a s h flo w lo n g a c c o u n tN o d o u b le b a la n c e A c c o u n t D a te s ta r t D a te e n d A c c o u n tin g P e r io d Tables
  • 21. 21 Account accountNo balance 1 0 increase balance for AccountPeriod Credits decrease balance for AccountPeriod Debits AccountingPeriod start end 01-Jan-07 31-Mar-07 trigger : acc.balance += cf.amount Account balance 1 -25 accountNo Creating Views with Triggers date amount type 12-Jan-07 100 CREDIT 1 2-Feb-07 200 DEBIT 1 18-May-07 50 CREDIT 1 9-Mar-07 75 CREDIT 1 CashFlow accountNo date amount type 12-Jan-07 100 CREDIT 9-Mar-07 75 CREDIT CashFlow date amount type 2-Feb-07 200 DEBIT CashFlow trigger : acc.balance -= cf.amounttrigger : acc.balance += cf.amount select * from Account acc, Cashflow cf, AccountPeriod ap where acc.accountNo == cf.accountNo and cf.type == CREDIT cf.date >= ap.start and cf.date <= ap.end trigger : acc.balance -= cf.amount select * from Account acc, Cashflow cf, AccountPeriod ap where acc.accountNo == cf.accountNo and cf.type == DEBIT cf.date >= ap.start and cf.date <= ap.end
  • 22. 22 date amount type 12-Jan-07 100 CREDIT 1 2-Feb-07 200 DEBIT 1 18-May-07 50 CREDIT 1 9-Mar-07 75 CREDIT 1 CashFlow accountNo Account accountNo balance 1 0 start end 01-Apr-07 30-Jun-07 AccountingPeriod date amount type 18-May-07 50 CREDIT CashFlow date amount type CashFlow balance 1 25 accountNo Creating Views with Triggers increase balance for AccountPeriod Credits decrease balance for AccountPeriod Debits trigger : acc.balance += cf.amount select * from Account acc, Cashflow cf, AccountPeriod ap where acc.accountNo == cf.accountNo and cf.type == CREDIT cf.date >= ap.start and cf.date <= ap.end trigger : acc.balance -= cf.amount select * from Account acc, Cashflow cf, AccountPeriod ap where acc.accountNo == cf.accountNo and cf.type == DEBIT cf.date >= ap.start and cf.date <= ap.end
  • 23. 23 A c c o u n t A c c o u n tin g P e r io d C a s h flo w v ie w 1 v ie w 2 m a in v ie w T a b le s V ie w s V ie w A c c o u n t A c c o u n tin g P e r io d C a s h flo w r u le 1 r u le 2 a g e n d a O b je c t T y p e s R u le s a g e n d a Rules as Views
  • 24. 24 (rule “increase balance for AccountPeriod Credits” ?ap <- (AccountPeriod) ?acc <- (Account (?accountNo accountNo ) ) (CashFlow { type == CREDIT, accountNo == ?accountNo, date >= ?ap.start && <= ?ap.end } (?amount amount ) ) -> (bind ?acc (balance (+ 1 ?amount) ) ) ) select * from Account acc, Cashflow cf, AccountPeriod ap where acc.accountNo == cf.accountNo and cf.type == CREDIT cf.date >= ap.start and cf.date <= ap.end trigger : acc.balance += cf.amount SQL / S-Expression Rule
  • 25. 25 rule “increase balance for AccountPeriod Credits” when ap : AccountPeriod() acc : Account( $accountNo : accountNo ) CashFlow( type == CREDIT, accountNo == $accountNo, date >= ap.start && date <= ap.end, $amount : amount ) then acc.balance += $amount; end DRL
  • 26. 26 rule “Print blance for AccountPeriod” salience -50 when ap : AccountPeriod() acc : Account() then System.out.println( acc.accountNo + “ : “ acc.balance ); end Salience Agenda 1 increase balance arbitrary2 decrease balance 3 increase balance 4 print balance Conflict Resolution with Salience
  • 28. 28 Same Author Rule rule sameAuthor $i1 : Item( ) $i2 : Item( author == $i1.author ) end select * from Item i1, Item i2, where i1.author == i2.author i1 != i2 create query(String author) select * from Item i1, Item i2, where i1.author == author i1.author == i2.author i1 != i2
  • 29. 29 Same Author Query query sameAuthor (Item $i1, Item $i2) $i1 : Item( ) $i2 : Item( this != $i1, author == $i1.author ) end Book Author Poems Tom Songs Tom Cars Bob Largs Cars Jane  sameAuthor( item1, item2 ) ● both are output vars ● returns full cross product  sameAuthor(new Item( new Book( Poems), item ) ● Item1 is input var ● Item2 is output var ● Returns Songs by Tom
  • 30. 30 Recommendations query sameSubject (Item $i1, Item $i2) $i1 : Item( ) $i2 : Item( this != $i1 ) exists( $s1 : ItemSubject(item == $i1) ItemSubject(item == $i2, subject == $s1.subject) ) end query recommended (Item $i1, Item $i2) $i1 : Item( ) $p1 : Purchase( item == $i1 ) $c : Customer( this == $p.customer ) $p2 : Purchase( customer == $c, item != $i1 ) $i2 : Item( this == $p2.item ) ( ?sameAuthor( $i1, $i2 ) or ?sameSubject( $i1, $i2 ) ) end query sameAuthor (Item $i1, Item $i2) $i1 : Item( ) $i2 : Item( this != $i1, author == $i1.author ) end '?' incalls the query. Bound vars are inputs. Unbound vars are outputs.
  • 32. 32 Functional Programming Basic Haskel Groups  List Processing  Arithmetic, Higher Order Functions  Tuples Arithmatic  Average ● avg [12, 4, 5, 9] ● 7.5
  • 33. 33 Functional Programming Higher Order Functions Map, Fold and Filter  Fold ● Fold (+) 0 [1, 2, 3, 4] ● 10  Map ● map (*2) [1, 2, 3] ● [2, 4, 6, 8]  Filter ● Filter (>2) [3, 4, 5]
  • 34. 34 rule "init" when then insert( new Acc( "sum red buses", STAGE.ACC_START ) ); end rule "action" when $b : Bus( colour == "red" ) $acc : Acc( name == "sum red buses", stage == STAGE.ACC_START ) then $acc.sum( $b.takings ); // do not notify the engine end Accumulate CE
  • 35. 35 Accumulate CE rule "result" when salience -5 $acc : Acc( name == "sum red buses", stage == STAGE.ACC_START ) then modify( $acc ) { stage = STAGE.ACC_END }; End rule "evaluate result" when $acc : Acc( sum > 100, stage == STAGE.ACC_END ) then print "sum is “ + $acc.sum; end
  • 36. 36 Functional Support select c, sum(bi.price) t from Customer c, BaskteItem bi where bi.customer == c group by c ?c <- (Customer ) acc( ?bi <- (BasketItem {customer == ?c} ) ?t <- (sum ?bi.price) )
  • 37. 37 Functional Support select c, bi.type type, sum(bi.price) t from Customer c, BaskteItem bi where bi.customer == c group by c , bi.type ?c <- (Customer) acc( ?bi <- (BasketItem {customer == ?c} ) ?type <- (distinct ?bi.price) ) acc( ?bi <- (BasketItem {customer == ?c, type == ?type} ) ?t <- (sum ?bi.price) )
  • 38. 38 DRL select c, sum(bi.price) t from Customer c, BaskteItem bi where bi.customer == c group by c $c : Customer() acc( $bi : BasketItem( customer == $c ); $t : sum( $bi.price) )
  • 39. 39 Nested acc( acc( $c : Customer() $bi : BasketItem( customer == $c ); $t : sum( $bi.price) ); $a : avg( $t ) )  Average the summed expenditure for all customers
  • 40. 40 Nested $c : Customer() acc( $bi : BasketItem() from acc( $bi : BasketItem( customer == $c ); filter( $bi, $bi.price > 100) ); $a : avg( $bi.price ) )  Average price for all item with a price over 100 Patterns can also filter “from” an acc result.
  • 43. 43 Discount Alert rule "alert customer to potential band change" $c : Customer() acc( $bi : BasketItem(customer == $c ) $s : sum( $bi.price ) ) acc( $bi : BasketItem(customer == $c ) ?recommended( $bi.item, $rec ) $rs : sum( $rec.price ) ) $b : Band( this != $c.band, min >= ($s + $rs), max <= ($s + $rs) ) then println( “If you buy all items and all recommendations, you move up a band with a new discount of “ + $b.discount ); end '$rec' is unbound and thusan output var
  • 45. 45 C : Customer [John, Sally] B : BasketItem b.customer == c [John, Sally] Simple Rete Rule
  • 46. 46 Simple Rete Rule  insert “sally” ● propagate to join ● Return as right memory is empty  insert “john” ● propagate to join ● Return as right memory is empty
  • 47. 47 Simple Rete Rule C : Customer [John, Sally] [BasktItem( John, Book, Cars ),] [John, Sally] [ [John,BasktItem( John, Book, Cars )] ] B : BasketItem b.customer == c [BasktItem( John, Book, Cars )] Token Node node Token leftParent Token rightParent List<Token> children
  • 48. 48 Simple Rete Rule  Insert BasktItem( John, Book, Cars ) ● propagate to join ● foreach( l-token : left-memory ) if ( r-token.customer == l-token ) create new Token and propagate [John, BasktItem( John, Book, Cars )] Token Node node Token leftParent Token rightParent List<Token> children
  • 49. 49 Simple Rete Rule C : Customer [John, Sally] [BasktItem( John, Book, Cars ), BasktItem( John, Book, Poems ), BasktItem( Sally, Book, Cinema )] [John, Sally] [ [John,BasktItem( John, Book, Cars )], [John, BasktItem( John, Book, Poems ) ], [Sally, BasktItem( Sally, Book, Cinema ) ] ] B : BasketItem b.customer == c [BasktItem( John, Book, Cars ), BasktItem( John, Book, Poems ), BasktItem( Sally, Book, Cinema )]
  • 50. 50 1 Rule 3 Joins
  • 51. 51 3 Rules 3 Joins
  • 54. 54 Task Oriented  Submit each Token propagation to Executor pool ● The join node is now an executable job  Wins ● Only the node is locked, allowing a “pipeline” ● Possible to lock only the current index bucket ● Solves recursive query problem of large stack frames  Loses ● Only a small amount of time in each node ● Each node repeatedly locked and scheduled, for a single WM action, due to tree “to leaf” traversal ● Previous papers show increases for only some use cases ● Network thrashing for subnetworks on accumulate
  • 55. 55 Subnetwork Thrashing $c : Customer() acc( $b : BasketItem(customer == $c ) $d : Discount( type == $b.type); $s : sum( $b.price * $d.multiplier ) ) Band( this != $c.band, min >= $s, max <= $s )
  • 56. 56 Set Oriented  Propagate Collections instead of Tokens ● Left Input trigger ● Iterate right memory create a collection of all matching right tokens ● Note multi-dimesional array of 1 ● [[l1[r1, r2, r3]]] ● Right Input trigger ● Iterate left memory create a collection of all left joins ● Note multi-dimensional array for each left token ● [ [l1, r1], [l2, r1] [l3, r1] ] Token Node node Token leftParent Token rightParent List<Token> children
  • 57. 57 Set Oriented  Wins ● More work done in a node ● scalable task scheduling ● Less indirection so better statement execution ● All the work for that node done for that WM action in one task ● Single network pass, so nodes locked just once per WM action ● Avoids repeatedly creating and destroying method stack frames ● Avoids sub network thrashing  Loses ● More complex algorithm ● Especially on “collection” merging
  • 58. 58 MVCC  Modifies ● Clone + new values and current transaction id ● Existing instance still there with older transaction id ● Node uses constraint to join with correct version  Isolation ● Scoped to rule or rule-group ● Scoped rule(s) see new data, others old ● Non blocking so reads (joins) can still continue  Fully Concurrent safe Queries ● Queries leave no state in join ● Node joins with correct instance, based on transaction id
  • 59. 59 Questions?Questions? • Dave Bowman: All right, HAL; I'll go in through the emergency airlock. • HAL: Without your space helmet, Dave, you're going to find that rather difficult. • Dave Bowman: HAL, I won't argue with you anymore! Open the doors! • HAL: Dave, this conversation can serve no purpose anymore. Goodbye. Joshua: Greetings, Professor Falken. Stephen Falken: Hello, Joshua. Joshua: A strange game. The only winning move is not to play. How about a nice game of chess?