Hitachi Vantara Pentaho Community Forums
Results 1 to 8 of 8

Thread: How to remember the previous row

  1. #1
    Join Date
    May 2009
    Posts
    11

    Question How to remember the previous row

    Hi,

    I need to remember the previous row values from the datasource to calcule the current values to display in the report.

    What I did was create a "BSHEExpression" report function and I added the follow Expression to the function:

    Object getValue()
    {
    var prev_row;
    if (prev_row == null)
    prev_row = dataRow;
    Number n = prev_row.get("closed");
    prev_row = dataRow;
    return new Long (n.longValue());
    }

    but I am getting the same current row value for field "closed" instead of the previous value for this field.

    Please could someone help me .

  2. #2
    Join Date
    Mar 2003
    Posts
    8,085

    Default

    Expressions are by definition stateless. So you cant use them to remember any state information here.

    You will have to implement your own function (org.jfree.report.function.Function) and maintain/remember your state in the "itemsAdvanced()" method (this is called when a row is processed and after that the cursor will move to the next row).
    Get the latest news and tips and tricks for Pentaho Reporting at the Pentaho Reporting Blog.

  3. #3
    Join Date
    May 2009
    Posts
    11

    Default

    I am a new Pentaho member and I don't know how to create the custom function.

    Please could you provide the steps to create the custom function.

    Let me know if there is a wiki with a complete explanation.

    Thanks for the help .

  4. #4
    Join Date
    May 2009
    Posts
    11

    Question Steps to create a custom function

    Please can someone provide me the steps to create a custom function?


  5. #5
    Join Date
    Mar 2003
    Posts
    8,085

    Default

    To create a custom function, you have to implement your own Java class, which has to implement the "Function" interface mentioned above. Usually, you will save yourself some troubles and start by extending AbstractFunction.

    Functions are parametrized via Bean getter and setter methods. Our XML-parser and writer can handle simple and indexed properties, as long as the property type is String, any of the built-in Number types, like Double, Long, Integer (and of course the primitive variants of them), Class, Date or Color.

    To teach the report-designer the new expression, create a "function.txt" file in the report-designer's "resource" directory and list the classnames of the functions, separate by comma with no whitespace or linebreak inbetween.

    We recommend that you put your function in your own package and not in one of the reporting-engine's or report-designer's or platform packages. Be aware that to use the function, all applications have to have your custom function on the classpath, so drop your jar into the report-designer and platform's lib-directory (and potentially into the design-studio's lib-directory as well).
    Get the latest news and tips and tricks for Pentaho Reporting at the Pentaho Reporting Blog.

  6. #6
    Join Date
    May 2009
    Posts
    11

    Question Working

    It is working now!

    but I see a issue that I would like understand.

    For example my query returns the follow values:
    1
    2
    3
    4
    5

    but in the itemsAdvanced() method I get:
    1
    2
    3
    4
    5
    1
    2
    3

    The reporter displays only five rows . No rows are repeated but I wonder why the reporter looks like pass two times for some values.

    Any idea?

    Thansk,
    Eric

  7. #7
    Join Date
    Mar 2003
    Posts
    8,085

    Default

    The reporting engine is a multi-pass engine. So it passes over the data at least 2 times (usually 3 times, sometimes even more, depending on what functions have been added). You see at least one data-pass (computes function values) and one repagination pass. If you actually run the report for creating documents (and not just for print-preview) then you will see a third pass that does the export and builds the document.

    The functions get cloned throughout the report processing, so as long as you implement the clone-method correctly, everything is fine. Any particular function instance always sees the data pass by as if it is a linear stream, so usually you dont have to worry about the multi-pass aspect. (Only exception is if you do really complicated stuff, which is close to genius and/or insanity.)

    If you want to see whats going on, then add the "EventMonitorFunction" to the report. It prints all kind of internal status messages to the log and helps to understand whats going on.
    Get the latest news and tips and tricks for Pentaho Reporting at the Pentaho Reporting Blog.

  8. #8
    Join Date
    May 2009
    Posts
    11

    Wink Thanks a lot for the help

    I would like to share to the community that I copied my jar file to:

    C:\Pentaho\biserver-ce\tomcat\webapps\pentaho\WEB-INF\lib\
    and
    C:\Pentaho\prd-ce-2.0.0.stable\report-designer\lib

    and that is important to implement
    reportInitialized()to initialize the variables that you are using.

    Also the follow links help:

    http://www.docjar.com/docs/api/org/j...ed(ReportEvent)

    http://www.docjar.com/html/api/org/j...tion.java.html

    http://www.docjar.com/docs/api/org/j...age-index.html

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.