A data traceability and logical root cause positioning method and device

By parsing SQL to generate an abstract syntax tree, assigning procedural traceability identifiers to subexpressions, and rewriting the generated value query and traceability query, the problem of difficulty in locating operator-level logical errors in multi-step data processing links in existing technologies is solved, and automated abnormal output location is achieved.

CN123178402APending Publication Date: 2026-11-27AGRICULTURAL BANK OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611559641.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-09
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

Existing technologies struggle to accurately locate operator-level logical errors in multi-step data processing chains, making it difficult to pinpoint abnormal data and requiring manual, step-by-step investigation.

Method used

By parsing SQL queries to generate abstract syntax trees, assigning procedural sourcing identifiers to subexpressions, rewriting generated value queries and sourcing queries, executing queries to obtain decision logs and sourcing information, propagating sourcing information step by step, and automatically locating abnormal logic in conjunction with a visual interface.

Benefits of technology

It enables automatic location of abnormal outputs in multi-step data processing links, avoiding manual step-by-step investigation and improving the accuracy and efficiency of location.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123178402A_ABST
    Figure CN123178402A_ABST
Patent Text Reader

Abstract

The application provides a data traceability and logical root cause positioning method and device, abstract syntax trees are generated by analyzing SQL, process traceability identifiers are allocated for sub-expressions, value query and traceability query are rewritten; business results and decision logs are obtained by executing value query, traceability information of each output cell is generated according to the decision logs by executing traceability query, which contains process traceability identifiers corresponding to sub-expressions participating in the calculation of the output cell; when multi-step query refers to previous output data, pre-stored traceability information is read and integrated to obtain traceability information after cross-step propagation; finally, according to the process traceability identifiers in the final output data traceability information, associated input data, judgment conditions and SQL sub-expressions are determined. Thus, bloodline tracing is refined to output cells and sub-expressions, and is connected through multi-step links, automatic positioning of query logic corresponding to abnormal output is realized, and manual step-by-step troubleshooting is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of database data processing and data governance technology, and in particular to a method and apparatus for data tracing and logical root cause localization. Background Technology

[0002] Corporate banking involves businesses such as deposits, loans, trade finance, and international settlements, generating a large amount of data in the process, including account balances, transaction records, and credit lines. This data typically requires multiple processing steps, including cleaning, filtering, correlation, and aggregation, to gradually transform raw data tables into intermediate data tables and final business reports, thus forming a continuous data processing chain.

[0003] For the aforementioned data processing chain, existing data lineage analysis methods based on Structured Query Language (SQL) typically acquire the SQL statement to be analyzed, perform lexical and syntactic analysis to generate a corresponding abstract syntax tree (AST), and identify table names, field names, and reference relationships between fields by traversing the AST, thereby determining the data transmission relationships between different fields. After obtaining the field reference relationships, a field-level data lineage relationship is constructed based on the upstream and downstream dependencies between fields, forming a lineage graph with fields as nodes and the data flow between fields as connections. By visualizing the lineage graph, the upstream source fields and downstream referencing fields corresponding to the target field can be presented, enabling the tracking of data transmission relationships between different tables and fields.

[0004] Since the above method mainly establishes data lineage based on field references in SQL statements, the obtained lineage primarily reflects the data source and transmission relationships between fields. During multi-step data processing, when anomalies occur in the final output data, it is difficult to further pinpoint the specific query logic that caused the anomaly based on the abnormal data. Manual investigation of the data processing process is required, combining relevant SQL statements step by step. Summary of the Invention

[0005] In view of this, embodiments of the present invention provide a data tracing and logical root cause localization method and apparatus to solve the technical problem that it is difficult to accurately locate operator-level logical errors in multi-step data processing links in the prior art.

[0006] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:

[0007] The first aspect of this invention discloses a method for data tracing and logical root cause localization, the method comprising:

[0008] Obtain the SQL query to be executed in the data processing chain and the input data corresponding to the SQL query;

[0009] The SQL query is parsed to generate an abstract syntax tree, and procedural sourcing identifiers are assigned to the sub-expressions in the SQL query based on the abstract syntax tree;

[0010] The SQL query is rewritten and transformed based on the abstract syntax tree to generate value queries and source queries;

[0011] Execute the value query to obtain business results and decision logs;

[0012] Execute the source tracing query and generate source tracing information corresponding to each output cell in the business result based on the decision log, wherein the source tracing information includes process source tracing identifiers corresponding to the sub-expressions that participated in the calculation of the output cells;

[0013] In a multi-step query in the data processing chain, if the current SQL query references the output data of the previous query, the source information stored in the output data is read and integrated with the source information generated by the current query to obtain the source information after the step-by-step propagation.

[0014] Based on the process traceability identifier contained in the traceability information corresponding to the final output data, determine the input data, judgment conditions, and SQL sub-expressions associated with the final output data.

[0015] Optionally, the step of parsing the SQL query to generate an abstract syntax tree and assigning procedural sourcing identifiers to the sub-expressions in the SQL query based on the abstract syntax tree includes:

[0016] Lexical and syntactic analysis are performed on the SQL query to generate an abstract syntax tree containing multiple syntax nodes;

[0017] Traverse the abstract syntax tree, assign a unique procedural traceability identifier to each syntax node, and establish a mapping relationship between the procedural traceability identifier and the subexpression corresponding to the syntax node.

[0018] Optionally, the step of rewriting and transforming the SQL query based on the abstract syntax tree to generate value queries and source queries includes:

[0019] The nodes of the abstract syntax tree are traversed recursively, and value query fragments and source query fragments are generated for each node.

[0020] The value query fragments are combined to form the value query, and the source query fragments are combined to form the source query; wherein, the value query retains the calculation logic of the original SQL query and adds a decision log output field, and the source query performs operations in the identifier space to propagate the source identifier, cause identifier and process source identifier.

[0021] Optionally, the execution of the value query to obtain business results and decision logs includes:

[0022] The value query is executed to calculate the business result data, and the evaluation results of each judgment condition in the SQL query and the short-circuit evaluation path are recorded to generate a decision log;

[0023] The business outcome data is associated with the decision log.

[0024] Optionally, the step of executing the source tracing query and generating source tracing information corresponding to each output cell in the business result based on the decision log includes:

[0025] Based on the decision log, the source tracing query is executed to identify the input data rows corresponding to each output cell in the business result and the judgment conditions for participating in the evaluation.

[0026] Obtain the source identifier of each cell in the input data row and form a source identifier set;

[0027] Obtain the identifiers of the input data cells referenced by the judgment conditions involved in the evaluation, and form a reason identifier set;

[0028] Obtain the process traceability identifiers corresponding to the sub-expressions involved in generating the output cell, and form a process identifier set;

[0029] The source identifier set, the cause identifier set, and the process identifier set are used as the tracing information corresponding to the output cell.

[0030] Optionally, in the multi-step query of the data processing chain, if the current SQL query references the output data of a previous query, the pre-stored source information in the output data is read and integrated with the source information generated by the current query to obtain the source information after propagation across steps, including:

[0031] In the multi-step query of the data processing chain, the business results of the preceding query are stored as the business column of the intermediate data table, and the traceability information generated by the preceding query is stored as the traceability column of the intermediate data table;

[0032] When it is detected that the current SQL query references the intermediate data table, the data in the source column is read as the initial source information referenced by the corresponding column in the current query;

[0033] During the current source tracing query execution, the initial source tracing information is merged with the process source tracing identifier and cause identifier generated in the current step to obtain the source tracing information after propagation across steps.

[0034] Optionally, determining the input data, judgment conditions, and SQL sub-expressions associated with the final output data based on the process traceability identifier contained in the traceability information corresponding to the final output data includes:

[0035] Receive a selection instruction for the target output cell in the final output data;

[0036] Extract the source identifier set, cause identifier set, and process identifier set of the target output cell from the traceability information corresponding to the final output data;

[0037] The corresponding input data cell is located according to the source identifier set; the corresponding judgment condition reference data cell is located according to the reason identifier set; and the corresponding SQL subexpression is located according to the process identifier set and the mapping relationship.

[0038] The input data cell, the judgment condition reference data cell, and the SQL subexpression are displayed in the visual interface.

[0039] Optionally, the method further includes:

[0040] When the input data is a raw data table, a globally unique row identifier is generated for each row in the raw data table, and a field identifier is generated for each column;

[0041] A cell-level source fingerprint is generated based on the row identifier and the field identifier, and the cell-level source fingerprint is used as the source identifier for each cell in the input data.

[0042] Optionally, the method further includes:

[0043] Based on the source information corresponding to the final output data, a preset error pattern library is matched, wherein the error pattern library includes logical or misuse patterns, missing association conditions patterns, and unfiltered patterns before aggregation.

[0044] If a match is found in the pre-defined error pattern library, a repair solution containing suggested corrections and modified SQL fragments is generated.

[0045] A second aspect of this invention discloses a data tracing and logical root cause localization device, the device comprising:

[0046] The query acquisition unit is used to acquire the SQL query to be executed in the data processing chain and the input data corresponding to the SQL query;

[0047] The parsing unit is used to parse the SQL query to generate an abstract syntax tree, and assign procedural sourcing identifiers to the sub-expressions in the SQL query according to the abstract syntax tree;

[0048] The rewrite and transformation unit is used to rewrite and transform the SQL query according to the abstract syntax tree to generate value query and source query;

[0049] The first execution unit is used to execute the value query to obtain business results and decision logs;

[0050] The second execution unit is used to execute the tracing query and generate tracing information corresponding to each output cell in the business result according to the decision log, wherein the tracing information includes process tracing identifiers corresponding to the sub-expressions that participate in the calculation of the output cells;

[0051] The fusion unit is used in multi-step queries in the data processing chain to read the pre-stored traceability information in the output data and integrate it with the traceability information generated by the current query in the current SQL query if the current SQL query references the output data of the previous query, so as to obtain the traceability information after the cross-step propagation.

[0052] The determining unit is used to determine the input data, judgment conditions, and SQL sub-expressions associated with the final output data based on the process traceability identifier contained in the traceability information corresponding to the final output data.

[0053] Based on the above embodiments of the present invention, a data tracing and logical root cause localization method and apparatus is provided. This method parses SQL to generate an abstract syntax tree, assigns process tracing identifiers to sub-expressions, and rewrites the generated value query and tracing query. The value query is executed to obtain business results and decision logs. The tracing query is executed to generate tracing information for each output cell based on the decision logs, which includes process tracing identifiers corresponding to the sub-expressions involved in calculating that output cell. When a multi-step query references preceding output data, its pre-stored tracing information is read and integrated to obtain the tracing information after cross-step propagation. Finally, based on the process tracing identifiers in the final output data tracing information, the associated input data, judgment conditions, and SQL sub-expressions are determined. Thus, lineage tracing is refined to the output cell and sub-expression, and multi-step links are connected, enabling automatic localization of the query logic corresponding to abnormal outputs, avoiding manual step-by-step investigation. Attached Figure Description

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

[0055] Figure 1 This invention provides an overall architecture diagram of a data tracing and logical root cause localization system.

[0056] Figure 2 A flowchart of a data tracing and logical root cause localization method provided in an embodiment of the present invention;

[0057] Figure 3 This is a schematic diagram illustrating the principle of the recursive rewriting function provided in an embodiment of the present invention;

[0058] Figure 4 This is a comparative diagram of operator-level parsing and field-level parsing provided in an embodiment of the present invention;

[0059] Figure 5 A schematic diagram of the visual interface provided in an embodiment of the present invention;

[0060] Figure 6 This is a structural block diagram of a data tracing and logical root cause localization device provided in an embodiment of the present invention. Detailed Implementation

[0061] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0062] In this application, the terms "comprising," "including," or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0063] As can be seen from the background technology, existing technologies mainly establish data lineage based on field reference relationships in SQL statements. The obtained lineage mainly reflects the data source and transmission relationship between fields, but cannot provide information such as what kind of calculation process the data has undergone, why it is included or excluded, etc., and it is even more difficult to locate operator-level logical errors in multi-step data processing.

[0064] Therefore, embodiments of the present invention provide a data tracing and logical root cause localization method and apparatus. This method involves parsing SQL to generate an abstract syntax tree, assigning process tracing identifiers to sub-expressions, and rewriting the generated value query and tracing query. The value query is executed to obtain business results and decision logs. The tracing query is executed to generate tracing information for each output cell based on the decision logs, which includes process tracing identifiers corresponding to the sub-expressions involved in calculating that output cell. When a multi-step query references preceding output data, its pre-stored tracing information is read and integrated to obtain the tracing information after cross-step propagation. Finally, based on the process tracing identifiers in the final output data tracing information, the associated input data, judgment conditions, and SQL sub-expressions are determined. Thus, lineage tracing is refined to the output cell and sub-expression level, connecting multiple steps and enabling automatic localization of the query logic corresponding to abnormal outputs, avoiding manual step-by-step investigation.

[0065] See Figure 1 This diagram illustrates the overall architecture of a data tracing and logical root cause localization system provided by an embodiment of the present invention. The system includes a data access and standardization module 101, an annotated data storage module 102, an SQL parsing and AST annotation module, a three-source integrated query rewriting engine 103, a database execution engine, a query result table, a tracing mapping table, and a logical root cause localization and visualization module 104.

[0066] The data access and standardization module 101 collects data from heterogeneous data sources such as the core accounting system, credit management system, corporate online banking system, and regulatory reporting platform. It performs standardized operations such as field mapping, type conversion, deduplication, and null value handling. It also generates a globally unique row identifier for each row and a field identifier for each column in the original data table, thus generating a cell-level traceability fingerprint. The labeled data storage module 102 stores business columns and their corresponding traceability columns. Business columns store regular numerical or string results, while traceability columns store the source identifier, cause identifier, and process traceability identifier set corresponding to each cell. The SQL parsing and AST labeling module and the three-source integrated query rewriting engine 103 receive SQL queries to be executed, parse them to generate an abstract syntax tree, assign process traceability identifiers to each sub-expression, and generate value queries and traceability queries through recursive rewriting. The database execution engine executes value queries and traceability queries, outputting a query result table and a traceability mapping table. The logical root cause localization and visualization module 104 is used to receive the user's selection instruction for the target cell in the output result, locate the input data cell, the judgment condition reference data cell and the SQL subexpression based on the source mapping table, and highlight and analyze the root cause in the visualization interface.

[0067] Figure 1 The arrows indicate the data flow direction: solid arrows represent the main data flow, and dashed arrows represent the control flow or log flow. The specific functions of each module will be explained below. Figure 2 The method and process shown are explained in detail.

[0068] See Figure 2 This document illustrates a flowchart of a data tracing and logical root cause localization method provided by an embodiment of the present invention. This method is applicable to scenarios involving multi-step SQL processing, such as corporate banking and e-commerce data processing. Its core lies in rewriting an SQL query using recursive rewriting technology, transforming it into a value query responsible for calculating numerical values ​​and a tracing query responsible for propagating identifiers. By persistently storing tracing information in an intermediate table, cross-step logical root cause tracing is achieved. The method includes:

[0069] Step S201: Obtain the SQL query to be executed in the data processing chain and the corresponding input data of the SQL query.

[0070] It should be noted that the data processing chain contains one or more SQL queries in one step. The output of each step's query serves as the input for the next step, forming a continuous data processing pipeline. The SQL query to be executed is the query statement of the current step in the data processing chain, which can be a data cleaning query, feature transformation query, aggregation and summarization query, or correlation query, etc.

[0071] In some specific embodiments, when the input data is an original data table, a globally unique row identifier is generated for each row in the original data table, and a field identifier is generated for each column; a cell-level traceability fingerprint is generated based on the row identifier and the field identifier, and the cell-level traceability fingerprint is used as the source identifier of each cell in the input data.

[0072] Specifically, input data includes account tables, transaction logs, and interest rate tables from bank core accounting systems, credit management systems, corporate online banking systems, and regulatory reporting platforms, as well as intermediate data tables generated in previous steps. For the original data tables, the system performs data standardization operations during the access phase, including field mapping, type conversion, deduplication, and null value handling. After standardization, a globally unique row identifier (ROW_ID) is generated for each row, for example, using an auto-incrementing sequence or UUID; a field identifier (COL_ID) is generated for each column, for example, based on field name hashing or predefined mapping. Furthermore, a cell-level traceability fingerprint is generated for each cell, composed of the ROW_ID and COL_ID (e.g., "R000001_COL_BALANCE"). This fingerprint serves as the source identifier for that cell and remains unique and unchanged throughout the entire data processing chain.

[0073] For intermediate data tables, in addition to storing business result columns (i.e., regular numerical or string values), the system automatically creates corresponding traceability columns, named with the original column name followed by the suffix "_prov" (e.g., the business column "adj_balance" corresponds to the traceability column "adj_balance_prov"). The traceability column is a data type of array or JSON, used to store the complete traceability set of the corresponding cells in that row and column. This design allows subsequent queries to directly read the pre-stored traceability information when referencing this intermediate table, without needing to recalculate, thus ensuring the efficiency and accuracy of multi-step data transfer.

[0074] Step S202: Parse the SQL query to generate an abstract syntax tree, and assign procedural sourcing identifiers to the subexpressions in the SQL query based on the abstract syntax tree.

[0075] As is understandable, an Abstract Syntax Tree (AST) is a tree-like representation of the syntactic structure of source code. Each node corresponds to a syntactic unit, such as a selection list, table reference, predicate, or function call. The process of generating an AST consists of two stages: lexical analysis and syntax analysis. Lexical analysis breaks down the SQL text into a sequence of words (keywords, identifiers, operators, constants, etc.); syntax analysis combines the word sequences into a tree structure according to SQL grammar rules and verifies the grammatical correctness.

[0076] In the specific implementation step S202, the SQL query (denoted as Q) undergoes lexical and syntactic analysis to generate an abstract syntax tree (AST) containing multiple syntax nodes. The AST is traversed, and a unique procedural traceability identifier is assigned to each syntax node. A mapping relationship is established between the procedural traceability identifier and the corresponding sub-expression of the syntax node. This mapping relationship is stored as a hash table or dictionary structure, where the key is the procedural traceability identifier and the value is the text representation of the corresponding sub-expression and its position information in the AST (such as row number and column number). For ease of subsequent visualization and interaction, the annotated SQL query is denoted as Q. ant And push it to the front end for rendering. Q ant The process traceability identifiers carried in the code are not visible to the user, but the front end can highlight the corresponding SQL subexpression when the user selects the target output cell based on the mapping relationship between these identifiers and syntax nodes.

[0077] Understandably, subexpressions include constants (numbers, strings, dates, etc.), column references (such as a.balance), unary operators (such as -, NOT), and binary operators (such as +, ...). This includes functions such as AND, OR, function calls (e.g., SUM, COUNT, CAST), aggregate functions, window functions, predicates (comparison, IN, LIKE, BETWEEN), and subqueries. Each subexpression is assigned a unique process sourcing identifier (PROCESS_ID). Naming rules can be defined based on actual business requirements, for example, using a prefix "P_" followed by a semantic abbreviation and a sequence number. For instance, the constant "0.015" is assigned "P_0_015", the aggregate function "SUM" is assigned "P_SUM", and the binary operator "..." is assigned "...". The process tracing identifiers are assigned as follows: "P_MUL", "P_OR" for the logical operator "OR", "P_CUST_EQ" for the comparison predicate "cust_id = 1001", and "P_CASE" for the CASE expression. These process tracing identifiers are used in subsequent steps to mark each operational stage through which the data flows, and are the foundation for achieving operator-level lineage tracing.

[0078] Step S203: Rewrite and transform the SQL query based on the abstract syntax tree to generate value query and source query.

[0079] Understandably, the essence of rewriting transformation is query algebraic transformation, that is, decomposing a single query into two collaborative query pairs without changing the original query semantics. This process is based on the fine-grained source-tracing semi-loop theory, ensuring that any semantically equivalent queries generate consistent source-tracing information.

[0080] It should be noted that the fine-grained source tracing semi-ring theory maps each operation in the data processing process to an algebraic expression, through addition (⊕) and multiplication (⊕) in the semi-ring structure. The algorithm performs formal combinations and derivations of the contribution relationships of the input data. In this embodiment, the propagation rules of the source identifier, cause identifier, and process tracing identifier correspond to the addition and multiplication operations in the semi-ring: the union operation corresponds to addition, and the join and aggregation operations correspond to multiplication. This ensures that any semantically equivalent SQL query generates consistent tracing information, providing a mathematical guarantee for subsequent step-by-step root cause localization.

[0081] In the specific implementation step S203, the nodes of the abstract syntax tree are traversed recursively, and value query fragments and source query fragments are generated for each node. The value query fragments are combined to form a value query, and the source query fragments are combined to form a source query. The value query retains the calculation logic of the original SQL query and adds a decision log output field. The source query performs operations in the identifier space to propagate the source identifier, cause identifier, and process source identifier.

[0082] It is understandable that the identifier space, also known as the identifier set operation domain, refers to the operation domain formed by the set of source identifiers, cause identifiers, and process tracing identifiers as elements. Tracing queries perform set operations within this identifier space, without performing numerical calculations.

[0083] It should be noted that the recursive rewrite function defines explicit transformation rules for each type of syntax element in the SQL query, combined with... Figure 3 The diagram shown illustrates the principle of the recursive rewriting function. The recursive rewriting function specifically includes:

[0084] (1) For constants (such as numbers and strings): the value version is the constant itself; the source version is a single-element set containing the source identifier of the procedure corresponding to the constant. For example, the value version of the constant 0.015 is 0.015, and the source version is {P_0_015}.

[0085] (2) For column references (e.g., a.balance): the value version is the value of the column; if the column comes from the original table, the source version is the source identifier of the cell (i.e., cell-level source fingerprint). If the column comes from an intermediate table and the table already has a corresponding source column, then in the generated source query fragment, the reference to the column is pointed to the corresponding source column so that the pre-stored source set can be used during the execution phase. For example, when referencing S.adj_balance, the source version is the set stored in S.adj_balance_prov.

[0086] (3) For binary operations (such as balance) 0.9): The value version is the operation performed by the value versions of the left operand and the right operand; the trace version is the union of the trace version of the left operand, the trace version of the right operand, and the procedure trace identifier corresponding to the operation.

[0087] (4) For aggregate functions (such as SUM(adj_balance)): the value version is the result of the aggregate calculation; the source version is the union of the source versions of all rows participating in the aggregation in the corresponding columns, plus the process source identifier corresponding to the aggregate function. If the aggregate function contains DISTINCT, the process identifier corresponding to the deduplication operation also needs to be marked in the source version.

[0088] (5) For filtering conditions (such as WHERE cust_id = 1001): The value version retains rows that meet the condition and records a decision log for each row (including the predicate evaluation result and the short-circuit path); the source version adds a "cause identifier set" to each output row based on the decision log. This set contains the source identifiers of all input cells referenced by the predicate being checked. For CASE WHEN expressions, the evaluation result of each branch and the selected branch are also recorded as the basis for generating cause identifiers.

[0089] Through the above recursive definition, a pair of queries is ultimately generated: value query (Q) v ) and source tracing query (Q p Value queries retain all the computational logic of the original SQL query, outputting a business result table and an additional structured decision log during execution. The decision log is stored in a structured manner, such as using a database array type. Each element is a key-value pair or structure, containing a decision point ID (an identifier corresponding to a predicate or branch), input values ​​(such as the compared column values), output results (Boolean values ​​or branch numbers), and a short-circuit flag. For example, for an OR condition, if the left operand is true, the decision log records that the right operand is skipped due to short-circuiting. The decision log corresponds one-to-one with the business result rows, linked by row number or primary key. The decision log records the evaluation result of each condition (such as WHERE, CASE WHEN) during data processing, and whether short-circuiting behavior exists (e.g., the right operand is skipped when the left operand is true in an OR condition). In simple terms, the decision log is like an audit record, noting "why this row of data was retained" or "why that row of data was excluded." For example, when performing an interest calculation query, the value query will record information such as whether each row of data satisfies the condition that the customer number equals 1001 and whether a CASE branch has been triggered.

[0090] Value lookup (Q) v Here is a simplified example of SQL rewriting for )

[0091] {-- Original query

[0092] SELECT a.cust_id, SUM(a.balance) 0.015 AS interest

[0093] FROM corporate_accounts a

[0094] WHERE a.cust_id = 1001 OR a.acct_type IN ('savings', 'money_market')

[0095] GROUP BY a.cust_id;

[0096] -- Qv rewrite (adding decision log)

[0097] SELECT a.cust_id, SUM(a.balance) 0.015 AS interest,

[0098] ARRAY

[0099] ROW('predicate1', a.cust_id = 1001),

[0100] ROW('predicate2', a.acct_type IN ('savings', 'money_market')),

[0101] ROW('shortcut', CASE WHEN a.cust_id = 1001 THEN 'skip_pred2' ELSE 'evaluate_pred2' END)

[0102] AS decision_log

[0103] FROM corporate_accounts a

[0104] GROUP BY a.cust_id;}

[0105] Source tracing query (Q) p It operates entirely within the identifier field, without calculating specific numerical values, but rather reads and queries the value (Q). vThe decision log generated propagates three types of identifiers: Source identifier: the fingerprint of the input cell, indicating which original cells a result value directly comes from; Cause identifier: the fingerprint of the input cell referenced in the predicate being checked, indicating which cell's value was checked because a result exists; Process identifier: the process tracing identifier corresponding to the subexpression, indicating which calculation steps a result has undergone.

[0106] The key mechanism lies in multi-step transmission: if the input table itself already has a traceability column (for example, an adjusted_balance_prov column in the intermediate table S generated by the upstream ETL), then when the traceability query references this column, it will not regenerate the fingerprint, but will directly use the pre-stored traceability set in this column. In this way, the traceability information from the upstream (such as the fingerprint of the original table M) will be automatically transmitted to the downstream, realizing cross-step traceability.

[0107] For example, for the query SELECT adjusted_balance 0.95 FROM S, after rewriting:

[0108] Value version: adjusted_balance 0.95

[0109] Source version: ARRAY[adjusted_balance_prov, 'P_0_95', 'P_MUL']

[0110] The adjusted_balance_prov is a source set pre-stored in table S, which contains fingerprints and process identifiers from further upstream sources (such as table M).

[0111] Step S204: Execute value query to obtain business results and decision logs.

[0112] In the specific implementation step S204, a value query is executed to calculate the business result data, and the evaluation results of each judgment condition in the SQL query and the short-circuit evaluation path are recorded to generate a decision log; the business result data is then associated with the decision log.

[0113] Understandably, the execution engine can be any relational database that supports standard SQL (such as PostgreSQL, MySQL, Oracle, etc.) or a big data computing framework (such as Spark SQL, Hive). Rewriting value queries adds extra output columns but does not change the correctness of the original business results.

[0114] It's important to note that the decision log is stored in a structured manner, such as using a database's JSONB or array type. Each record contains a decision point identifier, input values, output results, and the order of evaluation. For scenarios involving multi-row aggregation, the decision log also records which rows are included in the aggregation group, enabling traceability queries to accurately identify all data rows involved in the calculation.

[0115] Step S205: Execute the source tracing query and generate the source tracing information corresponding to each output cell in the business results based on the decision log.

[0116] The traceability information includes the process traceability identifiers corresponding to the sub-expressions that participate in the calculation output cells.

[0117] Understandably, sourcing queries operate entirely within the identifier domain and do not involve specific numerical calculations, thus resulting in high execution efficiency. It generates a sourcing mapping table by reading the decision logs generated from value queries, combining them with the sourcing columns (if any) from the input table, and following the same logical structure as value queries but operating on a set of identifiers.

[0118] In the specific implementation step S205, a source tracing query is performed based on the decision log to identify the input data rows and judgment conditions involved in the evaluation corresponding to each output cell in the business result; the source identifiers of each cell in the input data rows are obtained to form a source identifier set; the identifiers of the input data cells referenced by the judgment conditions involved in the evaluation are obtained to form a cause identifier set; the process source tracing identifiers corresponding to the sub-expressions involved in generating the output cells are obtained to form a process identifier set; and the source identifier set, cause identifier set, and process identifier set are used as the source tracing information corresponding to the output cells.

[0119] Specifically, for the original input table, the source identifier is a pre-generated cell-level traceability fingerprint for each cell; for the intermediate table, if its business column already includes a traceability column, the source identifier is directly taken from the set in that traceability column. The output of the traceability query is a traceability mapping table, where each row corresponds to a cell in the output result table, recording the set of three types of identifiers for that cell, as shown in Table 1. The physical storage of the traceability mapping table can be a separate database table or an additional column of the output result table.

[0120] Table 1

[0121]

[0122] Step S206: In the multi-step query of the data processing chain, if the current SQL query references the output data of the previous query, the source information stored in the output data is read and integrated with the source information generated by the current query to obtain the source information after the step propagation.

[0123] Understandably, the propagation of traceability information is a key challenge in multi-step processing chains. This invention persists traceability information as a subsidiary column of an intermediate table, allowing subsequent queries to achieve information transfer without recalculating upstream traceability; a simple reference suffices. This approach avoids the complexity and performance overhead of recursive backtracking and is fully compatible with standard SQL execution engines.

[0124] In the specific implementation of step S206, in the multi-step query of the data processing chain, the business results of the preceding query are stored as business columns of the intermediate data table, and the traceability information generated by the preceding query is stored as traceability columns of the intermediate data table; when the current SQL query is detected to reference the intermediate data table, the data in the traceability column is read as the initial traceability information referenced by the corresponding column in the current query; during the execution of the traceability query of the current query, the initial traceability information is merged with the process traceability identifier and cause identifier generated in the current step to obtain the traceability information after the cross-step propagation.

[0125] For example, if the preceding query Q1 generates an intermediate table S, where the source column adj_balance corresponding to the business column adj_balance stores the source set for each cell (including the fingerprint of the original table M and the process identifier in Q1), when the subsequent query Q2 references S.adj_balance, the source query of Q2 directly reads S.adj_balance_prov as the source version referenced by that column, and then adds the new operations added in Q2 (such as SUM, ...) on top of this. The process identifier (constant 0.015) is used to generate the final traceability set containing complete step information. This "portable" propagation mechanism ensures that even after multiple processing steps, the final output can still be traced back to the original input cell and each processing operator.

[0126] See Figure 4 This diagram illustrates a comparison between operator-level parsing and field-level parsing. Figure 4 The left side shows traditional field-level lineage analysis: the balance field in the accounts table points to the interest field through lineage analysis, which only reflects the reference relationship between fields and cannot reflect the filtering, aggregation, projection and multiplication operations that the balance field undergoes in the process of generating interest. Figure 4The right side of the diagram illustrates the operator-level tracing analysis of this invention: starting from a table scan, it sequentially passes through filtering operators, aggregation functions, projection operators, and multiplication operators. Each operator is assigned a unique process tracing identifier (such as P_FILTER, P_SUM, P_PROJ, P_MUL), and propagates upwards layer by layer along the data flow direction. Through operator-level parsing, the tracing information of the final output interest cell contains the process tracing identifiers of each operator, thus enabling the identification of the specific computational logic, rather than simply knowing that the interest originates from the balance field. Compared to traditional field-level lineage analysis, which can only provide single-step field-level dependencies, this invention refines the tracing granularity to the operator level and combines it with labeled data tables to achieve cross-step propagation, allowing the final output to be traced back to the original table cells and each step of the operator. Logical errors in multi-step ETL can also be quickly located.

[0127] Step S207: Based on the process traceability identifier contained in the traceability information corresponding to the final output data, determine the input data, judgment conditions, and SQL sub-expressions associated with the final output data.

[0128] This step enables reverse tracing from abnormal data to the root cause. When business personnel discover an anomaly in a value in the final report, they can click on that cell, and the system will automatically display all relevant data sources and logical processes that led to that value.

[0129] In the specific implementation step S207, a selection instruction for the target output cell in the final output data is received; the source identifier set, cause identifier set, and process identifier set of the target output cell are extracted from the traceability information corresponding to the final output data; the corresponding input data cell is located according to the source identifier set, the corresponding judgment condition reference data cell is located according to the cause identifier set, and the corresponding SQL subexpression is located according to the process identifier set and mapping relationship; the input data cell, judgment condition reference data cell, and SQL subexpression are displayed in the visualization interface.

[0130] Furthermore, the visual interface includes an SQL editing area, an input table preview area, and an output result area. When a user clicks on an abnormal value cell in the output result area, the system, based on its source information, highlights the input data cells corresponding to the source identifier in the current step's input table preview area with a first color (e.g., green), indicating that the values ​​of these cells directly participate in the calculation result; it highlights the data cells referencing the judgment conditions corresponding to the cause identifier with a second color (e.g., red), indicating that the values ​​of these cells determine whether the row of data is included or excluded; and in the current step's SQL editing area, it highlights the sub-expressions corresponding to the procedure identifier with a third color (e.g., blue) nested boxes, indicating that these computational logics act on the data. These three colors correspond to three types of source information, making it easy for users to quickly distinguish between data flow, decision flow, and computation flow.

[0131] Meanwhile, the system provides a "View Upstream Source" button. If the source identifier set contains fingerprints from the upstream table, clicking this button will jump to the query interface that generated the intermediate table and highlight the corresponding upstream cell and sub-expression, realizing recursive tracing back to the original input table.

[0132] In addition, the system supports two-way traceability: when a user clicks on a highlighted input cell in the input table preview area, the system queries the traceability mapping table in reverse to find all output result cells affected by that input cell, and highlights these cells in the output result area, thereby quickly assessing the scope of the impact of upstream data changes on downstream.

[0133] Furthermore, this embodiment also integrates an automatic logical error detection and repair suggestion function. Specifically, based on the source information corresponding to the final output data, it matches a pre-set error pattern library, which includes logical OR misuse patterns, missing association condition patterns, and unfiltered patterns before aggregation. If the pre-set error pattern library is successfully matched, a repair solution containing correction suggestions and modified SQL fragments is generated, and a suggestion window pops up in the visualization interface. Examples of repair solutions: For the OR misuse pattern, it is suggested to change "OR" to "AND"; for the missing association condition pattern, it is suggested to add the ON clause condition; for the unfiltered pattern before aggregation, it is suggested to add a time range filter in the WHERE clause. Users can apply the repair with one click, and the system automatically re-executes the query and updates all source markers, forming a closed loop and significantly improving debugging efficiency.

[0134] Specifically, the error mode library includes, but is not limited to:

[0135] Logical OR Misuse Pattern: The matching characteristic is that the process identifier set contains a logical "OR" node, and the reason identifier shows that rows that should not meet the condition (e.g., rows that should be filtered out) passed the check, indicating that the "OR" condition may have misused "AND". For example, if you want to filter out accounts with customer type "VIP" and balance greater than 10,000, but mistakenly write "type='VIP' OR balance>10,000", a large number of non-VIP accounts will enter the results. The traceability information will show that the reason identifier of these accounts only contains the balance condition and not the type condition, which indicates that OR is misused.

[0136] Missing Join Condition Pattern: The matching feature is that the process identifier set is missing a "JOIN" condition node (e.g., the process identifier corresponding to the ON clause is missing), and the source identifier set contains fingerprints of multiple tables that should be joined, but the cause identifier does not have a check record for the join key. For example, forgetting to write the ON condition when joining two tables results in a Cartesian product. The source information will show multiple rows from both tables, but the cause identifier does not have a comparison of the joined fields, thus locating the missing join condition.

[0137] Unfiltered before aggregation: The matching feature is that the process identifier corresponding to the aggregation function is highlighted, but the set of reason identifiers shows that rows that should have been filtered out before aggregation (such as those that do not meet the time range) still participated in the aggregation. For example, when calculating quarterly interest, the date range was not limited in the WHERE clause, resulting in data from multiple quarters being mixed in. The traceability information shows that the rows participating in the aggregation contain fingerprints of rows that exceed the target date range, but the date condition check is missing in the reason identifier. Based on this, it can be determined that the filtering before aggregation is missing.

[0138] Multi-step missing join condition pattern: The matching feature is that subsequent queries (such as the second step) lack join conditions, and the source identifier contains fingerprints of multiple tables, but the cause identifier does not check the join key. This pattern is an extension of the single-step missing join condition pattern in multi-step scenarios. The matching logic is similar, but it needs to be combined with cross-step tracing information for comprehensive judgment. If the pre-built error pattern library is successful, a repair solution containing correction suggestions and modified SQL fragments is generated based on the pre-built template, and a suggestion window pops up in the visualization interface. Users can apply the repair with one click, and the system automatically re-executes the query and updates all tracing markers, forming a closed loop.

[0139] In this embodiment of the invention, an abstract syntax tree is generated by parsing the SQL query and process tracing identifiers are assigned to sub-expressions. Recursive rewriting is used to generate value queries and tracing queries. Value queries record the evaluation results of judgment conditions and decision logs of short-circuit paths. Tracing queries propagate source identifiers, cause identifiers, and process tracing identifiers in the identifier space, associating each output cell with these three types of identifiers. This refines the tracing granularity to the operator level, allowing the location of specific SQL sub-expressions based on the process tracing identifiers. In multi-step queries, preceding tracing information is stored as a tracing column in an intermediate table, which is directly read and integrated into the current query, achieving cross-step propagation and full-link tracing. Decision logs are used to identify the data rows that actually participate in the evaluation, eliminating short-circuit branches that have not taken effect, achieving row-level pruning and reducing the false alarm rate in impact analysis. The visualization interface highlights input data, judgment conditions, and SQL sub-expressions according to the three types of identifiers, forming a complete evidence chain, and can match error pattern libraries to generate repair solutions. All operations are completed at the SQL level, requiring no modification to the database kernel, resulting in low deployment costs and compatibility with mainstream databases.

[0140] The following detailed description of the method provided in the embodiments of the present invention is based on a complete multi-step processing example.

[0141] Assume that in the corporate banking business, the original table M (corporate account table) has generated a row identifier (ROW_ID) for each row and a source identifier (ROW_ID) for each cell, as shown in Table 2:

[0142] Table 2

[0143]

[0144] Step 1: Query Q1 to generate intermediate table S.

[0145] Q1 (M→S): Filter customer 1001's accounts and calculate the adjusted balance (multiply current account balance by 0.9). Example as follows:

[0146] {SELECT acct_id, cust_id, acct_type,

[0147] CASE WHEN acct_type = 'checking' THEN balance 0.9 ELSE balance ENDAS adj_balance

[0148] FROM M

[0149] WHERE cust_id = 1001}.

[0150] Parse and rewrite Q1 to generate a value query for Q. 1v And traceability query Q 1p And execute. After execution, the intermediate table S is stored as shown in Table 3 (business columns and corresponding traceability columns):

[0151] Table 3

[0152]

[0153] The `adj_balance_prov` column is the source column, where each element is either a source identifier (e.g., `R1.balance`) or a process identifier (e.g., `P_MUL`). This column stores complete source information for each adjusted balance value, including the cell fingerprint of the original table and process identifiers such as the CASE expression, multiplication operations, and the constant 0.9 involved in the first step.

[0154] Step 2: Query Q2 to generate the final table A.

[0155] Q2 (S→A): Total interest per customer (interest rate 0.015%). Example as follows:

[0156] {SELECT cust_id, SUM(adj_balance) 0.015 AS interest

[0157] FROM S

[0158] GROUP BY cust_id}.

[0159] Q2 is parsed and rewritten. During the rewriting process, the source version of column references to S.adj_balance is directly taken from the pre-stored source set in S.adj_balance_prov; the source version of the constant 0.015 is {P_0_015}; operators... The source version of the function is {P_MUL}; the source version of the aggregation function SUM is {P_SUM}. Finally, the source set of the output line (cust_id=1001,interest=14250) is:

[0160] { P_0_015, P_SUM, P_MUL, P_CASE, P_MUL, P_0_9,

[0161] R1.balance, R1.cust_id, R2.balance, R2.cust_id, R3.balance, R3.cust_id}.

[0162] This set clearly shows which original cells (R1.balance, R1.cust_id, etc.) and which operations (P_CASE, P_MUL, P_SUM, P_0_9, P_0_015) were used to generate the final interest value, fully covering the entire chain from table M to table A.

[0163] Step 3: Visualization and root cause identification.

[0164] Combination Figure 5 The diagram shows a visualization interface. When a user clicks cell interest=14250 in table A, the system, based on the aforementioned source set, highlights the adj_balance cell corresponding to the source identifier (R1.balance, etc.) in green and the cust_id cell corresponding to the cause identifier (R1.cust_id, etc.) in red in the preview area of ​​table S. In the SQL editing area of ​​Q2, 0.015... The SUM subexpression is highlighted in blue. Clicking on a highlighted cell in table S allows the user to trace back to table M, highlighting the balance and cust_id cells in R1, R2, and R3, as well as the CASE expression in Q1. Sub-expressions such as 0.9 are used to present a complete chain of evidence from the original data to the final result. If the system detects that the interest value is abnormal and matches the "unfiltered pattern before aggregation", it will display a repair suggestion, such as adding a time range filter condition in Q2 (e.g., limiting the transaction date to within the quarter), and provide a corrected SQL fragment. After the user confirms, it will automatically re-execute and update the traceability.

[0165] Corresponding to the data tracing and logical root cause localization method provided in the above embodiments of the present invention, see also... Figure 6 The diagram shows a structural block diagram of a data tracing and logical root cause localization device provided in an embodiment of the present invention.

[0166] The device includes: a query acquisition unit 601, a parsing unit 602, a rewrite conversion unit 603, a first execution unit 604, a second execution unit 605, a fusion unit 606, and a determination unit 607.

[0167] The query acquisition unit 601 is used to acquire the SQL query to be executed in the data processing chain and the corresponding input data of the SQL query.

[0168] Parsing unit 602 is used to parse SQL queries to generate abstract syntax trees and assign procedural sourcing identifiers to subexpressions in SQL queries based on the abstract syntax trees.

[0169] The parsing unit 602 is specifically used to perform lexical and syntactic analysis on the SQL query, generate an abstract syntax tree containing multiple syntax nodes, traverse the abstract syntax tree, assign a unique procedural traceability identifier to each syntax node, and establish a mapping relationship between the procedural traceability identifier and the subexpression corresponding to the syntax node.

[0170] The rewrite transformation unit 603 is used to rewrite and transform SQL queries based on the abstract syntax tree to generate value queries and source queries.

[0171] The transformation unit 603 is rewritten to traverse the nodes of the abstract syntax tree recursively, generating value query fragments and source query fragments for each node; the value query fragments are combined to form a value query, and the source query fragments are combined to form a source query; the value query retains the calculation logic of the original SQL query and adds a decision log output field, while the source query performs operations in the identifier space to propagate the source identifier, cause identifier, and process source identifier.

[0172] The first execution unit 604 is used to perform value queries and obtain business results and decision logs.

[0173] The first execution unit 604 is specifically used to execute value queries to calculate business result data, record the evaluation results of each judgment condition in the SQL query and the short-circuit evaluation path, generate a decision log, and associate the business result data with the decision log.

[0174] The second execution unit 605 is used to perform traceability queries and generate traceability information corresponding to each output cell in the business results based on the decision log. The traceability information includes process traceability identifiers corresponding to the sub-expressions that participate in the calculation of the output cells.

[0175] The second execution unit 605 is specifically used to perform source tracing queries based on the decision log, identify the input data rows and judgment conditions involved in the evaluation corresponding to each output cell in the business results; obtain the source identifiers of each cell in the input data rows to form a source identifier set; obtain the identifiers of the input data cells referenced by the judgment conditions involved in the evaluation to form a cause identifier set; obtain the process source tracing identifiers corresponding to the sub-expressions involved in generating the output cells to form a process identifier set; and use the source identifier set, cause identifier set, and process identifier set as the source tracing information corresponding to the output cells.

[0176] The fusion unit 606 is used in multi-step queries in the data processing chain to read the pre-stored traceability information in the output data and integrate it with the traceability information generated by the current query in the multi-step query, so as to obtain the traceability information after the step propagation.

[0177] The fusion unit 606 is specifically used in multi-step queries in the data processing chain to store the business results of the preceding query as business columns of the intermediate data table, and to store the traceability information generated by the preceding query as traceability columns of the intermediate data table; when the current SQL query is detected to reference the intermediate data table, the data in the traceability column is read as the initial traceability information referenced by the corresponding column in the current query; during the execution of the traceability query of the current query, the initial traceability information is merged with the process traceability identifier and cause identifier generated in the current step to obtain the traceability information after the cross-step propagation.

[0178] The determining unit 607 is used to determine the input data, judgment conditions, and SQL sub-expressions associated with the final output data based on the process traceability identifier contained in the traceability information corresponding to the final output data.

[0179] The determination unit 607 is specifically used to receive the selection instruction for the target output cell in the final output data; extract the source identifier set, cause identifier set, and process identifier set of the target output cell from the traceability information corresponding to the final output data; locate the corresponding input data cell according to the source identifier set, locate the corresponding judgment condition reference data cell according to the cause identifier set, and locate the corresponding SQL sub-expression according to the process identifier set and mapping relationship; and display the input data cell, judgment condition reference data cell, and SQL sub-expression in the visualization interface.

[0180] In this embodiment of the invention, the query acquisition unit acquires the SQL query and input data; the parsing unit generates an abstract syntax tree and assigns process tracing identifiers; the rewriting and transformation unit generates a value query and a tracing query; the first execution unit executes the value query to obtain business results and decision logs; the second execution unit executes the tracing query and generates tracing information for each output cell based on the decision logs, including process tracing identifiers for the sub-expressions involved in the calculation; the fusion unit reads the pre-stored tracing information from the preceding output data in the multi-step query and integrates it with the current query's tracing information to obtain the tracing information after cross-step propagation; and the determination unit determines the associated input data, judgment conditions, and SQL sub-expressions accordingly. This elevates the tracing granularity from the field level to the operator level and enables cross-step tracing, solving the problem of difficulty in locating operator-level logical errors in multi-step processing.

[0181] Combination Figure 6 The device, as shown, also includes:

[0182] When the input data is a raw data table, a globally unique row identifier is generated for each row in the raw data table, and a field identifier is generated for each column.

[0183] A cell-level source fingerprint is generated based on the row identifier and field identifier, and the cell-level source fingerprint is used as the source identifier for each cell in the input data.

[0184] Combination Figure 6 The device, as shown, also includes:

[0185] The matching unit is used to match a pre-set error pattern library based on the source information corresponding to the final output data. The error pattern library includes logical OR misuse patterns, missing association conditions patterns, and unfiltered patterns before aggregation.

[0186] The generation unit is used to generate a repair solution containing correction suggestions and modified SQL fragments if a match with a preset error pattern library is successful.

[0187] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for system or system embodiments, since they are basically similar to method embodiments, the description is relatively simple, and relevant parts can be referred to the descriptions in the method embodiments. The systems and system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.

[0188] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0189] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for data tracing and logical root cause localization, characterized in that, The method includes: Obtain the SQL query to be executed in the data processing chain and the input data corresponding to the SQL query; The SQL query is parsed to generate an abstract syntax tree, and procedural sourcing identifiers are assigned to the sub-expressions in the SQL query based on the abstract syntax tree; The SQL query is rewritten and transformed based on the abstract syntax tree to generate value queries and source queries; Execute the value query to obtain business results and decision logs; Execute the source tracing query and generate source tracing information corresponding to each output cell in the business result based on the decision log, wherein the source tracing information includes process source tracing identifiers corresponding to the sub-expressions that participated in the calculation of the output cells; In a multi-step query in the data processing chain, if the current SQL query references the output data of the previous query, the source information stored in the output data is read and integrated with the source information generated by the current query to obtain the source information after the step-by-step propagation. Based on the process traceability identifier contained in the traceability information corresponding to the final output data, determine the input data, judgment conditions, and SQL sub-expressions associated with the final output data.

2. The method according to claim 1, characterized in that, The step of parsing the SQL query to generate an abstract syntax tree and assigning procedural sourcing identifiers to sub-expressions in the SQL query based on the abstract syntax tree includes: Lexical and syntactic analysis are performed on the SQL query to generate an abstract syntax tree containing multiple syntax nodes; Traverse the abstract syntax tree, assign a unique procedural traceability identifier to each syntax node, and establish a mapping relationship between the procedural traceability identifier and the subexpression corresponding to the syntax node.

3. The method according to claim 1, characterized in that, The step of rewriting and transforming the SQL query based on the abstract syntax tree to generate value queries and source queries includes: The nodes of the abstract syntax tree are traversed recursively, and value query fragments and source query fragments are generated for each node. The value query fragments are combined to form the value query, and the source query fragments are combined to form the source query; wherein, the value query retains the calculation logic of the original SQL query and adds a decision log output field, and the source query performs operations in the identifier space to propagate the source identifier, cause identifier and process source identifier.

4. The method according to claim 1, characterized in that, The execution of the value query yields business results and decision logs, including: The value query is executed to calculate the business result data, and the evaluation results of each judgment condition in the SQL query and the short-circuit evaluation path are recorded to generate a decision log; The business outcome data is associated with the decision log.

5. The method according to claim 1, characterized in that, The execution of the source tracing query, and the generation of source tracing information corresponding to each output cell in the business result based on the decision log, includes: Based on the decision log, the source tracing query is executed to identify the input data rows corresponding to each output cell in the business result and the judgment conditions for participating in the evaluation. Obtain the source identifier of each cell in the input data row and form a source identifier set; Obtain the identifiers of the input data cells referenced by the judgment conditions involved in the evaluation, and form a reason identifier set; Obtain the process traceability identifiers corresponding to the sub-expressions involved in generating the output cell, and form a process identifier set; The source identifier set, the cause identifier set, and the process identifier set are used as the tracing information corresponding to the output cell.

6. The method according to claim 1, characterized in that, In the multi-step query of the data processing chain, if the current SQL query references the output data of a previous query, the pre-stored source information in the output data is read and integrated with the source information generated by the current query to obtain the source information after propagation across steps, including: In the multi-step query of the data processing chain, the business results of the preceding query are stored as the business column of the intermediate data table, and the traceability information generated by the preceding query is stored as the traceability column of the intermediate data table; When it is detected that the current SQL query references the intermediate data table, the data in the source column is read as the initial source information referenced by the corresponding column in the current query; During the current source tracing query execution, the initial source tracing information is merged with the process source tracing identifier and cause identifier generated in the current step to obtain the source tracing information after propagation across steps.

7. The method according to claim 1, characterized in that, The step of determining the input data, judgment conditions, and SQL sub-expressions associated with the final output data based on the process traceability identifier contained in the traceability information corresponding to the final output data includes: Receive a selection instruction for the target output cell in the final output data; Extract the source identifier set, cause identifier set, and process identifier set of the target output cell from the traceability information corresponding to the final output data; The corresponding input data cell is located according to the source identifier set; the corresponding judgment condition reference data cell is located according to the reason identifier set; and the corresponding SQL subexpression is located according to the process identifier set and the mapping relationship. The input data cell, the judgment condition reference data cell, and the SQL subexpression are displayed in the visual interface.

8. The method according to claim 5, characterized in that, The method further includes: When the input data is a raw data table, a globally unique row identifier is generated for each row in the raw data table, and a field identifier is generated for each column; A cell-level source fingerprint is generated based on the row identifier and the field identifier, and the cell-level source fingerprint is used as the source identifier for each cell in the input data.

9. The method according to claim 1, characterized in that, The method further includes: Based on the source information corresponding to the final output data, a preset error pattern library is matched, wherein the error pattern library includes logical or misuse patterns, missing association conditions patterns, and unfiltered patterns before aggregation. If a match is found in the pre-defined error pattern library, a repair solution containing suggested corrections and modified SQL fragments is generated.

10. A data tracing and logical root cause localization device, characterized in that, The device includes: The query acquisition unit is used to acquire the SQL query to be executed in the data processing chain and the input data corresponding to the SQL query; The parsing unit is used to parse the SQL query to generate an abstract syntax tree, and assign procedural sourcing identifiers to the sub-expressions in the SQL query according to the abstract syntax tree; The rewrite and transformation unit is used to rewrite and transform the SQL query according to the abstract syntax tree to generate value query and source query; The first execution unit is used to execute the value query to obtain business results and decision logs; The second execution unit is used to execute the tracing query and generate tracing information corresponding to each output cell in the business result according to the decision log, wherein the tracing information includes process tracing identifiers corresponding to the sub-expressions that participate in the calculation of the output cells; The fusion unit is used in multi-step queries in the data processing chain to read the pre-stored traceability information in the output data and integrate it with the traceability information generated by the current query in the current SQL query if the current SQL query references the output data of the previous query, so as to obtain the traceability information after the cross-step propagation. The determining unit is used to determine the input data, judgment conditions, and SQL sub-expressions associated with the final output data based on the process traceability identifier contained in the traceability information corresponding to the final output data.