Hitachi Vantara Pentaho Community Forums
Results 1 to 3 of 3

Thread: Rule Executor - comparing two incoming field values

  1. #1
    Join Date
    Nov 2016
    Posts
    20

    Question Rule Executor - comparing two incoming field values

    Hi there,

    How do I get Rules Executor (drools) to compare two incoming stream fields?

    I have 3 incoming fields:
    * update_type
    * field_value_int
    * current_bedrooms

    Pseudocode for my rule is:
    WHEN
    update_type = "BED" AND field_value_int = current_bedrooms
    THEN
    [set output_topic, reason, rule_triggered]

    It's the "WHEN" part of my rule that is the problem. Simple as it sounds, I can't figure out how to compare two fields!

    Here's is my latest attempt:
    Code:
    rule "Update request is redundant (BED)"    
    dialect "mvel"
        when 
            Column ( name == "update_type", payload == "BED" )
            $field_value_int : Column ( name == "field_value_int")
            $current_bedrooms : Column ( name == "current_bedrooms")
            $field_value_int == $current_bedrooms
        then
            Column outputTopic = new Column();
            outputTopic.name = "output_topic"
            outputTopic.type = String.class
            outputTopic.payload = "Rejected"
            
            Column reason = new Column();
            reason.name = "reason"
            reason.type = String.class
            reason.payload = "The update request details are the same as current."
            
            Column ruleTriggered = new Column();
            ruleTriggered.name = "rule_triggered"
            ruleTriggered.type = String.class
            ruleTriggered.payload = drools.getRule().getName()
            
            insert(outputTopic);
            insert(reason);
            insert(ruleTriggered);
    end
    Can anyone point out where I am going wrong?


    Cheers,

    Stanbridge

  2. #2
    Join Date
    Jun 2012
    Posts
    5,534

    Default

    Shouldn't your LHS be a single complex predicate?

    Code:
    // ...
        when 
            Column ( name == "update_type", payload == "BED" ) and
            Column ( name == "field_value_int", $int : payload ) and
            Column ( name == "current_bedrooms", payload == $int )
        then
    // ...
    So long, and thanks for all the fish.

  3. #3
    Join Date
    Nov 2016
    Posts
    20

    Default

    Once again, you've put me on the right path! That works a treat, thanks Marabu!!!

    (Time for me to get back to reading up on Drools too)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.