A method for randomly generating sql based on vastbase syntax

By converting the external syntax tree into an internal syntax tree and obtaining database table structure information, and configuring the SQL semantic order, the problem of existing tools being unable to generate SQL that conforms to Vastbase syntax is solved. This enables the generation of SQL based on the application scenario's requirements, ensuring the correctness and executability of the generated SQL.

CN116049214BActive Publication Date: 2026-04-24BEIJING VASTDATA TECH
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEIJING VASTDATA TECH
Filing Date
2022-12-22
Publication Date
2026-04-24

AI Technical Summary

Technical Problem

Existing SQL generation tools cannot generate SQL that conforms to Vastbase syntax based on the current table structure of the target database, and they cannot generate SQL based on the emphasis requirements of the application scenario, making it difficult to verify the correctness of the syntax.

Method used

By annotating and converting the external syntax tree into an internal syntax tree, database table structure information is obtained, SQL semantic order is configured, element nodes are traversed and parsed, and SQL that conforms to Vastbase syntax is generated.

Benefits of technology

It enables SQL generation based on the current table structure of the database, which can be executed directly in the current database. It also prioritizes the generation based on the application scenario's requirements, ensuring that the generated SQL meets semantic requirements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116049214B_ABST
    Figure CN116049214B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of database semantics, and provides a method for randomly generating SQL based on a vastbase syntax, which comprises the following steps: converting an external syntax tree into an internal syntax tree by marking element nodes in the external syntax tree; obtaining database table structure information of a database used for generating SQL; configuring a SQL semantic sequence for the marked element nodes in the internal syntax tree according to the dependency relationship between the element nodes; and traversing and analyzing the element nodes in the internal syntax tree according to the configured SQL semantic sequence and the node information of the marked element nodes to generate SQL. According to the method for randomly generating SQL based on the vastbase syntax, the SQL of any syntax of vastbase can be randomly generated, the SQL of a certain syntax can be generated according to the biased requirements of an application scene, and the generated SQL can be directly executed in a current database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of database semantic technology, and in particular to a method for randomly generating SQL based on Vastbase syntax. Background Technology

[0002] As domestic database technologies and products continue to improve, more and more organizations and enterprises are switching from Oracle to domestic databases. Therefore, SQL generation tools are needed to verify the correctness and richness of Vastbase database syntax.

[0003] In practical applications, on the one hand, existing SQL generation tools cannot generate SQL based on the current table structure of the target database, nor can they generate SQL that conforms to Vastbase syntax. On the other hand, when the application scenario places a heavy emphasis on SQL generation, it is impossible to prioritize the generation of SQL with a specific syntax based on the required emphasis.

[0004] Therefore, how to provide a method that can combine the current table structure of the database and, based on the application scenario's emphasis requirements for SQL generation, prioritize the generation of SQL with a specific syntax to generate semantically correct SQL for verifying syntactic correctness has become an urgent technical problem to be solved. Summary of the Invention

[0005] In view of this, in order to overcome the shortcomings of the prior art, the present invention aims to provide a method for randomly generating SQL based on Vastbase syntax.

[0006] On the one hand, this invention provides a method for randomly generating SQL based on Vastbase syntax, including...

[0007] Step S1: Convert the outer syntax tree into an inner syntax tree by annotating the element nodes in the outer syntax tree;

[0008] Step S2: Obtain the database table structure information of the database used to generate SQL;

[0009] Step S3: Configure the SQL semantic order for the annotated element nodes in the internal syntax tree according to the dependencies between element nodes;

[0010] Step S4: Traverse and parse the element nodes in the internal syntax tree according to the configured SQL semantic order and the node information of the annotated element nodes to generate SQL.

[0011] Furthermore, the present invention provides a method for randomly generating SQL based on Vastbase syntax, wherein step S1 of the method includes:

[0012] Step S11: Convert the external syntax tree of the BNF paradigm into text format according to the Vastbase syntax;

[0013] Step S12: Annotate the element nodes in the SQL syntax and convert the text-formatted external syntax tree into an internal syntax tree.

[0014] Furthermore, the present invention provides a method for randomly generating SQL based on Vastbase syntax. In step S12 of the method, element nodes in the SQL syntax are annotated by annotating the node information of the element nodes. The node information of the element nodes includes: location information, whether it can continue to be traversed, whether it is a keyword, whether it can be repeated, whether it is a required option, and whether it is a multiple-choice option.

[0015] Furthermore, the present invention provides a method for randomly generating SQL based on Vastbase syntax. Step S2 of the method includes: querying information of database system tables and summarizing the information of the queried database tables as database table structure information of the database used to generate SQL.

[0016] Furthermore, the present invention provides a method for randomly generating SQL based on Vastbase syntax. In step S2 of this method, the database table structure information includes: information on all database schema names, information on tables created by users under the database schema, information on views created by users under the database schema, and column information of tables created by users under the database schema.

[0017] Furthermore, the present invention provides a method for randomly generating SQL based on Vastbase syntax, wherein step S4 of the method includes:

[0018] Traverse the element nodes in the internal syntax tree, and determine whether to parse the current element node or traverse and parse the next element node based on the node information.

[0019] If the value of whether the node information of an element node can continue to be traversed is yes, parse the current element node;

[0020] If the value of whether the element node information can continue to be traversed is no, and the value of whether the element node information is a keyword is yes, then traverse and parse the next element node.

[0021] Furthermore, this invention provides a method for randomly generating SQL based on Vastbase syntax. In step S4 of this method, when the value of whether the node information of an element node can continue to be traversed is yes, the current element node is parsed, including:

[0022] If the value of whether the node information of an element node can continue to be traversed is yes, search for the lower-level element node of the element node, determine whether the lower-level element node can be repeated, whether it is a required option, and whether it is a multiple-choice option, and control the number of the lower-level element nodes and whether they appear based on the determination results.

[0023] Replace the element node with a corresponding number of possible lower-level element nodes. If the value of whether the node information of the lower-level element node can continue to be traversed is yes, continue to search for the lower-level element node of the lower-level element node.

[0024] Furthermore, this invention provides a method for randomly generating SQL based on Vastbase syntax. In step S4 of this method, it is determined whether the lower-level element node is repeatable, whether it is a required option, and whether it is a multiple-choice option. Based on the determination results, the number and occurrence of the lower-level element nodes are controlled, including:

[0025] If the value of the repeatability information in the element node information of the lower-level element node is yes, configure the number of repeatable times for the lower-level element node and increase the number of the lower-level element node to a value equal to the number of repeatable times;

[0026] If the value of "whether it is required" in the element node information of the lower-level element node is "no", the occurrence probability of the lower-level element node is configured, and the occurrence probability of the element node is controlled according to the configured occurrence probability.

[0027] If the value of "whether it is a multiple-choice option" in the element node information of the lower-level element node is "yes", then configure the occurrence probability for the lower-level element node and multiple element nodes that have the same parent node as the lower-level element node, and control whether the element node appears according to the configured occurrence probability.

[0028] Furthermore, the present invention provides a method for randomly generating SQL based on Vastbase syntax, wherein step S4 of the method further includes:

[0029] If the value of whether the element node information can be traversed further is no, and the value of whether the element node information is a keyword is no, the database table structure information corresponding to the element node is obtained.

[0030] The element node information of the element node is replaced by the database table structure information, including all schema names, tables created by users under the database schema, views created by users under the database schema, and column information of tables created by users under the database schema, and then the next element node is traversed and parsed.

[0031] The method for randomly generating SQL based on Vastbase syntax in this invention has the following beneficial effects:

[0032] 1. Based on the sorted external syntax tree, achieve random generation of SQL with arbitrary syntax in Vastbase.

[0033] 2. By adjusting the probability configuration during the traversal process, the generated SQL can be guaranteed to contain or exclude certain syntax. Based on the application scenario's emphasis requirements for SQL generation, SQL with a specific syntax can be prioritized for generation.

[0034] 3. Based on the current table structure of the database, the generated SQL can be executed directly in the current database. Attached Figure Description

[0035] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0036] Figure 1 The flowchart illustrates a method for randomly generating SQL based on Vastbase syntax, which is an exemplary first embodiment of the present invention.

[0037] Figure 2 The flowchart illustrates a method for randomly generating SQL based on Vastbase syntax, as exemplarily described in the fourth embodiment of the present invention. Detailed Implementation

[0038] The embodiments of the present invention will now be described in detail with reference to the accompanying drawings.

[0039] It should be noted that, in the absence of conflict, the following embodiments and features can be combined with each other; and, based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.

[0040] It should be noted that various aspects of embodiments within the scope of the appended claims are described below. It will be apparent that the aspects described herein can be embodied in a wide variety of forms, and any particular structure and / or function described herein is merely illustrative. Based on this disclosure, those skilled in the art will understand that one aspect described herein can be implemented independently of any other aspect, and two or more of these aspects can be combined in various ways. For example, any number of aspects set forth herein can be used to implement the device and / or practice the method. Additionally, this device and / or method can be implemented using structures and / or functionalities other than one or more of the aspects set forth herein.

[0041] The technical principle of this invention is as follows:

[0042] By parsing Vastbase's BNF normalized syntax, it converts it into an internally customized syntax structure, continuously traversing the syntax structure to the next level of nodes, until the bottom-level node, and then combining it with the current database data structure to generate SQL. At the same time, the node selection during node traversal can be controlled through probability configuration, thus controlling the target syntax SQL to be generated.

[0043] Figure 1 This is a flowchart illustrating a method for randomly generating SQL based on Vastbase syntax according to an exemplary first embodiment of the present invention, as shown below. Figure 1 As shown, the method in this embodiment includes:

[0044] Step S1: Convert the outer syntax tree into an inner syntax tree by annotating the element nodes in the outer syntax tree;

[0045] Step S2: Obtain the database table structure information of the database used to generate SQL;

[0046] Step S3: Configure the SQL semantic order for the annotated element nodes in the internal syntax tree according to the dependencies between element nodes;

[0047] Step S4: Traverse and parse the element nodes in the internal syntax tree according to the configured SQL semantic order and the node information of the annotated element nodes to generate SQL.

[0048] The second exemplary embodiment of the present invention provides a method for randomly generating SQL based on Vastbase syntax. This embodiment is... Figure 1 In a preferred embodiment of the method shown, step S1 of the method in this embodiment includes:

[0049] Step S11: Convert the external syntax tree of the BNF paradigm into text format according to the Vastbase syntax;

[0050] Step S12: Annotate the element nodes in the SQL syntax and convert the text-formatted external syntax tree into an internal syntax tree.

[0051] In step S12 of this embodiment, element nodes in the SQL syntax are annotated by marking the node information of the element nodes. The node information of the element nodes includes: location information, whether it can continue to be traversed, whether it is a keyword, whether it can be repeated, whether it is a required option, and whether it is a multiple-choice option.

[0052] The method in this embodiment can generate random SQL with arbitrary syntax based on the sorted external syntax tree.

[0053] The third exemplary embodiment of the present invention provides a method for randomly generating SQL based on Vastbase syntax. This embodiment is... Figure 1 In a preferred embodiment of the method shown, step S2 of the method in this embodiment includes: querying information of the database system tables, and summarizing the information of the database tables obtained from the query as the database table structure information of the database used to generate SQL.

[0054] In this embodiment, the database table structure information includes: all database schema names, table information created by users within the database schema, view information created by users within the database schema, and column information of tables created by users within the database schema. In this embodiment, the table column information includes the number of columns, column names, primary keys, constraints, and index information.

[0055] Figure 2 This is a flowchart illustrating a method for randomly generating SQL based on Vastbase syntax according to an exemplary fourth embodiment of the present invention. This embodiment is... Figure 1 Preferred embodiments of the method shown are as follows: Figure 2 As shown, step S4 of the method in this embodiment includes:

[0056] Traverse the element nodes in the internal syntax tree, and determine whether to parse the current element node or traverse and parse the next element node based on the node information.

[0057] If the value of whether the node information of an element node can continue to be traversed is yes, parse the current element node;

[0058] If the value of whether the element node information can continue to be traversed is no, and the value of whether the element node information is a keyword is yes, then traverse and parse the next element node.

[0059] In step S4 of this embodiment, when the value of whether the node information of an element node can continue to be traversed is yes, the current element node is parsed, including:

[0060] If the value of the "whether it can continue traversing" information in the node information of an element node is "yes", then search for the lower-level element nodes of the element node. Determine whether the lower-level element nodes can be repeated, whether they are required options, and whether they are multiple-choice options. Based on the determination results, control the number of lower-level element nodes and whether they appear. Specifically:

[0061] If the value of the repeatability information in the element node information of the lower-level element node is yes, configure the number of repeatable times for the lower-level element node and increase the number of the lower-level element node to a value equal to the number of repeatable times;

[0062] If the value of "whether it is required" in the element node information of the lower-level element node is "no", the occurrence probability of the lower-level element node is configured, and the occurrence probability of the element node is controlled according to the configured occurrence probability.

[0063] If the value of "whether it is a multiple-choice option" in the element node information of the lower-level element node is "yes", then configure the occurrence probability for the lower-level element node and multiple element nodes that have the same parent node as the lower-level element node, and control whether the element node appears according to the configured occurrence probability.

[0064] Replace the element node with a corresponding number of possible lower-level element nodes. If the value of whether the node information of the lower-level element node can continue to be traversed is yes, continue to search for the lower-level element node of the lower-level element node.

[0065] The method in this embodiment can adjust the probability configuration during the traversal process to ensure that the generated SQL contains or does not contain certain syntax. It can also focus on generating SQL with a certain syntax based on the emphasis requirements of the application scenario.

[0066] Step S4 of the method in this embodiment further includes:

[0067] If the value of whether the element node information can be traversed further is no, and the value of whether the element node information is a keyword is no, the database table structure information corresponding to the element node is obtained.

[0068] The element node information of the element node is replaced by the database table structure information, including all schema names, tables created by users under the database schema, views created by users under the database schema, and column information of tables created by users under the database schema, and then the next element node is traversed and parsed.

[0069] The method in this embodiment can be based on obtaining the current table structure of the database, so that the generated SQL can be executed directly in the current database.

[0070] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A method for randomly generating SQL based on Vastbase syntax, characterized in that, The method includes: Step S1: Convert the outer syntax tree into an inner syntax tree by annotating the element nodes in the outer syntax tree; Step S2: Obtain the database table structure information of the database used to generate SQL; Step S3: Configure the SQL semantic order for the annotated element nodes in the internal syntax tree according to the dependencies between element nodes; Step S4: Traverse and parse the element nodes in the internal syntax tree according to the configured SQL semantic order and the node information of the annotated element nodes to generate SQL; Step S1 includes: Step S11: Convert the external syntax tree of the BNF paradigm into text format according to the Vastbase syntax; Step S12: Annotate the element nodes in the SQL syntax and convert the text-formatted external syntax tree into an internal syntax tree; In step S12, the element nodes in the SQL syntax are annotated by marking the node information of the element nodes. The node information of the element nodes includes: location information, whether it can continue to be traversed, whether it is a keyword, whether it can be repeated, whether it is a required option, and whether it is a multiple-choice option.

2. The method for randomly generating SQL based on Vastbase syntax according to claim 1, characterized in that, Step S2 includes: querying information from the database system tables, and summarizing the information from the queried database tables as the database table structure information used to generate SQL.

3. The method for randomly generating SQL based on Vastbase syntax according to claim 1, characterized in that, In step S2, the database table structure information includes: all database schema names, table information created by users under the database schema, view information created by users under the database schema, and column information of tables created by users under the database schema.

4. The method for randomly generating SQL based on Vastbase syntax according to claim 1, characterized in that, Step S4 includes: Traverse the element nodes in the internal syntax tree, and determine whether to parse the current element node or traverse and parse the next element node based on the node information. If the value of whether the node information can be traversed further is yes, parse the current element node; If the value of whether the element node information can continue to be traversed is no, and the value of whether the element node information is a keyword is yes, then traverse and parse the next element node.

5. The method for randomly generating SQL based on Vastbase syntax according to claim 4, characterized in that, In step S4, if the value of the "whether it can continue to be traversed" information in the node information of an element node is "yes", the current element node is parsed, including: If the value of whether the node information of an element node can continue to be traversed is yes, search for the lower-level element node of the element node, determine whether the lower-level element node can be repeated, whether it is a required option, and whether it is a multiple-choice option, and control the number of the lower-level element nodes and whether they appear based on the determination results. Replace the element node with a corresponding number of possible lower-level element nodes. If the value of whether the node information of the lower-level element node can continue to be traversed is yes, continue to search for the lower-level element node of the lower-level element node.

6. The method for randomly generating SQL based on Vastbase syntax according to claim 5, characterized in that, In step S4, it is determined whether the lower-level element node is repeatable, whether it is a required option, and whether it is a multiple-choice option. Based on the determination result, the number of lower-level element nodes and their appearance are controlled, including: If the value of the repeatability information in the element node information of the lower-level element node is yes, configure the number of repeatable times for the lower-level element node and increase the number of the lower-level element node to a value equal to the number of repeatable times; If the value of "whether it is required" in the element node information of the lower-level element node is "no", the occurrence probability of the lower-level element node is configured, and the occurrence probability of the element node is controlled according to the configured occurrence probability. If the value of "whether it is a multiple-choice option" in the element node information of the lower-level element node is "yes", then configure the occurrence probability for the lower-level element node and multiple element nodes that have the same parent node as the lower-level element node, and control whether the element node appears according to the configured occurrence probability.

7. The method for randomly generating SQL based on Vastbase syntax according to claim 6, characterized in that, Step S4 also includes: If the value of whether the element node information of the marked element node can be traversed further is no, and the value of whether the element node information of the element node is a keyword is no, obtain the database table structure information corresponding to the element node. The element node information of the element node is replaced by the database table structure information, including all schema names, tables created by users under the database schema, views created by users under the database schema, and column information of tables created by users under the database schema, and then the next element node is traversed and parsed.

Citation Information

Patent Citations

  • SQL statement automatic generation method, device and equipment and readable storage medium

    CN110597847A

  • SQL (Structured Query Language) statement syntax migration method and system between databases

    CN112765209A