[ http://issues.apache.org/jira/browse/OFBIZ-336?page=all ]

Leon Torres updated OFBIZ-336:
------------------------------

    Attachment: complex-alias-default-value.patch

Here's an implementation of default-value for complex alias.  I removed two 
constructor methods in ComplexAliasField that weren't being used, one of which 
would cause confusion with the new field.

To use, try something like the following:

      <alias entity-alias="OI" name="quantity" function="sum">
          <complex-alias operator="-">
              <complex-alias-field entity-alias="OI" field="quantity" 
default-value="0"/>
              <complex-alias-field entity-alias="OI" field="cancelQuantity" 
default-value="0"/>
          </complex-alias>
      </alias>

This should be tested across as many databases as possible.

There is an implementation quirk that absolutely needs review.  The coalesce 
function is generated as follows:

COALESCE(${fieldName},'${defaultValue}')

Note the single quotations around defaultVaue.  In the example, this gets 
resolved as COALESCE(OI.QUANTITY,'0').  This actually works on postgresql and 
mysql, but I don't know if this will cause issues on other databases. If it 
does, then we'll need to detect the field type and set it up accordingly.

> Improve complex-alias to handle nulls and defaults
> --------------------------------------------------
>
>                 Key: OFBIZ-336
>                 URL: http://issues.apache.org/jira/browse/OFBIZ-336
>             Project: OFBiz (The Open for Business Project)
>          Issue Type: Improvement
>          Components: framework
>            Reporter: Leon Torres
>            Priority: Minor
>         Attachments: complex-alias-default-value.patch
>
>
> The idea behind complex-alias is useful for certain things, but the way it 
> works now is not useful.  Suppose you build a simple addition rule.  If any 
> variable in the equation is null, the entire alias resolves to null.
> For example, suppose you create a view entity to report quantities on 
> OrderItem.  The query would be:
> select product_id, (quantity - cancel_quantity) from order_item;
> However if you run this, you'll see that where quantity or cancel_quantity 
> are null, the result is null.  A solution in postgresql is to use the 
> coalesce function to specify a default value:
> select product_id, (coalesce(quantity, 0) - coalesce(cancel_quantity, 0)) 
> from order_item;
> Now the query works.
> So the fix I think is to add another attribute default-value="something".  If 
> the default-value is present, then add the coalesce function.  Not sure 
> whether this is standard sql or not.
> I also encountered this issue for concatenation ||  operator, so I think it 
> affects most operations.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to