Search

CN-116127153-B - Data tracing method, device, medium and equipment

CN116127153BCN 116127153 BCN116127153 BCN 116127153BCN-116127153-B

Abstract

The embodiment of the specification discloses a data tracing method, a device, a storage medium and equipment. The method comprises the steps of analyzing the Structured Query Language (SQL) to be traced to obtain an abstract syntax tree corresponding to the SQL to be traced, obtaining preset element information corresponding to the SQL to be traced based on the abstract syntax tree, constructing reverse SQL corresponding to the SQL to be traced based on the preset element information and the syntax structure of the SQL to be traced, and carrying out data tracing based on the reverse SQL.

Inventors

  • HUANG SIWANG
  • Wu mou

Assignees

  • 支付宝(杭州)信息技术有限公司

Dates

Publication Date
20260505
Application Date
20230118

Claims (13)

  1. 1. A data tracing method, comprising: Analyzing SQL (structured query language) to be traced to obtain an abstract syntax tree corresponding to the SQL to be traced; Based on the abstract syntax tree, acquiring predetermined element information corresponding to the SQL to be traced; Constructing reverse SQL corresponding to the SQL to be traced based on the predetermined element information and the grammar structure of the SQL to be traced; Performing data tracing processing based on the reverse SQL, wherein the reverse SQL refers to SQL used for acquiring original data of a forward SQL sentence; The reverse SQL comprises a filling element, wherein the filling element is used for replacing fields in a corresponding data table, and the data tracing processing is performed based on the reverse SQL, and comprises the steps of acquiring the fields corresponding to the data table from metadata of the data table, filling the fields into the filling element of the reverse SQL, executing the reverse SQL, and performing the data tracing processing on an execution result corresponding to the SQL to be traced; The method comprises the steps of establishing a reverse SQL corresponding to the SQL to be traced based on the predetermined element information and the grammar structure of the SQL to be traced, wherein the method comprises the steps of determining a grammar structure type corresponding to the SQL to be traced based on the grammar structure of the SQL to be traced, and establishing the reverse SQL corresponding to the SQL to be traced based on the grammar structure type and the predetermined element information, wherein the grammar structure type is one type of a single-table type, a multi-table type and a multi-layer nested type; the method comprises the steps of constructing a tracing element model corresponding to the SQL to be traced based on the grammar structure type and the preset element information, and splicing all tracing elements in the tracing element model based on the SQL grammar structure corresponding to the grammar structure type to generate the reverse SQL corresponding to the SQL to be traced.
  2. 2. The method of claim 1, wherein the syntax structure type is a single table type, and the constructing the trace element model corresponding to the SQL to be traced based on the syntax structure type and the predetermined element information includes: determining a single form traceability element in the predetermined element information based on the single form type; Based on the single table tracing element, constructing a single table tracing element model corresponding to the SQL to be traced, The splicing each trace element in the trace element model based on the SQL grammar structure corresponding to the grammar structure type comprises the following steps: And splicing all the tracing elements in the single-table tracing element model based on the SQL grammar structure of the single-table type to generate the reverse SQL corresponding to the SQL to be traced.
  3. 3. The method of claim 1, wherein the syntax structure type is a multi-table type, and the constructing the trace element model corresponding to the SQL to be traced based on the syntax structure type and the predetermined element information includes: determining a multi-table tracing element in the predetermined element information based on the multi-table type, wherein the multi-table tracing element comprises a multi-table association element; based on the multi-table tracing element, constructing a multi-table tracing element model corresponding to the SQL to be traced, The splicing each trace element in the trace element model based on the SQL grammar structure corresponding to the grammar structure type comprises the following steps: And splicing all the trace elements in the multi-table trace element model based on the SQL grammar structure of the multi-table type and the multi-table associated elements.
  4. 4. The method of claim 3, wherein the stitching of individual trace elements in the multi-table trace element model based on the multi-table type SQL syntax structure and the multi-table association element comprises: determining a table association condition corresponding to the multi-table association element based on the abstract syntax tree; Determining a sub-query condition of reverse SQL for each data table of a plurality of data tables based on the table association condition; based on the sub-query conditions of the reverse SQL for each data table and the SQL grammar structure of the multi-table type, splicing the trace elements corresponding to each data table in the multi-table trace element model, The generating the reverse SQL corresponding to the to-be-traced SQL comprises: and generating reverse SQL of each data table corresponding to the SQL to be traced.
  5. 5. The method of claim 1, wherein the syntax structure type is a multi-layer nested type, and the constructing the trace element model corresponding to the SQL to be traced based on the syntax structure type and the predetermined element information includes: Determining a nested traceability element in the predetermined element information based on the multi-layer nesting type, wherein the nested traceability element comprises hierarchical information to which the element belongs; based on the nested tracing elements, constructing a multi-layer nested tracing element model corresponding to the SQL to be traced, The splicing each trace element in the trace element model based on the SQL grammar structure corresponding to the grammar structure type comprises the following steps: Based on the SQL grammar structure of the multi-layer nested type and the hierarchical information of the elements, splicing each trace element in the multi-layer nested trace element model layer by layer, The generating the reverse SQL corresponding to the to-be-traced SQL comprises: And generating reverse SQL of each level corresponding to the SQL to be traced.
  6. 6. The method of claim 5, wherein the stitching, layer by layer, each trace element in the multi-layer nested trace element model based on the multi-layer nested type SQL syntax structure and the hierarchical information to which the element belongs, comprises: Determining the hierarchy of each traceable element in the multi-layer nested traceable element model based on the hierarchy information of the element; Determining the grammar structure type of the SQL of each level based on the grammar structure of the SQL of each level according to the sequence from the inner layer to the outer layer; And splicing the trace elements in the multi-layer nested trace element model corresponding to each level based on the grammar structure type of SQL of each level.
  7. 7. The method of claim 6, wherein the stitching the trace elements in the multi-layer nested trace element model corresponding to each level based on the syntax structure type of the SQL of each level comprises: Splicing the trace elements in the multilayer nested trace element model corresponding to the outer layer by taking the SQL sub-query of the inner layer as a temporary table; and replacing the temporary table in the spliced reverse SQL with the SQL sub-query.
  8. 8. The method according to any one of claims 1 to 7, wherein the parsing the structured query language SQL to be traced to obtain an abstract syntax tree corresponding to the SQL to be traced includes: Performing lexical analysis on the SQL to be traced based on lexical rules of SQL language to obtain a symbol stream corresponding to the SQL to be traced; and carrying out grammar analysis on the symbol stream based on grammar rules of the SQL language, and generating an abstract grammar tree corresponding to the SQL to be traced.
  9. 9. The method of any one of claims 1 to 7, wherein the method further comprises: and displaying the processing result of the data tracing processing in a data blood-source map mode.
  10. 10. A data tracing apparatus, comprising: the analysis module is used for analyzing the SQL to be traced to obtain an abstract syntax tree corresponding to the SQL to be traced; the element acquisition module is used for acquiring the predetermined element information corresponding to the SQL to be traced based on the abstract syntax tree; The reverse function construction module is used for constructing reverse SQL corresponding to the SQL to be traced based on the predetermined element information and the grammar structure of the SQL to be traced; the tracing processing module is used for carrying out data tracing processing based on the reverse SQL, wherein the reverse SQL refers to SQL used for acquiring original data of a forward SQL sentence; The reverse SQL comprises a filling element, wherein the filling element is used for replacing fields in a corresponding data table, and the data tracing processing is performed based on the reverse SQL, and comprises the steps of acquiring the fields corresponding to the data table from metadata of the data table, filling the fields into the filling element of the reverse SQL, executing the reverse SQL, and performing the data tracing processing on an execution result corresponding to the SQL to be traced; The method comprises the steps of establishing a reverse SQL corresponding to the SQL to be traced based on the predetermined element information and the grammar structure of the SQL to be traced, wherein the method comprises the steps of determining a grammar structure type corresponding to the SQL to be traced based on the grammar structure of the SQL to be traced, and establishing the reverse SQL corresponding to the SQL to be traced based on the grammar structure type and the predetermined element information, wherein the grammar structure type is one type of a single-table type, a multi-table type and a multi-layer nested type; the method comprises the steps of constructing a tracing element model corresponding to the SQL to be traced based on the grammar structure type and the preset element information, and splicing all tracing elements in the tracing element model based on the SQL grammar structure corresponding to the grammar structure type to generate the reverse SQL corresponding to the SQL to be traced.
  11. 11. A computer storage medium storing a plurality of instructions adapted to be loaded by a processor and to perform the steps of the method according to any one of claims 1 to 9.
  12. 12. An electronic device comprising a processor and a memory, wherein the memory stores a computer program adapted to be loaded by the processor and to perform the steps of the method according to any of claims 1-9.
  13. 13. A computer program product comprising instructions which, when run on a computer or processor, cause the computer or processor to perform the steps of the method of any of claims 1-9.

Description

Data tracing method, device, medium and equipment Technical Field The present disclosure relates to the field of big data technologies, and in particular, to a data tracing method, device, storage medium, and apparatus. Background With the development of internet technology, a large amount of data is generated every day, and how to trace the generated data is a focus of attention. The data tracing can reproduce the circulation path and the evolution process of the data. In one technical scheme, a data tracing process is performed on target data by a reverse query method to obtain a tracing result of the target data, for example, the target data is reversely deduced according to a data conversion process, and original data of the target data is traced. However, when the current reverse query method performs data tracing processing on the target data, the accuracy of the tracing result of the obtained target data is low. Therefore, how to improve the accuracy of the tracing result of the data tracing process becomes a technical problem to be solved urgently. Disclosure of Invention The specification provides a data tracing method, a data tracing device, a storage medium and a data tracing device, which can improve the accuracy of tracing results of data tracing processing and can rapidly and accurately locate the source of data. In a first aspect, an embodiment of the present disclosure provides a data tracing method, including: Analyzing SQL (structured query language) to be traced to obtain an abstract syntax tree corresponding to the SQL to be traced; Based on the abstract syntax tree, acquiring predetermined element information corresponding to the SQL to be traced; Constructing reverse SQL corresponding to the SQL to be traced based on the predetermined element information and the grammar structure of the SQL to be traced; and performing data tracing processing based on the reverse SQL. In a second aspect, an embodiment of the present disclosure provides a data tracing apparatus, including: the analysis module is used for analyzing the SQL to be traced to obtain an abstract syntax tree corresponding to the SQL to be traced; the element acquisition module is used for acquiring the predetermined element information corresponding to the SQL to be traced based on the abstract syntax tree; The reverse function construction module is used for constructing reverse SQL corresponding to the SQL to be traced based on the predetermined element information and the grammar structure of the SQL to be traced; And the tracing processing module is used for carrying out data tracing processing based on the reverse SQL. In a third aspect, the present description provides a computer storage medium storing a plurality of instructions adapted to be loaded by a processor and to perform the steps of the method described above. In a fourth aspect, embodiments of the present description provide a computer program product comprising instructions which, when run on a computer or processor, cause the computer or processor to perform the steps of the method described above. In a fifth aspect, the present description provides an electronic device comprising a processor and a memory, wherein the memory stores a computer program adapted to be loaded by the processor and to perform the steps of the method described above. According to the technical scheme of the embodiment of the specification, on one hand, the corresponding abstract syntax tree is obtained through analyzing the SQL to be traced, the predetermined element information corresponding to the SQL to be traced is obtained based on the abstract syntax tree, key elements in the SQL to be traced can be accurately determined, on the other hand, the reverse SQL corresponding to the SQL to be traced is constructed based on the predetermined element information and the abstract syntax tree, the data tracing processing is carried out on the execution result corresponding to the SQL to be traced based on the reverse SQL, and the original data of the execution result of the SQL to be traced can be quickly and accurately queried due to the reverse SQL, so that the accuracy of the tracing result of the data tracing processing can be improved, the source of the data in the execution result can be quickly and accurately positioned, and on the other hand, the data in the execution result can be subjected to the data tracing processing only when needed, so that the storage space occupied by the data tracing processing can be reduced. Drawings In order to more clearly illustrate the embodiments of the present description or the technical solutions in the prior art, the drawings that are required in the embodiments or the description of the prior art will be briefly described below, it being obvious that the drawings in the following description are only some embodiments of the present description, and that other drawings may be obtained according to these drawings without inventive effort for