Method and device for calculating business indicators
By configuring dynamic formula calculation functions in the SQL data operation script, the operation expression and factor values are automatically obtained from the algorithm configuration library, which solves the problem of requiring redevelopment when adding business indicators in the existing technology and realizes flexible and efficient business indicator calculation.
Patent Information
- Application Number
- CN202110686689.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-21
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2041-06-21
AI Technical Summary
When calculating business indicators in the financial field using existing technologies, adding new financial businesses or business indicators requires redeveloping the code, resulting in high development costs and low computing efficiency.
By configuring dynamic formula calculation functions in the structured query language SQL data operation script, the business indicators' operation expressions and business values of operation factors are automatically obtained from the algorithm configuration library, and the operation expression engine toolkit is used to perform operations to achieve dynamic configuration of business indicators.
It reduces the workload of developers, improves the calculation efficiency of business indicators, and makes the execution of SQL data operation scripts more flexible.
Smart Images

Figure CN113326283B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of financial technology (Fintech), and in particular to a method and device for calculating business indicators. Background Art
[0002] With the development of computer technology, more and more technologies are being applied in the financial sector. Traditional finance is gradually transforming into FinTech. However, the security and real-time requirements of the financial industry also place higher demands on technology. In the financial sector, as financial services continue to update and change, the number of financial business indicators involved will also increase. Therefore, to ensure the quality of financial services, it is necessary to calculate the index values of various financial business indicators in a timely and accurate manner.
[0003] The existing solution is to calculate the index value of each business indicator in a financial business by pre-customizing the function operation expression involved in a certain financial business in the SQL script. Taking the calculation of a customer's financial loan interest over a certain period of time as an example, by pre-setting the expression for calculating the financial loan interest in the SQL query script, a SQL query script for calculating the financial loan interest is constructed, and then executing the SQL query script to obtain the customer's financial loan interest over this period of time. However, if a new financial business or new business indicator needs to be added using this existing solution, the index value calculation code involved in the new financial business or new business indicator needs to be redeveloped, which will increase the workload of developers, increase development costs, and lead to low efficiency in calculating the index value of the business indicator.
[0004] In summary, there is an urgent need for a method to calculate business indicators to achieve dynamic configuration of business indicator operation expressions and make the execution of SQL data operation scripts more flexible. Summary of the Invention
[0005] The embodiments of the present invention provide a method and apparatus for calculating business indicators, which are used to realize dynamic configuration of operation expressions of business indicators and make the execution of SQL data operation scripts more flexible.
[0006] In a first aspect, an embodiment of the present invention provides a method for calculating a service indicator, comprising:
[0007] Receive a data query instruction; the data query instruction is used to obtain indicator results of business indicators based on business data;
[0008] Obtaining the business indicator's operational expression from an algorithm configuration library and the business value of each operational factor of the operational expression from the business data through a dynamic formula calculation function configured in a structured query language SQL data operation script; the algorithm configuration library stores description information of the operational expression of each business indicator and description information of each operational factor;
[0009] Calling the operation expression engine toolkit through the dynamic formula calculation function;
[0010] Based on the operation expression and the business values of the operation factors, the operation expression engine toolkit is executed to obtain the indicator result of the business indicator.
[0011] In the above technical solution, after receiving a data query instruction for obtaining the indicator results of a business indicator based on business data, a dynamic formula calculation function configured in the SQL data calculation script can automatically obtain the business indicator's operation expression from the algorithm configuration library and the business values of each operation factor of the operation expression from the business data. The dynamic formula calculation function then calls the operation expression engine toolkit and executes the operation expression engine toolkit based on the operation expression and the business values of each operation factor, thereby obtaining the indicator results of the business indicator in a timely and accurate manner. In this way, this solution can automatically obtain the operation expression of the business indicator to be calculated by calling the dynamic formula calculation function, without having to pre-set a fixed operation expression in the SQL data calculation script. This allows for dynamic configuration of the operation expression of the business indicator and makes the execution of the SQL data calculation script more flexible. Furthermore, even if a new operation expression needs to be added, this solution only needs to configure the new operation expression in the algorithm configuration library. The dynamic formula calculation function in the SQL data calculation script can then automatically obtain the new operation expression without having to modify the SQL data calculation script. Therefore, this solution can reduce the workload of developers and improve the efficiency of calculating the indicator results of the business indicator.
[0012] Optionally, before receiving the data query instruction, the method further includes:
[0013] For each business indicator, set the description information of the corresponding operation expression and the description information of each operation factor of the operation expression for the business indicator;
[0014] The description information of the operation expression of each business indicator and the description information of each operation factor of the operation expression are stored in the algorithm configuration library.
[0015] In the above technical solution, by pre-configuring the description information of the corresponding operation expression and the description information of each operation factor of the operation expression for each business indicator, it is convenient for the dynamic formula calculation function in the subsequent SQL data operation script to automatically obtain the operation expression of the corresponding business indicator from the algorithm configuration library. Even if new business indicators are added, it is only necessary to configure the description information of the operation expression corresponding to the new business indicator and the description information of each operation factor of the operation expression in the algorithm configuration library to realize the automatic acquisition of the subsequent dynamic formula calculation function without changing the SQL data operation script, thereby realizing the dynamic configuration of the operation expression of the business indicator.
[0016] Optionally, the algorithm configuration library includes an algorithm description table and an algorithm attribute table; the algorithm description table is used to configure the type of the business indicator, the operation expression of the business indicator, the name of the business indicator, and the identifier of the operation expression; the algorithm attribute table is used to configure the identifier of the operation expression, the name of each operation factor of the operation expression, and the data type of each operation factor of the operation expression;
[0017] The method further comprises:
[0018] If a new business indicator is added, the type of the new business indicator, the operation expression of the new business indicator, the name of the new business indicator and the identifier of the operation expression of the new business indicator are configured in the algorithm description table, and the identifier of the operation expression of the new business indicator, the names of the various operation factors of the operation expression of the new business indicator and the data types of the various operation factors of the operation expression of the new business indicator are configured in the algorithm attribute table.
[0019] In the above technical solution, if a new business indicator is added, the solution only needs to configure the type of the new business indicator, the operation expression of the new business indicator, the name of the new business indicator and the identifier of the operation expression of the new business indicator in the algorithm description table, and configure the identifier of the operation expression of the new business indicator, the names of each operation factor of the operation expression of the new business indicator and the data type of each operation factor of the operation expression of the new business indicator in the algorithm attribute table. Then, the dynamic formula calculation function in the sql data operation script can automatically obtain the operation expression corresponding to the new business indicator from the algorithm configuration library without changing the sql data operation script, thereby realizing the dynamic configuration of the operation expression of the business indicator.
[0020] Optionally, before receiving the data query instruction, the method further includes:
[0021] Based on the dynamic formula calculation function, the algorithm configuration library and the business database, a sql data operation script for determining the indicator results of the business indicators is constructed; the business database stores the business values of each operation factor of the operation expression of each business indicator.
[0022] In the above technical solution, before receiving the data query instruction to execute the SQL data operation script, it is necessary to pre-write the SQL data operation script based on the dynamic formula calculation function, algorithm configuration library and business database, so that after receiving the data query instruction, the indicator results of the required business indicators can be obtained in a timely and effective manner.
[0023] Optionally, determine the operation expression engine toolkit in the following way:
[0024] Define a class for determining the indicator result corresponding to the business indicator, and define a first input parameter and a second input parameter of the class; the first input parameter is used to load the operation expression of the business indicator in the algorithm configuration library; the second input parameter is used to load the business value corresponding to each operation factor of the operation expression that meets the business indicator in the business data;
[0025] Define the output parameters of the class and define the calculation methods involved in the class;
[0026] The first input parameter, the second input parameter, the output parameter and the calculation method of the class are packaged into the operation expression engine toolkit.
[0027] In the above technical solution, by packaging the first input parameter, the second input parameter, the output parameter and the calculation method of the class into an operation expression engine toolkit, it is convenient for the dynamic formula calculation function in the SQL data operation script to call the operation expression engine toolkit in a timely and effective manner when executing the SQL data operation script, so that the operation expression of the business indicator to be queried can be dynamically obtained, and the indicator result of the business indicator can be calculated in a timely and accurate manner based on the operation expression.
[0028] Optionally, after obtaining the business value of each operation factor of the operation expression from the business data, the method further includes:
[0029] Verifying the business value of each operation factor of the operation expression to determine whether the data format of the business value of each operation factor of the operation expression meets the data format requirement corresponding to the second input parameter;
[0030] If not, the business value of each operation factor of the operation expression is converted into a business value that meets the data format requirement corresponding to the second input parameter.
[0031] In the above technical solution, before the business values of each operation factor of the operation expression obtained from the business data are passed into the dynamic formula calculation function, the business values of each operation factor of the operation expression need to be verified to determine whether the business values of each operation factor of the operation expression meet the data format requirements corresponding to the second input parameter. This can avoid calculation anomalies caused by the data format of the business values of each operation factor of the operation expression not meeting the data format requirements of the dynamic formula calculation function, and can ensure the accuracy of the indicator results of subsequent calculations of business indicators.
[0032] Optionally, the dynamic formula calculation function is a temporary function constructed in Hive; the operation expression engine toolkit is constructed based on the Java data format;
[0033] After obtaining the indicator results of the business indicators, the following steps are also included:
[0034] Convert the Java data format indicator results into the Hive data format requirements.
[0035] In the above technical solution, by converting the indicator results in Java data format into indicator results that meet the data format requirements of Hive, it is convenient for the subsequent Hive library to process the indicator results.
[0036] In a second aspect, an embodiment of the present invention further provides a device for calculating a business indicator, including:
[0037] A receiving unit, configured to receive a data query instruction; the data query instruction is used to obtain an indicator result of a business indicator based on business data;
[0038] A processing unit is configured to obtain the operation expression of the business indicator from an algorithm configuration library and the business value of each operation factor of the operation expression from the business data through a dynamic formula calculation function configured in a structured query language SQL data operation script; the algorithm configuration library stores description information of the operation expression of each business indicator and description information of each operation factor; call an operation expression engine toolkit through the dynamic formula calculation function; execute the operation expression engine toolkit based on the operation expression and the business value of each operation factor to obtain the indicator result of the business indicator.
[0039] Optionally, the processing unit is further configured to:
[0040] Before receiving the data query instruction, for each business indicator, setting the description information of the corresponding operation expression and the description information of each operation factor of the operation expression for the business indicator;
[0041] The description information of the operation expression of each business indicator and the description information of each operation factor of the operation expression are stored in the algorithm configuration library.
[0042] Optionally, the algorithm configuration library includes an algorithm description table and an algorithm attribute table; the algorithm description table is used to configure the type of the business indicator, the operation expression of the business indicator, the name of the business indicator, and the identifier of the operation expression; the algorithm attribute table is used to configure the identifier of the operation expression, the name of each operation factor of the operation expression, and the data type of each operation factor of the operation expression;
[0043] The processing unit is further configured to:
[0044] If a new business indicator is added, the type of the new business indicator, the operation expression of the new business indicator, the name of the new business indicator and the identifier of the operation expression of the new business indicator are configured in the algorithm description table, and the identifier of the operation expression of the new business indicator, the names of the various operation factors of the operation expression of the new business indicator and the data types of the various operation factors of the operation expression of the new business indicator are configured in the algorithm attribute table.
[0045] Optionally, the processing unit is further configured to:
[0046] Before receiving the data query instruction, a sql data operation script for determining the indicator results of the business indicator is constructed based on the dynamic formula calculation function, the algorithm configuration library and the business database; the business database stores the business values of each operation factor of the operation expression of each business indicator.
[0047] Optionally, the processing unit is specifically configured to:
[0048] Define a class for determining the indicator result corresponding to the business indicator, and define a first input parameter and a second input parameter of the class; the first input parameter is used to load the operation expression of the business indicator in the algorithm configuration library; the second input parameter is used to load the business value corresponding to each operation factor of the operation expression that meets the business indicator in the business data;
[0049] Define the output parameters of the class and define the calculation methods involved in the class;
[0050] The first input parameter, the second input parameter, the output parameter and the calculation method of the class are packaged into the operation expression engine toolkit.
[0051] Optionally, the processing unit is further configured to:
[0052] After obtaining the business value of each operation factor of the operation expression from the business data, verifying the business value of each operation factor of the operation expression to determine whether the data format of the business value of each operation factor of the operation expression meets the data format requirement corresponding to the second input parameter;
[0053] If not, the business value of each operation factor of the operation expression is converted into a business value that meets the data format requirement corresponding to the second input parameter.
[0054] Optionally, the dynamic formula calculation function is a temporary function constructed in Hive; the operation expression engine toolkit is constructed based on the Java data format;
[0055] The processing unit is further configured to:
[0056] After obtaining the indicator result of the business indicator, the indicator result in Java data format is converted into an indicator result that meets the data format requirements of Hive.
[0057] In a third aspect, an embodiment of the present invention provides a computing device comprising at least one processor and at least one memory, wherein the memory stores a computer program, and when the program is executed by the processor, the processor executes any method of calculating business indicators described in the first aspect above.
[0058] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium storing a computer program executable by a computing device. When the program runs on the computing device, the computing device executes any method of calculating business indicators described in the first aspect above. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0060] Figure 1 A flowchart of a method for calculating business indicators provided by an embodiment of the present invention;
[0061] Figure 2 A schematic diagram of the structure of a device for calculating business indicators provided by an embodiment of the present invention;
[0062] Figure 3 A schematic diagram of the structure of a computing device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0063] To make the objectives, technical solutions, and advantages of the present invention more apparent, the present invention will be further described in detail below with reference to the accompanying drawings. It is apparent that the embodiments described are only some of the embodiments of the present invention, rather than all of them. All other embodiments derived by persons of ordinary skill in the art based on the embodiments of the present invention without creative effort are intended to fall within the scope of protection of the present invention.
[0064] First, some terms involved in the embodiments of the present invention are explained below to facilitate understanding by those skilled in the art.
[0065] (1) UDF function: User Defined Function. Taking the Hive library as an example, the Hive library comes with some built-in functions, such as max / min, etc. However, since the range of built-in functions of the Hive library is limited, users can define UDFs to facilitate expansion.
[0066] (2) JEXL: Java Expression Language, is an expression language engine that can be used in applications or frameworks. For example, it can be used with Java programs to calculate expressions in complex scenarios.
[0067] The above introduces some of the terms involved in the embodiments of the present invention. The following introduces the technical features involved in the embodiments of the present invention.
[0068] Figure 1 The flow of a method for calculating a business indicator provided by an embodiment of the present invention is exemplarily shown, and the flow can be executed by a device for calculating a business indicator.
[0069] like Figure 1 As shown in the figure, the process specifically includes:
[0070] Step 101: Receive a data query instruction.
[0071] Step 102, through the dynamic formula calculation function configured in the structured query language SQL data operation script, obtain the operation expression of the business indicator from the algorithm configuration library, and obtain the business value of each operation factor of the operation expression from the business data.
[0072] Step 103: calling the operation expression engine toolkit through the dynamic formula calculation function.
[0073] Step 104: Execute the operation expression engine toolkit based on the operation expression and the business value of each operation factor to obtain the indicator result of the business indicator.
[0074] In the above step 101, when the user needs to query the indicator results of a certain business indicator or several business indicators, he can send a data query instruction to the SQL data query script. The data query instruction can include the business indicator name and the operation expression identifier corresponding to the business indicator name.
[0075] For example, assuming that a user wants to query the loan interest of a certain loan business, he or she may send a loan interest query instruction to the SQL data query script. The loan interest query instruction includes the loan interest name and an operation expression corresponding to the loan interest name.
[0076] Furthermore, before receiving a data query instruction, for each business indicator, description information of the corresponding operation expression and description information of each operation factor of the operation expression are set for the business indicator, and the description information of each operation factor of the operation expression is stored in the algorithm configuration library. Specifically, the algorithm configuration library includes an algorithm description table and an algorithm attribute table. The algorithm description table is used to configure the type of the business indicator, the operation expression of the business indicator, the name of the business indicator, and the identifier of the operation expression; the algorithm attribute table is used to configure the identifier of the operation expression, the names of each operation factor of the operation expression, and the data type of each operation factor of the operation expression. By pre-configuring the description information of the operation expression and the description information of each operation factor of the operation expression for each business indicator, it is possible to facilitate the dynamic formula calculation function in the subsequent SQL data operation script to automatically obtain the operation expression of the corresponding business indicator from the algorithm configuration library. Even if a new business indicator is added, the description information of the operation expression and the description information of each operation factor of the operation expression corresponding to the new business indicator only needs to be configured in the algorithm configuration library to achieve automatic retrieval of the subsequent dynamic formula calculation function without having to modify the SQL data operation script, thereby achieving dynamic configuration of the operation expression of the business indicator.
[0077] If you need to add a new business indicator, configure the type of the new business indicator, the operation expression of the new business indicator, the name of the new business indicator and the identifier of the operation expression of the new business indicator in the algorithm description table, and configure the identifier of the operation expression of the new business indicator, the names of the various operation factors of the operation expression of the new business indicator and the data types of the various operation factors of the operation expression of the new business indicator in the algorithm property table. Then, the dynamic formula calculation function in the SQL data operation script can automatically obtain the operation expression corresponding to the new business indicator from the algorithm configuration library without changing the SQL data operation script.
[0078] Furthermore, before executing an SQL data operation script upon receiving a data query instruction, the SQL data operation script must be pre-written based on the dynamic formula calculation function, the algorithm configuration library, and the business database. This allows for timely and efficient acquisition of the required business indicator results upon receiving the data query instruction. The business database stores the business values of each operation factor in the operation expression of each business indicator.
[0079] In steps 102 and 103 above, after obtaining the business indicator name and the corresponding operation expression identifier, the dynamic formula calculation function configured in the SQL data operation script retrieves the operation expression corresponding to the business indicator name from the algorithm configuration library and obtains the business values of each operation factor contained in the operation expression from the business data. The operation expression engine toolkit is then called through the dynamic formula calculation function. After obtaining the business values of each operation factor of the operation expression from the business data, the business values of each operation factor of the operation expression need to be verified to determine whether the data format of the business values of each operation factor of the operation expression meets the data format requirements corresponding to the second input parameter. If so, the business values of each operation factor of the operation expression are directly passed into the dynamic formula calculation function; if not, the business values of each operation factor of the operation expression are converted to business values that meet the data format requirements corresponding to the second input parameter, and then the business values that meet the data format requirements corresponding to the second input parameter are passed into the dynamic formula calculation function. In this way, calculation anomalies caused by the data format of the business values of each operation factor of the operation expression not meeting the data format requirements of the dynamic formula calculation function can be avoided, and the accuracy of the indicator results of subsequent calculations of business indicators can be ensured.
[0080] In addition, the operation expression engine toolkit can be determined in the following manner: first, define a class for determining the indicator result corresponding to the business indicator, and define the first input parameter and second input parameter of the class. Then define the output parameter of the class, and define the calculation method involved in the class. Then, package the first input parameter, second input parameter, output parameter, and calculation method of the class into an operation expression engine toolkit. In this way, when executing the SQL data operation script, the dynamic formula calculation function in the SQL data operation script can call the operation expression engine toolkit in a timely and effective manner, so that the operation expression of the business indicator to be queried can be dynamically obtained, and the indicator result of the business indicator can be calculated in a timely and accurate manner based on the operation expression. Among them, the first input parameter is used to load the operation expression of the business indicator in the algorithm configuration library; the second input parameter is used to load the business values corresponding to each operation factor of the operation expression that meets the business indicator in the business data.
[0081] For example, assume there are two business indicators, namely, business indicator A and business indicator B. The existing technology requires pre-customizing the calculation formulas for business indicator A and business indicator B in the SQL data operation script when calculating the indicator results for business indicator A and business indicator B. For example, the SQL data operation script for business indicator A is select A*f1*f2 as FeeAfrom table1; the SQL data operation script for business indicator B is select B*f1*f2 as FeeB from table1. However, this solution does not require pre-customizing the calculation formulas for business indicator A and business indicator B in the SQL data operation script. Instead, it requires configuring the description of business indicator A's calculation formula and the descriptions of each operational factor in business indicator A's calculation formula in the algorithm configuration library, as well as the description of each operational factor in business indicator B's calculation formula in the algorithm configuration library. A class, such as the CalcFeeOnFeeType class, is also created, defining its input and output parameters and the associated calculation methods, such as the evaluate method. The CalcFeeOnFeeType class and the entire project are packaged as a class toolkit. Next, a temporary function called calcfee is created in the Hive library. This temporary function serves as a dynamic formula calculation function, which is used to call the class toolkit. This dynamic formula calculation function can dynamically and uniformly call the calculation formulas corresponding to business indicator A and business indicator B. For example, the SQL data calculation script that is dynamically called is select calcfee(FA,map1)as FeeA,calcfee(FB,map1)as FeeB fromtable1. This allows the temporary function calcfee() to calculate the corresponding business indicator results.
[0082] In step 104, the expression engine toolkit executes the expression engine based on the expression and the business values of each operation factor to obtain the indicator results for the business indicator. Because the dynamic formula calculation function is a temporary function built in Hive, and the expression engine toolkit is built based on the Java data format, after obtaining the indicator results for the business indicator, the indicator results in the Java data format must be converted to the indicator results that meet the data format requirements of Hive. This facilitates subsequent processing of the indicator results by the Hive library.
[0083] Based on this, the following takes the SQL data operation script involved in the Hive library as an example to specifically describe the implementation process of the method for calculating business indicators in an embodiment of the present invention.
[0084] Step 1: Define the algorithm configuration table and algorithm attribute table.
[0085] In an embodiment of the present invention, in order to enable the SQL data operation script written in the database to dynamically obtain the configured operation expression, it is necessary to pre-configure each operation expression in advance, that is, pre-define the algorithm configuration table TM_CBS_CALCULATE and the algorithm property table TM_CBS_CALC_PROPERTY in advance, and configure the corresponding configuration information in the algorithm configuration table TM_CBS_CALCULATE, and configure the corresponding configuration information in the algorithm property table TM_CBS_CALC_PROPERTY. For example, for a financial product in a certain business scenario, such as a loan business or an insurance business, if settlement processing is performed on the financial product, such as settlement processing on the transaction information of the financial product, or settlement processing can be performed on the order information of a certain financial product, or settlement processing can be performed on the promissory note information of a certain financial product, etc., then it is necessary to calculate the data associated with the various business indicators involved in the financial product. For example, a UDF function can be defined, and a temporary function can be created in the Hive library. The temporary function is built into the SQL data operation script corresponding to the financial product. The temporary function can be used to call the UDF function to dynamically obtain the relevant operation expressions in the algorithm configuration table. In this way, the indicator results of various business indicators can be calculated in a timely manner without the need to customize the operation expressions related to the various business indicators in the SQL data operation script in advance, which can make the execution of the SQL data operation script more flexible.
[0086] The algorithm configuration table TM_CBS_CALCULATE may be in the form shown in Table 1.
[0087] Table 1
[0088]
[0089]
[0090] The format of the algorithm property table TM_CBS_CALC_PROPERTY may be as shown in Table 2.
[0091] Table 2
[0092] Field Name describe Is it a query condition? ID Primary key ID yes Calc_ID Operation expression ID yes Property_Name Property Name yes Property_Type Attribute data type no Create_Time Creation time no Update_Time Modification time no
[0093] For example, the definition of the algorithm configuration table and the algorithm attribute table is described by taking the loan principal channel fee as an example.
[0094] For Loan_Prin_Amt (loan principal channel fee), if the difference between the loan settlement date Paidoutdate and the loan disbursement date Registerdate exceeds the preset interval number of days Nday, the settled loan principal channel fee amount will be returned, and the settled loan principal channel fee amount Clear_Amt = discount rate Dis_Rate * loan principal Loan_Amt * channel fee rate Fee_Rate; if the difference between the loan settlement date Paidoutdate and the loan disbursement date Registerdate exceeds the preset interval number of days Nday and is less than or equal to the preset interval number of days Nday, the settled loan principal channel fee amount will be returned, and the settled loan principal channel fee amount Clear_Amt = loan principal Loan_Amt * channel fee rate Fee_Rate.
[0095] Among them, the algorithm configuration table of the loan principal channel fee Loan_Prin_Amt can be shown in Table 3.
[0096] Table 3
[0097]
[0098]
[0099] The attribute table of the operation expression of the loan principal channel fee Loan_Prin_Amt can be shown in Table 4.
[0100] Table 4
[0101]
[0102] Step 2: Define a UDF function and call a JEXL expression based on the defined UDF function to implement dynamic calculation.
[0103] In this embodiment of the present invention, before calling a JEXL expression based on a defined UDF function, JEXL is first added to the Maven repository to enable the defined UDF function to call the JEXL expression. It should be noted that in addition to JEXL expressions, other expressions such as fel expressions, El expressions, and aviator expressions can also be used in this embodiment of the present invention, and this embodiment is not limited to these.
[0104] For example, the execution code for adding JEXL dependencies in the Maven repository can be:
[0105]
[0106] After adding the JEXL dependency to the Maven repository, this embodiment of the present invention defines a class that implements the UDF function and defines its input and output parameters. Specifically, a CalcFeeOnFeeType class is defined. This class implements the UDF function and extends the GenericUDF class. An initialize method is also defined in this class to validate its input parameters.
[0107] Among them, for the CalcFeeOnFeeType class, two input parameters are defined, namely the first input parameter and the second input parameter. Among them, the first input parameter is the string expressionStr, which is used to load the operation expression corresponding to a business indicator in a business scenario in the algorithm configuration table; the second input parameter is the string inParaMap, which is used to load the business data corresponding to a business indicator in a business scenario. That is to say, when calculating the indicator result of a business indicator in a business scenario, the second input parameter passes in a map composed of the calculation factors required in the operation expression corresponding to the business indicator, which is provided by the business data at runtime. In addition, for the CalcFeeOnFeeType class, an output parameter will also be defined. For example, the type of the output parameter can be defined as BigDecimal type.
[0108] In addition, for the CalcFeeOnFeeType class, the logical operation method in the CalcFeeOnFeeType class is defined, that is, the evaluate calculation method of the CalcFeeOnFeeType class is implemented. The evaluate calculation method includes three parts, namely, (1) extracting the first input parameter expressionStr and the second input parameter inParaMap, (2) calling the calculation service, that is, using the jexl package to implement the dynamic calculation function, that is, jexlEvaluate.Evaluate(expressionStr, inParaMap), and (3) converting the data type of the data result calculated by the jexl package into a data type that can be processed by Hive.
[0109] After defining the CalcFeeOnFeeType class, package the CalcFeeOnFeeType class and the entire project into a class toolkit, such as bdp-udf-cbs1.2.jar.
[0110] In addition, the specific process of using the jexl package to implement dynamic calculation functions is as follows:
[0111] Step a: Create a JEXL expression calculation engine and load the extended custom function into the JEXL expression calculation engine.
[0112] Among them, you can define any function library required for any task scenario to implement the extension of Hive library functions (such as operation expressions), and add the extended functions to the JEXL expression calculation engine.
[0113] Step b: Create a calculation expression to be executed through the first input parameter expressionStr.
[0114] The calculation expression to be executed can support extended custom operation expressions. For example, through the first input parameter, the execution script for creating a calculation expression to be executed can be JexlExpression e = jexl.createExpression (formula). Taking the calculation of the loan principal channel fee as an example, the formula can be expressed as:
[0115]
[0116] Step c: Load the business data required for executing the calculation expression through the second input parameter inParaMap, and push the business data into the jexl expression calculation engine.
[0117] For example, through the second input parameter, the execution script for loading the business data required for executing the calculation expression can be:
[0118]
[0119]
[0120] Step d: Execute the calculation expression and return the result.
[0121] For example, taking the calculation of the loan principal channel fee as an example, assuming that the difference between the loan settlement date Paidoutdate and the loan disbursement date Registerdate exceeds the preset interval number of days (Nday=30), the expression for calculating the loan principal channel fee is executed, and the returned result (i.e., the loan principal channel fee) = 1*500*0.05=25.
[0122] Step 3: Call the UDF function through the SQL data operation script written in the Hive library to calculate the indicator results of any business indicator.
[0123] Before executing a SQL data operation script written in the Hive library, load the custom class toolkit and the corresponding class method information. Then, create a temporary function, calcfee, in the Hive library. This temporary function serves as a dynamic formula calculation function, dynamically calling the class method corresponding to the class toolkit to calculate the results of any business indicator. This temporary function can then be called when executing the SQL data operation script to calculate the results of any business indicator.
[0124] The script to create the temporary function calcfee in the Hive library can be:
[0125] add jar viewfs: / / / apps-data / cnc-common / cnc_udf / bdp-udf-cbs1.2.jar;
[0126] create temporary function calcfee as "cn.xxxx.cnc.bdp.udf.cbs.feeCalc.impl.CalcFeeOnFeeType";
[0127] After creating the temporary function calcfee, pre-write a general SQL framework, build input parameters, and then call the UDF function through select calcfee() to obtain the indicator results of any business indicator. In this way, this solution does not need to pre-customize the operation expression in the SQL data operation script. Based on the configuration information in the algorithm configuration table TM_CBS_CALCULATE, the corresponding operation expression can be dynamically obtained and passed into the parameter list to achieve dynamic calculation of the indicator results of one or several business indicators.
[0128] Assume there are three business indicators, namely business indicator A, business indicator B, and business indicator C. The operation expression corresponding to business indicator A is configured as F(A), the operation expression corresponding to business indicator B is configured as F(B), and the operation expression corresponding to business indicator C is configured as F(C). If the indicator results of these three business indicators are calculated using the existing technical solution, the SQL data operation script written to calculate the indicator results of these three business indicators is as follows:
[0129] Select loan_id,
[0130] F(A)as A,
[0131] F(B)as B,
[0132] F(C)as C,
[0133] From TM_LOAN;
[0134] However, if a new business indicator needs to be added, such as a new business indicator D, in order to calculate the indicator result of the new business indicator D, the SQL data operation script must be modified and redeveloped to achieve the calculation of the indicator result of the new business indicator D. However, modifying the SQL data operation script may also affect the indicator results of the calculation of business indicators A, business indicator B and business indicator C.
[0135] If the solution of the present invention is adopted, the operation expressions corresponding to business indicators A, B, and C are pre-configured in the algorithm configuration table TM_CBS_CALCULATE, that is, A=F(A), B=F(B), and C=F(C). In this way, F(A), F(B), and F(C) can be automatically obtained through the temporary function calcfee() in the pre-written SQL data operation script, rather than pre-setting F(A), F(B), and F(C) in the SQL data operation script. If a new business indicator is needed, such as a new business indicator D, it is only necessary to configure the operation expression corresponding to the new business indicator D in the algorithm configuration table TM_CBS_CALCULATE, that is, configure D=F(D). This can achieve dynamic acquisition of the indicator results of the new business indicator D through configuration without modifying the pre-written SQL data operation script.
[0136] Taking the calculation of loan principal channel fees as an example, the SQL data operation script written in the Hive library to obtain the loan principal channel fees is:
[0137] Select l.loan_id,c,formula,
[0138] calcfee(c.formula,map(“Nday”,l.Nday,
[0139] "Paidoutdate",l.Paidoutdate,
[0140] "Registerdate",l.Registerdate,
[0141] "Fee_Rate",l.Fee_Rate,
[0142] "Loan_Amt", l.Loan_Amt)
[0143] )as calcAmt
[0144] From TM_CBS_CALCULATE c
[0145] join TM_LOAN l
[0146] on c.product_id=l.product_id
[0147] where c.id = "xx";
[0148] After receiving the user's instruction to query the loan principal channel fee, based on the operation expression identifier for calculating the loan principal channel fee, the corresponding operation expression is obtained from the algorithm configuration table TM_CBS_CALCULATE, and the business data matching the operation expression is obtained from the business database TM_LOAN corresponding to the loan principal channel fee, that is, the business data matching each attribute in the attribute table of the operation expression is obtained, and then the operation expression and the business data are passed to the temporary function calcfee, and the class toolkit is called through the temporary function calcfee. Based on the operation expression and the business data, the class toolkit is executed to calculate the loan principal channel fee.
[0149] The above embodiment demonstrates that after receiving a data query instruction for obtaining the indicator results of a business indicator based on business data, a dynamic formula calculation function configured in an SQL data operation script can automatically obtain the business indicator's operation expression from the algorithm configuration library, as well as the business values of each operation factor of the operation expression from the business data. The dynamic formula calculation function then calls the operation expression engine toolkit and executes the operation expression engine toolkit based on the operation expression and the business values of each operation factor, thereby obtaining the indicator results of the business indicator in a timely and accurate manner. In this way, this solution can automatically obtain the operation expression of the business indicator to be calculated by calling the dynamic formula calculation function, without having to pre-set a fixed operation expression in the SQL data operation script. This allows for dynamic configuration of the operation expression of the business indicator and makes the execution of the SQL data operation script more flexible. Furthermore, even if a new operation expression needs to be added, this solution only needs to configure the new operation expression in the algorithm configuration library. The dynamic formula calculation function in the SQL data operation script can then automatically obtain the new operation expression without having to modify the SQL data operation script. Therefore, this solution can reduce the workload of developers and improve the efficiency of calculating the indicator results of the business indicator.
[0150] Based on the same technical concept, Figure 2 An apparatus for calculating a business indicator provided by an embodiment of the present invention is exemplarily shown, and the apparatus can execute the process of the method for calculating a business indicator.
[0151] like Figure 2 As shown, the device includes:
[0152] The receiving unit 201 is configured to receive a data query instruction; the data query instruction is configured to obtain an indicator result of a business indicator based on business data;
[0153] The processing unit 202 is used to obtain the operation expression of the business indicator from the algorithm configuration library and the business value of each operation factor of the operation expression from the business data through the dynamic formula calculation function configured in the structured query language SQL data operation script; the algorithm configuration library stores the description information of the operation expression of each business indicator and the description information of each operation factor; call the operation expression engine toolkit through the dynamic formula calculation function; execute the operation expression engine toolkit based on the operation expression and the business value of each operation factor to obtain the indicator result of the business indicator.
[0154] Optionally, the processing unit 202 is further configured to:
[0155] Before receiving the data query instruction, for each business indicator, setting the description information of the corresponding operation expression and the description information of each operation factor of the operation expression for the business indicator;
[0156] The description information of the operation expression of each business indicator and the description information of each operation factor of the operation expression are stored in the algorithm configuration library.
[0157] Optionally, the algorithm configuration library includes an algorithm description table and an algorithm attribute table; the algorithm description table is used to configure the type of the business indicator, the operation expression of the business indicator, the name of the business indicator, and the identifier of the operation expression; the algorithm attribute table is used to configure the identifier of the operation expression, the name of each operation factor of the operation expression, and the data type of each operation factor of the operation expression;
[0158] The processing unit 202 is further configured to:
[0159] If a new business indicator is added, the type of the new business indicator, the operation expression of the new business indicator, the name of the new business indicator and the identifier of the operation expression of the new business indicator are configured in the algorithm description table, and the identifier of the operation expression of the new business indicator, the names of the various operation factors of the operation expression of the new business indicator and the data types of the various operation factors of the operation expression of the new business indicator are configured in the algorithm attribute table.
[0160] Optionally, the processing unit 202 is further configured to:
[0161] Before receiving the data query instruction, a sql data operation script for determining the indicator results of the business indicator is constructed based on the dynamic formula calculation function, the algorithm configuration library and the business database; the business database stores the business values of each operation factor of the operation expression of each business indicator.
[0162] Optionally, the processing unit 202 is specifically configured to:
[0163] Define a class for determining the indicator result corresponding to the business indicator, and define a first input parameter and a second input parameter of the class; the first input parameter is used to load the operation expression of the business indicator in the algorithm configuration library; the second input parameter is used to load the business value corresponding to each operation factor of the operation expression that meets the business indicator in the business data;
[0164] Define the output parameters of the class and define the calculation methods involved in the class;
[0165] The first input parameter, the second input parameter, the output parameter and the calculation method of the class are packaged into the operation expression engine toolkit.
[0166] Optionally, the processing unit 202 is further configured to:
[0167] After obtaining the business value of each operation factor of the operation expression from the business data, verifying the business value of each operation factor of the operation expression to determine whether the data format of the business value of each operation factor of the operation expression meets the data format requirement corresponding to the second input parameter;
[0168] If not, the business value of each operation factor of the operation expression is converted into a business value that meets the data format requirement corresponding to the second input parameter.
[0169] Optionally, the dynamic formula calculation function is a temporary function constructed in Hive; the operation expression engine toolkit is constructed based on the Java data format;
[0170] The processing unit 202 is further configured to:
[0171] After obtaining the indicator result of the business indicator, the indicator result in Java data format is converted into an indicator result that meets the data format requirements of Hive.
[0172] Based on the same technical concept, an embodiment of the present invention further provides a computing device, such as Figure 3 As shown, it includes at least one processor 301 and a memory 302 connected to the at least one processor. The embodiment of the present invention does not limit the specific connection medium between the processor 301 and the memory 302. Figure 3For example, the processor 301 and the memory 302 are connected via a bus. The bus can be divided into an address bus, a data bus, a control bus, and the like.
[0173] In an embodiment of the present invention, the memory 302 stores instructions that can be executed by at least one processor 301. By executing the instructions stored in the memory 302, the at least one processor 301 can execute the steps included in the aforementioned method for calculating business indicators.
[0174] Among them, the processor 301 is the control center of the computing device. It can use various interfaces and lines to connect various parts of the computing device, and realize data processing by running or executing instructions stored in the memory 302 and calling data stored in the memory 302. Optionally, the processor 301 may include one or more processing units. The processor 301 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, etc., and the modem processor mainly processes the issuance of instructions. It is understandable that the above-mentioned modem processor may not be integrated into the processor 301. In some embodiments, the processor 301 and the memory 302 may be implemented on the same chip. In some embodiments, they may also be implemented on separate chips.
[0175] The processor 301 can be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit (ASIC), a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component, and can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present invention. A general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in the embodiment of the method for calculating business indicators can be directly embodied as being executed by a hardware processor, or can be executed by a combination of hardware and software modules in the processor.
[0176] The memory 302 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs, and modules. The memory 302 may include at least one type of storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory, a random access memory (RAM), a static random access memory (SRAM), a programmable read-only memory (PROM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic memory, a magnetic disk, an optical disk, and the like. The memory 302 is any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 302 in the embodiment of the present invention may also be a circuit or any other device that can implement a storage function, for storing program instructions and / or data.
[0177] Based on the same technical concept, an embodiment of the present invention also provides a computer-readable storage medium, which stores a computer program that can be executed by a computing device. When the program runs on the computing device, the computing device executes the steps of the above-mentioned method for calculating business indicators.
[0178] It will be understood by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0179] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. Figure 1a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0180] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0181] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 The steps for the function specified in one or more boxes.
[0182] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.
[0183] Obviously, those skilled in the art may make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if such changes and modifications of the present invention fall within the scope of the claims and their equivalents, the present invention is intended to include such changes and modifications.
Claims
1. A method for calculating business indicators, characterized in that: include: Receive a data query instruction; the data query instruction is used to obtain indicator results of business indicators based on business data; Obtaining the business indicator's operational expression from an algorithm configuration library and the business value of each operational factor of the operational expression from the business data through a dynamic formula calculation function configured in a structured query language SQL data operation script; the algorithm configuration library stores description information of the operational expression of each business indicator and description information of each operational factor; Calling the operation expression engine toolkit through the dynamic formula calculation function; Based on the operation expression and the business values of the operation factors, executing the operation expression engine toolkit to obtain the indicator result of the business indicator; The algorithm configuration library includes an algorithm description table and an algorithm attribute table; the algorithm description table is used to configure the type of the business indicator, the operation expression of the business indicator, the name of the business indicator and the identifier of the operation expression; The algorithm attribute table is used to configure the identifier of the operation expression, the name of each operation factor of the operation expression, and the data type of each operation factor of the operation expression; The method further comprises: If a new business indicator is added, the type of the new business indicator, the operation expression of the new business indicator, the name of the new business indicator and the identifier of the operation expression of the new business indicator are configured in the algorithm description table, and the identifier of the operation expression of the new business indicator, the names of the various operation factors of the operation expression of the new business indicator and the data types of the various operation factors of the operation expression of the new business indicator are configured in the algorithm attribute table.
2. The method according to claim 1, wherein Before receiving the data query instruction, it also includes: For each business indicator, set the description information of the corresponding operation expression and the description information of each operation factor of the operation expression for the business indicator; The description information of the operation expression of each business indicator and the description information of each operation factor of the operation expression are stored in the algorithm configuration library.
3. The method according to claim 1, wherein Before receiving the data query instruction, it also includes: Based on the dynamic formula calculation function, the algorithm configuration library and the business database, a sql data operation script for determining the indicator results of the business indicators is constructed; the business database stores the business values of each operation factor of the operation expression of each business indicator.
4. The method according to claim 1, wherein Determine the expression engine toolkit as follows: Define a class for determining the indicator result corresponding to the business indicator, and define a first input parameter and a second input parameter of the class; the first input parameter is used to load the operation expression of the business indicator in the algorithm configuration library; the second input parameter is used to load the business value corresponding to each operation factor of the operation expression that meets the business indicator in the business data; Define the output parameters of the class and define the calculation methods involved in the class; The first input parameter, the second input parameter, the output parameter and the calculation method of the class are packaged into the operation expression engine toolkit.
5. The method according to claim 4, wherein After obtaining the business value of each operation factor of the operation expression from the business data, the method further includes: Verifying the business value of each operation factor of the operation expression to determine whether the data format of the business value of each operation factor of the operation expression meets the data format requirement corresponding to the second input parameter; If not, the business value of each operation factor of the operation expression is converted into a business value that meets the data format requirement corresponding to the second input parameter.
6. The method according to any one of claims 1 to 5, characterized in that The dynamic formula calculation function is a temporary function built in Hive; the operation expression engine toolkit is built based on the Java data format; After obtaining the indicator results of the business indicators, the following steps are also included: Convert the Java data format indicator results into the Hive data format requirements.
7. A device for calculating business indicators, characterized in that: include: A receiving unit, configured to receive a data query instruction; the data query instruction is used to obtain an indicator result of a business indicator based on business data; A processing unit is configured to obtain, through a dynamic formula calculation function configured in a structured query language (SQL) data operation script, an operation expression for the business indicator from an algorithm configuration library, and obtain business values of each operation factor of the operation expression from the business data; the algorithm configuration library stores description information of the operation expression for each business indicator and description information of each operation factor; call an operation expression engine toolkit through the dynamic formula calculation function; execute the operation expression engine toolkit based on the operation expression and the business values of each operation factor to obtain an indicator result for the business indicator; The algorithm configuration library includes an algorithm description table and an algorithm attribute table; the algorithm description table is used to configure the type of the business indicator, the operation expression of the business indicator, the name of the business indicator and the identifier of the operation expression; The algorithm attribute table is used to configure the identifier of the operation expression, the name of each operation factor of the operation expression, and the data type of each operation factor of the operation expression; The processing unit is further configured to: If a new business indicator is added, the type of the new business indicator, the operation expression of the new business indicator, the name of the new business indicator and the identifier of the operation expression of the new business indicator are configured in the algorithm description table, and the identifier of the operation expression of the new business indicator, the names of the various operation factors of the operation expression of the new business indicator and the data types of the various operation factors of the operation expression of the new business indicator are configured in the algorithm attribute table.
8. A computing device, characterized in that The system comprises at least one processor and at least one memory, wherein the memory stores a computer program, and when the program is executed by the processor, the processor executes the method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that The device stores a computer program executable by a computing device. When the program is run on the computing device, the computing device is caused to execute the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Method and device for determining liquidity indexes of business assets
CN108804166A
Business numerical calculation method and device, computer equipment and storage medium
CN110390072A