A chain calling method of object methods in vastbase object-oriented programming

By adding new SQL engine syntax parsing rules to the PL/pgSQL procedural language of the vastbase database, supporting chain calls of object methods, the problem of code redundant variables and intuitiveness is solved, concise and intuitive code writing is achieved and readability and maintainability is improved.

CN116719838BActive Publication Date: 2025-08-15广州海量数据库技术有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310771443.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-28
Publication Date
2025-08-15
Estimated Expiration
2043-06-28

AI Technical Summary

Technical Problem

The PL/pgSQL procedural language of the vastbase database does not support chain calls, resulting in the use of redundant code variables and lack of intuitiveness, affecting the readability and maintainability of the code.

Method used

In the PL/pgSQL procedural language of the vastbase database, by adding new syntax parsing rules in the syntax parsing stage of the SQL engine, a syntax tree equivalent to nested calls of traditional functions is built, and identifiers are added to each layer of method calls to distinguish between method calls and ordinary function calls, and chain calls of object methods are implemented.

Benefits of technology

It simplifies the code structure, reduces the use of intermediate variables, improves the readability and maintainability of the code, and makes chain calls more concise and intuitive.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116719838B_ABST
    Figure CN116719838B_ABST
Patent Text Reader

Abstract

The present invention relates to a method and system for chaining object methods in vastbase object-oriented programming. The method includes adding a new SQL engine syntax parsing rule to the syntax parsing phase of the vastbase database SQL engine. The syntax parsing rule is used to parse chained calls of object methods and construct a syntax tree equivalent to traditional nested function calls. A method call identifier is added to each layer of method calls in the syntax tree to distinguish method calls from ordinary function calls. The method solves the problem that the PL / pgSQL procedural language does not support chained calls, enabling users to write code in a more concise and intuitive manner. By supporting chained calls, the method can reduce the use of intermediate variables, simplify the code structure, and improve the readability and maintainability of the code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of chain calling methods, and in particular relates to a chain calling method and system based on object methods in vastbase object-oriented programming. Background Art

[0002] Object-oriented programming (OOP) is a programming paradigm in which a program's functionality is organized into a collection of objects that interact through message passing. Chaining is a common programming technique in OOP that allows multiple methods to be called consecutively within a single line of code by calling a method on an object and returning the object itself. Object-oriented programming languages that support chaining provide appropriate syntactic and semantic support, making it easy for developers to use chaining to write concise and readable code. Proper application of chaining can improve code maintainability and scalability, while increasing development efficiency.

[0003] The current vastbase database has enhanced the type function to support object-oriented programming, allowing the creation of member variables and member methods, and the use of object types and the calling of object member methods in the PL / pgSQL procedural language. However, compared with the chain call of object methods, the traditional function call method used by vastbase has the following shortcomings: (1) Redundant variable use: When multiple functions need to be called continuously, the traditional writing method requires the use of intermediate variables to save the results of each function call, resulting in a large number of redundant variables in the code, reducing the readability and conciseness of the code; (2) Lack of intuitiveness: The traditional vastbase syntax requires that each function call must explicitly specify the parameters in parentheses, resulting in the code's hierarchical structure being less intuitive and difficult to quickly understand the order and relationship of function calls. Therefore, it is necessary to provide a solution to support the chain call of object methods to improve the object-oriented programming paradigm of vastbase.

[0004] Furthermore, the syntax of the PL / pgSQL procedural language doesn't support chained calls. Therefore, to support chained function calls, one feasible solution is to define a handler function whose argument is a string containing a function call chain. This function converts the string into a traditional function call and executes it. This solution is easy to implement, as it doesn't require modifying the PL / pgSQL syntax. However, it's not straightforward and concise, as the handler method must be called each time a chained call is required. Therefore, to fully support chained object method calls, it's necessary to design and define new syntax rules that support this chained function form within the PL / pgSQL procedural language. Summary of the Invention

[0005] To address the issue of the PL / pgSQL procedural language not supporting chained calls, this paper provides a method for implementing function calls of the form object.m1(args1).m2(args2) in the PL / pgSQL procedural language of the vastbase database, enabling users to write code in a more concise and intuitive manner. By supporting chained calls, this method reduces the use of intermediate variables, simplifies code structure, and improves code readability and maintainability.

[0006] Explanation of terms

[0007] vastbase database: vastbase database is an enterprise-level relational database developed for massive data based on the open source OpenGauss kernel. In A-compatible mode, vastbase supports the creation of object types and the creation of constructor functions, member properties, member methods, and static methods in object types.

[0008] Chain call: Chain call is a programming style that allows you to build complex chains of operations by using the dot operator between method calls. In a chain call, each method call returns an object that can continue to call other methods, forming a chain of call sequences.

[0009] PL / pgSQL: PL / pgSQL is a programming language that can be used to write stored procedures, triggers, functions, and anonymous code blocks in the VastBase database. It is a built-in extension language provided by VastBase to extend the functionality and flexibility of the database.

[0010] SQL Engine: The SQL engine is a highly optimized and feature-rich core component of the vastbase database. It has functions such as lexical parsing, semantic analysis, and query optimization. It is the module responsible for parsing, optimizing, and executing SQL queries.

[0011] Object-oriented support: The VastBase database enhances type creation and supports object-oriented programming, allowing the creation of member variables and member methods. Object types can also be used in the PL / pgSQL procedural language and object member methods can be called. Object member methods, like ordinary functions, are recorded in the pg_proc system table. However, a prototypekind value of m indicates that the function is a member method, and the first parameter is of object type; this parameter must be omitted when calling the function as an object.

[0012] The present invention utilizes PL / pgSQL, SQL engine and object-oriented support functions in the vastbase database to enhance the syntax of method function calls and support chain calls of object methods.

[0013] The collaborative workflow of the vastbase database's PL / pgSQL and SQL engines for object method calls is as follows: Figure 1 As shown, the following steps are included:

[0014] 1. The PL / pgSQL lexical parser receives the input code statement (taking obj.m(args) as an example) and calls the SQL engine's lexical parser to perform lexical analysis on the code.

[0015] 2. The SQL engine's lexical parser breaks down the code into a series of lexical units and performs corresponding lexical analysis and processing.

[0016] 3. The PL / pgSQL lexical parser processes the lexical units returned by the SQL engine, such as forward caching the SQL engine lexical parsing results.

[0017] 4. The PL / pgSQL parser parses the lexical units output by the lexical analyzer, matches them to the corresponding syntax rules, verifies and constructs a syntax tree, understands the structure and semantics of the code, and constructs the corresponding SQL statement to pass to the SQL engine. During this process, the parsing process determines whether the type of obj is an object type and whether m is a member function. If both are true, the call of the form obj.m(args) is converted into the SQL statement select m(obj,args).

[0018] 5. The SQL engine parses, optimizes, and executes SQL queries on the SQL statements passed by PL / pgSQL.

[0019] As can be seen from the above process, the object method call obj.m(args) is ultimately implemented by converting it into a traditional function call m(obj,args). Therefore, we consider implementing this chain syntax by converting object method chain calls into traditional nested function calls at the underlying level. For example, converting the call obj.m1(args1).m2(args2) into a call m2(m1(obj,args1),args2). To achieve this goal, there are usually two solutions:

[0020] 1. During the PL / pgSQL syntax parsing phase, chained object method calls are converted into nested function calls. For example, obj.m1(args1).m2(args2) is converted into the SQL statement select m2(m1(obj,args1),args2). However, PL / pgSQL syntax parsing primarily converts programming statements into SQL statements. Therefore, in this scenario, the SQL engine cannot distinguish whether the statement itself is a function call or an object method call. If the chained method is a regular function rather than a member method, the SQL engine's semantic parsing phase fails to recognize this as a chained call, resulting in erroneous usage (regular functions are not supposed to support chained calls). Therefore, semantic checking for improper chained calls in regular functions also needs to be performed during the PL / pgSQL syntax parsing phase, which complicates syntax and semantic parsing.

[0021] 2. Add a new SQL engine parsing rule for parsing chained object method calls and constructing a syntax tree equivalent to traditional nested function calls. For example, obj.m1(args1).m2(args2) will construct a syntax tree equivalent to the m2(m1(obj,args1),args2) call rule. However, due to VastBase's naming parsing rules, function call expressions may consist of a schema name (schema) and a function name (function), namely, schema.function(args). Therefore, when VastBase's parsing tool, bison, parses the object method chain syntax obj.m1(args1), it will cause a shift-reduce conflict with the function expression syntax schema.function(args) (both syntaxes are in the form of identifier. and identifier()).

[0022] From the above, we can see that solution 1 will increase the difficulty of semantic analysis, and solution 2 is difficult to implement. Therefore, we consider parsing the obj.m(arg) process (such as Figure 1 ), combined with Scheme 1 and Scheme 2, a new syntax implementation method for object method chain call is constructed. The specific process of the method of the present invention is as follows Figure 3 As shown. In the syntax parsing stage of PL / pgSQL, only the first layer of the object method chain call is parsed and converted, such as converting the obj.m1(args1).m2(args2) statement into only the select m1(obj,args1).m2(args2) SQL statement. Then, in the syntax parsing stage of the SQL engine, add the following Figure 4The grammar parsing rules shown in the figure construct a grammar tree equivalent to a traditional nested function call, and add an identifier to each method call layer in the grammar tree to distinguish between method calls and ordinary function calls. For example, for the expression m1(obj,args1).m2(args2), a grammar tree equivalent to m2(m1(obj,args1),args2) will be constructed. The semantic parsing of the solution of the present invention is simple, and only one identifier can be used to distinguish whether it is a method call or an ordinary function call. At the same time, the grammar implementation is simple, and only needs to be based on the PL / pgSQL parsing of obj.m1(args) ( Figure 1 Flow), concatenating the above method calls completes the conversion. Furthermore, through simple PL / pgSQL processing, this solution can uniformly parse chained calls of the form function(args0).m1(args1) and obj.m1(args1).m2(args2) without any additional processing.

[0023] Specifically, the present invention provides a chain call method for object methods in vastbase object-oriented programming, the purpose of which is to enable the Vastbase database to support chain calls on the basis of supporting object-oriented programming. This method includes adding a new SQL engine syntax parsing rule in the syntax parsing stage of the vastbase database SQL engine. The syntax parsing rule is used to parse the chain call of the object method and construct a syntax tree equivalent to the traditional nested function call for it. At the same time, a method call identifier is added to each layer of method call in the syntax tree. The identifier is used to distinguish method calls from ordinary function calls.

[0024] In a first aspect, the present invention provides a method for chaining object methods in VastBase object-oriented programming to allow users to chain call member methods of objects in the PL / pgSQL procedural language of the VastBase database. The method comprises the following steps:

[0025] S1. Based on the object call, the PL / pgSQL module converts the obj.m1(args1) statement into m1(obj,args1), then adds the subsequent method.m2(args2) to construct the SQL statement m1(obj,args1).m2(args2), and passes it to the SQL engine;

[0026] S2. Add a new SQL engine parsing rule that constructs a syntax tree equivalent to m2(m1(obj,args1),args2) for the statement m1(obj,args1).m2(args2). This rule converts each method call into a node in the syntax tree and adds a method call identifier to each method call level in the syntax tree.

[0027] S3. During the semantic parsing phase, each function call node is traversed for verification. For each function call node, the corresponding function is checked and the node is verified to be a method call. If the node is a method call, the node is verified to be a member method. If so, the first parameter node is removed and the process is repeated until the first parameter node is not a function node.

[0028] S4. Starting from the last node, execute the function according to the logic of nested calls. For each function call node, pass the result of its function call as the first parameter to the function call of the previous layer, and execute upward in sequence. Finally, get the result of the entire method call chain and return it to the caller.

[0029] Furthermore, the present invention is based on the chain calling method of object methods in vastbase object-oriented programming. The newly added SQL engine syntax parsing rule method expression in step S2 is composed of a function call plus a method chain, and the method chain is composed of multiple method calls.

[0030] Furthermore, in the chain calling method of object methods in vastbase object-oriented programming of the present invention, the connection order of the function nodes in the syntax tree in step S2 is the same as the order in the SQL statement.

[0031] Furthermore, in step S3 of the chain calling method of object methods in vastbase object-oriented programming of the present invention, if it is checked that the function corresponding to a function calling node does not exist or it is verified that a function calling node is a method call but not a member method, an error is reported.

[0032] Furthermore, the present invention is based on the chain calling method of object methods in vastbase object-oriented programming and can uniformly parse chain calls in the form of function(args0).m1(args1) and obj.m1(args1).m2(args2).

[0033] In a second aspect, the present invention provides a chain calling system for object methods in vastbase object-oriented programming, the system comprising:

[0034] Statement processing module: used for the form conversion and splicing of object method function statements;

[0035] Rule management module: used to add new SQL engine syntax parsing rules, use the new rules to build a syntax tree for nested function calls, and add a method call identifier to each layer of method call in the syntax tree;

[0036] Check and Verification Module: used to check whether the function call node has a corresponding function, whether it is a method call, and whether it is a member method;

[0037] Function execution module: used to execute functions layer by layer from bottom to top according to the logic of nested calls.

[0038] Furthermore, the present invention is based on the chain call system of object methods in vastbase object-oriented programming, and the new SQL engine syntax parsing rule method expression added by the rule management module is composed of a function call plus a method chain, and the method chain is composed of multiple method calls.

[0039] Finally, the present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the above-mentioned chain calling method of object methods in vastbase object-oriented programming.

[0040] In summary, the chain calling method of object methods in vastbase object-oriented programming of the present invention has the following characteristics:

[0041] (1) The present invention provides a method for implementing a function call in the form of object.m1(args1).m2(args2) in the PL / pgSQL procedural language of the vastbase database, which solves the problem that the PL / pgSQL procedural language does not support chain calls and enables users to write code in a more concise and intuitive way.

[0042] (2) By supporting chain calls, the method of the present invention can reduce the use of intermediate variables, simplify the code structure, and improve the readability and maintainability of the code.

[0043] (3) The semantic parsing of the method of the present invention is simple, and a method call and an ordinary function call can be distinguished by only one identifier. At the same time, the grammatical implementation is simple, and the conversion can be completed by simply splicing subsequent method calls based on the PL / pgSQL parsing of obj.m1(args).

[0044] (4) After simple processing by PL / pgSQL, the method of the present invention can uniformly parse chain calls in the form of function(args0).m1(args1) and obj.m1(args1).m2(args2). BRIEF DESCRIPTION OF THE DRAWINGS

[0045] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments of the present invention. Obviously, the following drawings are only some embodiments recorded in the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0046] Figure 1 This is a collaborative workflow diagram of the vastbase database's PL / pgSQL and SQL engines for object method calls in the present invention, taking obj.m(args) as an example.

[0047] Figure 2 This is a flowchart for implementing the object method chain calling method of the present invention.

[0048] Figure 3 This is a collaborative workflow diagram of the vastbase database's PL / pgSQL and SQL engines for object method chain calls in the present invention, taking obj.m1(args1).m2(args2) as an example.

[0049] Figure 4 This is a schematic diagram of the SQL engine syntax parsing rules newly added to the vastbase database of the present invention.

[0050] Figure 5 This is a structural diagram of the object method chain calling system of the present invention. DETAILED DESCRIPTION

[0051] To make the objectives, technical solutions, and advantages of the present invention more clearly apparent, the technical solutions of the present invention will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. The present invention may also be implemented or applied through different specific implementation methods, and the details in this specification may be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention.

[0052] At the same time, it should be understood that the scope of protection of the present invention is not limited to the specific embodiments described below; it should also be understood that the terms used in the embodiments of the present invention are for describing specific embodiments rather than for limiting the scope of protection of the present invention.

[0053] Example 1: A chain calling method of object methods in vastbase object-oriented programming

[0054] The technical solution of the present invention is described below with reference to the accompanying drawings.

[0055] The method described in this invention is to allow users to chain member methods of objects in the PL / pgSQL procedural language of the Vastbase database. The processing flow of this method is as follows (taking obj.m1(args1).m2(args2) as an example). The specific process is shown in Figure 2 and Figure 3 .

[0056] 1. Based on the object call, the PL / pgSQL module converts the obj.m1(args1) statement into m1(obj,args1), and then adds the subsequent method.m2(args2). Finally, it constructs the SQL statement m1(obj,args1).m2(args2) and passes it to the SQL engine.

[0057] 2. In the syntax parsing stage, add a new SQL engine syntax parsing rule. The new SQL engine syntax parsing rule is as follows: Figure 4 As shown, a method expression consists of a function call plus a method chain, and a method chain is composed of multiple method calls. This rule constructs a syntax tree equivalent to m2(m1(obj,args1),args2) for the statement m1(obj,args1).m2(args2), converts each method call into a node in the syntax tree, and adds a method call identifier to each layer of method call in the syntax tree to indicate that this is a method call operation. The connection order of the syntax tree function nodes of m1(obj,args1).m2(args2) is the same as that of m2(m1(obj,args1),args2).

[0058] 3. In the semantic parsing phase, traverse each function call node for verification. For each function call node, check whether the corresponding function exists at the node, and verify whether the node is a method call. If the node is a method call, continue to verify whether it is a member method. If so, take out the first parameter node and repeat this judgment until the first parameter node is not a function node. If the check finds that the function corresponding to a function call node does not exist or the verification finds that a function call node is a method call but not a member method, an error is reported because the method call cannot be executed. In this example, it is necessary to verify whether the function of m2 exists and whether the function node of m2 is a method call. If it is a method call, it is also necessary to verify whether m2 is a member method. If there is a method call of m3 after m2, m3 needs to be verified. It should be noted that m1 has been verified in the PL / pgSQL syntax parsing phase (see Figure 1 ).

[0059] 4. Starting from the last node, functions are executed according to the nested call logic. For each function call node, the result of the function call is passed as the first parameter to the function call in the previous layer. The execution continues upwards, and the result of the entire method call chain is finally obtained and returned to the caller. In this example, method m1 is executed first, and then the execution result of method m2 is used as the first parameter to continue calling method m2 and return the final result.

[0060] Example 2: A chain call system based on object methods in vastbase object-oriented programming

[0061] See also Figure 5 , this system includes:

[0062] Statement processing module: used for the form conversion and splicing of object method function statements;

[0063] Rule management module: used to add new SQL engine syntax parsing rules, use the new rules to build a syntax tree for nested function calls, and add a method call identifier to each layer of method call in the syntax tree;

[0064] Check and Verification Module: used to check whether the function call node has a corresponding function, whether it is a method call, and whether it is a member method;

[0065] Function execution module: used to execute functions layer by layer from bottom to top according to the logic of nested calls.

[0066] Each module is implemented and operated according to the chain calling method of object methods in the above-mentioned vastbase object-oriented programming.

[0067] The foregoing is merely an embodiment of the present invention and is not intended to limit the present invention. It will be apparent to those skilled in the art that various modifications and variations of the present invention are possible. Any modifications, substitutions, etc. made within the spirit and principles of the present invention are intended to be included within the scope of the claims of the present invention.

Claims

1. A chain calling method of object methods in vastbase object-oriented programming, characterized in that: The method includes adding a new SQL engine syntax parsing rule in the syntax parsing phase of the SQL engine of the vastbase database, the syntax parsing rule being used to parse the chain call of the object method and constructing a syntax tree equivalent to the traditional nested function call for it, and adding a method call identifier to each layer of method call in the syntax tree, the identifier being used to distinguish method calls from ordinary function calls; The method comprises the following steps: S1. The PL / pgSQL module converts the statement obj.m1(args1) into m1(obj, args1), then adds the subsequent method.m2(args2) to construct the SQL statement m1(obj, args1).m2(args2), and passes it to the SQL engine. S2. Add a new SQL engine parsing rule. This rule constructs a syntax tree equivalent to m2(m1(obj, args1), args2) for the statement m1(obj, args1).m2(args2). This rule converts each method call into a node in the syntax tree and adds a method call identifier to each method call level in the syntax tree. S3. During the semantic parsing phase, each function call node is traversed and verified. For each function call node, the corresponding function is checked and the node is verified to be a method call. If the node is a method call, the node is verified to be a member method. If so, the first parameter node is removed and the process is repeated until the first parameter node is not a function node. S4. Starting from the last node, execute functions according to the nested call logic. For each function call node, pass the result of its function call as the first parameter to the function call of the previous layer, and execute upward in sequence. Finally, get the result of the entire method call chain and return it to the caller.

2. The chain calling method of object method in vastbase object-oriented programming according to claim 1, characterized in that: The SQL engine grammar parsing rule method expression newly added in step S2 is composed of a function call plus a method chain, and the method chain is composed of multiple method calls.

3. The chain calling method of object method in vastbase object-oriented programming according to claim 1, characterized in that: The connection order of the function nodes in the syntax tree in step S2 is the same as the order in the SQL statement.

4. The chain calling method of object method in vastbase object-oriented programming according to claim 1, characterized in that: In step S3, if it is found that the function corresponding to a function call node does not exist or it is found that a function call node is a method call but not a member method, an error is reported.

5. The chain calling method of object method in vastbase object-oriented programming according to claim 1, characterized in that: The chain call method of the object method can uniformly parse chain calls in the form of function(args0).m1(args1) and obj.m1(args1).m2(args2).

6. A chain calling system of object methods in vastbase object-oriented programming, characterized in that: When the system is running, the steps of implementing the chain calling method of object method in vastbase object-oriented programming according to any one of claims 1 to 5 are implemented; The system comprises: Statement processing module: used for the form conversion and splicing of object method function statements; Rule management module: used to add new SQL engine syntax parsing rules, use the new rules to build a syntax tree for nested function calls, and add a method call identifier to each layer of method call in the syntax tree; Check and Verification Module: used to check whether the function call node has a corresponding function, whether it is a method call, and whether it is a member method; Function execution module: used to execute functions layer by layer from bottom to top according to the logic of nested calls.

7. A computer-readable storage medium having a computer program stored thereon, wherein when the program is executed by a processor, the steps of the chain calling method of object methods in vastbase object-oriented programming according to any one of claims 1 to 5 are implemented.

Citation Information

Patent Citations

  • Program call chain generation method and system, electronic equipment and medium

    CN113110947A

  • Data query method based on general data access framework

    CN115964385A