Expression precision calculation method, device, storage medium and program product
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-21
- Publication Date
- 2026-08-11
AI Technical Summary
[0005]本申请实施例提供一种表达式精度计算方法、设备、存储介质及程序产品,用以解决现有数据库系统对表达式节点结果精度的支持覆盖不完整、且缺乏统一精度计算框架的技术问题
[0005]本申请实施例提供一种表达式精度计算方法、设备、存储介质及程序产品,用以解决现有数据库系统对表达式节点结果精度的支持覆盖不完整、且缺乏统一精度计算框架的技术问题。
Smart Images

Figure CN122548073A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of database technology, and in particular to a method, device, storage medium, and program product for calculating expression precision. Background Technology
[0002] In database systems, applications need to allocate memory space based on the precision of query results to avoid memory overflow or resource waste.
[0003] Existing database systems can provide the data type and precision of database table columns, for example, through the numeric(p,s) or varchar(n) definition of system table record columns. For expressions in user queries, some database products can return the precision of certain types of expressions; for example, SQL Server can return the precision of string functions, numeric functions, and date / time functions, while Oracle can return the precision of string functions and date / time functions.
[0004] However, for dynamically generated expression nodes such as function nodes, existing database systems do not provide complete support for the precision of expression results and lack a unified precision calculation framework. Summary of the Invention
[0005] This application provides an expression precision calculation method, device, storage medium, and program product to solve the technical problems of incomplete support coverage for expression node result precision in existing database systems and the lack of a unified precision calculation framework.
[0006] In a first aspect, embodiments of this application provide a method for calculating expression precision, the method comprising:
[0007] Get the node type of the expression node, where the data structure of the expression node contains a precision field;
[0008] Based on the node type, the corresponding precision determination strategy is used to calculate the result precision of the expression node. The precision determination strategy includes: when the expression node is a function node, the pre-stored precision value of the function node is obtained from the function buffer. If the pre-stored precision value is valid, the pre-stored precision value is used as the result precision; otherwise, the corresponding precision calculation function is called to calculate the result precision.
[0009] The result precision is stored in a precision field, which is then retrieved by the application through a metadata interface.
[0010] In this embodiment, by pre-setting a precision field in the data structure of the expression node, and using a corresponding precision determination strategy according to the node type to calculate the result precision of the expression node, the calculation result is stored in the precision field and output, so that the application can obtain the result precision of the expression node, thereby accurately allocating memory space.
[0011] In one possible implementation, the precision of the result is calculated by calling the corresponding precision calculation function, including:
[0012] Select the corresponding precision calculation function based on the operation logic of the expression node;
[0013] Input the parameters of the expression node into the precision calculation function, and obtain the precision of the result output by the precision calculation function.
[0014] In this implementation, by standardizing the calling process of the precision calculation function, the precision calculation logic of different expression nodes can be organized and called in a unified way, thereby reducing the implementation complexity of the precision calculation function when adding new expression types and improving the scalability and maintainability of the system.
[0015] In one possible implementation, calling the corresponding precision calculation function to calculate the result precision also includes:
[0016] Construct a function buffer and store the address of the precision calculation function in the function buffer;
[0017] The address of the precision calculation function is obtained by retrieving the function buffer from the hash table;
[0018] The precision calculation function is called based on its address.
[0019] In this implementation, by constructing a function buffer and using a hash table retrieval mechanism, the search method for precision calculation functions is optimized from traversal search to hash index search. This improves the location speed of precision calculation functions when there are a large number of built-in functions (such as hundreds), thereby enhancing the overall execution efficiency of expression precision calculation.
[0020] In one possible implementation, the method further includes:
[0021] A predefined type conversion rule table is used to record the precision mapping logic when converting different source types to the target type.
[0022] When an expression node involves data type conversion, the precision of the target type is determined based on the type conversion rule table.
[0023] In this implementation, a predefined type conversion rule table is used to centrally manage the precision mapping logic between different data types. This allows expression nodes to determine the precision of the target type based on unified rules when data type conversion is involved, thus solving the problem of inconsistent precision derivation in type conversion scenarios.
[0024] In one possible implementation, the accuracy determination strategy also includes:
[0025] When the expression node is a CASE node or a COALESCE node, the data types of each branch of the expression node are unified, and the accuracy of the result is calculated according to the aggregation rules.
[0026] In this implementation, by unifying the data types of each branch of the CASE node or COALESCE node before calculating the precision according to the aggregation rules, the problem of not being able to determine the precision of the result due to inconsistent branch types or precision in multi-branch expressions is solved, enabling multi-branch expressions to return definite precision information.
[0027] In one possible implementation, the aggregation rules include:
[0028] When the data type is string, the maximum length of each branch of the expression node is taken as the result precision;
[0029] When the data type is numeric, the sum of the maximum value of the integer part and the maximum value of the decimal part in each branch of the expression node is taken as the total number of digits, and the maximum value of the decimal part is taken as the number of decimal places. The total number of digits and the number of decimal places are used as the precision of the result.
[0030] When the data type is date / time, the maximum precision among the branches of the expression node is taken as the result precision.
[0031] In this implementation, by adopting differentiated aggregation rules for different data types, the CASE node or COALESCE node can accurately calculate the result precision based on the characteristics of the data type after unifying the data type, thereby improving the accuracy and rationality of the precision derivation of multi-branch expressions.
[0032] In a second aspect, this application provides an electronic device, including: a processor and a memory communicatively connected to the processor;
[0033] The memory stores instructions that the computer executes;
[0034] The processor executes computer-executable instructions stored in memory to implement any of the methods of the first aspect.
[0035] Thirdly, this application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the method of any one of the first aspects.
[0036] Fourthly, this application provides a computer program product, including a computer program that, when executed by a processor, implements the method of any one of the first aspects. Attached Figure Description
[0037] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0038] Figure 1 A flowchart illustrating an expression precision calculation method provided in an embodiment of this application;
[0039] Figure 2 This is a flowchart of node type branch determination provided in an embodiment of this application;
[0040] Figure 3 This is a flowchart illustrating the function node precision calculation method provided in an embodiment of this application.
[0041] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0042] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application.
[0043] It should be noted that the expression precision calculation method, device, storage medium and program product provided in the embodiments of this application can be used in the field of database technology, or in any field other than database technology. The embodiments of this application do not limit the application field of the expression precision calculation method, device, storage medium and program product.
[0044] The specific application scenarios of this application embodiment can be applied to query optimization and resource management scenarios in database management systems (DBMS). In high-precision data processing fields such as finance, healthcare, and real-time analytics, applications need to adjust memory allocation, verify data consistency, and optimize query plans based on the precision of expression results.
[0045] For example, in financial trading systems, the precision of power(value,2) directly affects memory pre-allocation strategies; in real-time data analysis scenarios, the precision derivation of the case when expression or the coalesce function determines the correctness of data type conversion; in set operations involving multi-table queries, the precision unification rules of union or intersect affect the accuracy of query results.
[0046] For the above application scenarios, existing database systems typically handle expression precision in the following ways.
[0047] Oracle supports precision calculations for string functions and date / time functions. For example, the substr function returns the corresponding precision based on the length of the input string, but numeric functions such as power or avg return the system's default maximum precision.
[0048] SQL Server supports precision calculations for string, numeric, and date / time functions. For example, the precision of avg(value) is explicitly numeric(38,max(s,6)), and the precision of the result can be deduced based on the input parameters.
[0049] In addition, some database systems can obtain the precision information of database table columns (such as numeric(p,s) or varchar(n)) through metadata interfaces, but the precision calculation and storage mechanism for dynamically generated expressions such as function nodes, numerical operation nodes, and string operation nodes in queries is not yet perfect.
[0050] However, the solution described above has the following technical problems:
[0051] Existing database systems lack a unified computational framework for handling the precision of expression nodes. Although some database systems have set up precision return capabilities for some function nodes, their precision calculation logic is scattered and the rules are inconsistent. For complex expression scenarios such as function nesting, type conversion, CASE expressions, and set operations, there is a lack of a general precision calculation and storage mechanism.
[0052] Furthermore, the precision calculation rules differ significantly across different data types. For example, the precision of string types depends on their length, the precision of numeric types depends on the number of integer and decimal places, and the precision of date and time types depends on the precision in seconds. Existing systems, when processing multi-branch expressions (such as case expressions or the coalesce function), cannot determine the precision of the result after unifying the data types of each branch due to the lack of unified aggregation rules.
[0053] Furthermore, existing systems lack defined precision mapping rules for data type conversion. For example, when converting a string to a numeric type, the lack of a string format validation mechanism and rules for adjusting the precision after conversion leads to unpredictable precision of the conversion result.
[0054] For precision calculations of hundreds of built-in functions, existing systems use a traversal search method to locate the corresponding precision calculation function. Because no caching mechanism is implemented, each lookup requires traversing the function list, resulting in low function location efficiency.
[0055] The expression precision calculation method provided in this application aims to solve the above-mentioned technical problems of the prior art. The core technical concept of this application is to construct a unified expression precision calculation mechanism. This mechanism enables dynamically generated expression nodes such as function nodes, numerical operation nodes, and string operation nodes to store result precision information by configuring a precision field in the data structure of the expression node.
[0056] For different expression node types, this mechanism employs corresponding precision determination strategies and combines them with function buffer optimization techniques to improve the efficiency of precision calculation for function nodes. Furthermore, this mechanism covers three core data types: strings, numbers, and dates / times, and supports precision calculation for various complex expressions such as CASE nodes, COALESCE nodes, and set operation nodes.
[0057] Through the above technical means, the embodiments of this application solve the problems of incomplete configuration of precision fields in expression nodes, inconsistent precision calculation rules, unclear type conversion precision derivation, and low efficiency of large-scale function processing in existing database systems.
[0058] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.
[0059] First, combine Figures 1 to 3 The expression precision calculation method provided in the embodiments of this application will be introduced. Figure 1This is a flowchart illustrating an expression precision calculation method provided in an embodiment of this application. Figure 2 This is a flowchart of node type branch determination provided in an embodiment of this application. Figure 3 This is a flowchart illustrating the function node precision calculation method provided in an embodiment of this application.
[0060] like Figure 1 As shown, the expression precision calculation method provided in this application includes the following steps:
[0061] S101. Get the node type of the expression node.
[0062] The database parsing layer parses the SQL query statement entered by the user, abstracts the expressions in the SQL query statement into corresponding expression nodes, and identifies the node type of the expression node. The data structure of the expression node includes a precision field to store the precision of the calculation result.
[0063] S102. Based on the node type, use the corresponding precision determination strategy to calculate the result precision of the expression node.
[0064] Based on the node type identified by S101, the system uses a precision determination strategy that matches the node type to calculate the result precision of the expression node.
[0065] Specifically, such as Figure 2 As shown, the system sequentially determines the node type of the current parsing layer node through conditional branches, including constant nodes, table column or variable nodes, function nodes, numerical or string operation nodes, CASE or COALESCE expression nodes, and set operation nodes. It should be noted that... Figure 2 The order of judgment shown is only used to distinguish node types and does not indicate that there is a sequential execution dependency between the processing steps. Those skilled in the art will understand that this judgment process corresponds to the conventional conditional branching logic in a database parser.
[0066] When an expression node is identified as a function node, the system executes the function node precision calculation process. For example... Figure 3 As shown, the process includes the following steps:
[0067] First, the system retrieves the pre-stored precision value corresponding to the function node from the pre-built function buffer. The function buffer is built during system initialization and stores the pre-stored precision value corresponding to each built-in function. The pre-stored precision value is represented using a preset encoding rule. For example, an integer type is used to identify the precision, where -1 represents the maximum precision (e.g., timestamp type), non-negative integers represent specific precision values (e.g., 6 represents timestamp(6)), and other negative numbers (e.g., -2, -3) represent illegal values, i.e., the precision needs to be dynamically calculated.
[0068] Next, the system determines whether the obtained pre-stored precision value is valid. According to the preset encoding rules, a precision value greater than or equal to -1 (i.e., -1, 0, 1, 2...) is a valid value, and a precision value less than -1 (i.e., -2, -3...) is an invalid value.
[0069] If the pre-stored precision value is valid, the system will directly use the pre-stored precision value as the result precision of the function node, and the process will end.
[0070] If the pre-stored precision value is invalid, the system proceeds with the calculation process. Specifically, the system retrieves the precision calculation function index corresponding to the function from the function buffer, locates the address of the precision calculation function in the dedicated area based on the index, calls the precision calculation function through the address, and uses the precision information of the function node's input parameters as input. The precision calculation function then outputs the precision result.
[0071] For example, for the absolute value function `abs`, its input parameter is a numeric type, and the precision calculation function directly returns the precision of the input parameter; that is, if the input is `numeric(10,2)`, the output is `numeric(10,2)`. For the rounding function `round(value,d)`, its input parameters include the value to be rounded and the number of rounding digits. The precision calculation function determines the precision of the result based on the number of rounding digits; that is, if the input is `numeric(10,2)` and the number of rounding digits is 1, the output is `numeric(10,1)`.
[0072] S103. Store the result precision in the precision field for the application to obtain through the metadata interface.
[0073] The system stores the calculated precision in the precision field of the expression node for later use. The application can obtain this precision information through the database's metadata interface, thereby accurately allocating memory space.
[0074] The expression precision calculation method provided in this embodiment offers precision storage capability for dynamically generated expressions such as function nodes by configuring a precision field in the data structure of the expression node. Based on this, by combining the pre-stored precision value in the function buffer with a dynamic calculation mechanism, the database can accurately calculate and store the precision of the function node results. By storing the calculation results in the precision field, applications can obtain the precision information of the expression results through a metadata interface, thereby solving the technical problems of incomplete support for the precision of expression node results and the lack of a unified precision calculation framework in existing database systems.
[0075] In one possible implementation, when the system determines that it needs to call the precision calculation function to calculate the precision of the result, the following steps are performed.
[0076] First, the system selects the corresponding precision calculation function based on the operation logic of the expression node. Different function nodes have different operation logics; for example, the absolute value function `abs` calculates the absolute value, the rounding function `round` rounds to a specified number of digits, and the string concatenation function `concat` joins multiple strings. The system matches the corresponding precision calculation function from a pre-defined function library based on the function identifier determined during the expression node's parsing phase.
[0077] Secondly, the system inputs the precision information of the parameters of the expression node into the selected precision calculation function. The parameters of the expression node include the actual parameters passed in when the function is called. These parameters may be constants, table entries, or other expressions. The system needs to obtain the precision information of these parameters first. For example, for the function call abs(c1), the parameter is table entry c1, and the system obtains the precision information of c1 (e.g., numeric(10,2)) as input; for the function call round(c1,2), the parameters include table entry c1 and constant 2, and the system obtains the precision information of c1 (e.g., numeric(10,2)) and the precision information of constant 2 (as an integer with a precision of numeric(1,0)) as input.
[0078] Finally, the system obtains the precision of the result output by the precision calculation function. The precision calculation function calculates and returns the precision based on the precision information of the input parameters and its own computational logic. For example, for the `abs` function, the precision calculation function directly returns the precision of the input parameters; if the input is `numeric(10,2)`, the output is `numeric(10,2)`. For the `round` function, the precision calculation function adjusts the number of decimal places based on the rounding digits; if the input is `numeric(10,2)` and the rounding digit is 1, the output is `numeric(10,1)`. For the `concat` function, the precision calculation function adds the string lengths of each input parameter; if the input is `varchar(50)` and `varchar(20)`, the output is `varchar(70)`.
[0079] By standardizing the calling process of precision calculation functions into a unified flow, the precision calculation logic of different function nodes can be executed in a consistent manner. This standardized flow decouples the function's own computational logic from its precision calculation logic. When adding a new function, only the corresponding precision calculation function needs to be added, without modifying the core calculation framework. This reduces the system's implementation complexity and improves code maintainability and scalability.
[0080] In one possible implementation, to improve the efficiency of precision calculation for large-scale built-in functions, the system constructs a function buffer during the initialization phase and uses a hash table for fast retrieval.
[0081] First, the system creates a dedicated area in memory as a function buffer to store the addresses of the precision calculation functions corresponding to each built-in function. The system iterates through the list of built-in functions, determines the precision calculation function for each function, and establishes a mapping between the function's identifier and the address of the precision calculation function, storing this mapping in the function buffer. For example, for the absolute value function `abs`, the system stores the address of its precision calculation function `abs_precision` in the buffer; for the rounding function `round`, the system stores the address of its precision calculation function `round_precision` in the buffer.
[0082] Secondly, the system uses a hash table structure to manage the function buffer. The key of the hash table is the function identifier (e.g., function name), and the value is the index or direct address of the precision calculation function corresponding to that function in the buffer. By calculating the function identifier using a hash function, the system can quickly locate the corresponding storage location. For example, when it is necessary to retrieve the precision calculation function of the `abs` function, the system calculates `hash("abs")`, directly locating the location in the buffer where the address of the `abs_precision` function is stored, without needing to traverse the entire function list.
[0083] When the system needs to call a precision calculation function in the real-time computing process, it retrieves the function buffer through the hash table, calculates the hash value based on the function identifier of the current function node, quickly obtains the address of the corresponding precision calculation function, and then calls the precision calculation function based on the address to perform precision calculation.
[0084] By constructing a function buffer and employing a hash table retrieval mechanism, the lookup method for precision calculation functions is optimized from traversal search to hash index search. When the number of built-in functions in the system is large (e.g., hundreds), this mechanism reduces the time complexity of function location from O(n) to O(1), improving the lookup efficiency of precision calculation functions, reducing resource consumption during system runtime and startup, and thus improving the overall execution performance of expression precision calculation.
[0085] In one possible implementation, the system predefines a type conversion rule table to record the precision mapping logic when converting different source types to target types. The type conversion rule table contains multiple mapping rules, each defining how to determine the precision when converting from a specific source type (e.g., string type, numeric type, date / time type) to a specific target type.
[0086] When an expression node involves data type conversion, the system queries the type conversion rule table based on the source and target types of the expression node to obtain the corresponding precision mapping rule, and determines the precision of the target type according to the rule.
[0087] For example, a type conversion rule table may include the following mapping rules:
[0088] When the source type is a string and the target type is a numeric type, if the string conforms to the numeric format, the target precision is the total number of digits and the number of decimal places in the corresponding numeric value. For example, when the string constant '123.45' is converted to a numeric type, its total number of digits is 5 and its number of decimal places is 2, so the target precision is numeric(5,2). If the string does not conform to the numeric format, it is marked as an illegal value.
[0089] When the source type is a string and the target type is a date / time type, the precision in seconds is determined based on the string's format. For example, when the string constant '2024-01-01 12:34:56.123' is converted to a date / time type, its precision in seconds is 3, therefore the target precision is timestamp(3).
[0090] When the source type is numeric and the target type is string, the string length is the total number of digits plus 2. For example, when the numeric(10,2) is converted to a string, the target precision is varchar(12) according to the conversion rules.
[0091] By using a predefined type conversion rule table, the precision mapping logic between different data types is centrally managed. When an expression node involves data type conversion, the system determines the precision of the target type according to unified rules, thereby solving the problems of inconsistent precision derivation and unpredictable results in type conversion scenarios and improving the accuracy of data type conversion.
[0092] In one possible implementation, when the expression node is a CASE node or a COALESCE node, the system adopts a multi-branch unified processing strategy to calculate the accuracy of the result.
[0093] A CASE expression contains multiple branches, each corresponding to a result expression; a COALESCE expression contains multiple parameters and returns the first non-null value. Since the data types and precision of the branches or parameters may differ, the system first standardizes the data types of all branches and then calculates the final precision according to the aggregation rules.
[0094] Specifically, the system traverses all branches of the CASE or COALESCE node, collecting the result type information of each branch. If the data types of the branches are inconsistent, the system performs type promotion according to preset type priority rules, unifying all branches to a compatible data type. For example, if one branch returns varchar(50) and another branch returns varchar(20), then both are promoted to varchar(50).
[0095] After unifying the data types, the system calculates the result precision according to the corresponding aggregation rules based on the data type. If the data type is a string, the maximum length in each branch is taken as the result precision; if the data type is a numeric type, the sum of the maximum integer part and the maximum decimal part in each branch is taken as the total number of digits, and the maximum decimal part is taken as the number of decimal places; if the data type is a date / time type, the maximum precision in each branch is taken as the result precision.
[0096] For example, for the following CASE expression:
[0097] CASE
[0098] WHEN age > 18 THEN name -- varchar(50)
[0099] WHEN age > 12 THEN nickname -- varchar(20)
[0100] ELSE 'unknown' -- varchar(7)
[0101] END
[0102] The system unifies the data type of each branch to string, and takes the maximum value of the length of each branch (the maximum value of 50 among 50, 20, and 7, which is 50), so the precision of the result is varchar(50).
[0103] For example, consider the following COALESCE expression:
[0104] COALESCE(price1,price2,price3) -- price1 is numeric(10,2), price2 is numeric(8,4), and price3 is numeric(12,3).
[0105] The system unifies the data type of all branches to numeric type, takes the maximum value of the integer part (the maximum value of 9 among 8, 4, and 9), and takes the maximum value of the decimal part (the maximum value of 4 among 2, 4, and 3). Therefore, the precision of the result is numeric(13,4) (total number of digits 9+4=13, number of decimal places 4).
[0106] By unifying the data types of each branch in the CASE or COALESCE node and calculating the precision according to the aggregation rules, the problem of not being able to determine the precision of the result in multi-branch expressions due to inconsistent branch types or precision is solved. This enables multi-branch expressions to return definite precision information, improving the completeness and accuracy of expression precision derivation.
[0107] In one possible implementation, the system uses corresponding aggregation rules to calculate the accuracy of the results for different data types.
[0108] When the unified data type is a string, the system takes the maximum string length from each branch as the result precision. For example, if the three branches of a CASE expression return strings of length 50, 20, and 7 respectively, then the result precision is the string of length 50.
[0109] When the unified data type is numeric, the system first determines the maximum value of the integer part and the maximum value of the decimal part in each branch. Then, the sum of the two is used as the total number of digits, and the maximum value of the decimal part is used as the number of decimal places. For a detailed implementation, please refer to the example of the COALESCE expression in the previous embodiment, which will not be repeated here.
[0110] When the unified data type is a date / time type, the system takes the maximum value of the second precision among the branches as the result precision. For example, if the two branches of the CASE expression return timestamp(2) and timestamp(6) respectively, then the result precision is timestamp(6).
[0111] By defining differentiated precision aggregation rules for different data types (such as strings, numbers, and dates / times), multi-branch expressions can accurately calculate the precision of the result based on the inherent characteristics of the data type after unifying the data type, thereby improving the accuracy of precision derivation for multi-branch expressions.
[0112] The electronic device provided in this application embodiment can execute the method provided in the above method embodiment. Its implementation principle and technical effect are similar, and will not be described in detail here.
[0113] This application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the methods in any of the above method embodiments.
[0114] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the methods in any of the above method embodiments.
[0115] All or part of the steps in the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a readable memory. When the program is executed, it performs the steps of the above method embodiments; and the aforementioned memory (storage medium) includes: read-only memory (ROM), RAM, flash memory, hard disk, solid-state drive, magnetic tape, floppy disk, optical disk, and any combination thereof.
[0116] This application describes embodiments with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processing unit of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processing unit of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0117] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0118] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0119] Obviously, those skilled in the art can make various modifications and variations to the embodiments of this application without departing from the spirit and scope of this application. Therefore, if these modifications and variations to the embodiments of this application fall within the scope of the claims of this application and their equivalents, this application also intends to include these modifications and variations.
[0120] In this application, the term "comprising" and its variations can refer to non-limiting inclusion; the term "or" and its variations can refer to "and / or". The terms "first", "second", etc., in this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. In this application, "multiple" refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.
[0121] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily essential to this application.
[0122] It should be further noted that although the steps in the flowchart are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowchart may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.
[0123] Furthermore, unless otherwise specified, the functional units / modules in the various embodiments of this application can be integrated into one unit / module, or each unit / module can exist physically separately, or two or more units / modules can be integrated together. The integrated units / modules described above can be implemented in hardware or as software program modules.
[0124] In the above embodiments, the descriptions of each embodiment have their own emphasis. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments. The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as the combination of these technical features does not contradict each other, it should be considered within the scope of this specification.
[0125] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.
[0126] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.
Claims
1. An expression precision calculation method characterized by, The method includes: Obtain the node type of the expression node, wherein the data structure of the expression node includes a precision field; Based on the node type, the precision of the expression node is calculated using a corresponding precision determination strategy. The precision determination strategy includes: when the expression node is a function node, obtaining the pre-stored precision value of the function node from the function buffer; if the pre-stored precision value is valid, then using the pre-stored precision value as the result precision; otherwise, calling the corresponding precision calculation function to calculate the result precision. The precision of the result is stored in the precision field, which is then retrieved by the application through the metadata interface.
2. The method of claim 1, wherein, The step of calling the corresponding precision calculation function to calculate the precision of the result includes: Select the corresponding precision calculation function based on the operation logic of the expression node; The parameters of the expression node are input into the precision calculation function to obtain the precision of the result output by the precision calculation function.
3. The method of claim 2, wherein, The step of calling the corresponding precision calculation function to calculate the precision of the result also includes: Construct a function buffer and store the address of the precision calculation function in the function buffer; The address of the precision calculation function is obtained by retrieving the function buffer from the hash table; The precision calculation function is invoked based on its address.
4. The method of claim 1, wherein, The method further includes: A predefined type conversion rule table is used to record the precision mapping logic when converting different source types to target types; When the expression node involves data type conversion, the precision of the target type is determined according to the type conversion rule table.
5. The method according to claim 1, characterized in that, The accuracy determination strategy also includes: When the expression node is a CASE node or a COALESCE node, the data type of each branch of the expression node is unified, and the accuracy of the result is calculated according to the aggregation rules.
6. The method according to claim 5, characterized in that, The aggregation rules include: When the data type is string, the maximum length of each branch of the expression node is taken as the result precision; When the data type is numeric, the sum of the maximum value of the integer part and the maximum value of the decimal part in each branch of the expression node is taken as the total number of digits, and the maximum value of the decimal part is taken as the number of decimal places. The total number of digits and the number of decimal places are used as the precision of the result. When the data type is date / time, the maximum precision among the branches of the expression node is taken as the precision of the result.
7. An electronic device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the method as described in any one of claims 1 to 6.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1 to 6.
9. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method of any one of claims 1 to 6.