G4 file-based multi-database SQL bloodline analysis method and system

Through the multi-database SQL lineage parsing method based on G4 files, the problem of SQL syntax differences in multi-database environments is solved, unified lineage analysis of SQL statements is achieved, the parsing accuracy and efficiency are improved, and complete lineage analysis results are generated to support data governance and security audits.

CN120492488BActive Publication Date: 2025-10-17北京科杰科技有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510984700.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-07-17
Publication Date
2025-10-17
Estimated Expiration
2045-07-17

AI Technical Summary

Technical Problem

When dealing with SQL syntax differences in a multi-database environment, existing technologies have high development costs and are difficult to maintain. They are unable to uniformly handle the SQL syntax characteristics of different databases, resulting in incomplete lineage analysis results and an inability to accurately reflect the data flow path and the dependency relationship between SQL statements.

Method used

A multi-database SQL lineage parsing method based on G4 files obtains the grammatical rule set of SQL statements through the G4 grammar file, performs lexical cleaning and normalization, constructs a statement dependency directed graph, optimizes the grammatical rule sequence using the dialect feature matrix and Markov decision process, generates a mapping relationship table, identifies the field lineage link graph, and outputs the lineage analysis results.

Benefits of technology

It realizes unified lineage analysis of SQL statements in different databases, improves the accuracy and efficiency of parsing, especially the processing ability of complex queries, generates complete and accurate lineage analysis results, and provides technical support for data governance and security audits.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120492488B_ABST
    Figure CN120492488B_ABST
Patent Text Reader

Abstract

The application provides a multi-database SQL blood relationship analysis method and system based on a G4 file, relates to the technical field of database management, and comprises the following steps: analyzing an SQL statement based on a G4 syntax file, constructing a front-rear dependency relationship through a statement dependency directed graph, optimizing syntax rules by using a dialect feature matrix and a Markov decision process, sequentially analyzing the SQL to extract a data operation and a flow sequence, generating a field blood relationship link graph, and outputting a structured result, can accurately identify multi-database SQL syntax features, solves a complex SQL analysis problem, effectively improves blood relationship analysis accuracy and efficiency, and supports unified blood relationship management across databases.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of database management, and in particular to a multi-database SQL bloodline analysis method and system based on G4 files. BACKGROUND

[0002] With the deepening of enterprise informatization construction, data asset management and governance become more and more important, SQL as the mainstream database query language is widely used in various data processing and analysis scenarios. Data bloodline reveals the dependency relationship and conversion operation between data by tracking the whole flow process of data from source to target, helps enterprises understand the source, flow direction of data and the changes occurred in the flow process, and accurately constructing data bloodline relationship in complex data environment is crucial for data quality management, compliance audit, impact analysis and other work;

[0003] The traditional SQL bloodline analysis method usually depends on a specific database syntax parser, and multiple sets of parsing systems need to be developed and maintained for different types of databases, resulting in high development cost and great maintenance difficulty. The existing parsing technology still has limited support for multi-database environment when processing complex SQL statements, cannot uniformly process the SQL syntax characteristics of different databases, and cannot effectively process complex SQL syntax structures, resulting in broken or incorrect bloodline relationship in actual application scenarios, unable to accurately reflect the data flow path and lack of in-depth analysis ability of the dependency relationship between SQL statements, difficult to accurately identify cross-statement reference relationship and data flow link, resulting in incomplete bloodline analysis results and unable to meet actual business requirements and other problems.

[0004] Therefore, there is an urgent need for a solution to solve the problems in the prior art. SUMMARY

[0005] The embodiments of the present application provide a multi-database SQL bloodline analysis method and system based on G4 files, which can at least solve some of the problems in the prior art.

[0006] In a first aspect, the embodiments of the present application provide a multi-database SQL bloodline analysis method based on G4 files, comprising:

[0007] According to the G4 syntax file, a set of syntax rules of the SQL statement is obtained, the SQL statement is subjected to lexical cleaning and normalization processing and is split according to semicolons to obtain an independent statement sequence, and the independent statement sequence is analyzed to construct a statement dependency directed graph describing the dependency relationship before and after.

[0008] The database configuration, running parameters and temporary table information are acquired to form parsed basic data, a dialect feature matrix describing the syntax features of the database is constructed using the parsed basic data, a syntax rule probability transition matrix is established based on the dialect feature matrix, an optimal rule chain is predicted in the probability transition matrix through a Markov decision process to obtain an optimized syntax rule sequence, the independent sentence sequence is matched with the optimized syntax rule sequence in features, and a mapping relationship table of each sentence corresponding to a parsing rule is generated.

[0009] The sentence nodes in the sentence dependency directed graph are traversed, the corresponding parsing rule is selected according to the mapping relationship table to perform parsing, the field filtering condition and the calculation expression are extracted to generate a data operation sequence, the subquery nesting and the temporary table flow transfer are identified to generate a data flow transfer sequence, and the field blood relationship link graph is constructed using the data operation sequence and the data flow transfer sequence.

[0010] The field blood relationship link graph is structured to obtain a blood analysis result and output the blood analysis result in a specified format.

[0011] In an optional implementation,

[0012] The syntax rule set of the SQL statement is acquired according to the G4 syntax file, the SQL statement is subjected to lexical cleaning and normalization processing and is split according to a semicolon to obtain an independent sentence sequence, the independent sentence sequence is analyzed to construct a sentence dependency directed graph describing the dependency relationship before and after the sentence, including:

[0013] The G4 syntax file is subjected to syntax parsing, the syntax definition file content is read, the lexical analyzer and the syntax analyzer are constructed, and the standard syntax rule set of the SQL statement is generated;

[0014] The SQL statement to be processed is received, the syntax rule set is used for lexical analysis, the keywords, identifiers, operators and literal quantities in the SQL statement are identified, the redundant white spaces and comments are removed, the case and line feed are unified to obtain a normalized SQL text, and the normalized SQL text is split into an independent sentence sequence according to a semicolon separator;

[0015] The independent sentence sequence is traversed, the syntax structure of each sentence is parsed based on the syntax rule set, the table name, the field name and the temporary table definition in the sentence are extracted, the data reference and the dependency relationship between the sentences are identified, each sentence is constructed into a sentence node containing the sentence content and the reference information, the directed connection between the nodes is established according to the data reference and the dependency relationship, and the sentence dependency directed graph recording the execution process of the SQL statement is generated.

[0016] In an optional implementation,

[0017] The database configuration, running parameters and temporary table information are acquired to form parsed basic data, a dialect feature matrix describing the syntax features of the database is constructed using the parsed basic data, a syntax rule probability transition matrix is established based on the dialect feature matrix, and an optimal rule chain is predicted in the probability transition matrix through a Markov decision process to obtain an optimized syntax rule sequence including:

[0018] The database configuration and running parameters are acquired, the connection strings in the database configuration and running parameters are standardized, the intermediate results and temporary table information of the execution plan of the SQL statement are parsed, and the running parameters, intermediate results and temporary table information are organized to form parsed basic data;

[0019] A feature vector space is constructed, the feature vector space includes a function syntax feature dimension, a keyword usage feature dimension and a syntax structure feature dimension, the frequency of occurrence and the inverse document frequency of the features in different databases are calculated based on the parsed basic data, the feature weight scores are determined according to the frequency of occurrence and the inverse document frequency, and the feature weight scores are filled into the dialect feature matrix;

[0020] A rule state set is constructed based on the dialect feature matrix, the transition probability between the rule nodes in the rule state set is calculated to form a syntax rule probability transition matrix, the initial probability distribution of the rule state set is calculated according to the historical usage frequency of the rules, the state value function is iteratively calculated using the Bellman equation based on the syntax rule probability transition matrix and the initial probability distribution, the action sequence maximizing the long-term return is selected to form an optimal rule chain, and the optimized syntax rule sequence is obtained by performing redundant rule elimination on the optimal rule chain. In an optional implementation,

[0021] A rule state set is constructed based on the dialect feature matrix, the transition probability between the rule nodes in the rule state set is calculated to form a syntax rule probability transition matrix, the initial probability distribution of the rule state set is calculated according to the historical usage frequency of the rules including:

[0022] The dialect feature matrix is acquired and the rule state set is constructed, the basic operation complexity of each rule node in the rule state set is extracted and summed to obtain a time complexity value, the memory occupation value and the processor usage value of the rule node are read and added to obtain a resource consumption value, and the time complexity value and the resource consumption value are added to calculate the comprehensive execution cost of the rule node;

[0023] Traverse the rule nodes in the rule state set, select two adjacent rule nodes in the rule execution sequence as a starting rule node and a target rule node to form a rule node pair, count the historical execution frequency of the rule node pair, calculate the historical execution frequency sum of the target rule node corresponding to the starting rule node, divide the historical execution frequency by the historical execution frequency sum to obtain a basic transition probability, multiply the comprehensive execution cost of the target rule node by a decay coefficient to obtain a decay value, and multiply the decay value by the basic transition probability to obtain a decayed transition probability;

[0024] Count the historical execution frequency and sum of the rule nodes to calculate the original usage frequency, multiply the comprehensive execution cost of the rule node by an adjustment coefficient, add one, take the reciprocal to obtain a cost adjustment value, multiply the original usage frequency by the cost adjustment value, and normalize to obtain an initial probability distribution of the rule state set, and divide the decayed transition probability by a row normalization coefficient to construct a syntax rule probability transition matrix.

[0025] In an optional implementation,

[0026] The feature matching of the independent sentence sequence and the optimized syntax rule sequence generates a mapping relationship table of the parsing rule corresponding to each sentence, which includes:

[0027] The sentence sequence feature information is extracted from the independent sentence sequence, the part-of-speech sequence of each sentence is obtained to generate a syntax structure feature, the keyword set of each sentence is extracted to generate a vocabulary feature, the pre-sequence sentence information, the current sentence information, and the post-sequence sentence information of each sentence are collected to generate a context feature, and the syntax structure feature, the vocabulary feature, and the context feature are combined to construct a sentence comprehensive feature vector;

[0028] The matching mode of each rule is extracted from the optimized syntax rule sequence to form a rule mode feature, the constraint condition of each rule is extracted to form a rule constraint feature, and the rule mode feature and the rule constraint feature are combined to construct a rule feature template vector;

[0029] The matching degree of the sentence comprehensive feature vector and the rule feature template vector is calculated, the intersection cardinality of the syntax structure feature and the rule mode feature is divided by the union cardinality to calculate the structure similarity, the sum of the products of each keyword in the vocabulary feature and the rule matching degree is divided by the number of keywords to calculate the vocabulary similarity, the similarity degree of the context feature and the rule constraint feature is obtained to calculate the context similarity, and the structure similarity, the vocabulary similarity, and the context similarity are weighted and combined to obtain a comprehensive similarity;

[0030] The rule with the highest comprehensive similarity is selected as the parsing rule corresponding to each sentence, and the sentence identifier, the parsing rule identifier, and the corresponding comprehensive similarity are combined to generate a mapping relationship table.

[0031] In an optional implementation,

[0032] The traversal statement dependency directed graph traverses the statement nodes in the statement dependency directed graph, selects corresponding parsing rules according to the mapping relationship table, extracts field filtering conditions and calculation expressions to generate data operation sequences, identifies subquery nesting and temporary table flow to generate data flow sequences, and constructs a field blood relationship link graph using the data operation sequences and the data flow sequences, including:

[0033] The traversal statement dependency directed graph traverses the statement nodes in the statement dependency directed graph, selects corresponding parsing rules according to the mapping relationship table, extracts field filtering conditions and calculation expressions to generate data operation sequences, identifies subquery nesting and temporary table flow to generate data flow sequences, and constructs a field blood relationship link graph using the data operation sequences and the data flow sequences, including:

[0034] The data dependency relationship between the statement nodes is identified, the mapping relationship of the source field to the target field in the subquery statement is extracted to generate subquery nesting, the table identifier and the transmission field of the temporary table are extracted to generate temporary table flow, and the field identifier and its reference type across the statement are extracted to generate cross-statement reference, and the subquery nesting, temporary table flow and cross-statement reference are combined to generate data flow sequences.

[0035] The data operation sequences are used to construct an intra-statement field transmission path, the data flow sequences are used to construct an inter-statement field transmission path, and the intra-statement field transmission path and the inter-statement field transmission path are combined to form a complete field transmission path set.

[0036] The field identifier, field type and field source are extracted from the field transmission path set to construct a field node, the mutual conversion relationship between the field nodes and the conversion operation thereof are extracted to construct a conversion edge, and the field node and the conversion edge are combined to generate a field blood relationship link graph that records the complete blood relationship of the field.

[0037] In an optional implementation,

[0038] The field blood relationship link graph is structured to obtain a blood analysis result and output in a specified format, including:

[0039] The blood hierarchical relationship of the field nodes in the field blood relationship link graph is extracted, the direct predecessor node and the direct successor node of each field node are identified, a blood transmission link is constructed, and the field nodes are grouped to form a blood hierarchical structure according to the blood hierarchical relationship;

[0040] The field nodes in the blood hierarchical structure are traversed, the conversion operation type and the conversion parameter in the conversion edge corresponding to each field node are extracted, and the blood hierarchical relationship of the field nodes and the conversion operation information are combined to form a blood analysis result;

[0041] The field node identifier, blood level, conversion operation, predecessor node and successor node in the blood analysis result are reorganized and output according to a preset structured format.

[0042] A second aspect of an embodiment of the present invention provides a multi-database SQL lineage analysis system based on G4 files, comprising:

[0043] The first unit is used to obtain the grammatical rule set of SQL statements based on the G4 grammar file, perform lexical cleaning and normalization processing on the SQL statements, split them by semicolons to obtain independent statement sequences, and analyze the independent statement sequences to construct a statement dependency directed graph that describes the dependencies between the previous and next statements.

[0044] The second unit is configured to obtain database configuration, operating parameters, and temporary table information to form basic parsing data, use the basic parsing data to construct a dialect feature matrix describing the grammatical features of the database, establish a grammatical rule probability transition matrix based on the dialect feature matrix, predict the optimal rule chain in the probability transition matrix through a Markov decision process to obtain an optimized grammatical rule sequence, perform feature matching on the independent statement sequence and the optimized grammatical rule sequence, and generate a mapping relationship table corresponding to the parsing rules for each statement;

[0045] The third unit is used to traverse the statement nodes in the statement dependency directed graph, select the corresponding parsing rules according to the mapping relationship table, extract the field screening conditions and calculation expressions to generate data operation sequences, identify subquery nesting and temporary table flow to generate data flow sequences, and use the data operation sequences and data flow sequences to construct a field lineage link diagram;

[0046] The fourth unit is used to process the field blood relationship link diagram in a structural manner to obtain a blood relationship analysis result and output it in a specified format.

[0047] According to a third aspect of an embodiment of the present invention, an electronic device is provided, including:

[0048] A processor and a memory for storing processor-executable instructions, wherein the processor is configured to call the instructions stored in the memory to execute the aforementioned method.

[0049] According to a fourth aspect of an embodiment of the present invention, a computer-readable storage medium is provided, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the method described above is implemented.

[0050] In the present invention, a multi-database SQL lineage parsing method based on G4 files is used to achieve unified lineage analysis of SQL statements in different database dialects, effectively solving the problem that the existing technology is difficult to handle SQL syntax differences in a multi-database environment. The Markov decision process is used to optimize the grammatical rule sequence, and the probability transfer matrix constructed in combination with the dialect feature matrix can intelligently identify and adapt to the grammatical characteristics of different databases, greatly improving the accuracy and efficiency of SQL parsing, especially significantly enhancing the processing ability of complex queries. By constructing a statement dependency directed graph and a field lineage link graph, the field transfer path and conversion operations in the SQL statement are systematically parsed, making the lineage analysis results more complete and accurate, and providing reliable technical support for data governance, security auditing and system optimization. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] Figure 1 Schematic diagram of the process of a multi-database SQL lineage parsing method based on G4 files according to an embodiment of the present invention;

[0052] Figure 2 This is a diagram of the SQL statement processing flow;

[0053] Figure 3 Schematic diagram of the mapping process for matching SQL statements with grammar rules. DETAILED DESCRIPTION

[0054] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.

[0055] The following specific embodiments are used to describe the technical solution of the present invention in detail. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.

[0056] Figure 1 FIG. 1 is a flow chart of a multi-database SQL lineage parsing method based on a G4 file according to an embodiment of the present invention. Figure 1 As shown, the method includes:

[0057] Obtain the grammatical rule set for SQL statements based on the G4 grammar file, perform lexical cleaning and normalization on the SQL statements, and split them by semicolons to obtain a sequence of independent statements. Analyze the independent statement sequence to construct a statement dependency directed graph that describes the dependencies between the previous and next statements.

[0058] The database configuration, running parameters and temporary table information are acquired to form parsed basic data, a dialect feature matrix describing the syntax features of the database is constructed using the parsed basic data, a syntax rule probability transition matrix is established based on the dialect feature matrix, an optimal rule chain is predicted in the probability transition matrix through a Markov decision process to obtain an optimized syntax rule sequence, the independent sentence sequence is matched with the optimized syntax rule sequence in features, and a mapping relationship table of each sentence corresponding to a parsing rule is generated.

[0059] The sentence nodes in the sentence dependency directed graph are traversed, the corresponding parsing rule is selected according to the mapping relationship table to perform parsing, a data operation sequence is generated by extracting the field filtering condition and the calculation expression, a data flow sequence is generated by identifying the subquery nesting and the temporary table flow transfer, and the field blood relationship link graph is constructed using the data operation sequence and the data flow sequence.

[0060] The field blood relationship link graph is structured to obtain a blood analysis result and output the blood analysis result in a specified format.

[0061] In an optional implementation,

[0062] A syntax rule set of the SQL statement is acquired according to a G4 syntax file, a lexical cleaning and normalization process is performed on the SQL statement, and an independent sentence sequence is obtained by splitting according to a semicolon, and a sentence dependency directed graph describing the dependency relationship before and after is constructed by analyzing the independent sentence sequence.

[0063] The G4 syntax file is parsed, the content of the syntax definition file is read, a lexical analyzer and a syntax analyzer are constructed, and a standard syntax rule set of the SQL statement is generated;

[0064] The SQL statement to be processed is received, the syntax rule set is used for lexical analysis, keywords, identifiers, operators and literals in the SQL statement are identified, redundant white spaces and comments are removed, and the normalized SQL text is obtained by unifying the case and line feed, the normalized SQL text is split into an independent sentence sequence according to a semicolon separator;

[0065] The independent sentence sequence is traversed, the syntax structure of each sentence is parsed based on the syntax rule set, the table name, the field name and the temporary table definition in the sentence are extracted, the data reference and the dependency relationship between the sentences are identified, each sentence is constructed as a sentence node containing the sentence content and the reference information, the directed connection between the nodes is established according to the data reference and the dependency relationship, and a sentence dependency directed graph recording the execution process of the SQL statement is generated.

[0066] Figure 2The SQL statement processing flowchart is shown in FIG. 1. A G4 grammar definition file is read, which contains complete lexical and syntax rules of the SQL language. By parsing these rules, lexical rules are extracted to identify basic units of the SQL language, such as keywords, identifiers, numbers, etc., and syntax rules are extracted to define how these basic units are combined into valid SQL statements. During the parsing process, the rules in the G4 file are converted into internal data structures, a syntax tree is constructed, and regular expression patterns are created for the lexical rules to identify various lexical units in the subsequent process. For the syntax rules, a set of syntax productions is constructed to form a parsing table, which guides the subsequent syntax analysis process.

[0067] In constructing the lexical analyzer, the recognition rules for all keywords, operators, punctuation symbols, and other special characters are organized into a priority queue to ensure that longer patterns are matched first, avoiding incorrect recognition. In constructing the syntax analyzer, a top-down recursive descent analysis method or a bottom-up analysis method is used to generate a complete syntax analysis table according to the syntax rules. The syntax analysis table defines the actions to be taken when a specific lexical unit is recognized, resulting in a complete parsing system that includes a lexical analyzer and a syntax analyzer, capable of processing input SQL statements according to standard SQL syntax rules.

[0068] After receiving the SQL statement to be processed, lexical analysis is performed, and the input SQL text is traversed to identify various lexical units according to the previously constructed lexical rules. The lexical analyzer scans the input text character by character and, when a character sequence matching a lexical rule is found, it is marked as the corresponding lexical unit type, such as keywords, identifiers, operators, comparison operators, string literals, numeric literals, etc. Normalization processing is performed, including removing all comments, uniform white space processing, replacing multiple consecutive spaces, tabs, line breaks, etc. with a single space, unifying keyword case, usually converting to uppercase, unifying identifier format, maintaining the original case or converting according to configuration, and unifying line breaks to ensure consistency across platforms.

[0069] After normalization processing is complete, a uniformly formatted SQL text is obtained, and the entire SQL text is split into multiple independent SQL statements using semicolons as delimiters to form a statement sequence. Each statement represents a complete SQL command, which can be a table creation, query, insertion, or other operation. The independent statements are traversed, and in-depth syntax analysis is performed on each statement. The syntax analysis process uses the previously constructed set of syntax rules to construct a detailed syntax tree for each statement. The syntax tree construction process strictly follows the syntax rules and can analyze the statement structure from top to bottom or bottom to top. For example, for a query statement, the query clause, source clause, condition clause, and other components are identified, and the internal structure of each clause is further analyzed.

[0070] After the syntax analysis is completed, key information is extracted from the syntax tree, including table names, field names, temporary table definitions, and table aliases. Table names can be extracted from source clauses, join clauses, insert, update, and delete statements; field names are extracted from query clauses, condition clauses, grouping, sorting, and other parts; temporary table definitions are extracted from accompanying clauses or subqueries; and table aliases are established by parsing the alias definitions of the tables to establish the mapping relationship between table names and aliases. For each statement, a statement node is created, containing the content of the statement itself and various information extracted from the syntax tree, such as statement type, involved tables and fields, defined temporary tables or views, etc.

[0071] After the statement node creation is completed, the dependency graph between statements is established by analyzing the data reference relationship between statements. When a statement references a table or view created by another statement, a directed connection is established between the two statement nodes; when a statement modifies a table referenced by another statement, a corresponding dependency relationship is established; for subqueries or temporary table references in complex queries, these internal dependencies are also identified and recorded. Dependency relationship identification is mainly achieved by comparing table definitions and table reference information in each statement node. For example, if statement A creates table C, and statement B queries table C, a directed connection from statement A to statement B is established, generating a complete statement dependency directed graph.

[0072] Exemplarily, a complete SQL script is taken as an example to create a user table containing user number, user name, email, and creation time fields. An order table is created containing order number, user number, order date, and total amount fields, and the user number is set as a foreign key to the user table. Two user data are inserted into the user table. An analysis query is executed to define active users using a temporary table, count the number of orders for each active user, and filter out users with order quantity greater than zero.

[0073] When parsing the G4 syntax file, the G4 file of the SQL syntax is read, and the lexical and syntax rules defined therein are parsed. The lexical rules define how to identify keywords such as "create", "table", "query", etc., as well as identifiers, numbers, strings, and other basic patterns. The syntax rules define how to combine these basic elements into valid SQL statement structures. Through these rules, a lexical analyzer that can identify various elements in SQL statements and a syntax analyzer that can parse complete SQL statement structures are constructed.

[0074] After receiving the example SQL script, the lexical analyzer starts working, removing all comments in the script, such as the comment before creating the user table and the comment before creating the order table. All lexical units are identified, extra white spaces are normalized, and keyword cases are unified. The normalized SQL text is split by the semicolon delimiter, resulting in four independent statements: the create user table statement, the create order table statement, the insert user data statement, and the analyze active user query statement.

[0075] The four statements are analyzed one by one. When parsing the create user table statement, the table name "user table" and the fields "user number", "user name", "email", and "creation time" are identified, as well as the data types and constraint conditions of each field. When parsing the create order table statement, the table name "order table" and the fields "order number", "user number", "order date", and "total amount" are identified, as well as the foreign key constraint reference to "user number" of "user table". When parsing the insert statement, the target table "user table" and the inserted fields and corresponding values are identified. When parsing the last query statement, the temporary table definition "active user" is identified, and it is found that the temporary table references "user table" and "order table", and the main query part references the temporary table "active user" and the table "order table".

[0076] Based on the parsing results, a statement dependency directed graph is constructed. The create user table statement serves as the basis and does not depend on other statements. The create order table statement depends on the create user table statement because the order table's foreign key references the user table. The insert statement depends on the create user table statement because the data is inserted into the user table, and the query statement depends on all previous statements, the query involves the user table and the order table, and the query result depends on the inserted data, generating a dependency directed graph.

[0077] In this embodiment, the statement dependency directed graph clearly shows the execution flow and data dependency relationship of the SQL statements, realizes comprehensive and standardized processing of the SQL statements, can effectively eliminate the problems caused by different development styles of different developers, and the accurate recognition capability can process various complex SQL syntax structures, including subqueries, temporary table definitions, table joins, and other advanced syntax features. By constructing the statement dependency directed graph, the execution flow of the SQL script is visually expressed, which can help developers quickly grasp the entire data processing link and identify potential logical problems or optimization opportunities. By analyzing the statement dependency relationship, possible performance bottlenecks and optimization opportunities can be identified, such as repeated calculations, redundant queries, or unnecessary data conversions, which can guide developers to perform SQL restructuring and optimization, improve query efficiency and resource utilization.

[0078] In an alternative embodiment,

[0079] The database configuration, running parameters and temporary table information are acquired to form parsed basic data, a dialect feature matrix describing the syntax features of the database is constructed using the parsed basic data, a syntax rule probability transition matrix is established based on the dialect feature matrix, and an optimal rule chain is predicted in the probability transition matrix through a Markov decision process to obtain an optimized syntax rule sequence including:

[0080] The database configuration and running parameters are acquired, the connection string in the database configuration and running parameters is standardized, the execution plan of the SQL statement is parsed to obtain intermediate results and temporary table information, and the running parameters, intermediate results and temporary table information are organized to form parsed basic data;

[0081] A feature vector space is constructed, the feature vector space includes function syntax feature dimensions, keyword usage feature dimensions and syntax structure feature dimensions, the frequency of occurrence and the inverse document frequency of the features in different databases are calculated based on the parsed basic data, the feature weight scores are determined according to the frequency of occurrence and the inverse document frequency, and the feature weight scores are filled into the dialect feature matrix;

[0082] A rule state set is constructed based on the dialect feature matrix, the transition probability between the rule nodes in the rule state set is calculated to form a syntax rule probability transition matrix, the initial probability distribution of the rule state set is calculated according to the historical usage frequency of the rules, the state value function is iteratively calculated using the Bellman equation based on the syntax rule probability transition matrix and the initial probability distribution, the action sequence maximizing the long-term return is selected to form an optimal rule chain, and the optimized syntax rule sequence is obtained by performing redundant rule elimination on the optimal rule chain. Comprehensive database configuration and running parameters, table structure definitions and field attributes, SQL statement intermediate results and temporary table information are acquired. The connection string is extracted from the database connection configuration, standardized processing is performed, specific environment-related paths and authentication information are removed, and the core connection parameters are retained. By analyzing the driver identification and service information in the connection string, the database type identifier is extracted, such as a relational database, a columnar storage database or a time series database, and the version information, including the major version number and the minor version number, is acquired. These information is crucial for subsequent feature analysis.

[0083] Deeply collect table structure definition and field attribute information. Obtain complete table structure definition by querying database metadata view or system table, including table name, table type, storage engine and partition strategy, etc. Collect detailed attribute of each table field, record field name, data type, length precision, default value and null value processing strategy, etc. Organize the information into attribute mapping table, establish the corresponding relationship between field name and its complete attribute set. At the same time, extract the constraint relationship between tables, such as primary key constraint, foreign key constraint, unique constraint and check constraint, etc., form the constraint relationship table, record the constraint type, associated field and reference table information. In addition, index information needs to be collected, including index name, index type, covered field and cardinality estimation, etc., to build the index feature table.

[0084] After completing the table structure collection, the execution plan of SQL statement needs to be parsed to obtain the execution strategy generated by the query optimizer, and the intermediate result and temporary table information needs to be analyzed. Through the execution plan, the decision logic of the query optimizer is understood, including table access method, connection algorithm selection and sorting implementation method, etc. Extract the estimated row number, cache usage and parallelism setting in the execution plan, etc. Performance related parameters. Pay attention to the generation and processing of intermediate results, record the size of subquery result set, the creation and use of temporary table, and the data flow path. Integrate the execution information with the structure information collected before to form a complete analysis basis data, which provides data support for subsequent feature analysis.

[0085] Based on the analysis basis data, start to build the feature vector space. The feature vector space includes multiple dimensions, the function syntax feature dimension covers the use characteristics of various functions, such as aggregation function, window function, date processing function and string operation function, etc., the keyword use feature dimension includes the use of query keywords, condition keywords, connection keywords and transaction control keywords, etc., the syntax structure feature dimension describes the complex query structure, subquery nesting level, common table expression use and recursive query, etc. Advanced syntax characteristics. For each feature, calculate its frequency of occurrence in different database dialects, that is, the number of times the feature appears in a particular database divided by the total number of features in that database, which reflects the universality of the feature. At the same time, calculate the inverse document frequency to measure the discrimination ability of the feature, that is, the inverse ratio relationship between the number of databases containing the feature and the total number of databases. Combine the frequency of occurrence and the inverse document frequency to determine the weight score of each feature, the higher the weight, the more important the feature in distinguishing different database dialects. Fill the feature weight into the dialect feature matrix to form the mathematical expression of the database dialect.

[0086] The rule state set is constructed based on the dialect feature matrix. The rule state set contains multiple syntax conversion rules, each of which represents a conversion from one syntax form to another. For example, converting a date function of one database to a corresponding date function of another database, or rewriting a specific query structure into an equivalent but more efficient form. The transition probabilities between the rule nodes in the rule state set are calculated to form a syntax rule probability transition matrix. The transition probabilities reflect which rules are likely to be applied next and their probability distribution after applying a rule. The initial probability distribution of the rule state set is calculated based on historical usage data, i.e., the probability of selecting each rule at the beginning of optimization. Generally, more commonly used rules have higher initial probabilities.

[0087] Based on the constructed syntax rule probability transition matrix and initial probability distribution, a Markov decision process is used to find the optimal rule sequence. In each decision step, a set of available actions is calculated based on the current state, i.e., the applicable rule conversions. For each possible action, its immediate reward value and future potential income value are evaluated. The immediate reward reflects the performance improvement or code simplification degree obtained immediately after applying the rule, and the future income considers the long-term optimization effect. The Bellman equation is used to iteratively calculate the value function of each state to find the action sequence that maximizes the long-term income, forming the optimal rule chain. Redundant rules are removed from the generated optimal rule chain to remove mutually offsetting or repeatedly applied rules, resulting in a simplified and efficient optimization rule sequence for actual database dialect conversion and query optimization.

[0088] Taking a cross-database migration scenario as an example, an application system originally running on database A is migrated to database platform B. The connection configuration information of database A is obtained, and the connection string is standardized to extract the database type as a relational database, the version as a mainstream commercial version, and the support for advanced analysis functions and stored procedures. The complete table structure definition is obtained by querying the system table, and it is found that there are core business tables such as user information table, order table, commodity table, and transaction log table, as well as multiple statistical summary tables and log tables.

[0089] Detailed field attribute collection is performed to record the name, data type, and constraint conditions of each field. For example, the user information table contains fields such as user number, user name, registration time, and account status, among which the user number is an integer primary key, the user name is a variable-length string with a unique index, the registration time uses a specific format of date and time type, and the account status is an enumeration type. The information is organized into an attribute mapping table to establish the correspondence between fields and their attributes. The constraint relationships between tables are extracted, such as the order table being associated to the user information table and the commodity table through foreign keys to form a constraint relationship table. In addition, the index information of each table is collected, including primary key index, unique index, and ordinary index, to construct an index feature table.

[0090] Analyze the typical SQL query in the system, parse its execution plan to get the intermediate results and temporary table information. For example, a complex sales report query contains multiple table joins, grouping and sorting operations, the execution plan shows that the query uses index scan, hash join and sort merge operations, and generates two temporary tables to store intermediate results. Through analysis, it is found that the query uses a large number of date functions and window functions specific to the A database, and uses a specific paging syntax. Integrate these execution information with the previous structure information to form a complete analysis of the basic data.

[0091] Based on the analysis of the basic data, construct the feature vector space. In the function syntax feature dimension, identify the date formatting function, string concatenation function and statistical analysis function specific to the A database. In the keyword usage feature dimension, it is found that a large number of specific join syntax and paging keywords are used. In the syntax structure feature dimension, the use mode of multi-layer nested subquery and recursive common table expression is observed. Calculate the frequency and inverse document frequency of the features in the A database and the B database to determine the feature weight score. For example, the date processing function has significant syntax difference in the two databases, and obtains higher weight; while the basic query keywords are more common in each database, and the weight is lower. Fill these weights into the dialect feature matrix.

[0092] According to the dialect feature matrix, construct a rule state set, including various syntax conversion rules. For example, the rule of converting the date function of the A database to the corresponding function of the B database, the rule of rewriting the specific join syntax to the standard join syntax, and the rule of rewriting the paging query to the form suitable for the B database. Calculate the transition probability between rule nodes to form the syntax rule probability transition matrix. For example, after applying the date function conversion rule, the string processing rule needs to be applied, so the transition probability between these two rules is higher. According to the historical optimization experience, calculate the initial probability distribution of the rule state set, and the commonly used basic conversion rules obtain higher initial probability.

[0093] Use Markov decision process to find the optimal rule sequence. Starting from the initial state, the system evaluates the available rule conversion actions. For the optimization of the sales report query, consider the date function conversion rule, calculate its immediate reward and future income. The immediate reward reflects the compatibility problems that can be directly solved by the conversion, and the future income considers the subsequent optimization space. Through the iterative calculation of Bellman equation, a series of rules are selected, including date function conversion, window function rewriting, join syntax standardization and paging query rewriting, to form the optimal rule chain. Remove some conversion steps that mutually cancel or repeat each other to get the simplified and efficient optimization rule sequence.

[0094] In this embodiment, by constructing a feature vector space and an optimization mechanism based on Markov decision process, accurate recognition and automatic conversion of database dialects are realized, the efficiency and accuracy of cross-database migration are improved, through automatic generation of feature matrix and optimization rule sequence, the conversion process is systematized and standardized, the migration cost and risk are significantly reduced, through analysis of database characteristics and SQL execution plan, performance bottlenecks can be automatically identified and targeted optimization rules can be generated, so that the query can obtain the best performance in the target database environment, a complete data structure view and dependency graph can be provided to help developers and data management personnel better understand and manage data assets, and support data governance and compliance requirements.

[0095] In an alternative embodiment,

[0096] Based on the dialect feature matrix, a rule state set is constructed, the transition probability between rule nodes in the rule state set is calculated to form a syntax rule probability transition matrix, and the initial probability distribution of the rule state set is calculated according to the historical use frequency of the rule, including:

[0097] The dialect feature matrix is obtained and the rule state set is constructed, the basic operation complexity of each rule node in the rule state set is extracted and summed to obtain a time complexity value, the memory occupation value and the processor usage value of the rule node are read and added to obtain a resource consumption value, and the time complexity value and the resource consumption value are added to calculate the comprehensive execution cost of the rule node;

[0098] The rule nodes in the rule state set are traversed, the two adjacent rule nodes in the rule execution sequence are selected as the starting rule node and the target rule node to form a rule node pair, the historical execution frequency of the rule node pair is counted, the historical execution frequency sum of the target rule node corresponding to the starting rule node is calculated, the historical execution frequency is divided by the historical execution frequency sum to obtain the basic transition probability, the comprehensive execution cost of the target rule node is multiplied by the decay coefficient, and then the decay value is obtained by substituting it into the negative exponential function, and the decay value is multiplied by the basic transition probability to obtain the decayed transition probability;

[0099] The historical execution frequency and the sum of the rule nodes are counted to calculate the original use frequency, the comprehensive execution cost of the rule node is multiplied by the adjustment coefficient, then one is added and the reciprocal is taken to obtain the cost adjustment value, the original use frequency is multiplied by the cost adjustment value and normalized to obtain the initial probability distribution of the rule state set, and the decayed transition probability is divided by the row normalization coefficient to construct the syntax rule probability transition matrix.

[0100] A dialect feature matrix is obtained and a rule state set is constructed. The dialect feature matrix contains the syntax features and usage patterns of different database dialects and is the basis for constructing the rule state set. Based on the dialect feature matrix, a set of syntax rules that need to be supported is determined. The rules cover various aspects of SQL statement parsing and conversion, such as expression parsing, condition parsing, join parsing, and aggregation function parsing. Each rule represents a specific syntax structure processing or conversion method and has independent execution logic and resource requirements. The rules are organized into a rule state set as the state space of a Markov decision process.

[0101] For each rule node in the rule state set, detailed performance characteristic analysis is performed, and the basic operation complexity of the rule node is extracted, including time complexity and space complexity. The basic operation complexity reflects the algorithm complexity of rule execution and is usually described in big O notation, such as O(n), O(n 2 ), O(log n), etc. Different types of rule nodes have different complexity characteristics. For example, a simple field mapping rule may have O(1) complexity, while a complex subquery parsing rule has O(n 2 ) complexity. The weighted sum of the basic operation complexities of the rule nodes is obtained to obtain the overall time complexity value. The higher the value, the more computing resources are required for rule execution.

[0102] The memory occupation value of the rule node is read. The memory occupation value reflects the memory resource requirements during rule execution, including the storage space of the rule itself and the temporary data space during execution. Different rules have different memory requirements. For example, rules that handle large data sets may require more memory to store intermediate results. The processor usage value of the rule node is read. The processor usage value reflects the degree of CPU resource occupation during rule execution and is usually expressed in percentage. Processor-intensive rules, such as complex regular expression matching or string processing, often have high processor usage. The memory occupation value and the processor usage value are added to obtain the resource consumption value.

[0103] The time complexity value and the resource consumption value are added to obtain the comprehensive execution cost of the rule node. The comprehensive execution cost is a comprehensive index that considers the computational complexity and resource consumption of rule execution and provides a quantitative basis for subsequent probability calculation. Rules with higher execution costs should have lower priority in the system to avoid resource bottlenecks and performance problems.

[0104] After the rule node execution cost analysis is completed, a syntax rule probability transition matrix is constructed. All rule nodes in the rule state set are traversed, and two adjacent rule nodes are selected from the historical execution records. The rule node that is executed first is taken as the starting rule node, and the rule node that is executed later is taken as the target rule node to form a rule node pair. The node pair reflects the execution order relationship between rules and is the basic unit for constructing the transition matrix.

[0105] For each rule node pair, the historical execution frequency is counted, i.e., the number of times that the starting rule node is followed by the target rule node in the past rule execution sequence. The historical execution frequency reflects the degree of association between the two rules, and the higher the frequency, the more likely the two rules are executed in order. For each starting rule node, the historical execution frequency sum of all possible target rule nodes is calculated, which represents the total execution times of all rules that can follow the starting rule node.

[0106] The historical execution frequency of the rule node pair is divided by the historical execution frequency sum to obtain the basic transition probability. The basic transition probability reflects the original probability of transitioning from the starting rule node to the target rule node, which is based only on the historical execution mode and does not consider the execution cost factor. The basic transition probability satisfies the probability distribution property, i.e., for a specific starting rule node, the sum of the basic transition probabilities of all possible target rule nodes is 1.

[0107] The comprehensive execution cost of the target rule node is multiplied by the decay coefficient to obtain the decay factor. The decay coefficient is a system parameter that adjusts the degree of influence of the execution cost on the transition probability. The larger the coefficient, the more significant the influence of the execution cost. The decay factor is substituted into the negative exponential function to calculate the decay value, i.e., e^(-decay factor). The negative exponential function ensures that the higher the execution cost, the closer the decay value is to 0; the lower the execution cost, the closer the decay value is to 1. The basic transition probability is multiplied by the decay value to obtain the decayed transition probability. The decayed transition probability considers both the historical execution mode and the execution cost, reducing the transition probability of high-cost rules and relatively increasing the transition probability of low-cost rules.

[0108] Since the introduction of the execution cost decay mechanism, the sum of all transition probabilities from a specific starting rule node may no longer equal 1. Normalization processing is performed, and the sum of all decayed transition probabilities corresponding to the starting rule node is accumulated to obtain the row normalization coefficient. Each decayed transition probability is divided by the row normalization coefficient to obtain the balanced transition probability.

[0109] The balanced transition probability is used to construct a probability transition matrix of grammar rules. The matrix is an N*N square matrix, where N is the number of rule nodes in the rule state set. The element Pij in the matrix represents the probability of transitioning from rule node i to rule node j. The transition matrix satisfies the Markov property, i.e., the transition probability from the current state to the next state only depends on the current state and is independent of the previous state.

[0110] After the transition matrix is constructed, the initial probability distribution of the rule state set is calculated. The frequency of each rule node as a starting rule in the historical execution sequence is counted, and the total frequency of all rule nodes as starting rules is also counted. The frequency of each rule node is divided by the total frequency to obtain the original usage frequency.

[0111] In order to consider the influence of execution cost, a cost adjustment mechanism is introduced. The comprehensive execution cost of the rule node is multiplied by the adjustment coefficient, added by one and taken the reciprocal to obtain the cost adjustment value. The adjustment coefficient is a system parameter used to control the degree of influence of execution cost on the initial probability. The calculation of the cost adjustment value ensures that the higher the execution cost, the closer the adjustment value to 0; the lower the execution cost, the closer the adjustment value to 1. The original usage frequency is multiplied by the cost adjustment value to obtain the adjusted usage frequency. The adjusted usage frequency reduces the initial probability of high-cost rules and increases the initial probability of low-cost rules.

[0112] The adjusted usage frequency is normalized to ensure that the sum of the initial probabilities of all rule nodes is 1, and the initial probability distribution of the rule state set is obtained. The initial probability distribution determines the starting point selection of the rule sequence in the Markov decision process, and directly affects the subsequent rule selection and execution path.

[0113] In this embodiment, through Markov decision process and execution cost optimization, the optimal rule path can be adaptively selected according to specific conditions, and close to optimal performance can be obtained in different scenarios, significantly improving the adaptability and robustness of the system. By combining historical execution frequency and execution cost analysis, the overuse of high-cost rules is avoided, and the organic combination of experience and efficiency is realized. A more balanced and efficient solution is provided. The fine optimization method still maintains good performance and resource utilization efficiency when processing large-scale or complex SQL statements, avoiding resource bottlenecks and performance collapse.

[0114] In an alternative embodiment,

[0115] The feature matching of the independent statement sequence and the optimized grammar rule sequence generates a mapping relationship table of the parsing rules corresponding to each statement, which includes:

[0116] The sentence sequence feature information is extracted from the independent sentence sequence, the part-of-speech sequence of each sentence is generated to generate a syntax structure feature, the keyword set of each sentence is extracted to generate a vocabulary feature, the pre-sequence sentence information, the current sentence information and the post-sequence sentence information of each sentence are collected to generate a context feature, and the syntax structure feature, the vocabulary feature and the context feature are combined to construct a sentence comprehensive feature vector;

[0117] The matching mode of each rule is extracted from the optimized syntax rule sequence to form a rule mode feature, the constraint condition of each rule is extracted to form a rule constraint feature, and the rule mode feature and the rule constraint feature are combined to construct a rule feature template vector;

[0118] The matching degree of the sentence comprehensive feature vector and the rule feature template vector is calculated, the intersection cardinality of the syntax structure feature and the rule mode feature is divided by the union cardinality to calculate the structure similarity, the sum of the products of each keyword in the vocabulary feature and the rule matching degree is divided by the number of keywords to calculate the vocabulary similarity, the similarity degree of the context feature and the rule constraint feature is calculated to obtain the context similarity, and the structure similarity, the vocabulary similarity and the context similarity are weighted and combined to obtain the comprehensive similarity.

[0119] The rule with the highest comprehensive similarity is selected as the parsing rule corresponding to each sentence, and the sentence identifier, the parsing rule identifier and the corresponding comprehensive similarity are combined to generate a mapping relationship table.

[0120] The part-of-speech of each SQL sentence is annotated, and the SQL keywords (such as SELECT, FROM, WHERE), identifiers (table name, field name), operators, function names and literal values and other syntax elements in the sentence are identified. The part-of-speech of each SQL sentence is obtained through part-of-speech annotation, and the part-of-speech sequence reflects the basic syntax structure of the SQL sentence. The combination mode in the part-of-speech sequence can reveal the type and complexity of the SQL sentence, such as simple query, join query, nested subquery or complex analysis query, etc.

[0121] The keyword set of each SQL statement is extracted to generate lexical features. The core keywords in the SQL statement are identified, such as DML operation keywords (SELECT, INSERT, UPDATE, DELETE), DDL operation keywords (CREATE, ALTER, DROP), query modification keywords (DISTINCT, GROUP BY, HAVING, ORDER BY), etc. Important identifiers in the statement are extracted, including table names, view names, field names, aliases, etc. Identifiers are crucial to understanding the operation objects and data flow of SQL statements. For different types of SQL statements, specific functional keywords are focused on, such as aggregation functions (SUM, COUNT, AVG), window functions (ROW_NUMBER, RANK), conditional expressions (CASE WHEN), etc. These keywords reflect the specific operation types of SQL statements.

[0122] Context information of each SQL statement is collected to generate context features. Preceding statement information includes the content of relevant statements before the current SQL statement, table objects created or modified by preceding statements, output results of preceding statements, etc. Current statement information includes the type of SQL statement (query, insert, update, etc.), the main operation object of the statement (table, view, temporary table, etc.), the complexity and nesting level of the statement, etc. Posterior statement information includes the content of relevant statements after the current SQL statement, the case where the current statement result is referenced by subsequent statements, etc.

[0123] The syntax structure features, lexical features and context features are combined to construct a comprehensive feature vector of SQL statements. The comprehensive feature vector comprehensively describes the syntax characteristics, operation types and context relationships of SQL statements, providing multi-dimensional feature representation for subsequent rule matching.

[0124] From the optimized SQL syntax rule sequence, the matching pattern of each rule is extracted to form rule pattern features. The matching pattern of SQL syntax rule describes the applicable SQL statement type and structure features of the rule, including SQL keyword pattern, syntax structure pattern and operation type pattern, etc. The keyword pattern specifies the specific SQL keyword combination applicable to the rule, such as the query statement rule containing SELECT-FROM-WHERE combination. The syntax structure pattern defines the SQL syntax structure applicable to the rule, such as simple query rule, join query rule, subquery rule, common table expression (CTE) rule, etc. The operation type pattern specifies the SQL operation type applicable to the rule, such as data query rule, data modification rule, table creation rule, etc.

[0125] The constraint condition of each rule is extracted to form a rule constraint feature. The constraint condition further limits the conditions and requirements of rule application, ensuring that the rule is correctly used in appropriate cases. The constraint condition includes database dialect constraints, syntax version constraints, and functional feature constraints, among other aspects. Database dialect constraints specify the database types to which the rule applies, such as MySQL rules, Oracle rules, SQL Server rules, and the like. Syntax version constraints define the SQL syntax versions to which the rule applies, such as SQL-92 rules, SQL:2003 rules, SQL:2011 rules, and the like. Functional feature constraints specify specific functional requirements to which the rule applies, such as window function parsing rules that may only apply to SQL versions that support window functions.

[0126] The rule pattern feature and the rule constraint feature are combined to construct a rule feature template vector. The rule feature template vector is a mathematical representation of the rule feature, containing the matching conditions and constraint requirements of the rule, and is represented in the same feature space as the SQL statement comprehensive feature vector, facilitating subsequent similarity calculation and matching degree evaluation.

[0127] The matching degree of the SQL statement comprehensive feature vector and the rule feature template vector is calculated, and the structural similarity of the syntax structure feature and the rule pattern feature is calculated. The intersection cardinality divided by the union cardinality of the two feature sets is calculated using the intersection-union ratio method of set theory to obtain the structural similarity. For example, for a SELECT query statement, its syntax structure feature contains elements such as SELECT, FROM, WHERE, etc. If the rule pattern feature also contains these elements, the intersection of the two is larger, and the structural similarity is higher.

[0128] The lexical similarity of the lexical feature and the rule pattern is calculated. For each keyword and important identifier in the SQL statement, the matching degree is calculated. For example, for a SQL statement containing aggregate functions, the keywords include GROUP BY, SUM, COUNT, etc. If the rule is specifically used to process aggregate queries, the matching degree of the keywords is higher. The sum of the product of all keyword matching degrees divided by the total number of keywords is used to obtain the overall lexical similarity.

[0129] The context similarity of the context feature and the rule constraint feature is calculated. The execution environment and context relationship of the SQL statement are evaluated to determine whether they meet the constraint requirements of the rule. For example, for a SQL statement that references a temporary table, the rule needs to be able to handle temporary table references; for a SQL statement that depends on the results of a previous statement, the rule needs to be able to handle cross-statement dependencies.

[0130] The structural similarity, the lexical similarity and the contextual similarity are combined by weighting to calculate the comprehensive similarity. Different types of similarity can be given different weights according to specific application requirements, reflecting their relative importance in the rule matching process.

[0131] Based on the calculation result of the comprehensive similarity, the most suitable parsing rule is selected for each SQL statement. The comprehensive similarity of the statement and all rules is compared, and the rule with the highest similarity is selected as the parsing rule of the statement. If multiple rules have similar comprehensive similarity, the final selection is determined through an additional priority mechanism or secondary similarity comparison. After determining the parsing rule, the SQL statement identifier, the parsing rule identifier and the corresponding comprehensive similarity are combined to generate a mapping relationship table.

[0132] In this embodiment, by comprehensively considering multiple dimensions such as syntax structure, keyword features and context environment, the most suitable parsing rule is found for each SQL statement, which can correctly understand the structure and intent of complex SQL statements, significantly improve the parsing accuracy and the reliability of lineage analysis, and through the construction of feature vectors and the calculation of multi-dimensional similarity, it can handle incomplete matching cases. For SQL statements with variant syntax or mixed characteristics, the closest parsing rule can be found, and by considering the context relationship and dependency of SQL statements, the data flow and reference relationship between statements can be better understood, providing more comprehensive and accurate basic information for subsequent lineage analysis.

[0133] Figure 3 A flowchart of the mapping process of SQL statements and syntax rules.

[0134] In an optional implementation,

[0135] The statement nodes in the statement dependency directed graph are traversed, the corresponding parsing rule is selected according to the mapping relationship table to perform parsing, the field filtering conditions and calculation expressions are extracted to generate data operation sequences, the subquery nesting and temporary table flow are identified to generate data flow sequences, and the data operation sequences and data flow sequences are used to construct a field lineage link graph, including:

[0136] The field identifiers and operation information are extracted from each statement node in the statement dependency directed graph to generate field filtering conditions and calculation expressions, and the field filtering conditions and calculation expressions are combined to generate data operation sequences;

[0137] The data dependency relationship between the statement nodes is identified, the mapping relationship from the source field to the target field in the subquery statement is extracted to generate subquery nesting, the table identifier of the temporary table and its transmission field are extracted to generate temporary table flow, and the field identifier and its reference type across the statement are extracted to generate cross-statement reference, and the subquery nesting, temporary table flow and cross-statement reference are combined to generate data flow sequences.

[0138] According to the data operation sequence, a statement field transmission path is constructed, according to the data flow sequence, an inter-statement field transmission path is constructed, and the statement field transmission path and the inter-statement field transmission path are combined to form a complete field transmission path set;

[0139] From the field transmission path set, a field node is constructed by extracting a field identifier, a field type and a field source, a conversion edge is constructed by extracting a mutual conversion relationship between field nodes and a conversion operation, and a field lineage link graph recording complete field lineage relationships is generated by combining the field node and the conversion edge.

[0140] Starting from the statement dependency directed graph, each statement node is traversed one by one, and the field level operation information and dependency relationship are extracted. For each statement node, a field filtering condition is extracted. From the WHERE clause, the HAVING clause and the JOIN condition, a field identifier, an operator and an operation value are identified to form a complete filtering condition description. The field identifier can be a table field name, an expression or a function call result; the operator includes a comparison operator (such as equal, greater than, less than), a logical operator (such as AND, OR, NOT) and a special operator (such as LIKE, IN, BETWEEN); and the operation value can be a constant, a variable, a field reference or a subquery result. By identifying these elements and their combination relationships, a field filtering condition set in the statement is constructed.

[0141] Extracting a calculation expression, a part related to field calculation is identified from the SELECT clause, the WHERE clause, the HAVING clause and other expression positions. Field identifiers, function identifiers and function parameters are extracted, and the calculation logic and dependency relationship of the expression are analyzed. Field calculation can involve arithmetic operations (addition, subtraction, multiplication, division), string operations (concatenation, truncation, replacement), date processing (formatting, interval calculation) or conditional expressions (CASE WHEN) and other forms. For complex nested expressions, the structure is recursively analyzed to ensure that all calculation components and dependency relationships are correctly extracted.

[0142] Extracting an aggregation function, a field identifier, an aggregation function type and a grouping condition are identified from the GROUP BY clause and the aggregation function call. Common aggregation functions include SUM, COUNT, AVG, MAX, MIN, etc., and the function aggregates multiple rows of data into a single result. The grouping condition defines how data is grouped, usually from the field list specified in the GROUP BY clause.

[0143] Extract window function, identify field identifier, window function type and partition condition from window function call. Window functions include ranking functions (ROW_NUMBER, RANK, DENSE_RANK), aggregate window functions (SUM OVER, AVG OVER) and offset functions (LAG, LEAD) etc. Partition condition defines the scope of window function, usually comes from PARTITION BY clause and ORDER BY clause.

[0144] Combine extracted field filter condition, calculation expression, aggregate function and window function to generate complete data operation sequence, identify data dependency relationship between statement nodes on the basis of understanding single statement internal field operation, extract subquery nesting relationship, analyze subquery structure in SQL statement, identify mapping relationship between source field and target field of subquery. Subquery may appear in FROM clause, WHERE clause, SELECT clause and other positions, field mapping relationship may be different in each case. For example, derived table in FROM clause creates direct mapping from source table field to target field, while subquery in WHERE clause may establish conditional association between fields. Through analyzing subquery structure and context, extract complete field mapping information.

[0145] Extract temporary table flow information, identify creation and use of temporary table in SQL statement, extract temporary table identifier and transfer field. Temporary table plays an important role in intermediate storage and data transfer in data processing process, understanding how fields are transferred from one statement to another through temporary table is crucial for building complete lineage. Temporary table may be explicitly created (such as CREATE TEMPORARY TABLE) or implicitly generated (such as common table expression CTE), all types of temporary table and their field transfer path need to be identified.

[0146] Extract cross-statement reference, analyze field reference relationship between different SQL statements, identify cross-statement field identifier and reference type. Cross-statement reference may be direct reference (such as subsequent statement using prequel statement created table), indirect reference (such as reference through temporary table or view) or conditional reference (such as reference in EXISTS clause). Through analyzing inter-statement dependency relationship and reference mode, extract complete cross-statement field reference information.

[0147] Combine extracted subquery nesting, temporary table flow and cross-statement reference to generate data flow sequence. Data flow sequence describes data transfer and conversion path between different SQL statements, provides basis for building cross-statement field lineage.

[0148] Based on the data operation sequence, construct the intra-statement field transmission path. Analyze the field dependency relationship in field filtering conditions, calculation expressions, aggregation functions, and window functions, and identify the transmission and conversion process between fields. For example, in the calculation expression, the result field depends on the source field used in the expression; in the aggregation function, the aggregation result depends on the field being aggregated and the grouping field; in the window function, the calculation result depends on the parameter field and the partition field of the window function. Build a directed graph that describes the intra-statement field transmission path through the dependency relationship.

[0149] Based on the data flow sequence, construct the inter-statement field transmission path. Analyze the field mapping relationship in subquery nesting, temporary table flow, and cross-statement reference, and identify the field transmission and conversion process between different statements. For example, when one statement creates a temporary table and another statement queries the temporary table, there is a mapping relationship between the output field of the source statement and the input field of the target statement; when a subquery in one statement references the result of another statement, there is also a dependency relationship between the related fields of the two statements. Build a directed graph that describes the inter-statement field transmission path through the mapping relationship.

[0150] Combine the intra-statement field transmission path and the inter-statement field transmission path to form a complete field transmission path set, which contains the transmission and conversion relationship between all fields in the entire SQL script.

[0151] Extract field node information from the field transmission path set, including field identifier, field type, and field source. The field identifier uniquely identifies a field, including table name or alias prefix; the field type describes the data type of the field, such as integer, string, date, etc.; the field source explains the data source of the field, such as original table field, calculation field, aggregation result, or temporary table field, etc. Organize into field nodes as the basic unit of the bloodline link graph.

[0152] Extract conversion edge information from the field transmission path set, including the mutual conversion relationship between field nodes and the conversion operation. The conversion relationship describes the mapping method from the source field to the target field, which may be direct mapping, calculation conversion, aggregation conversion, or conditional filtering, etc.; the conversion operation explains the specific operation to achieve this conversion, such as arithmetic operation, function call, aggregation calculation, or window function, etc. Weave into conversion edges to describe the connection relationship between field nodes.

[0153] Combine field nodes and conversion edges to generate a complete field bloodline link graph. This link graph is a directed graph, where nodes represent fields and edges represent the conversion relationship between fields, fully recording the field-level bloodline relationship and data flow path in the entire SQL script. Through the link graph, you can trace the source and destination of the field, understand the changes and conversions of the data in the processing process.

[0154] In this embodiment, by analyzing the SQL statement in detail, the field filtering conditions, calculation expressions, aggregation functions and window functions and other information are extracted, and a field-level blood relationship graph is constructed, which can accurately track the source, conversion path and final destination of each field, providing more detailed support for data governance and quality management. By identifying complex relationships such as subquery nesting, temporary table flow and cross-statement reference, the field dependency relationship in the multi-level, multi-step data processing process can be accurately captured, so that the blood analysis can cope with various complex scenarios in actual business. By extracting and recording the conversion operations between fields, not only can the source, destination and conversion method of the data be displayed, but also by constructing a complete field blood link graph, the potential impact of upstream changes on downstream applications can be quickly identified, or the upstream source of downstream problems can be tracked, greatly improving the safety of data changes and the efficiency of problem troubleshooting.

[0155] In an optional implementation,

[0156] Structuring the field blood link graph to obtain a blood analysis result and outputting the blood analysis result in a specified format includes:

[0157] Extract the blood hierarchy relationship of the field nodes from the field blood link graph, identify the direct predecessor nodes and direct successor nodes of each field node, construct the blood transmission link, and group the field nodes according to the blood hierarchy relationship to form a blood hierarchy structure;

[0158] Traverse the field nodes in the blood hierarchy structure, extract the conversion operation type and conversion parameter in the conversion edge corresponding to each field node, and combine the blood hierarchy relationship of the field nodes with the conversion operation information to form a blood analysis result;

[0159] Reorganize and output the field node identifier, blood hierarchy, conversion operation, predecessor node and successor node in the blood analysis result according to a preset structured format.

[0160] Extract the blood hierarchy relationship between each field node, analyze the topology of the graph, and identify the direct predecessor nodes and direct successor nodes of each field node. The predecessor node refers to the upstream field that directly provides data to the current node, representing the source of the data; the successor node refers to the downstream field that directly receives the data of the current node, representing the destination of the data. By traversing all conversion edges in the graph, a complete mapping of predecessor and successor nodes between nodes is established. For each field node, record the set of all direct predecessor nodes and the set of all direct successor nodes to form a local blood view of the node.

[0161] Based on the predecessor-successor relationship, a lineage transmission link is constructed between fields. Starting from a source field without a predecessor node, the link is gradually transferred downstream along the transformation edge to form a complete lineage path. Multiple different lineage paths may exist regardless of the field. For example, when a field is generated by multiple source fields through different transformation paths, all possible lineage paths need to be recorded to ensure the integrity of the lineage analysis. At the same time, possible circular dependencies in the lineage chain are identified. This situation may occur in recursive queries or iterative calculations and needs to be handled separately to avoid infinite loops.

[0162] Based on the lineage transmission link, the lineage level of each field node is determined. Starting from the source field, fields without predecessor nodes are defined as the first level, and the level number is passed down layer by layer according to the data flow. If a field has multiple predecessor nodes at different levels, the level of the field is generally determined by the level of its deepest predecessor node plus one, ensuring that the hierarchical structure reflects the actual flow order of the data. In cases where there are multiple paths, it may be necessary to consider the level differences under different paths and select the most appropriate level representation.

[0163] Field nodes are grouped according to a certain lineage level to form a clear lineage hierarchy structure. The hierarchy structure organizes all fields into an orderly hierarchical system, and each level contains field nodes with the same lineage depth.

[0164] After building the lineage hierarchy, we traverse each field node to extract more detailed transformation operation information. We extract the transformation operation type and parameters from the transformation edges associated with the field node. The transformation operation type describes the basic method of data transformation, such as direct mapping, calculation transformation, aggregation transformation, and filtering transformation. The transformation parameters provide the specific details of the operation, such as the calculation formula, aggregation function, and filtering conditions.

[0165] For complex transformation operations, further analysis of the internal structure and logic is required. For example, a calculation expression containing multiple steps needs to be broken down into basic operation units; for nested conditional expressions, each branch condition and corresponding result needs to be identified.

[0166] The lineage hierarchy of field nodes is combined with the transformation operation information to form a complete lineage analysis result. The lineage analysis result includes basic information about each field (such as field identifier and field type), lineage relationship information (such as predecessor node, successor node, lineage hierarchy), and transformation information (such as transformation operation type and transformation parameters).

[0167] The blood relationship analysis result is reorganized and output according to a preset structured format. According to actual needs and application scenarios, appropriate output formats are selected, such as relational tables, hierarchical tree structures or network graphical representations. For table form, columns include field identification, table belonging, field type, blood relationship level, predecessor field list, conversion operation description, successor field list, etc. For tree structure, field nodes are organized according to blood relationship level to show the derivation relationship between fields. For network graphics, the complex connection relationship and conversion operation between fields are intuitively displayed. Different representation methods are suitable for different analysis needs and use scenarios, and can be flexibly selected according to specific circumstances.

[0168] In this embodiment, the hierarchical representation method makes the complex data processing flow intuitive and easy to understand, enabling users to easily understand the life cycle and conversion process of data, providing a global perspective for data asset management. By supporting multiple structured output formats such as tables, tree structures and network graphics, it can meet the needs of different user groups and application scenarios, and provide a foundation for data quality management by recording the blood relationship and conversion process of data, providing comprehensive and in-depth technical support for modern data governance and intelligent data management.

[0169] The second aspect of the embodiment of the application provides a multi-database SQL blood relationship analysis system based on a G4 file, comprising:

[0170] The first unit is configured to obtain a syntax rule set of a SQL statement according to a G4 syntax file, perform lexical cleaning and normalization processing on the SQL statement, and split the SQL statement into an independent statement sequence according to a semicolon, analyze the independent statement sequence to construct a statement dependency directed graph describing the dependency relationship between statements, and obtain a database configuration, a running parameter and temporary table information to form analysis basic data.

[0171] The second unit is configured to construct a dialect feature matrix describing the syntax features of the database by using the analysis basic data, establish a syntax rule probability transition matrix based on the dialect feature matrix, predict an optimal rule chain in the probability transition matrix through a Markov decision process to obtain an optimized syntax rule sequence, and perform feature matching on the independent statement sequence and the optimized syntax rule sequence to generate a mapping relationship table of each statement corresponding to an analysis rule.

[0172] The third unit is configured to traverse a statement node in the statement dependency directed graph, select a corresponding analysis rule according to the mapping relationship table to perform analysis, extract a field filtering condition and a calculation expression to generate a data operation sequence, identify a subquery nesting and a temporary table flow to generate a data flow sequence, and construct a field blood relationship link graph by using the data operation sequence and the data flow sequence.

[0173] The fourth unit is used to process the field blood relationship link diagram in a structural manner to obtain a blood relationship analysis result and output it in a specified format.

[0174] According to a third aspect of an embodiment of the present invention, an electronic device is provided, including:

[0175] A processor and a memory for storing processor-executable instructions, wherein the processor is configured to call the instructions stored in the memory to execute the aforementioned method.

[0176] According to a fourth aspect of an embodiment of the present invention, a computer-readable storage medium is provided, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the method described above is implemented.

[0177] The present invention may be a method, an apparatus, a system and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for executing various aspects of the present invention.

[0178] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A multi-database SQL lineage parsing method based on G4 files, characterized by: include: Obtain the grammatical rule set for SQL statements based on the G4 grammar file, perform lexical cleaning and normalization on the SQL statements, and split them by semicolons to obtain a sequence of independent statements. Analyze the independent statement sequence to construct a statement dependency directed graph that describes the dependencies between the previous and next statements. Obtaining database configuration, operating parameters, and temporary table information to form parsing basic data, using the parsing basic data to construct a dialect feature matrix describing database grammatical features, establishing a grammatical rule probability transition matrix based on the dialect feature matrix, and predicting the optimal rule chain in the probability transition matrix through a Markov decision process to obtain an optimized grammatical rule sequence, including: Obtain database configuration and operating parameters, standardize the connection strings in the database configuration and operating parameters, parse the execution plan of the SQL statement to obtain intermediate results and temporary table information, and organize the operating parameters, intermediate results and temporary table information into basic parsing data; Construct a feature vector space, which includes the dimensions of function syntax features, keyword usage features, and grammatical structure features. Based on the parsed basic data, calculate the frequency of occurrence and inverse document frequency of features in different databases. Determine feature weight scores based on the frequency of occurrence and inverse document frequency, and populate the feature weight scores into the dialect feature matrix. Based on the dialect feature matrix, a rule state set is constructed. The transition probabilities between rule nodes in the rule state set are calculated to form a grammatical rule probability transition matrix. The initial probability distribution of the rule state set is calculated based on the historical usage frequency of the rules. Based on the grammatical rule probability transition matrix and the initial probability distribution, the state value function is iteratively calculated using the Bellman equation. The action sequence that maximizes long-term benefits is selected to form an optimal rule chain. Redundant rules are eliminated on the optimal rule chain to obtain an optimized grammatical rule sequence. Perform feature matching on the independent statement sequence and the optimized grammar rule sequence to generate a mapping relationship table of corresponding parsing rules for each statement; Traverse the statement nodes in the statement dependency directed graph, select the corresponding parsing rules based on the mapping relationship table for parsing, extract field screening conditions and calculation expressions to generate data operation sequences, identify subquery nesting and temporary table flow to generate data flow sequences, and use data operation sequences and data flow sequences to build a field lineage link diagram; The field lineage link graph is structured to obtain a lineage analysis result and output it in a specified format.

2. The method according to claim 1, characterized in that Obtain the grammatical rule set for SQL statements based on the G4 grammar file, perform lexical cleaning and normalization on the SQL statements, and split them by semicolon to obtain a sequence of independent statements. Analyze the independent statement sequence to construct a statement dependency directed graph that describes the dependencies between the previous and next statements, including: Parse the G4 grammar file, read the grammar definition file content, build the lexical analyzer and syntax analyzer, and generate a set of standard grammar rules for SQL statements; Receive an SQL statement to be processed, perform lexical analysis using the grammar rule set, identify keywords, identifiers, operators, and literals in the SQL statement, remove redundant whitespace characters and comments, unify capitalization and line breaks to obtain a normalized SQL text, and split the normalized SQL text into a sequence of independent statements based on semicolon delimiters; Traverse the independent statement sequence, parse the grammatical structure of each statement based on the grammatical rule set, extract the table name, field name and temporary table definition in the statement, identify the data references and dependencies between statements, construct each statement into a statement node containing statement content and reference information, establish directed connections between nodes based on the data references and dependencies, and generate a statement dependency directed graph that records the execution process of the SQL statement.

3. The method according to claim 1, characterized in that The rule state set is constructed based on the dialect feature matrix, the transition probabilities between the rule nodes in the rule state set are calculated to form the grammatical rule probability transition matrix, and the initial probability distribution of the rule state set is calculated based on the historical usage frequency of the rules. Obtain the dialect feature matrix and construct a rule state set. Extract the basic operation complexity of each rule node in the rule state set and sum them to obtain the time complexity value. Read the memory usage value and processor utilization value of the rule node and add them to obtain the resource consumption value. Add the time complexity value and resource consumption value to calculate the comprehensive execution cost of the rule node. Traverse the rule nodes in the rule state set, select two adjacent rule nodes in the rule execution sequence as the starting rule node and the target rule node to form a rule node pair, count the historical execution frequencies of the rule node pair, calculate the sum of the historical execution frequencies of the target rule nodes corresponding to the starting rule node, divide the historical execution frequencies by the sum of the historical execution frequencies to obtain the basic transition probability, multiply the comprehensive execution cost of the target rule node by the attenuation coefficient, and then subtract the result from the negative exponential function to obtain the attenuation value, which is then multiplied by the basic transition probability to obtain the attenuated transition probability; The original usage frequency is calculated by counting the historical execution frequency and the sum of the rule nodes. The comprehensive execution cost of the rule node is multiplied by the adjustment coefficient, added with one and the inverse is taken to obtain the cost adjustment value. The original usage frequency is multiplied by the cost adjustment value and normalized to obtain the initial probability distribution of the rule state set. The attenuated transition probability is divided by the row normalization coefficient to construct the grammar rule probability transition matrix.

4. The method according to claim 1, wherein Performing feature matching on the independent statement sequence and the optimized grammar rule sequence to generate a mapping relationship table corresponding to the parsing rule for each statement includes: Extract sentence sequence feature information from independent sentence sequences, obtain the part-of-speech sequence of each sentence to generate grammatical structure features, extract the keyword set of each sentence to generate lexical features, collect the preceding sentence information, current sentence information, and subsequent sentence information of each sentence to generate context features, and combine the grammatical structure features, lexical features, and context features to construct a sentence comprehensive feature vector; Extract the matching pattern of each rule from the optimized grammar rule sequence to form the rule pattern feature, extract the constraint condition of each rule to form the rule constraint feature, and combine the rule pattern feature and the rule constraint feature to construct the rule feature template vector; Calculate the matching degree between the sentence comprehensive feature vector and the rule feature template vector, divide the intersection cardinality of the grammatical structure features and the rule pattern features by the union cardinality to calculate the structural similarity, divide the sum of the products of the matching degrees of each keyword in the lexical feature and the rule by the number of keywords to calculate the lexical similarity, calculate the similarity between the context features and the rule constraint features to obtain the contextual similarity, and perform a weighted combination of the structural similarity, lexical similarity, and contextual similarity to obtain the comprehensive similarity; The rule with the highest comprehensive similarity is selected as the parsing rule corresponding to each statement, and the statement identifier, parsing rule identifier, and corresponding comprehensive similarity are combined to generate a mapping relationship table.

5. The method according to claim 1, wherein Traversing the statement nodes in the directed graph of statement dependencies, selecting the corresponding parsing rules according to the mapping relationship table for parsing, extracting field screening conditions and calculation expressions to generate data operation sequences, identifying subquery nesting and temporary table flow to generate data flow sequences, and using data operation sequences and data flow sequences to build a field lineage link graph, including: Traverse the statement nodes in the statement dependency directed graph, extract the field identifier and operation information from each statement node to generate field screening conditions and calculation expressions, and combine the field screening conditions and calculation expressions to generate a data operation sequence; Identify data dependencies between statement nodes, extract the mapping relationship from source fields to target fields in subquery statements to generate subquery nesting, extract the table identifier of the temporary table and its transfer fields to generate temporary table flow, extract the cross-statement field identifier and its reference type to generate cross-statement reference, and combine subquery nesting, temporary table flow, and cross-statement reference to generate a data flow sequence; Construct an intra-statement field transfer path based on the data operation sequence, construct an inter-statement field transfer path based on the data flow sequence, and merge the intra-statement field transfer path and the inter-statement field transfer path to form a complete field transfer path set; The field identifier, field type and field source are extracted from the field transfer path set to construct field nodes, the mutual conversion relationship between field nodes and their conversion operations are extracted to construct conversion edges, and the field nodes and conversion edges are combined to generate a field lineage link diagram that records the complete lineage relationship of the fields.

6. The method according to claim 1, characterized in that Structural processing of the field lineage link graph to obtain lineage analysis results and outputting them into a specified format includes: Extract the lineage hierarchical relationship of field nodes from the field lineage link graph, identify the direct predecessor node and direct successor node of each field node, build a lineage transmission link, and group the field nodes according to the lineage hierarchical relationship to form a lineage hierarchical structure; Traversing the field nodes in the lineage hierarchical structure, extracting the conversion operation type and conversion parameters in the conversion edge corresponding to each field node, and combining the lineage hierarchical relationship of the field node with the conversion operation information to form a lineage analysis result; The field node identifiers, lineage levels, conversion operations, predecessor nodes, and successor nodes in the lineage analysis results are reorganized and output according to a preset structured format.

7. A multi-database SQL lineage analysis system based on G4 files, used to implement the method according to any one of claims 1 to 6, characterized in that: include: The first unit is used to obtain the grammatical rule set of SQL statements based on the G4 grammar file, perform lexical cleaning and normalization processing on the SQL statements, split them by semicolons to obtain independent statement sequences, and analyze the independent statement sequences to construct a statement dependency directed graph that describes the dependencies between the previous and next statements. The second unit is configured to obtain database configuration, operating parameters, and temporary table information to form basic parsing data, use the basic parsing data to construct a dialect feature matrix describing the grammatical features of the database, establish a grammatical rule probability transition matrix based on the dialect feature matrix, predict the optimal rule chain in the probability transition matrix through a Markov decision process to obtain an optimized grammatical rule sequence, perform feature matching on the independent statement sequence and the optimized grammatical rule sequence, and generate a mapping relationship table corresponding to the parsing rules for each statement; The third unit is used to traverse the statement nodes in the statement dependency directed graph, select the corresponding parsing rules according to the mapping relationship table, extract the field screening conditions and calculation expressions to generate data operation sequences, identify subquery nesting and temporary table flow to generate data flow sequences, and use the data operation sequences and data flow sequences to construct a field lineage link diagram; The fourth unit is used to structure the field bloodline link graph to obtain the bloodline analysis result and output it into a specified format.

8. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; The processor is configured to call the instructions stored in the memory to execute the method according to any one of claims 1 to 6.

9. A computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the computer program instructions are executed by a processor, the method according to any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Data blood relationship processing method and device

    CN111538744A

  • Data card application building method and system, electronic device, and storage medium

    WO2024250877A1