Field traceability method, apparatus and system, device, cluster, product and medium
By parsing the query statement into multiple sub-statements and combining them with preset relationship rules, the source tracing system can accurately locate the source of field modifications in the database, solving the problem of being unable to trace complex relationships in existing technologies and achieving efficient error root cause location.
Patent Information
- Application Number
- PCT/CN2025/087558
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-05-23
- Filing Date
- 2025-04-07
- Publication Date
- 2025-11-27
AI Technical Summary
Existing tracing techniques can only trace back to fields with relationships in the SQL syntax tree, and cannot further trace back to the complex relationships between different data tables, resulting in the inability to accurately locate the root cause of errors when errors are found.
The tracing system parses the query statement into multiple sub-statements, determines the source of the fields based on the target sub-statement, and uses a combination of processing, filtering, and value retrieval operations, combined with preset relationship rules, to achieve multi-level tracing.
It enables multi-level tracing of field modification relationships, accurately locating the root cause of errors and improving the accuracy and efficiency of tracing.
Smart Images

Figure CN2025087558_27112025_PF_FP_ABST
Abstract
Description
Method, device, system, equipment, cluster, product and medium for field traceability
[0001] The present application claims priority to the Chinese patent application No. 202410651341.9, filed on May 23, 2024, and entitled “Method, device, system, equipment, cluster, product and medium for field traceability”, the entire content of which is incorporated herein by reference. TECHNICAL FIELD
[0002] The present application relates to the field of databases, and in particular to a method, device, system, equipment, cluster, product and medium for field traceability. BACKGROUND
[0003] When a user operates a data table in a database, the user needs to operate through a query statement (for example, an SQL statement). One SQL statement often involves operations on multiple fields of multiple tables. When an error occurs during the execution of the SQL statement, a traceability technology is needed to determine which table and which field have the error.
[0004] The current traceability technology can only trace to the fields having an association relationship in a syntax tree according to the syntax tree. However, in actual scenarios, there can be various complex relationships between fields of different data tables. For example, as shown in FIG. 1, it is assumed that there is an a field in an A data table, a b field in a B data table, and a c field in a C data table, wherein the c field is obtained by processing the a field and the b field (for example, adding the a field to the b field). When the user finds that the value of the c field is incorrect, the root cause of the problem can not be in the c field itself, but in the a field or the b field. Therefore, to locate the error, it is necessary to trace to the a field in the A data table and the b field in the B data table.
[0005] Alternatively, there are c and d fields in a D data table, and the c field in the C data table is obtained by filtering the fields in the D data table to remove the d field. If the c field is missing in the C data table, the root cause of the problem can be that the c field is also removed by mistake when the fields in the D data table are filtered. Therefore, to locate the error, it is necessary to trace to the D data table.
[0006] However, according to the current traceability technology, it is only possible to trace to the c field, and it is not possible to further trace to the c field. SUMMARY
[0007] The present application provides a method, device, system, equipment, cluster, product and medium for field traceability, which can trace the modification relationship of a field.
[0008] In a first aspect, a field provenance method is provided. The method can include the following steps:
[0009] The provenance system obtains a provenance request. The provenance request includes an identifier of a first table and an identifier of a first field in the first table.
[0010] The provenance system finds a query statement including the identifier of the first table in a database, parses the query statement into a plurality of sub-statements, determines a target sub-statement including the first field and being modified in the plurality of sub-statements, determines a source of the first field according to the target sub-statement, and the source indicates that the field is obtained from a second field in a second table through a modification operation. The database includes executed query statements. The modification operation includes one or a combination of a plurality of processing operations, filtering operations, and value operations. The processing operation includes one or a combination of a plurality of mathematical operations, logical operations, bit operations, comparison operations, assignment operations, matrix operations, and vector operations. The data operation includes one or a combination of a plurality of addition, subtraction, multiplication, and division operations. The logical operation includes one or a combination of a plurality of AND, OR, and NOT operations. The filtering operation is an operation for filtering based on the second field.
[0011] The value operation is used to take the value of the second field as the value of the first field.
[0012] In the above scheme, the query statement including the identifier of the first table can be found, and the target sub-statement including the first field and being modified can be found in the query statement. The second field of the second table through the modification operation to obtain the first field is determined according to the target sub-statement, and the modification relationship of the second field to obtain the first field through the modification operation is traced.
[0013] In some possible designs, determining the target sub-statement including the first field and being modified in the plurality of sub-statements includes the following steps:
[0014] Finding a sub-statement including the field. The sub-statement including the field can include a sub-statement including a keyword indicating a modification operation and a sub-statement not including the keyword indicating the modification operation.
[0015] The sub-statement including the keyword indicating the modification operation in the sub-statement including the field is the target sub-statement.
[0016] In the above scheme, only the sub-statement including the keyword indicating the modification operation is taken as the target sub-statement, which can effectively reduce the number of sub-statements that need to be analyzed.
[0017] In some possible design, determining the source of the field according to the target sub-sentence includes the following steps:
[0018] Matching the target sub-sentence according to a preset relationship rule, wherein the relationship rule is used to represent a modification operation performed on a field.
[0019] If the first field of the target sub-sentence and a second field in the second table match the relationship rule, it is determined that the second field in the second table is the source of the first field.
[0020] In the above solution, the second field in the second table can be found as the source of the first field according to the preset relationship rule, and when different preset relationship rules are set, the traceability of different modification relationships can be realized.
[0021] In some possible design, the traceability of the second field is continued, and when no second field including the second field is found and the second field is a target sub-sentence modified by the second field, the traceability is stopped, and the source of the first field is output; if the second field is found and the second field is a target sub-sentence modified by the second field, the source of the second field is recorded.
[0022] In the above solution, the traceability of the first field can be implemented in multiple layers, so that the problem of the first field can be tracked.
[0023] In a second aspect, a field traceability apparatus is provided. The apparatus includes:
[0024] An acquisition module configured to acquire a traceability request, wherein the traceability request includes an identifier of a first table and an identifier of a first field in the first table.
[0025] A search module configured to search for a query statement including the identifier of the first table in a database, wherein the database includes executed query statements.
[0026] An analysis module configured to analyze the query statement into a plurality of sub-sentences.
[0027] A determination module configured to determine, from the plurality of sub-sentences, a sub-sentence including the first field and a target sub-sentence modified by the first field.
[0028] The tracing module is configured to determine the origin of the first field according to the target sub-sentence, and the origin indicates that the first field is obtained by a modification operation on a second field in a second table. The modification operation includes one or a combination of a processing operation, a filtering operation, and a value operation. The processing operation includes one or a combination of a mathematical operation, a logical operation, a bit operation, a comparison operation, an assignment operation, a matrix operation, and a vector operation. The data operation includes one or a combination of addition, subtraction, multiplication, and division. The logical operation includes one or a combination of AND, OR, and NOT. The filtering operation is an operation of filtering based on the second field.
[0029] The value operation is configured to take the value of the second field as the value of the first field.
[0030] In some possible designs, the determining module is further configured to search for a sub-sentence including the field, and search for a sub-sentence including a keyword indicating a modification operation in the sub-sentence including the field as the target sub-sentence. The sub-sentence including the field can include a sub-sentence including a keyword indicating a modification operation and a sub-sentence not including a keyword indicating a modification operation.
[0031] In some possible designs, the tracing module is further configured to match the target sub-sentence according to a preset relationship rule, and determine the second field in the second table as the origin of the first field if the first field in the target sub-sentence and the second field in the second table match the relationship rule.
[0032] In some possible designs, the tracing module is further configured to continue tracing the second field, stop and output the origin of the first field when the second field is not found and the second field is a modified target sub-sentence, and record the origin of the second field if the second field is found and the second field is a modified target sub-sentence.
[0033] In a third aspect, a field tracing system is provided, and the system includes:
[0034] A client is configured to send a tracing request, and the tracing request includes an identifier of a first table and an identifier of a first field in the first table.
[0035] The field tracing device is configured to acquire a tracing request, search a database for a query statement including an identifier of the first table, the database including executed query statements, parse the query statement into a plurality of sub-statements, determine a target sub-statement including the first field and modified from the field among the plurality of sub-statements, determine a source of the first field according to the target sub-statement, the source indicating that the field is obtained from a second field in a second table through a modification operation.
[0036] In a fourth aspect, a chip system is provided, the chip system comprising a processor and a power supply circuit configured to supply power to the processor, the processor configured to perform the operational steps of the method according to any one of the first aspect.
[0037] In a fifth aspect, a computing device is provided, the computing device comprising a processor and a memory;
[0038] The processor is configured to execute instructions stored in the memory to cause the computing device to perform the operational steps of the method according to any one of the first aspect.
[0039] In a sixth aspect, a computing device cluster is provided, comprising at least one computing device, each computing device comprising a processor and a memory;
[0040] The processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device to cause the computing device cluster to perform the operational steps of the method according to any one of the first aspect.
[0041] In a seventh aspect, a computer program product comprising instructions which, when executed by a computing device cluster, cause the computing device cluster to perform the operational steps of the method according to any one of the first aspect.
[0042] In an eighth aspect, a computer-readable storage medium is provided, comprising computer program instructions which, when executed by a computing device cluster, cause the computing device cluster to perform the operational steps of the method according to any one of the first aspect. BRIEF DESCRIPTION OF DRAWINGS
[0043] FIG. 1 is a structural schematic diagram of a database system provided by the present application;
[0044] FIG. 2 is a structural schematic diagram of a database system provided by the present application;
[0045] FIG. 3 is a flow schematic diagram of a field tracing method provided by the present application;
[0046] FIG. 4 is a structural schematic diagram of a target SQL syntax tree provided by the present application;
[0047] FIG. 5 is a flow diagram of acquiring a first field according to the present application;
[0048] FIG. 6 is a structural diagram of tracing a SQL syntax tree according to the present application;
[0049] FIG. 7 is a flow diagram of acquiring a second field according to the present application;
[0050] FIG. 8 is a diagram of tracing a relationship according to the present application;
[0051] FIG. 9 is a structural diagram of a field tracing system according to the present application;
[0052] FIG. 10 is a structural diagram of a computing device according to the present application;
[0053] FIG. 11 is a structural diagram of a computing device cluster according to the present application;
[0054] FIG. 12 is a structural diagram of another computing device cluster according to the present application. DETAILED DESCRIPTION
[0055] The database system will be described in detail below with reference to the accompanying drawings.
[0056] Referring to FIG. 2, FIG. 2 is a structural diagram of a database system according to the present application. As shown in FIG. 2, the database system according to the present application includes a client 110 and a tracing system 120.
[0057] The client 110 is configured to implement human-computer interaction, and can be deployed on a terminal device or a computing device. The terminal device includes a personal computer, a smart phone, a wearable device, a palm-held processing device, a tablet computer, a mobile notebook, an augmented reality (AR) device, a virtual reality (VR) device, an integrated handheld game console, a wearable device, a vehicle-mounted device, a smart conference device, a smart advertising device, a smart home appliance, and the like. The smart home appliance can be a sweeping robot, a mopping robot, and the like, which are not limited herein. The computing device can be described in the next paragraph.
[0058] The client 110 can be a software or an application running on a terminal device or a computing device controlled by a user, such as a personal computer (PC) client, a web client based on a browser, an application (APP) client running on a mobile terminal, or a console of a cloud platform, which are not limited herein.
[0059] The client 110 can also be a client of a cloud platform, such as a console of the cloud platform, which can be a web-based console or an application programming interface (API)-based console, without limitation.
[0060] The traceability system 120 is a system for tracing a field in a table. How to trace the field will be described in detail in FIG. 3 and related embodiments below, which will not be described here. The traceability system 120 can be deployed on a computing device, a cluster of computing devices, or a terminal device. The computing device includes a server, a virtual machine, a container, or an edge computing device. The virtual machine and the container both refer to a computing system composed of virtualization of computing, storage, network, and other hardware resources by a virtualization platform. The edge computing device refers to a device closer to a data source and an end user, with low latency and high bandwidth characteristics, such as a smart router, an edge server, and the like. The cluster of computing devices can include a plurality of computing devices described above, such as a data center, without limitation. The terminal device is described above and will not be repeated here.
[0061] It can be understood that the database system shown in FIG. 2 is only a specific example. In actual applications, the database system can further include more devices and systems, such as a storage system, and the number of clients can be more, without limitation.
[0062] After introducing the database system, the method for field traceability performed under the database system will be described in detail below. Referring to FIG. 3, FIG. 3 is a flowchart of a method for field traceability provided by the present application. As shown in FIG. 3, the method for field traceability provided by the present application includes the following steps:
[0063] S101: The client sends an identification of a first table and an identification of a first field in the first table to the traceability system. Correspondingly, the traceability system receives the identification of the first table and the identification of the first field in the first table sent by the client.
[0064] The first table can be any data table. The first table can include a plurality of fields including the first field. The first field can be different according to different businesses. For example, when the business is a financial business, the first field can be a quantity, a unit price, a total amount, an exchange rate, and the like. When the business is a management business, the first field can be a progress completion rate, a budget execution rate, a defect rate, and the like. When the business is a data analysis business, the first field can be an average value, a standard deviation, a correlation coefficient, and the like. When the business is a marketing business, the first field can be a click-through rate, a conversion rate, and the like.
[0065] In addition to the above examples, in actual applications, the first field can be any field specified by a user as needed, which is not specifically limited here.
[0066] S102: The traceability system finds a first query statement including the identifier of the first table in the database.
[0067] The database can include a plurality of files, such as program files and the like. The program files can include one or more executed query statements. In a specific embodiment, the program text can be an SQL file or the like. The SQL text includes one or more query statements. For example, the SQL statements can include a statement (WITH AS) for creating a temporary named result set in a query, a data query statement (SELECT statement) for retrieving data from the database, a data insertion statement (INSERT statement) for inserting a new data row into a database table, a data update statement (UPDATE statement) for updating an existing data row in a database table, a data deletion statement (DELETE) for deleting a data row from a database table, a table creation statement (CREATE TABLE statement) for creating a new database table, a table modification statement (ALTER TABLE statement) for modifying the structure of a database table, a table deletion statement (DROP TABLE statement) for deleting a table in the database and all data in the table, and the like data manipulation language (DML) statements. Since the core complex part of a complex DML statement is generally a SELECT query statement, the analysis of the SELECT statement is the core, and the following will be mainly described by taking the SELECT statement as an example.
[0068] The first query statement can be a single sentence or a compound sentence. When the first query statement is a compound sentence, the first query statement can include a plurality of clauses. Taking the SELECT statement as an example, the SELECT statement can include one or more clauses. For example, when the first query statement is a single sentence, the SELECT statement can only include a SELECT clause, and when the SELECT statement is a compound sentence, the SELECT statement can include one or more of a FROM clause, a WHERE clause, and the like in addition to the SELECT clause. Among them, the SELECT clause is a clause starting with the keyword SELECT, the FROM clause is a clause starting with the keyword FROM, and the WHERE clause is a clause starting with the keyword WHERE.
[0069] For example, it is assumed that the SQL text includes two query statements:
[0070] (1) The first query statement is:
[0071] INSERT INTO PTP()
[0072] SELECT
[0073] 7.2*PRO.PO_AMT AS USD_AMT
[0074] FROM PRO
[0075] WHERE
[0076] PRO.BUSINESS_TYPE=’GP’
[0077] INSERT INTO is a keyword used to insert new row data into a data table, so INSERT INTO PTP() is an INSERT INTO clause starting with the keyword INSERT INTO,
[0078] SELECT is a keyword used to retrieve data from a data table, so SELECT RATE.USD_RATE*PRO.AMT AS USD_AMT is a SELECT clause starting with the keyword SELECT, AS is a keyword used to specify an alias for a column or table in the query result, 7.2*PRO.AMT AS USD_AMT means that the result of 7.2*PRO.AMT is specified as an alias USD_AMT, where 7.2 is a constant, * is a multiplication operator, and PRO.AMT is a field in the data table PRO,
[0079] FROM is a keyword used to specify the name of a data table from which data is to be retrieved, so FROM PRO, RATE is a FROM clause starting with the keyword FROM,
[0080] WHERE is a keyword used to specify a condition to filter the retrieved data, so WHERE PRO.BUSINESS_TYPE=’GP’ is a WHERE clause starting with the keyword WHERE, and PRO.BUSINESS_TYPE=’GP’ is the filter condition, PRO.BUSINESS_TYPE is a field in the data table PRO,
[0081] In summary, the entire SQL statement means filtering data from the PRO data table that meets the filter condition, extracting PRO.AMT from the data that meets the filter condition, specifying the result of 7.2*PRO.AMT as an alias PO_AMT, and inserting PO_AMT into the data table PTP.
[0082] (2) The second query statement is:
[0083] INSERT INTO PRO()
[0084] SELECT
[0085] PO.UNIT_PRICE*(PO.QUANTITY-PO.CANCEL_QTY)AS PO_AMT,
[0086] DECODE(PO.SOURCE_CODE,‘ERP1’,’GP’)AS BUSINESS_TYPE
[0087] FROM PO
[0088] Where, INSERT INTO is a keyword for inserting new row data into a data table, so INSERT INTO PTP() is an INSERT INTO clause starting with the keyword INSERT INTO,
[0089] SELECT is a keyword for retrieving data from a data table, so PO.UNIT_PRICE*(PO.QUANTITY-PO.CANCEL_QTY)AS PO_AMT, DECODE(PO.SOURCE_CODE,‘ERP1’,‘GP’)AS BUSINESS_TYPE is a SELECT clause starting with the keyword SELECT, AS is a keyword for specifying an alias for a column or table in the query result, the meaning of PO.UNIT_PRICE*(PO.QUANTITY-PO.CANCEL_QTY)AS PO_AMT is to specify the result of PO.UNIT_PRICE*(PO.QUANTITY-PO.CANCEL_QTY) as PO_AMT, wherein PO.UNIT_PRICE, PO.QUANTITY, PO.CANCEL_QTY are all fields in the data table PO, * is a multiplication operator, - is a subtraction operator, the meaning of DECODE(PO.SOURCE_CODE,‘ERP1’,‘GP’)AS BUSINESS_TYPE is to compare ERP1 and PO.SOURCE_CODE field, if the values of ERP1 and PO.SOURCE_CODE field match, return GP as the result and specify the alias as BUSINESS_TYPE, DECODE() is a comparison function, PO.SOURCE_CODE is a field in the data table PO, ‘ERP1’ is a string, ‘GP’ is a string,
[0090] FROM is used to specify the name of the data table from which data is to be retrieved, so, FROM PO is the FROM clause starting with the keyword FROM, and PO is the data table,
[0091] In summary, the meaning of the entire SQL statement is to extract PO.UNIT_PRICE, PO.QUANTITY, PO.CANCEL_QTY, and PO.SOURCE_CODE from the PO data table, and to specify the result of the operation of PO.UNIT_PRICE*(PO.QUANTITY-PO.CANCEL_QTY) as the alias PO_AMT, and to specify the result of the operation of DECODE(PO.SOURCE_CODE,‘ERP1’,‘GP’) as the alias BUSINESS_TYPE, and to insert PO_AMT and BUSINESS_TYPE into the PRO data table.
[0092] The first query statement including the identification of the first table that the traceability system looks up in the database can be:
[0093] Step one: the traceability system performs table-level relationship analysis on the program text, thereby obtaining the data tables in the program text, the relationship between the data tables, and the corresponding relationship between the data tables and the first query statement. The table-level relationship analysis can refer to the prior art. After the table-level relationship analysis on the program text, a directed graph is obtained, wherein the nodes of the graph are composed of tables, the edges are composed of DML statements, and the direction of the edges is from the source table to the target table, and the target table is the table obtained by operating the source table through the DML statement.
[0094] Continuing with the example of the program text in step S102, after the table-level relationship analysis, a directed graph composed of the PTP table, the PRO table, and the PO table is obtained, and the relationship among the PTP table, the PRO table, and the PO table is that the PTP table points to the PRO table, and the edge between them is the first query statement, and the PRO table points to the PO table, and the edge between them is the second query statement.
[0095] Step two: compare the identification of the first field with each field in the data table respectively, thereby finding the field with the same identification as the first field and the target data table where the field is located. Continuing with the example in the above step, when the identification of the first field is USD_AMT, compare the identification of the first field with each field in the PTP table, the PRO table, and the PO table respectively, and then find the field USD_AMT, thereby determining that the target data table where the field USD_AMT is located is the PTP table.
[0096] Step three: determining the first query statement according to the target data table and the corresponding relationship between the data table and the query statement. Since the corresponding relationship between the data table and the query statement has been obtained in the table-level relationship analysis of the program text, the first query statement can be obtained by searching the corresponding relationship between the data table and the query statement according to the target data table. Continue with the example in the above step, since the relationship between the data table and the query statement is: the PRO table is the source table of the first query statement, and the PTP table is the target table of the first query statement; the PO table is the source table of the second query statement, and the PRO table is the target table of the second query statement, so in the case that the target data table is the PTP table, the target statement in which the field USD AMT is located is determined to be the first query statement in the example shown in step one.
[0097] S103: The traceability system parses the first query statement into a plurality of sub-statements, determines a first target sub-statement including the first field and the field being modified in the plurality of sub-statements, and determines the source of the first field to be the second field according to the first target sub-statement.
[0098] The second field is used to perform a modification operation to obtain the first field. The modification operation can include one or more of a processing operation, a filtering operation, and a value operation. That is, the relationship between the second field and the first field mainly includes two kinds:
[0099] The first kind is to obtain the first field by performing a processing operation on the second field. The processing operation can include mathematical operations, logical operations, bitwise operations, comparison operations, assignment operations, matrix operations, vector operations, etc. The data operation can include addition, subtraction, multiplication, and division operations. The logical operation can include AND, OR, and NOT operations. Taking the first field as USD AMT and the target SQL statement as the example of the target SQL statement in step S102, it can be known from the target SQL statement that USD AMT is equal to 7.2*PRO.AMT, where the second field is field PRO.AMT, and the processing operation is to multiply 7.2 and field PRO.AMT.
[0100] The second kind is to obtain the first field by filtering according to the filtering operation including the second field. The filtering operation can be used to specify the conditions required to be met when retrieving or processing data. Taking the first field as USD AMT and the target SQL statement as the example of the target SQL statement in step S102, it can be known from the target SQL statement that the filtering logic of the WHERE clause is: PRO.BUSINESS_TYPE=’GP’. Here, the second field included in the filtering logic is PRO.BUSINESS_TYPE.
[0101] The third is to get the first field by taking the value of the second field. That is, the value obtained from the second field is the first field, without processing or filtering, etc.
[0102] The process of parsing the first query statement into a plurality of sub-statements, determining the first target sub-statement including the first field and the field being modified in the plurality of sub-statements can be:
[0103] According to the first query statement, a target syntax tree is parsed to obtain a plurality of sub-statements, and the first query statement is parsed into a plurality of sub-statements based on the target syntax tree, and the first target sub-statement is determined in the plurality of sub-statements including the first field and the field being modified.
[0104] The target syntax tree includes nodes and relationships between nodes. Each node represents a syntax element in the first query statement, and the relationship between the nodes represents the hierarchical structure and dependency relationship between the syntax elements. The syntax elements can include keywords, constants, variables, operator symbols, etc. Among them,
[0105] The keyword can be a keyword in the first query statement, for example, SELECT, FROM, WHERE, AS, etc. in the first query statement in step S102.
[0106] The constant can be a constant in the first query statement, for example, 7.2 in the first query statement in step S102.
[0107] The variable can be a variable in the first query statement, for example, PRO.PO AMT, USD AMT in the first query statement in step S102.
[0108] The operator symbol is a symbol in the first query statement, for example, * and = in the two query statements in step S102.
[0109] The hierarchical structure and dependency relationship between the syntax elements, for example, in the sentence SELECT 7.2*PRO.PO AMT AS USD AMT, the hierarchical structure between the syntax elements is: the keyword SELECT includes the constant 7.2, the variable PRO.PO AMT, the keyword AS, and the variable USD AMT. It can also be said that the constant 7.2, the variable PRO.PO AMT, the keyword AS, and the variable USD AMT depend on the keyword SELECT.
[0110] Correspondingly, the nodes corresponding to these syntax elements can include:
[0111] The keyword corresponding node, for example, the SELECT node, the FROM node, the WHERE node, and the like. The SELECT node is the node corresponding to the keyword SELECT in the first query statement, the FROM node is the node corresponding to the keyword FROM in the first query statement, the WHERE node is the node corresponding to the keyword WHERE in the first query statement, and the AS node is the node corresponding to the keyword AS in the first query statement.
[0112] The constant corresponding node, for example, the 7.2 node, and the like. The 7.2 node is the node corresponding to the constant 7.2 in the first query statement.
[0113] The variable corresponding node, for example, the PRO.PO AMT node, the USD AMT node, and the like. The PRO.PO AMT node is the node corresponding to the variable PRO.PO AMT in the first query statement, and the USD AMT node is the node corresponding to the variable USD AMT in the first query statement.
[0114] The operator corresponding node, for example, the multiplication sign (*) node, the equal sign (=) node, and the like. The multiplication sign node is the node corresponding to the * operator in the first query statement, and the equal sign node is the node corresponding to the = operator in the first query statement.
[0115] In addition to the syntax elements and the syntax element corresponding nodes described above, the target syntax tree further includes other syntax elements and syntax element corresponding nodes, which are not specifically limited here.
[0116] The relationship between the nodes corresponds to the hierarchy and dependency relationship between the syntax elements, for example, the keyword SELECT includes the constant 7.2, the variable PRO.PO AMT, the keyword AS, and the variable USD AMT. Then, the relationship between the nodes is that the SELECT node is the upper node, and the 7.2 node, the PRO.PO AMT node, the AS node, and the USD AMT node are the lower nodes under the SELECT node.
[0117] In a specific embodiment, when the first query statement is a target SQL statement, the target syntax tree can be a target SQL syntax tree (SQL syntax tree), and the like. Continuing to take the target SQL statement in step S102 as an example, the target SQL syntax tree corresponding to the target SQL statement can be as shown in FIG. 4:
[0118] The target SQL syntax tree includes a Query_BLOCK node, and the Query_BLOCK node includes a SELECT node, a FROM node, and a WHERE node. The SELECT node includes an express1 node, and the express1 node includes a USD_AMT node, a 7.2 node, a multiplication node, a PRO.PO_AMT node, and an AS node. The FROM node includes a PO node. The WHERE node includes an express2 node, and the express2 node includes:
[0119] In order to make the relationship between nodes more intuitive, the above target SQL syntax tree is a simplified syntax tree, and in actual application, the nodes of the target SQL syntax tree will be more, and the relationship between the nodes will be more complex.
[0120] The traceability system obtains the target SQL syntax tree according to the target SQL statement in the following manner: inputting the target SQL statement into a special tool or library, and the target SQL syntax tree can be obtained. The special tool can include another tool for language recognition (ANTLR), ANTLR4, PLY (Python Lex-Yacc), Tree-sitter, ANTLRWorks, and the like. The special library can include the sqlparse library in Python, and the like.
[0121] The process of parsing the first query statement into a plurality of sub-statements based on the target syntax tree, determining that the first field is included and the field is modified to obtain the first target sub-statement, and determining the source of the first field as the second field according to the first target sub-statement can be as follows: taking the target syntax tree shown in FIG. 4 as the target SQL syntax tree as an example, as shown in FIG. 5, the process of parsing the first query statement into a plurality of sub-statements based on the target syntax tree, determining that the first field is included and the field is modified to obtain the first target sub-statement, and determining the source of the first field as the second field according to the first target sub-statement is as follows:
[0122] S1031: The traceability system interprets the WITH AS node of the target SQL syntax tree and the nodes below the WITH AS node to obtain a WITH AS clause, and determines whether the WITH AS clause is a first target sub-statement including a first field and the field is modified, in the case where the WITH AS clause is the first target sub-statement, determining the source of the first field as a second field according to the WITH AS clause.
[0123] The traceability system traverses the target SQL syntax tree to find a WITH AS node. When the target SQL syntax tree is traversed and no WITH AS node exists, step S1032 is directly entered. When the WITH AS node is found, the WITH AS clause is found. The WITH AS node and the nodes below the WITH AS node are analyzed. For example, it is found whether the subordinate nodes of the WITH AS node exist AS nodes. After the AS node is found, it is determined whether the right node of the AS node is the node corresponding to the first field. If the right node of the AS node is the USD AMT node, it is found whether the variable node exists in the left node of the AS node. If the variable node exists, it is determined that the WITH AS clause is the first target substatement. The variable corresponding to the variable node is taken as the second field, and step S1032 is entered. If the AS node does not exist or the left side of the AS node does not exist the variable node, step S1032 is entered.
[0124] Taking the target SQL statement in step S102 and the target SQL syntax tree shown in FIG. 4 as examples, since the target syntax tree does not include the WITH AS node, step S1032 can be directly entered.
[0125] S1032: The traceability system interprets the SELECT node and the nodes below the SELECT node of the target SQL syntax tree, obtains the SELECT clause, and determines whether the SELECT clause is the first target substatement including the first field and the field is modified to obtain the first target substatement. In the case where the SELECT clause is the first target substatement, the source of the first field is determined to be the second field according to the SELECT clause.
[0126] The traceability system traverses the target SQL syntax tree to find a SELECT node. When the target SQL syntax tree is traversed and no SELECT node exists, step S1033 is directly entered. When the SELECT node is found, the SELECT clause is found. The SELECT node and the nodes below the SELECT node are analyzed. For example, it is found whether the subordinate nodes of the SELECT node exist AS nodes. After the AS node is found, it is determined whether the right node of the AS node is the node corresponding to the first field (for example, the USD AMT node). If the right node of the AS node is the USD AMT node, it is found whether the variable node exists in the left node of the AS node. If the variable node exists, it is determined that the SELECT clause is the first target substatement. The variable corresponding to the variable node is taken as the second field, and step S1033 is entered. If the AS node does not exist or the left side of the AS node does not exist the variable node, step S1033 is entered.
[0127] Continuing with the example of the target SQL statement in step S102 and the target SQL syntax tree shown in FIG. 4, after the SELECT node is found, the AS node of the subordinate node of the SELECT node is found, and after the AS node is found, it is determined whether the right node of the AS node is the node corresponding to the first field (i.e., the USD AMT node). If the right node of the AS node is the USD AMT node, the node to the left of the AS node is found to include the 7.2 node, the multiplication node, the PRO.PO AMT node, and so on. The PRO.PO AMT node is a variable node, and thus, PRO.PO AMT can be extracted as the second field.
[0128] S1033: The provenance system interprets the FORM node of the target SQL syntax tree and the nodes below the FORM node to obtain a FORM clause, and determines whether the FORM clause is the first target sub-statement that includes the first field and the field is modified to obtain the first target sub-statement. In the case where the FORM clause is the first target sub-statement, the provenance system determines that the source of the first field is the second field according to the FORM clause.
[0129] The provenance system traverses the target SQL syntax tree to find the FORM node. When the FORM node is not found after traversing the target SQL syntax tree, step S1034 is directly entered. When the FORM node is found, the FORM clause is found. The FORM node and the nodes below the FORM node are analyzed, for example, it is determined whether the subordinate node of the FORM node exists. After the equal node is found, it is determined whether the right node of the equal node is a constant node. If the right node of the equal node is a constant node, it is determined whether a variable node exists in the node to the left of the equal node. If the variable node exists, it is determined that the FORM clause is the first target sub-statement, and the variable corresponding to the variable node is taken as the second field. Step S1034 is entered. If the equal node does not exist or the variable node does not exist to the left of the equal node, step S1034 is entered.
[0130] Continuing with the example of the target SQL statement in step S102 and the target SQL syntax tree shown in FIG. 4, although the target syntax tree includes the FROM node, only the PRO node is included below the FROM node, and the equal node is not included. Thus, step S1034 is directly entered.
[0131] S1034: The provenance system interprets the WHERE node of the target SQL syntax tree and the nodes below the WHERE node to obtain a WHERE clause, and determines whether the WHERE clause is the first target sub-statement that includes the first field and the field is modified to obtain the first target sub-statement. In the case where the WHERE clause is the first target sub-statement, the provenance system determines that the source of the first field is the second field according to the WHERE clause.
[0132] The trace system traverses the target SQL syntax tree to find the WHERE node. When the WHERE node is not found after traversing the target SQL syntax tree, step S1035 is directly entered. When the WHERE node is found, the SELECT clause is found. The WHERE node and the nodes below the WHERE node are analyzed. For example, it is determined whether the subordinate nodes of the WHERE node include an equal node. After the equal node is found, it is determined whether the right node of the equal node is a constant node. If the right node of the equal node is a constant node, it is determined whether a variable node exists in the left node of the equal node. If the variable node exists, it is determined that the FORM clause is the first target sub-clause. The variable corresponding to the variable node is taken as the second field, and step S1035 is entered. If the equal node does not exist or the left node of the equal node does not include the variable node, step S1035 is entered.
[0133] Taking the target SQL statement in step S102 and the target SQL syntax tree shown in FIG. 4 as examples, when the WHERE node is found, the WHERE node and the nodes below the WHERE node are analyzed to determine that the subordinate nodes of the WHERE node include an equal node. After the equal node is found, it is determined that the right node of the equal node is a constant node (GP node). It is determined that the left node of the equal node is a variable node PRO.BUSINESS_TYPE node. Therefore, the variable PRO.BUSINESS_TYPE corresponding to the PRO.BUSINESS_TYPE node is taken as the second field.
[0134] S1035: The trace system finds the second table in which the second field is located based on the FROM node in the target SQL syntax tree.
[0135] Since the second field exists, the second table in which the second field is located also exists. That is, only when the second field exists, the target SQL statement must include the FROM clause. Therefore, the target SQL syntax tree must also include the FROM node. Since the relationship between the field and the data table is obtained through the data bloodline analysis, after the second field is obtained, the second table in which the second field is located can be determined according to the second field and the relationship between the field and the table.
[0136] Continuing with the example target SQL statement in step S102 and the target SQL syntax tree shown in FIG. 4, the second fields include the field PRO.PO AMT and the field PRO.BUSINESS TYPE. According to the correspondence between the field PRO.PO AMT and the PRO table, it can be determined that the table in which the second field PRO.PO AMT is located is the PRO data table. According to the correspondence between the field PRO.BUSINESS TYPE and the PRO table, it can be determined that the table in which the second field PRO.BUSINESS TYPE is located is the PRO data table.
[0137] It can be understood that the execution steps of steps S1031 to S1034 described above can not be in sequence, for example, step S1033 can be executed first, and then step S1034 can be executed, or step S1034 can be executed first, and then step S1033 can be executed, or step S1033 and step S1034 can be executed simultaneously, which is not limited here.
[0138] S104: The traceability system finds a second query statement including the identification of the second table in the database.
[0139] The second query statement can be a single sentence or a compound sentence. When the second query statement is a compound sentence, the second query statement can include multiple clauses. Taking the second query statement as a SELECT statement as an example, the SELECT statement can include one or more clauses. For example, when the SELECT statement is a single sentence, the SELECT statement can only include a SELECT clause, and when the SELECT statement is a compound sentence, the SELECT statement can include one or more of a FROM clause, a WHERE clause, etc. in addition to the SELECT clause. Among them, the SELECT clause is a clause starting with the keyword SELECT, the FROM clause is a clause starting with the keyword FROM, and the WHERE clause is a clause starting with the keyword WHERE.
[0140] The method for the traceability system to find the second query statement containing the second field from the program text according to the second field can be:
[0141] The second query statement is determined according to the second table and the corresponding relationship between the data table and the query statement. Since the corresponding relationship between the data table and the query statement is obtained when the table-level relationship analysis is performed on the program text, the second query statement can be obtained by searching the corresponding relationship between the data table and the query statement according to the second query statement. Taking the example in step S102 as an example, since the relationship between the data table and the query statement is that the PRO table is the source table of the first query statement and the PTP table is the target table of the first query statement, and the PO table is the source table of the second query statement and the PRO table is the target table of the second query statement, when the second table is determined to be the PRO table, the statement in which the PRO table is the target table is found as the second query statement, and then the second query statement in which the field PRO.BUSINESS_TYPE and the field PRO.PO_AMT are located is determined to be the second query statement in the example shown in step S102.
[0142] S105: The traceability system parses the second query statement into a plurality of sub-statements, determines a target sub-statement including the second field and the field being modified in the plurality of sub-statements, and determines the source of the second field to be a third field according to the second target sub-statement.
[0143] The third field is used to perform a modification operation to obtain the second field. The modification operation can include one or more of a processing operation, a filtering operation, and a value obtaining operation. That is, the relationship between the third field and the second field mainly includes two types:
[0144] The first kind is to obtain the second field by performing a processing operation on the third field. The processing operation can include mathematical operation, logical operation, bit operation, comparison operation, assignment operation, matrix operation, vector operation, etc. The data operation can include addition, subtraction, multiplication and division operation. The logical operation can include AND, OR and NOT operation. Taking the second field as PO AMT and the second query statement as the example of the second query statement in step S104, it can be known from the second query statement that PO AMT is equal to PO.UNIT_PRICE*(PO.QUANTITY-PO.CANCEL_QTY), where the third field includes the field PO.UNIT_PRICE, the field PO.QUANTITY and the field PO.CANCEL_QTY, and the processing operation is to multiply PO.UNIT_PRICE by the difference obtained by subtracting PO.CANCEL_QTY from PO.QUANTITY. Taking the second field as BUSINESS_TYPE and the second query statement as the example of the second query statement in step S104, it can be known from the second query statement that BUSINESS_TYPE is equal to DECODE(PO.SOURCE_CODE,‘ERP1’,’GP’), where the third field is PO.SOURCE_CODE, and the processing operation is to input PO.SOURCE_CODE as a parameter into a function for processing.
[0145] The second kind is to obtain the second field by filtering according to a filtering operation including the third field. The filtering operation can refer to the introduction above.
[0146] The third kind is to obtain the second field by performing a value obtaining operation on the third field. That is, the value obtained from the third field is taken as the value of the second field, without processing or filtering, etc.
[0147] The process of parsing the second query statement into a plurality of sub-statements, determining the second target sub-statement including the second field and being modified to obtain the second field in the plurality of sub-statements can be:
[0148] The process of parsing the second query statement into a plurality of sub-statements, determining the second target sub-statement including the second field and being modified to obtain the second field in the plurality of sub-statements can be:
[0149] The traceable syntax tree includes nodes and the relationship between the nodes. Wherein, each node represents a syntax element in the second query statement, and the relationship between the nodes represents the hierarchical structure and the dependency relationship between the syntax elements. The syntax element can include key, constant, variable, operator, etc. Wherein,
[0150] The keywords can be keywords in the second query statement, for example, SELECT, FROM, AS, etc. in the second query statement in step S102.
[0151] The constants can be constants in the second query statement, for example, ERP1, GP, etc. in the second query statement in step S102.
[0152] The variables can be variables in the second query statement, for example, PO.UNIT_PRICE, PO.QUANTITY, PO.CANCEL_QTY, PO_AMT, etc. in the second query statement in step S102.
[0153] The operator symbols are symbols in the second query statement, for example, *, -, etc. in the second query statement in step S102.
[0154] The hierarchy and dependency among the syntax elements, for example, SELECT PO.UNIT_PRICE*(PO.QUANTITY-PO.CANCEL_QTY) AS PO_AMT, in this statement, the hierarchy among the syntax elements is: the keyword SELECT is below the variable PO.UNIT_PRICE, the operator symbol *, the variable PO.QUANTITY, the operator symbol -, the variable PO.CANCEL_QTY, the keyword AS, and the variable PO_AMT. In other words, the variable PO.UNIT_PRICE, the operator symbol *, the variable PO.QUANTITY, the operator symbol -, the variable PO.CANCEL_QTY, the keyword AS, and the variable PO_AMT depend on the keyword SELECT.
[0155] Correspondingly, the nodes corresponding to these syntax elements can include:
[0156] The nodes corresponding to the keywords, for example, the SELECT node, the FROM node, the WHERE node, etc. The SELECT node is the node corresponding to the keyword SELECT in the second query statement, the FROM node is the node corresponding to the keyword FROM in the second query statement, and the AS node is the node corresponding to the keyword AS in the second query statement.
[0157] The nodes corresponding to the constants, for example, the ERP1 node, the GP node, etc. The ERP1 node is the node corresponding to the constant ERP1 in the second query statement, and the GP node is the node corresponding to the constant GP in the second query statement.
[0158] The nodes corresponding to the variables, such as the node of PO.UNIT_PRICE, the node of PO.QUANTITY, the node of PO.CANCEL_QTY, the node of PO_AMT, and the like. The node of PO.UNIT_PRICE is the node corresponding to the variable PO.UNIT_PRICE in the second query statement, the node of PO.CANCEL_QTY is the node corresponding to the variable PO.CANCEL_QTY in the second query statement, and the node of PO_AMT is the node corresponding to the variable PO_AMT in the second query statement.
[0159] The nodes corresponding to the operators, such as the node of *, the node of -. The node of * is the node corresponding to the * operator in the second query statement, and the node of - is the node corresponding to the - operator in the second query statement.
[0160] In addition to the syntax elements and the nodes corresponding to the syntax elements described above, the provenance syntax tree further includes other syntax elements and the nodes corresponding to the syntax elements, which are not specifically limited here.
[0161] The relationships between the nodes correspond to the hierarchy and dependency relationships between the syntax elements, such as the keyword SELECT, the variable PO.UNIT_PRICE, the operator *, the variable PO.QUANTITY, the operator -, the variable PO.CANCEL_QTY, the keyword AS, and the variable PO_AMT. Then, the relationships between the nodes are that the node of SELECT is the upper node, and the nodes of PO.UNIT_PRICE, the node of *, the node of PO.QUANTITY, the node of -, the node of PO.CANCEL_QTY, the node of AS, and the node of PO_AMT are the lower nodes under the node of SELECT.
[0162] In a specific embodiment, when the second query statement is an SQL statement, the provenance syntax tree can be a provenance SQL syntax tree, and the like. Continuing with the second query statement in step S102 as an example, the provenance SQL syntax tree corresponding to the second query statement can be as shown in FIG. 6:
[0163] The trace SQL syntax tree comprises: a Query_BLOCK node, a SELECT node and a FROM node under the Query_BLOCK node. The SELECT node comprises an express3 node and an express4 node. The express3 node comprises a PO.UNIT_PRICE node, a multiplication node, a PO.QUANTITY node, a minus node, a PO.CANCEL_QTY node, an AS node and a PO_AMT node. The express4 node comprises a DECODE node, a PO.SOURCE_CODE node, an ERP1 node, a GP node, an AS node and a BUSINESS_TYPE node. The FROM node comprises a PO node. The Query_BLOCK node represents SELECT PO.UNIT_PRICE*(PO.QUANTITY-PO.CANCEL_QTY) AS PO_AMT, DECODE(PO.SOURCE_CODE, 'ERP1', 'GP') AS BUSINESS_TYPE FROM PO. The express3 node represents PO.UNIT_PRICE*(PO.QUANTITY-PO.CANCEL_QTY) AS PO_AMT. The express4 node represents DECODE(PO.SOURCE_CODE, 'ERP1', 'GP') AS BUSINESS_TYPE.
[0164] In order to make the relationship between nodes more intuitive, the trace SQL syntax tree above is a simplified syntax tree, and in actual application, the nodes of the trace SQL syntax tree will be more, and the relationship between the nodes will be more complex.
[0165] The trace system obtains the trace SQL syntax tree according to the trace SQL statement in the following manner: inputting the trace SQL statement into a special tool or library, and the trace SQL syntax tree can be obtained. The special tool can comprise another tool for language recognition (ANTLR), ANTLR4, PLY (Python Lex-Yacc), Tree-sitter and ANTLRWorks and the like. The special library can comprise a sqlparse library in Python and the like.
[0166] The process of parsing the second query statement into a plurality of sub-statements based on the provenance SQL syntax tree, determining that the second field is included in the second target sub-statement and that the field is modified, and determining that the source of the second field is the third field according to the second target sub-statement can be as follows: taking the provenance syntax tree shown in FIG. 6 as an example, as shown in FIG. 7, the process of parsing the second query statement into a plurality of sub-statements based on the provenance syntax tree, determining that the second field is included in the second target sub-statement and that the field is modified, and determining that the source of the second field is the third field according to the second target sub-statement is as follows:
[0167] S1051: The provenance system interprets the WITH AS node and the nodes under the WITH AS node of the provenance SQL syntax tree to obtain a WITH AS sub-clause, and determines whether the WITH AS sub-clause is the second target sub-statement including the second field and the field being modified. In the case where the WITH AS sub-clause is the second target sub-statement, the provenance system determines that the source of the second field is the third field according to the WITH AS sub-clause.
[0168] The provenance system traverses the provenance SQL syntax tree to find the WITH AS node. When no WITH AS node exists after traversing the provenance SQL syntax tree, the process directly proceeds to step S1052. When a WITH AS node is found, the WITH AS sub-clause is found. The WITH AS node and the nodes under the WITH AS node are analyzed, for example, whether an AS node exists under the WITH AS node is found. After the AS node is found, whether the right node of the AS node is the node corresponding to the second field is determined. If the right node of the AS node is the node corresponding to the second field, whether a variable node exists in the left node of the AS node is found. If the variable node exists, it is determined that the WITH AS sub-clause is the second target sub-statement, and the variable corresponding to the variable node is taken as the third field. The process proceeds to step S1052. If the AS node does not exist or the left node of the AS node does not have the variable node, the process proceeds to step S1052.
[0169] Taking the provenance SQL statement in the example in step S104 and the provenance SQL syntax tree shown in FIG. 6 as an example, since the provenance syntax tree does not include the WITH AS node, the process directly proceeds to step S1052.
[0170] S1052: The provenance system interprets the SELECT node and the nodes under the SELECT node of the provenance SQL syntax tree to obtain a SELECT sub-clause, and determines whether the SELECT sub-clause is the second target sub-statement including the second field and the field being modified. In the case where the SELECT sub-clause is the second target sub-statement, the provenance system determines that the source of the second field is the third field according to the SELECT sub-clause.
[0171] The trace system traverses the trace SQL syntax tree to find a SELECT node. When no SELECT node exists after traversing the trace SQL syntax tree, step S1053 is directly entered. When a SELECT node is found, a SELECT clause is found. The SELECT node and nodes below the SELECT node are analyzed. For example, it is determined whether an AS node exists in the nodes below the SELECT node. After the AS node is found, it is determined whether the node on the right side of the AS node is a node corresponding to the second field (for example, a PO AMT node). If the node on the right side of the AS node is the node corresponding to the second field, it is determined whether a variable node exists in the node on the left side of the AS node. If the variable node exists, the SELECT clause is determined to be the second target sub-clause, and a variable corresponding to the variable node is taken as the third field. Step S1053 is entered. If the AS node does not exist or the variable node does not exist on the left side of the AS node, step S1053 is entered.
[0172] For example, it is determined whether a function node (for example, a DECODE function node) exists in the nodes below the SELECT node. After the function node is found, it is determined whether a variable node exists in the nodes below the function node. If the variable node exists, the variable node corresponding to the variable is taken as the third field. Step S1053 is entered. If the function node does not exist or the variable node does not exist in the nodes below the function node, step S1053 is entered.
[0173] Continuing with the example of the trace SQL statement in step S104 and the trace SQL syntax tree shown in FIG. 6, after the SELECT node is found, the AS node of the subordinate node of the SELECT node is found, after the AS node is found, it is determined whether the right node of the AS node is the node corresponding to the second field (i.e., the PO AMT node), if the right node of the AS node is the PO AMT node, the node left of the AS node is found to include the PO.UNIT_PRICE node, the multiplication node, the PO.QUANTITY node, the - node, the PO.CANCEL_QTY node, and the like. Among them, the PO.UNIT_PRICE node, the PO.QUANTITY node, and the PO.CANCEL_QTY node are variable nodes, and therefore, the PO.UNIT_PRICE node, the PO.QUANTITY node, and the PO.CANCEL_QTY node can be extracted as the third field. Then, the function node in the subordinate node of the SELECT node, i.e., the DECODE function node, is found, after the DECODE function node is found, it is determined that there is a variable node, i.e., the PO.SOURCE_CODE node, in the subordinate node of the DECODE function node, and the variable PO.SOURCE_CODE corresponding to the PO.SOURCE_CODE node is taken as the third field.
[0174] S1053: The trace system interprets the FORM node of the trace SQL syntax tree and the nodes below the FORM node, obtains a FORM clause, and determines whether the FORM clause is a second target sub-clause including a second field and the field is modified to obtain a second target sub-clause, in the case where the FORM clause is the second target sub-clause, the source of the second field is determined to be a third field according to the FORM clause.
[0175] The trace system traverses the trace SQL syntax tree to find the FORM node, when there is no FORM node in the target SQL syntax tree after the traversal, step S1054 is directly entered; when the FORM node is found, the FORM clause is found. The FORM node and the nodes below the FORM node are analyzed, for example, it is found whether there is an equal node in the subordinate node of the FORM node, after the equal node is found, it is determined whether the right node of the equal node is a constant node, if the right node of the equal node is a constant node, it is found whether there is a variable node in the left node of the equal node, if there is a variable node, it is determined that the FORM clause is the second target sub-clause, and the variable corresponding to the variable node is taken as the third field, step S1054 is entered, if there is no equal node or there is no variable node in the left of the equal node, step S1054 is entered.
[0176] Continuing with the example of the provenance SQL statement in step S104 and the provenance SQL syntax tree shown in FIG. 6, although the target syntax tree includes a FROM node, only a PO node is included under the FROM node, and no equal node is included. Therefore, step S1054 is directly entered.
[0177] S1054: The provenance system finds a third table in which a third field is located based on the FROM node in the provenance SQL syntax tree.
[0178] Since the second table in which the third field is located exists in the case where the third field exists. That is, only in the case where the third field exists, the provenance SQL statement must include a FROM clause. Therefore, the provenance SQL syntax tree must also include a FROM node. Since the relationship between the field and the data table is obtained through the data lineage analysis, after the third field is obtained, the third table in which the third field is located can be determined according to the third field and the relationship between the field and the data table.
[0179] Continuing with the example of the provenance SQL statement in step S104 and the provenance SQL syntax tree shown in FIG. 6, the third field includes the field PO.UNIT_PRICE, the field PO.QUANTITY, the field PO.CANCEL_QTY, and the field PO.SOURCE_CODE. According to the correspondence between the field PO.UNIT_PRICE, the field PO.QUANTITY, the field PO.CANCEL_QTY, and the field PO.SOURCE_CODE and the PO table, it can be determined that the third table in which the field PO.UNIT_PRICE, the field PO.QUANTITY, the field PO.CANCEL_QTY, and the field PO.SOURCE_CODE PRO.PO_AMT are located is the PO data table.
[0180] It can be understood that the execution steps of steps S1051 to S1053 can not be in sequence, for example, step S1053 can be executed first, and then step S1054 can be executed, or step S1054 can be executed first, and then step S1053 can be executed, or steps S1053 and S1054 can be executed simultaneously, which is not specifically limited here.
[0181] Therefore, by the above steps, the relationship as shown in FIG. 8 can be found: the field USD AMT can be traced to the field PRO.BUSINESS TYPE, the field PRO.AMT, and the field RATE.USD_RATE, the field PRO.BUSINESS TYPE can be traced to the field PO.SOURCE_CODE, and the field PRO.AMT can be traced to the field PO.UNIT_PRICE, the field PO.QUANTITY, and the field PO.CANCEL_QTY.
[0182] It can be understood that the above example only takes two layers of tracing as an example for illustration, and in actual application, the tracing can be continued, for example, the field PO.CANCEL_QTY can be continuously traced until the tracing of a specified number of layers is completed or until the last layer is traced.
[0183] The field tracing system, the field tracing device, the computing device, the computing device cluster, the computer program product, and the computer readable storage medium will be described in detail below.
[0184] Referring to FIG. 9, FIG. 9 is a structural schematic diagram of a field tracing system provided by the present application. As shown in FIG. 9, the field tracing system of the present application comprises a client 210 and a field tracing device 220.
[0185] The client 210 is configured to send a tracing request, wherein the tracing request comprises an identifier of a first table and an identifier of a first field in the first table.
[0186] The field tracing device 220 is configured to acquire the tracing request, find a query statement comprising the identifier of the first table in a database, the database comprising executed query statements, parse the query statement into a plurality of sub-statements, determine a target sub-statement comprising the first field and the field being modified in the plurality of sub-statements, determine a source of the first field according to the target sub-statement, the source indicating that the field is obtained by a modification operation on a second field in a second table.
[0187] The field tracing device 220 and the client 210 can be implemented by software or by hardware. For example, the implementation of the field tracing device 220 will be introduced below. Similarly, the implementation of the client 210 can refer to the implementation of the field tracing device 220.
[0188] As an example of a software functional unit, the field provenance device 220 can include code running on a compute instance. The compute instance can be at least one of a physical host (computing device), a virtual machine, a container, etc. Further, the computing device can be one or more. For example, the field provenance device 220 can include code running on multiple hosts / virtual machines / containers. It is noted that the multiple hosts / virtual machines / containers running the application can be distributed in the same region, or in different regions. The multiple hosts / virtual machines / containers running the code can be distributed in the same AZ, or in different AZs. Each AZ includes one data center or multiple data centers in close geographical proximity. Typically, one region can include multiple AZs.
[0189] Similarly, the multiple hosts / virtual machines / containers running the code can be distributed in the same VPC, or in multiple VPCs. Typically, one VPC is set up within one region. Communication between two VPCs in the same region, or between VPCs in different regions, requires a communication gateway in each VPC to achieve interconnection between VPCs.
[0190] As an example of a hardware functional unit, the field provenance device 220 can include at least one computing device, such as a server, etc. Alternatively, the field provenance device 220 can also be a device implemented by a CPU, ASIC, PLD, CPLD, FPGA, GAL, DPU, NPU, SoC, offload card, acceleration card, etc. The PLD can be implemented by a CPLD, FPGA, GAL, or any combination thereof.
[0191] The multiple computing devices included in the field provenance device 220 can be distributed in the same region, or in different regions. The multiple computing devices included in the field provenance device 220 can be distributed in the same AZ, or in different AZs. Similarly, the multiple computing devices included in the field provenance device 220 can be distributed in the same VPC, or in multiple VPCs. The multiple computing devices can be any combination of servers, ASICs, PLDs, CPLDs, FPGAs, GALs, DPUs, NPUs, SoCs, offload cards, acceleration cards, etc.
[0192] Further, the present application also provides a field provenance device 220, as shown in FIG. 9, which includes:
[0193] The obtaining module 221 is configured to obtain a provenance request. The provenance request includes an identifier of a first table and an identifier of a first field in the first table.
[0194] The searching module 222 is configured to search, in a database, a query statement including the identifier of the first table, the database including executed query statements.
[0195] The parsing module 223 is configured to parse the query statement into a plurality of sub-statements.
[0196] The determining module 224 is configured to determine, in the plurality of sub-statements, a target sub-statement including the first field and the field being modified.
[0197] The tracing module 225 is configured to determine, according to the target sub-statement, a source of the first field, the source indicating that the field is obtained through a modification operation from a second field in a second table.
[0198] The obtaining module, the searching module, the parsing module, the determining module, and the tracing module can be implemented by software or by hardware. For example, the implementation of the parsing module is described below. The implementation of the obtaining module, the searching module, the determining module, and the tracing module can be similar to the implementation of the parsing module.
[0199] As an example of a software functional unit, the parsing module can include code running on a computing instance. The computing instance can include at least one of a physical host (computing device), a virtual machine, and a container. Further, the computing instance can be one or more. For example, the parsing module can include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers running the code can be distributed in the same region or in different regions. Further, the multiple hosts / virtual machines / containers running the code can be distributed in the same availability zone (AZ) or in different AZs, each AZ including one data center or multiple data centers in close geographical proximity. Generally, one region can include multiple AZs.
[0200] Similarly, the multiple hosts / virtual machines / containers running the code can be distributed in the same virtual private cloud (VPC) or in multiple VPCs. Generally, one VPC is set in one region, and a communication gateway needs to be set in each VPC for cross-region communication between two VPCs in the same region or between VPCs in different regions, and the interconnection between VPCs is realized through the communication gateway.
[0201] As an example of a hardware functional unit, the parsing module can include at least one computing device, such as a server or the like. Alternatively, the parsing module can also be a device implemented using a central processing unit (CPU), or implemented using an application-specific integrated circuit (ASIC), or implemented using a programmable logic device (PLD), and the like. Among them, the PLD can be implemented by a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), a data processing unit (DPU), a neural network processing unit (NPU), a system on chip (SoC), an offload card, an acceleration card, or any combination thereof.
[0202] The multiple computing devices included in the parsing module can be distributed in the same region, or can be distributed in different regions. The multiple computing devices included in the parsing module can be distributed in the same AZ, or can be distributed in different AZs. Similarly, the multiple computing devices included in the parsing module can be distributed in the same VPC, or can be distributed in multiple VPCs. Among them, the multiple computing devices can be any combination of servers, ASICs, PLDs, CPLDs, FPGAs, GALs, DPUs, NPUs, SoCs, offload cards, acceleration cards, and the like.
[0203] It should be noted that in other embodiments, the parsing module can be used to perform any step in field provenance, the obtaining module, the searching module, the determining module, and the tracing module can be used to perform any step in the field provenance method, and the steps implemented by the parsing module, the obtaining module, the searching module, the determining module, and the tracing module can be specified as needed. By implementing different steps in the field provenance method through the parsing module, the obtaining module, the searching module, the determining module, and the tracing module, the entire function of the field provenance device 220 can be implemented.
[0204] The application further provides a chip system, which comprises a processor and a power supply circuit, the power supply circuit is used for performing power supply for the processor, and the processor is used for performing operation steps corresponding to the field traceability method. For brevity, details are not repeated here. The processor can be implemented by a GPU, or can be implemented by a DPU, an NPU, an XPU, a SoC, an offload card, an acceleration card or the like computing device.
[0205] The application further provides a computing device 300. As shown in FIG. 10, the computing device 300 comprises a bus 302, a processor 304, a memory 306 and a communication interface 308. The processor 304, the memory 306 and the communication interface 308 communicate through the bus 302. The computing device 300 can be a server or a terminal device. It should be understood that the number of processors and memories in the computing device 300 is not limited by the application.
[0206] The bus 302 can be a peripheral component interconnect Express (PCIe) bus or an extended industry standard architecture (EISA) bus, a unified bus (Ubus or UB), a compute express link (CXL), a cache coherent interconnect for accelerators (CCIX) or the like. The unified bus is also referred to as a smart bus. The bus can be divided into an address bus, a data bus, a control bus and the like. For convenience of representation, only one line is used in FIG. 11, but it does not mean that there is only one bus or only one type of bus. The bus 302 can comprise a path for transmitting information between various components (for example, the memory 306, the processor 304 and the communication interface 308) of the computing device 300. The unified bus can also be referred to as a smart bus.
[0207] The processor 304 can comprise any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a micro processor (MP), or a digital signal processor (DSP), an ASIC, an FPGA, a CPLD, an NPU, a SoC, an offload card, an acceleration card or the like computing device.
[0208] The memory 306 can include volatile memory, such as random access memory (RAM) including a cache area for the temporary storage of data. The processor 304 can also include one or more processors 304A, 304B, 304C, etc. from a processing device family, a multi-core processing device family, or multiple processing device families. A memory 306 can also include non-volatile memory, such as read-only memory (ROM), electrically programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), flash memory, or nonvolatile random access memory (NVRAM) (e.g., ferroelectric, ovonic, phase change, or the like). The memory 306 can also be implemented by storage class memory (SCM), phase change memory (PCM), or other types of storage media.
[0209] It is worth noting that the same type of storage medium can be configured in the same computing device to implement the memory 306 function, or two or more types of storage media can be configured to implement the memory 306 function, which is not limited in the present application.
[0210] The memory 306 stores executable program code, and the processor 304 executes the executable program code to respectively implement the functions of the aforementioned parsing module, obtaining module, searching module, determining module, and tracing module, thereby implementing the field tracing method. That is, the memory 306 stores instructions for executing the field tracing method.
[0211] Alternatively, the memory 306 stores executable program code, and the processor 304 executes the executable program code to respectively implement the functions of the aforementioned field tracing apparatus 220 and client 210, thereby implementing the field tracing method. That is, the memory 306 stores instructions for executing the field tracing method.
[0212] The communication interface 308 uses a transceiver module such as, but not limited to, a network interface card, a transceiver, and the like to implement communication between the computing device 300 and other devices or communication networks.
[0213] As a possible implementation, the computing device 300 can also include a chip system including a processor and a power supply circuit for performing power supply to the processor, and the processor is used to perform the operation steps corresponding to the field tracing method. For the sake of brevity, it will not be repeated here. The processor can be implemented by a GPU, and can also be implemented by a DPU, NPU, XPU, SoC, offload card, acceleration card, and the like computing device or AI chip.
[0214] As a possible implementation, a plurality of types of processors 304 can be included in the computing device 300, i.e., the computing device 300 is a heterogeneous device, for example, the computing device 300 includes a CPU and a GPU, and the operation steps corresponding to the field tracing method can be executed by at least one of the processors 304. For the sake of brevity, details are not repeated here.
[0215] Embodiments of the present application also provide a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, for example, a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device such as a desktop computer, a notebook computer, or a smart phone.
[0216] As shown in FIG. 11, the computing device cluster includes at least one computing device 300. The same instructions for executing the field tracing method can be stored in the memory 306 of one or more computing devices 300 in the computing device cluster.
[0217] In some possible implementations, partial instructions for executing the field tracing method can also be respectively stored in the memory 306 of one or more computing devices 300 in the computing device cluster. In other words, the combination of one or more computing devices 300 can collectively execute the instructions for executing the field tracing method.
[0218] It should be noted that the memory 306 in different computing devices 300 in the computing device cluster can store different instructions, respectively used to execute part of the functions of the field tracing apparatus 220. That is, the instructions stored in the memory 306 in different computing devices 300 can implement the functions of one or more of the parsing module, the obtaining module, the searching module, the determining module, and the tracing module.
[0219] In some possible implementations, one or more computing devices in the computing device cluster can be connected through a network. The network can be a wide area network or a local area network, etc. FIG. 12 shows a possible implementation. As shown in FIG. 12, two computing devices 300A and 300B are connected through a network. Specifically, the communication interface in each computing device is connected to the network. In this type of possible implementation, the memory 306 in the computing device 300A stores instructions for executing the functions of the parsing module. Meanwhile, the memory 306 in the computing device 300B stores instructions for executing the functions of the obtaining module, the searching module, the determining module, and the tracing module.
[0220] The connection manner between the computing device clusters shown in FIG. 12 can be that, considering that the field traceability method provided in the present application needs to store a large amount of data and perform a large amount of calculation, the functions implemented by the acquisition module, the search module, the determination module, and the traceability module are transferred to the computing device 300B for execution.
[0221] It should be understood that the functions of the computing device 300A shown in FIG. 12 can also be completed by multiple computing devices 300. Similarly, the functions of the computing device 300B can also be completed by multiple computing devices 300.
[0222] The present application also provides another computing device cluster. The connection relationship between the computing devices in the computing device cluster can be similar to the connection manners of the computing device clusters described with reference to FIG. 11 and FIG. 12. The difference is that the memory 306 in one or more computing devices 300 in the computing device cluster can store the same instructions for executing the field traceability method.
[0223] In some possible implementation manners, the memory 306 in one or more computing devices 300 in the computing device cluster can also respectively store partial instructions for executing the field traceability method. In other words, the combination of one or more computing devices 300 can collectively execute the instructions for executing the field traceability method.
[0224] It should be noted that the memory 306 in different computing devices 300 in the computing device cluster can store different instructions for executing partial functions of the field traceability system. That is, the instructions stored in the memory 306 in different computing devices 300 can implement the functions of one or more devices in the field traceability apparatus 220 and the client 210.
[0225] The present application also provides a computer program product containing instructions. The computer program product can be a software or program product containing instructions, which can be run on a computing device or stored in any available medium. When the computer program product is run on at least one computing device, the at least one computing device is caused to execute the field traceability method, or the field traceability method.
[0226] The present application also provides a computer readable storage medium. The computer readable storage medium can be any available medium that can be stored by a computing device or a data storage device such as a data center containing one or more available media. The available medium can be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk), etc. The computer readable storage medium contains instructions, which instruct the computing device to execute the field traceability method, or instruct the computing device to execute the field traceability method.
[0227] It should be noted that the above examples are only used to illustrate the technical solutions of the present application, and are not intended to limit the same. Although the present application has been described in detail with reference to the foregoing examples, those skilled in the art should understand that the technical solutions recorded in the foregoing examples can be modified, or some of the technical features can be replaced by equivalent features. Such modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the protection scope of the technical solutions of the embodiments of the present application.
Claims
A method of field provenance, characterized in that, The method comprises: obtaining a traceability request, wherein the traceability request comprises an identifier of a first table and an identifier of a first field in the first table; finding a query statement comprising the identifier of the first table in a database, wherein the database comprises executed query statements; parsing the query statement into a plurality of sub-statements; determining, among the plurality of sub-statements, a target sub-statement comprising the first field and being modified; determining a source of the first field according to the target sub-statement, wherein the source indicates that the first field is obtained by a second field in a second table through a modification operation. The method of claim 1, wherein The determining, among the plurality of sub-statements, of the target sub-statement comprising the first field and being modified comprises: finding a sub-statement comprising the field; finding, among the sub-statement comprising the field, a sub-statement comprising a keyword indicating the modification operation as the target sub-statement. The method of claim 1, wherein The determining of the source of the first field according to the target sub-statement comprises: matching the target sub-statement with a preset relationship rule, wherein the relationship rule is used to indicate the modification operation on the field; if the first field of the target sub-statement and the second field in the second table match the relationship rule, determining the second field in the second table as the source of the first field. The method of claim 1, wherein The modification operation comprises one or a combination of a plurality of processing operations, filtering operations and value operations, wherein the processing operation comprises one or a combination of a plurality of mathematical operations, logical operations, bit operations, comparison operations, assignment operations, matrix operations and vector operations, the data operation comprises one or a combination of a plurality of addition, subtraction, multiplication and division operations, and the logical operation comprises one or a combination of a plurality of AND, OR and NOT operations; the filtering operation is used to filter based on the second field; the value operation is used to take the value of the second field as the value of the first field. The method according to any one of claims 1 to 4, characterized in that The method further comprises: continuing to trace the second field, and stopping and outputting the source of the first field when no target sub-statement comprising the second field and being modified is found; if the target sub-statement comprising the second field and being modified is found, recording the source of the second field. A field provenance device, characterized in that The device comprises: an obtaining module configured to obtain a traceability request, wherein the traceability request comprises an identifier of a first table and an identifier of a first field in the first table; a finding module configured to find a query statement comprising the identifier of the first table in a database, wherein the database comprises executed query statements; a parsing module configured to parse the query statement into a plurality of sub-statements; a determining module configured to determine, among the plurality of sub-statements, a target sub-statement comprising the first field and being modified; a tracing module configured to determine a source of the first field according to the target sub-statement, wherein the source indicates that the first field is obtained by a second field in a second table through a modification operation. The device according to claim 6, wherein The determining module is further configured to search for a sub-statement including the field, and search for a sub-statement including a keyword representing a modification operation as the target sub-statement in the sub-statement including the field. The apparatus according to claim 6, wherein The tracing module is further configured to match the target sub-statement with a preset relationship rule, the relationship rule being used to represent a modification operation on a field, and determine a second field in the second table as a source of the first field when the first field and the second field in the second table in the target sub-statement match the relationship rule. The apparatus of claim 6, wherein The modification operation includes one or a combination of a processing operation, a filtering operation, and a value obtaining operation. The processing operation includes one or a combination of a mathematical operation, a logic operation, a bit operation, a comparison operation, an assignment operation, a matrix operation, and a vector operation. The filtering operation is used to filter based on the second field. The value obtaining operation is used to take a value of the second field as a value of the first field. The apparatus according to any one of claims 6 to 9, wherein The tracing field is further configured to continue tracing the second field, stop and output a source of the first field when a sub-statement including the second field is not found and the second field is a target sub-statement modified, and record a source of the second field when the second field is found and the second field is a target sub-statement modified. A computing device, comprising a processor and a memory; The processor is configured to execute instructions stored in the memory to cause the computing device to perform the operation steps of the method according to any one of claims 1 to 5. A cluster of computing devices, characterized in that, A plurality of computing devices, each computing device comprising a processor and a memory; The processors of the plurality of computing devices are configured to execute instructions stored in the memories of the plurality of computing devices to cause the cluster of computing devices to perform the operation steps of the method according to any one of claims 1 to 5. A computer program product comprising instructions, characterized in that The instructions, when executed by the cluster of computing devices, cause the cluster of computing devices to perform the operation steps of the method according to any one of claims 1 to 5. A computer-readable storage medium, characterized by The computer program instructions, when executed by the cluster of computing devices, cause the cluster of computing devices to perform the operation steps of the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Data query method and device, electronic equipment and storage medium
CN111708805A
SQL (Structured Query Language) statement processing method, database system, equipment and storage medium
CN117194473A
Data blood relationship construction method and device, electronic equipment and storage medium
CN117472940A
SQL (Structured Query Language)-based code conversion method and device, equipment and medium
CN117632999A
Translating functional graph traversal language to extended structured query language
US20210034615A1