Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Too Many Arguments/Bindings #6193

Open
piacenti opened this issue Dec 11, 2024 · 0 comments
Open

Too Many Arguments/Bindings #6193

piacenti opened this issue Dec 11, 2024 · 0 comments

Comments

@piacenti
Copy link

piacenti commented Dec 11, 2024

I'm working in migrating IBM ODM rule to Drools and I'm starting to hit some issues on larger rules. I'm using Drools version 9.44.0.Final and RuleUnit. I'm writing automation to facilitate the migration effort which means that the output is not necessarily the ideal approach for the rules in Drools so you may see for example a mix of OOPath as well as usages of from in migrated rules.
I've hit two flavors of hitting the limits of the number of arguments supported by existing interfaces.
One is in the code generated for from

ule "Sb And P S Combination Not Valid for A (P C) - Validate Ver2"
	when
		$response: /ruleResponse
		$ac: /ac
		$p: P() from BindingUtils.getPoliciesUnder($ac)
		$rule: Rule(ruleIsInScope("Sb And P S Combination Not Valid for A (P C) - Validate Ver2")) from $p.rules
		Optional($p_s_prefix: ((String)this.orElse(null)), $p_s_prefix != null) from Optional.ofNullable(JavaStringUtils.subString($ac.selectedPType, 0, 2))
		$pACStatPlanCCodes: List() from collect (String() from $rule.findVariableAsListFromCommaSeparatedString("pACStatPlanCCodes"))
		$pNonOwnedCStatPlanCCodes: List() from collect (String() from $rule.findVariableAsListFromCommaSeparatedString("pNonOwnedCStatPlanCCodes"))
		$pNonOwnedVolunteerCStatPlanCCodes: List() from collect (String() from $rule.findVariableAsListFromCommaSeparatedString("pNonOwnedVolunteerCStatPlanCCodes"))
		$pDocCStatPlanCCodes: List() from collect (String() from $rule.findVariableAsListFromCommaSeparatedString("pDocCStatPlanCoveargeCodes"))
		$pAMiscellaneousCStatPlanCCodes: List() from collect (String() from $rule.findVariableAsListFromCommaSeparatedString("pAMiscellaneousCStatPlanCoveargeCodes"))
		$pHACStatPlanCoveargeCodes: List() from collect (String() from $rule.findVariableAsListFromCommaSeparatedString("pHACStatPlanCoveargeCodes"))
                 // problem statement
		$c: C() from CUtils.getCByCCodeA($pACStatPlanCCodes, $p.aC, $pNonOwnedCStatPlanCCodes, $p.nonOwnedEmployeesC, $pNonOwnedVolunteerCStatPlanCCodes, $p.nonOwnedVolunteersC, $pDocCStatPlanCCodes, $p.docC, $pAMiscellaneousCStatPlanCCodes, $p.aMiscellaneousC, $pHACStatPlanCoveargeCodes, $p.hAC)
		$pr_bl: PrBl(statisticalPSbCode != null, OperatorOverride.IsNot(statisticalPSbCode, "000")) from $c.prBl
		$validSbPSDataTable: DataTable() from $rule.findVariableAsDataTable("validSbPSDataTable")
		$validSbPSDataTable_criteria: Criteria($validSbPSDataTable.firstMatching(this) == null) from $validSbPSDataTable.newCriteria("PSPrefix", $p_s_prefix, "StatSbCode", $pr_bl.statisticalPSbCode)
	then
		...
end

This rule generates the code below:

final org.drools.model.Variable<rules.xom.C> var_$c = D.declarationOf(rules.xom.C.class,
                                                        DomainClassesMetadata496d704c60974bf395ea779de8b891a8.rules_xom_C_Metadata_INSTANCE,
                                                        "$c",
                                                        D.from(var_$p,
                                                               var_$pACStatPlanCCodes,
                                                               var_$pNonOwnedCStatPlanCCodes,
                                                               var_$pNonOwnedVolunteerCStatPlanCCodes,
                                                               var_$pDocCStatPlanCCodes,
                                                               var_$pAMiscellaneousCStatPlanCCodes,
                                                               var_$pHACStatPlanCoveargeCodes,
                                                               rules.P8F.LambdaExtractor8F90ADB9CA625E650E75380AFD4DCB44.INSTANCE));

It fails to compile because D.from is only overloaded to take up to 4 binding variables.
The generated LambdaExtractor referenced above also has issues. It generates the following

public enum LambdaExtractor8F90ADB9CA625E650E75380AFD4DCB44 implements org.drools.model.functions.Function7<rules.xom.P, java.util.List, java.util.List, java.util.List, java.util.List, java.util.List, java.util.List, java.util.Collection<rules.xom.C>>, org.drools.model.functions.HashedExpression

The problem is there is no interface for a Function7, it only goes up to Function6. I've looked at those classes and was able to create the proper implementations for From5, From6, From7 as well as Function7` but I'm not aware of any process being present that would allow me to inject those.

I also noticed another issue with another extreme case where there are too many bindings for the rule below.

rule "Sr Balancing A - Validate"
	when
		$response: /ruleResponse
		$ac: /ac
		$p: P() from BindingUtils.getPUnder($ac)
		$st: St() from BindingUtils.getStsUnder($p)
		$rule: Rule(ruleIsInScope("Sr Balancing A - Validate")) from $st.rules
		$pACLevelCCodes: List() from collect (String() from $rule.findVariableAsListFromCommaSeparatedString("pACLevelCCodes"))
		$pNonOwnedEmployeeCLevelCCodes: List() from collect (String() from $rule.findVariableAsListFromCommaSeparatedString("pNonOwnedEmployeeCLevelCCodes"))
		$pNonOwnedVolunteerCLevelCCodes: List() from collect (String() from $rule.findVariableAsListFromCommaSeparatedString("pNonOwnedVolunteerCLevelCCodes"))
		$pDocCLevelCCodes: List() from collect (String() from $rule.findVariableAsListFromCommaSeparatedString("pDocCLevelCCodes"))
		$pAMiscellaneousCLevelCCodes: List() from collect (String() from $rule.findVariableAsListFromCommaSeparatedString("pAMiscellaneousCLevelCCodes"))
		$pHACLevelCCodes: List() from collect (String() from $rule.findVariableAsListFromCommaSeparatedString("pHACLevelCCodes"))
		$stACLevelCCodes: List() from collect (String() from $rule.findVariableAsListFromCommaSeparatedString("stACLevelCCodes"))
		$vACLevelCCodes: List() from collect (String() from $rule.findVariableAsListFromCommaSeparatedString("vACLevelCCodes"))
		$lACLevelCCodes: List() from collect (String() from $rule.findVariableAsListFromCommaSeparatedString("lACLevelCCodes"))
		$created_object:
			CreatedObjects() from
			CreatedObjects.createdObjects($rule)
		Optional($st_level_sr: ((BigDecimal)this.orElse(null))) from Optional.ofNullable(PrBlUtils.sumStLevel($ac, GeneralConstants.Sr, $st.stCode + GeneralConstants.Sr, $created_object.blPrBlList))
		Optional($p_a_c_sr_level_balances: ((BigDecimal)this.orElse(null))) from Optional.ofNullable(PrBlUtils.sumPACTaxOrSrs($ac, $st, $pACLevelCCodes, GeneralConstants.Sr, $created_object.blPrBlList))
		Optional($p_non_owned_employee_sr_level_balances: ((BigDecimal)this.orElse(null))) from Optional.ofNullable(PrBlUtils.sumPNonOwnedEmployeesTaxOrSrs($ac, $st, $pNonOwnedEmployeeCLevelCCodes, GeneralConstants.Sr, $created_object.blPrBlList))
		Optional($p_non_owned_volunteer_sr_level_balances: ((BigDecimal)this.orElse(null))) from Optional.ofNullable(PrBlUtils.sumPNonOwnedVoluteersTaxOrSrs($ac, $st, $pNonOwnedVolunteerCLevelCCodes, GeneralConstants.Sr, $created_object.blPrBlList))
		Optional($p_doc_c_sr_level_balances: ((BigDecimal)this.orElse(null))) from Optional.ofNullable(PrBlUtils.sumPDocCTaxOrSrs($ac, $st, $pDocCLevelCCodes, GeneralConstants.Sr, $created_object.blPrBlList))
		Optional($p_a_misc_c_sr_level_balances: ((BigDecimal)this.orElse(null))) from Optional.ofNullable(PrBlUtils.sumAMiscellaneousCTaxOrSrs($ac, $st, $pAMiscellaneousCLevelCCodes, GeneralConstants.Sr, $created_object.blPrBlList))
		Optional($p_h_a_c_sr_level_balances: ((BigDecimal)this.orElse(null))) from Optional.ofNullable(PrBlUtils.sumhACTaxOrSrs($ac, $st, $pHACLevelCCodes, GeneralConstants.Sr, $created_object.blPrBlList))
		Optional($st_a_c_sr_level_balances: ((BigDecimal)this.orElse(null))) from Optional.ofNullable(PrBlUtils.sumStACTaxOrSrs($st, $stACLevelCCodes, GeneralConstants.Sr, $created_object.blPrBlList))
		Optional($v_pr_sr_level_balances: ((BigDecimal)this.orElse(null))) from Optional.ofNullable(PrBlUtils.sumvAC($st, $vACLevelCCodes, GeneralConstants.Sr, $created_object.blPrBlList))
		Optional($l_a_c_sr_level_balances: ((BigDecimal)this.orElse(null)), OperatorOverride.DoesNotEqual($st_level_sr, MathUtils.plus(MathUtils.plus(MathUtils.plus(MathUtils.plus(MathUtils.plus(MathUtils.plus(MathUtils.plus(MathUtils.plus($p_a_c_sr_level_balances, $v_pr_sr_level_balances), $p_non_owned_employee_sr_level_balances), $p_non_owned_volunteer_sr_level_balances), $l_a_c_sr_level_balances), $p_doc_c_sr_level_balances), $p_a_misc_c_sr_level_balances), $p_h_a_c_sr_level_balances), $st_a_c_sr_level_balances))) from Optional.ofNullable(PrBlUtils.sumlAC($st, $lACLevelCCodes, GeneralConstants.Sr, $created_object.blPrBlList))
	then
		for(PrBl var$_$0 : $created_object.getBlPrBlList()){
			$created_object.addToValidationParameters(
					ValidationParameter.create(var$_$0,
					new NVPType[]{
						NVPType.createNewNVPType("blAmount", var$_$0.getBlAmount())
					}));
                   }		
                   Outcome.generate($response, $p, $rule, (ValidationParameter[])$created_object.getValidationParameters().toArray(
				new ValidationParameter[$created_object.getValidationParameters().size()]),
			new RuleParameter[]{
				RuleParameter.create("sumPACLevelSrs", $p_a_c_sr_level_balances),
				RuleParameter.create("sumvLevelSrs", $v_pr_sr_level_balances),
				RuleParameter.create("sumPNonOwnedEmployeeLevelSrs", $p_non_owned_employee_sr_level_balances),
				RuleParameter.create("sumPNonOwnedVolunteerLevelSrs", $p_non_owned_volunteer_sr_level_balances),
				RuleParameter.create("sumlACLevelSrs", $l_a_c_sr_level_balances),
				RuleParameter.create("sumPDocCLevelSrs", $p_doc_c_sr_level_balances),
				RuleParameter.create("sumAMiscCLevelSrs", $p_a_misc_c_sr_level_balances),
				RuleParameter.create("sumPHACLevelSrs", $p_h_a_c_sr_level_balances),
				RuleParameter.create("sumStACLevelSrs", $st_a_c_sr_level_balances),
				RuleParameter.create("sumStLevelSrs", "St Sr Total", $st_level_sr),
				RuleParameter.create("pACLevelCCodes", (String[])$pACLevelCCodes.toArray(
					new String[$pACLevelCCodes.size()])),
				RuleParameter.create("vACLevelCCodes", (String[])$vACLevelCCodes.toArray(
					new String[$vACLevelCCodes.size()])),
				RuleParameter.create("pNonOwnedEmployeeCLevelCCodes", (String[])$pNonOwnedEmployeeCLevelCCodes.toArray(
					new String[$pNonOwnedEmployeeCLevelCCodes.size()])),
				RuleParameter.create("pNonOwnedVolunteerCLevelCCodes", (String[])$pNonOwnedVolunteerCLevelCCodes.toArray(
					new String[$pNonOwnedVolunteerCLevelCCodes.size()])),
				RuleParameter.create("lACLevelCCodes", (String[])$lACLevelCCodes.toArray(
					new String[$lACLevelCCodes.size()])),
				RuleParameter.create("pDocCLevelCCodes", (String[])$pDocCLevelCCodes.toArray(
					new String[$pDocCLevelCCodes.size()])),
				RuleParameter.create("pAMiscellaneousCLevelCCodes", (String[])$pAMiscellaneousCLevelCCodes.toArray(
					new String[$pAMiscellaneousCLevelCCodes.size()])),
				RuleParameter.create("pHACLevelCCodes", (String[])$pHACLevelCCodes.toArray(
					new String[$pHACLevelCCodes.size()])),
				RuleParameter.create("stACLevelCCodes", (String[])$stACLevelCCodes.toArray(
					new String[$stACLevelCCodes.size()])),
				RuleParameter.create("St.stcode", "st code", $st.getStCode()),
				RuleParameter.create("assessment", $st.getStCode() + GeneralConstants.Sr()),
				RuleParameter.create("Ac.primaryRiskSt", "primary risk st", $ac.getPrimaryRiskSt()),
				RuleParameter.create("Sr sums", "SOC Sr Total", MathUtils.plus(MathUtils.plus(MathUtils.plus(MathUtils.plus(MathUtils.plus(MathUtils.plus(MathUtils.plus(MathUtils.plus($p_a_c_sr_level_balances, $v_pr_sr_level_balances), $p_non_owned_employee_sr_level_balances), $p_non_owned_volunteer_sr_level_balances), $l_a_c_sr_level_balances), $p_doc_c_sr_level_balances), $p_a_misc_c_sr_level_balances), $p_h_a_c_sr_level_balances), $st_a_c_sr_level_balances))
			});
end

This rules ends up with two problems. It generates a broken from provider and a Consequence that is unable to execute

final org.drools.model.Variable<java.util.Optional> var_GENERATED_$pattern_Optional$962$ = D.declarationOf(java.util.Optional.class,
              DomainClassesMetadata63a2c5657ba94a49b9854eb2f46f3c7e.java_util_Optional_Metadata_INSTANCE,
              "GENERATED_$pattern_Optional$962$",
              D.from(var_$st,
                     var_$created_object,
                     var_$ac,
                     (rules.xom.St _this, 
                     rules.xom.Ac $ac,
                      rules.xom.utilities.CreatedObjects $created_object) -> Optional.ofNullable(PrBlUtils.sumStLevel($ac,
                                                                                                                                            GeneralConstants.Sr(),
                                                                                                                                            _this.getStCode() + GeneralConstants.Sr(),
                                                                                                                                            $created_object.getBlPrBlList()))));

The above format was edited to fit better here
The problem above is the order of parameters var_$st, var_$created_object, var_$ac does not follow the order of parameters expected by the lambda which is var_$st, var_$ac, var_$created_object (last two are reversed) so it throws a compilation error.

D.on(var_$p_doc_c_sr_level_balances,
       var_$st_level_sr,
       var_$pDocCLevelCCodes,
       var_$l_a_c_sr_level_balances,
       var_$pACLevelCCodes,
       var_$stACLevelCCodes,
       var_$pHACLevelCCodes,
       var_$rule,
       var_$p_non_owned_employee_sr_level_balances,
       var_$st,
       var_$pNonOwnedVolunteerCLevelCCodes,
       var_$p,
       var_$p_a_c_sr_level_balances,
       var_$p_a_misc_c_sr_level_balances,
       var_$pAMiscellaneousCLevelCCodes,
       var_$v_pr_sr_level_balances,
       var_$pNonOwnedEmployeeCLevelCCodes,
       var_$vACLevelCCodes,
       var_$lACLevelCCodes,
       var_$response,
       var_$ac,
       var_$p_non_owned_volunteer_sr_level_balances,
       var_$created_object,
       var_$st_a_c_sr_level_balances,
    var_$p_h_a_c_sr_level_balances).execute(rules.PD2.LambdaConsequenceD263DEBC42CB8BDA168C5ACC18919448.INSTANCE));

The execute method call above doesn't exist so it throws a compilation error. For these many arguments it generates a ConsequenceBuilder._N which only has an executeScript method. Similar to the problem above, even if I were to implement something higher than ConsequenceBuilder._24 (which is the highest implementation, one short of the number of parameters above), I have no way to inject that implementation into the process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant