反馈已提交

网络繁忙

You are viewing 5.1 help doc. More details are displayed in the latest help doc.

Brief introduction of custom function

  • Recent Updates: May 05, 2022
  • 1. Overview

    1.1 Application scenario

    FineBI has provided a large number of self-contained functions, which are sufficient to meet users' template creation needs under normal circumstances, but in some special areas, some special functions may be required, in this case, FineBI provides custom functions, which can be defined by users themselves according to business needs, but these functions must meet FineBI function definition rules.

    Note: Only extracted data is supported.

    1.2 Scope of use

    • Only the extracted data version is supported.

    • Does not support custom aggregation class functions, such as aggregation functions、quick calculation functions.

    1.3 Definition rules

    FineBI function definition rules: Functionname(Para,Para,...) where Functionname is the function name and Para is the parameter.

    In FineBI, each function is defined as a class, which must implement the Function interface, and the class is first reflected by the function name and then its run(Object[] agrs) method is called.

    Take the SUM function as an example, the SUM class is used to calculate the SUM function and inherits from the AbstractFunction class, which implements the Function interface.

    When the function operates, it first obtains the class of the function according to the function name, such as SUM(2,4, true), which first obtains the class SUM according to the function name, and then calls the run(Object[] args) method of the SUM class. args stores the arguments of the SUM function, which can be obtained from args to perform the operation. For example, the result isSUM(2,4,true)=2+4+1=7

    SUM function used in the code.

    package com.fr.report.script;
    import com.fr.general.FArray;
    import com.fr.script.AbstractFunction;
    public class CSUM extends AbstractFunction {
    public Object run(Object[] args) {
    double result = 0;
    for (int i = 0; i < args.length; i++) {
    if (args[i] == null) {
    continue;
    }
    result += parseObject(args[i]);
    }
    return result;
    }
    private double parseObject(Object obj) {
    if (obj instanceof Number) {
    return ((Number) obj).doubleValue();
    } else if (obj instanceof Boolean) {
    return ((Boolean) obj).booleanValue() ? 1 : 0;
    } else if (obj instanceof FArray) {
    FArray array = (FArray) obj;
    double sum = 0;
    for (int i = 0; i < array.length(); i++) {
    sum += parseObject(array.elementAt(i));
    }
    return sum;
    } else if (obj != null) {
    try {
    return Double.parseDouble(obj.toString());
    } catch (NumberFormatException exp) {
    return 0;
    }
    }
    return 0;
    }
    }

    1.4 Compile environment preparation

    For more information, see Compiling Java Programs.

    2. Example

    A simple custom function example is used to illustrate the use of custom functions.

    Define a function StringCat that serves to concatenate all parameters as strings.

    For more details, see Custom Functions for String Concatenation.

    3. Cautions

    1)Custom function names are based on class filenames.

    2)Custom function filenames support English only, including pure upper case, pure lower case, mixed case input.

    3)The added functions are shown in "Other Functions".

    4)Currently, mixed case input is not supported.


    Attachment List


    Theme: Advanced Data Analyis
    Already the First
    Already the Last
    • Helpful
    • Not helpful
    • Only read

    售前咨询电话

    400-811-8890转1

    在线技术支持

    在线QQ:800049425

    热线电话:400-811-8890转2

    总裁办24H投诉

    热线电话:173-1278-1526

    文 档反 馈

    鼠标选中内容,快速反馈问题

    鼠标选中存在疑惑的内容,即可快速反馈问题,我们将会跟进处理。

    不再提示

    10s后关闭