Uploaded image for project: 'JBRULES'
  1. JBRULES
  2. JBRULES-2781

Optimization for sub-attributes in LHS conditions

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more

    XMLWordPrintable

Details

    • Workaround Exists
    • Hide

      Instead of using the == operator, use explicit predicate (the "-> (<condition>) " construction).

      Show
      Instead of using the == operator, use explicit predicate (the "-> (<condition>) " construction).

    Description

      When building a simple rule, we discovered that the resulting "rete tree" did not reused some node conditions, dispite they are listed in the same order. After some different approaches we get to the expected tree using explicit predicates.

      Shouldn't both alternatives generate the same tree? And if don't, can some optimization be created in Drools CORE to handle this?

      Note that although the tree is different, it uses the same node types.

      OPTION 1: OPTIMIZED RETE TREE
      ------
      {{{
      #created on: 09/11/2010
      package aa

      #list any import classes here.
      import br.com.auster.om.invoice.telco.CallDetail;
      import br.com.auster.om.invoice.telco.ServiceTypeEnum;
      import br.com.auster.om.util.UnitCounter;
      import br.com.auster.om.util.UnitCounter.TypeOfUnitEnum;
      import br.com.auster.om.invoice.telco.TelcoCustomer;

      rule "call duration check 1"

      when
      CallDetail( serviceType == ServiceTypeEnum.VOICE,
      $realDuration : realDuration -> ($realDuration.getType() == TypeOfUnitEnum.TIME),
      $billedDuration : billedDuration -> ($billedDuration.getType() == TypeOfUnitEnum.TIME),
      realDuration.seconds <= 3 )
      then
      // TODO
      end

      rule "call duration check 2"

      when
      CallDetail( serviceType == ServiceTypeEnum.VOICE,
      $realDuration : realDuration -> ($realDuration.getType() == TypeOfUnitEnum.TIME),
      $billedDuration : billedDuration -> ($billedDuration.getType() == TypeOfUnitEnum.TIME),
      realDuration.seconds > 3 )

      then
      // TODO
      end

      rule "call-duration-check - realDuration > 30"

      when
      CallDetail( serviceType == ServiceTypeEnum.VOICE,
      $realDuration : realDuration -> ($realDuration.getType() == TypeOfUnitEnum.TIME),
      $billedDuration : billedDuration -> ($billedDuration.getType() == TypeOfUnitEnum.TIME),
      realDuration.seconds > 30 )
      then
      // TODO

      end
      }}}

      OPTION 2: NOT-OPTIMIZED RETE TREE
      ------
      {{

      { #created on: 09/11/2010 package aa #list any import classes here. import br.com.auster.om.invoice.telco.CallDetail; import br.com.auster.om.invoice.telco.ServiceTypeEnum; import br.com.auster.om.util.UnitCounter; import br.com.auster.om.util.UnitCounter.TypeOfUnitEnum; import br.com.auster.om.invoice.telco.TelcoCustomer; rule "call duration check 1" when CallDetail( serviceType == ServiceTypeEnum.VOICE, $realDuration : realDuration.type == TypeOfUnitEnum.TIME, $billedDuration : billedDuration.type == TypeOfUnitEnum.TIME, realDuration.seconds <= 3 ) then // TODO end rule "call duration check 2" when CallDetail( serviceType == ServiceTypeEnum.VOICE, $realDuration : realDuration.type == TypeOfUnitEnum.TIME, $billedDuration : billedDuration.type == TypeOfUnitEnum.TIME, realDuration.seconds > 3 ) then // TODO end rule "call-duration-check - realDuration > 30" when CallDetail( serviceType == ServiceTypeEnum.VOICE, $realDuration : realDuration.type == TypeOfUnitEnum.TIME, $billedDuration : billedDuration.type == TypeOfUnitEnum.TIME, realDuration.seconds > 30 ) then // TODO end }}

      }

      Attachments

        1. notOptimized.png
          notOptimized.png
          12 kB
        2. optimized.png
          optimized.png
          10 kB

        Activity

          People

            mproctor@redhat.com Mark Proctor
            fredramos1978 Frederico Ramos (Inactive)
            Archiver:
            rhn-support-ceverson Clark Everson

            Dates

              Created:
              Updated:
              Archived:

              PagerDuty