A method, device, and equipment for processing SQL statements

By converting SQL statements into AST and executing differential privacy algorithms in AST, the problem of not being able to directly execute differential privacy algorithms in the prior art is solved, and the privacy protection of SQL statements is achieved.

CN116226169BActive Publication Date: 2025-07-18BEIJING ZITIAO NETWORK TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202310201045.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-03
Publication Date
2025-07-18
Estimated Expiration
2043-03-03

AI Technical Summary

Technical Problem

The prior art cannot directly execute differential privacy algorithms on SQL statements, especially complex SQL statements cannot be presented in a structured manner, resulting in the inability to find queries that require differential privacy algorithms to be executed.

Method used

Convert SQL statements into an abstract syntax tree (AST) structure, and find the target node of the aggregate expression in the expression node of the AST, call the sensitivity calculation function of its internal nodes, and execute the differential privacy algorithm.

Benefits of technology

It realizes the execution of the differential privacy algorithm after entering the SQL statement, protects the privacy of data, and is compatible with different types of SQL statements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116226169B_ABST
    Figure CN116226169B_ABST
Patent Text Reader

Abstract

The present application discloses a method, apparatus and device for processing SQL statements, which are used to convert SQL statements into an AST structure, and then use this structure to implement the execution of the differential privacy algorithm. The method includes: obtaining an SQL statement; converting the SQL statement into an AST according to the AST conversion rule corresponding to the type of the SQL statement; the node types of the AST include statement nodes, block nodes and expression nodes, the statement node includes at least one block node, and the block node includes at least one expression node; finding a first target node belonging to an aggregate expression among the expression nodes of the AST; calling the sensitivity calculation function of the internal node of the first target node to obtain the sensitivity of the internal node of the first target node, and the sensitivity of the internal node of the first target node is used to execute the differential privacy algorithm for the first target node.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of database technology, and particularly to a method, apparatus, and device for processing SQL (Structured Query Language) statements. Background Art

[0002] Differential Privacy (DP) is a privacy protection measure mainly used for protecting aggregated statistical data. It can protect the sensitive information of individuals while keeping the overall statistical characteristics of the data stable. Its main approach is to add appropriate noise to the statistical results to ensure that modifying a single individual record in the data will not have a significant impact on the statistical results, aiming to solve the problem of user privacy leakage in the statistical release process of data.

[0003] Currently, SQL statements can be used to query data tables in a database. However, the differential privacy algorithm cannot be directly executed on SQL statements that belong to strings. Summary of the Invention

[0004] In view of this, embodiments of this application provide a method, apparatus, and device for processing SQL statements, which can convert SQL statements into an intermediate representation structure and then use this structure to implement the execution of the differential privacy algorithm.

[0005] To solve the above problems, the technical solutions provided by the embodiments of this application are as follows:

[0006] In a first aspect, embodiments of this application provide a method for processing SQL statements of Structured Query Language. The method includes:

[0007] Obtain an SQL statement;

[0008] Convert the SQL statement into an Abstract Syntax Tree (AST) according to the AST conversion rules corresponding to the type of the SQL statement. The node types of the AST include statement nodes, block nodes, and expression nodes. The statement nodes include at least one block node, and the block nodes include at least one expression node;

[0009] Find a first target node belonging to an aggregate expression among the expression nodes of the AST;

[0010] Call the sensitivity calculation function of the internal nodes of the first target node to obtain the sensitivity of the internal nodes of the first target node, and the sensitivity of the internal nodes of the first target node is used to execute the differential privacy algorithm for the first target node.

[0011] Second aspect, an embodiment of the present application provides a processing device for Structured Query Language (SQL) statements, the device comprising:

[0012] A first acquisition unit, configured to acquire an SQL statement;

[0013] A conversion unit, configured to convert the SQL statement into an Abstract Syntax Tree (AST) according to an AST conversion rule corresponding to the type of the SQL statement; node types of the AST include statement nodes, block nodes, and expression nodes, the statement nodes include at least one block node, and the block nodes include at least one expression node;

[0014] A first search unit, configured to search for a first target node belonging to an aggregate expression among the expression nodes of the AST;

[0015] An invocation unit, configured to invoke a sensitivity calculation function of an internal node of the first target node to obtain the sensitivity of the internal node of the first target node, and the sensitivity of the internal node of the first target node is used to perform a differential privacy algorithm on the first target node.

[0016] Third aspect, an embodiment of the present application provides a processing device for Structured Query Language (SQL) statements, including: a memory, a processor, and a computer program stored on the memory and executable on the processor, when the processor executes the computer program, implementing the processing method of the SQL statement as described above.

[0017] Fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein instructions are stored in the computer-readable storage medium, and when the instructions are run on a terminal device, the terminal device is caused to execute the processing method of the SQL statement as described above.

[0018] It can be seen that the embodiments of the present application have the following beneficial effects:

[0019] The embodiments of the present application have pre-established AST (Abstract Syntax Tree) conversion rules corresponding to different SQL statement types, can be compatible with different types of SQL statements, convert the SQL statements into ASTs, and the ASTs are represented by a three-level node structure of statement nodes, block nodes, and expression nodes. Then, among the expression nodes in the AST, a first target node belonging to an aggregate expression that needs to execute the differential privacy algorithm is determined, and the sensitivity calculation function of the internal node of the first target node is invoked, so as to calculate the sensitivity of the internal node of the first target node, and the sensitivity of the internal node of the first target node can be used to implement the differential privacy algorithm for the first target node. Thus, the execution of the differential privacy algorithm after inputting the SQL statement is realized. Description of the Drawings

[0020] Figure 1 It is a schematic diagram of an exemplary application scenario provided by an embodiment of the present application;

[0021] Figure 2 It is a flowchart of a method for processing an SQL statement provided by an embodiment of the present application;

[0022] Figure 3 It is a schematic diagram of generating an AST provided by an embodiment of the present application;

[0023] Figure 4 It is a schematic diagram of a device for processing an SQL statement provided by an embodiment of the present application;

[0024] Figure 5 It is a schematic diagram of an electronic device provided by an embodiment of the present application. Detailed implementation manners

[0025] To make the above objects, features, and advantages of the present application more obvious and understandable, the embodiments of the present application will be further described in detail below with reference to the accompanying drawings and specific implementation manners.

[0026] To facilitate the understanding and explanation of the technical solutions provided by the embodiments of the present application, the background technology of the present application will be described first below.

[0027] Differential Privacy (DP for short) is a privacy protection means mainly used for the protection of aggregated statistical data, which can protect the sensitive information of individuals while maintaining the stability of the overall statistical characteristics of the data.

[0028] For example, suppose there is a database of user information records, using boolean values to record whether each person has a certain user characteristic. Among them, the boolean value for having this user characteristic is 1, and the boolean value for not having this user characteristic is 2. Suppose a malicious user (usually called an attacker) wants to know whether a person has this user characteristic. Suppose the attacker knows which row of the database this person is in, for example, in the 10th row. The attacker uses a specific form to query the sum of the boolean values of the first 10 rows and the first 9 rows in the user information record database, and then calculates the difference between the two queries, that is, the result of whether a person has this user characteristic can be obtained. This is the differential privacy attack. If the results of querying 9 people's information and querying 10 people's information are the same, then the attacker has no way to determine the information of the 10th person. This is differential privacy protection.

[0029] The main approach of differential privacy protection is to add an appropriate amount of noise to the aggregated statistical results to ensure that modifying an individual record in the data will not have a significant impact on the statistical results, aiming to solve the problem of user privacy leakage in the process of statistical publication of data.

[0030] Currently, SQL statements can be used to query data tables in a database to obtain aggregated query results. However, SQL statements are strings, and complex SQL statements cannot be presented in a structured manner, nor can it be determined which queries among them need to execute the differential privacy algorithm. Therefore, it is currently impossible to directly execute the differential privacy algorithm on SQL statements that are strings.

[0031] Based on this, embodiments of the present application provide a method, device, and equipment for processing SQL statements, which convert SQL statements into an intermediate representation structure AST for representation, and then use this structure to implement the execution of the differential privacy algorithm.

[0032] To facilitate understanding of the method for processing SQL statements provided by embodiments of the present application, the following will be described in conjunction with Figure 1 the following scenario example. Refer to Figure 1 As shown, this figure is a schematic diagram of an exemplary application scenario provided by embodiments of the present application.

[0033] The differential privacy protection system of embodiments of the present application takes SQL statements as input, converts SQL statements into ASTs, and ASTs include three levels of nodes: statement nodes, block nodes, and expression (Expr) nodes. When executing the differential privacy algorithm, the first target nodes belonging to aggregate expressions that need to execute the differential privacy algorithm are found from the various expression nodes of the AST. For example, Figure 1 the shaded node expressions in

[0034] Those skilled in the art can understand that Figure 1 the schematic framework diagram shown is only an example in which the implementation manner of the present application can be realized. The scope of application of the implementation manner of the present application is not limited by any aspect of this framework.

[0035] To facilitate understanding of the present application, the following will describe a method for processing SQL statements provided by embodiments of the present application with reference to the accompanying drawings.

[0036] Refer to Figure 2 As shown, this figure is a flowchart of a method for processing SQL statements provided by embodiments of the present application. As Figure 2 shown, the method may include S201 - S204:

[0037] S201: Obtain an SQL statement.

[0038] Data tables in a database can be queried through SQL statements. In practical applications, there are different types of SQL statements, namely various SQL statement dialects, such as SQL statements of the Mysql type, SQL statements of the Hive type, and so on. Each type of SQL statement has its own unique syntax structure, and the writing method of SQL statements is relatively free, which poses challenges to the parsing of SQL statements.

[0039] S202: Convert the SQL statement into an AST according to the abstract syntax tree AST conversion rules corresponding to the type of the SQL statement. Among them, the node types of the AST include statement nodes, block nodes, and expression nodes. A statement node includes at least one block node, and a block node includes at least one expression node.

[0040] For the convenience of subsequent understanding, first, the structure of the AST provided in the embodiments of the present application is described. The AST includes three levels of nodes: statement (Statement) nodes, block (Block) nodes, and expression (Expr) nodes. A statement node includes at least one block node, and a block node includes at least one expression node.

[0041] A statement node represents a statement. There are syntactic differences among different types of SQL statements, and the content that may be included in a statement is different. Therefore, different types of SQL statements are processed by constructing different statement nodes for different types of SQL statements. The inside of a statement node is composed of different block nodes. Different statement nodes may include different block nodes. For example, statement nodes include ClickHouseStatement (the statement node corresponding to the SQL statement of the ClickHouse type), HiveStatement (the statement node corresponding to the SQL statement of the Hive type), MysqlStatement (the statement node corresponding to the SQL statement of the Mysql type), SparkStatement (the statement node corresponding to the SQL statement of the Spark type), and OtherStatement (the statement node corresponding to other types of SQL statements), etc. The prewhere syntax block may be included in the SQL statement of the ClickHouse type, while the prewhere syntax block is not supported syntactically in the SQL statement of the Hive type. At this time, the prewhere block node can be filled in when creating ClickHouseStatement, but not in HiveStatement, that is, ClickHouseStatement includes the prewhere block node and HiveStatement does not include the prewhere block node. There can only be one same block node inside a statement node.

[0042] A block node represents a relatively independent block structure in an SQL statement, similar to a short sentence (different parts separated by commas in a sentence). In the current AST representation system, to support different types of SQL statements, the syntax parts with different characteristics included in each type of SQL statement are encapsulated as independent block nodes. For example, block nodes include SelectBlock (Select block node), FromBlock (From block node), WhereBlock (Where block node), GroupByBlock (GroupBy block node), HavingBlock (Having block node), OrderByBlock (OrderBy block node), LimitByBlock (LimitByt block node), LimitBlock (Limit syntax block), TeaLimitBlock (TeaLimit block node), WithBlock (With block node), PrewhereBlock (Prewhere block node), SettingBlock (Setting block node), SampleBlock (Sample block node), etc.

[0043] A block node can also include other block nodes. For example, WithBlock includes WithFromExpressionBlock (WithFromExpression block node) and WithAsQueryBlock (WithAsQuery block node). A block node is composed of different expression nodes inside, and the expression nodes inside the block node can be freely combined, and there can be multiple identical expression nodes inside a block node.

[0044] An expression node represents a single field or a composite field expression, and it has the largest number of node types in the current AST representation system. An expression node can include nodes of multiple expression types in major directions, and each direction is further divided into more lower-level expression nodes. For example, an expression node includes BaseExpr (expression node of the Base type), AggFunctionExpr (expression node of the AggFunction type), ArithmeticExpr (expression node of the Arithmetic type), CondExpr (expression node of the Cond type), FunctionExpr (expression node of the Function type), LogicalExpr (expression node of the Logical type), BoolExpr (expression node of the Bool type), etc. Taking BaseExpr as an example, it can be further divided into different expression nodes internally, such as LiteralExpr (constant expression node), IdentifierExpr (identifier expression node), NumberExprExpr (numeric expression node), and so on.

[0045] In the embodiments of this application, in order to achieve the correct parsing of SQL statements, AST conversion rules corresponding to different types of SQL statements are established in advance to convert SQL statements into ASTs. The AST conversion rule for each type of SQL statement can be understood as the nodes in the AST that the type of SQL statement may include and the node hierarchy relationship between each node. For example, the AST conversion rule for ClickHouse's SQL statement indicates that ClickHouse's SQL statement can include ClickHouseStatement, ClickHouseStatement includes SelectBlock, FromBlock, PrewhereBlock, etc., and which expression nodes each block node includes. By matching the SQL statement with the corresponding AST conversion rule, it can be recognized which nodes the SQL statement includes and the node hierarchy relationship between these nodes, thereby establishing the AST corresponding to the SQL statement.

[0046] In a possible implementation manner, the specific implementation of converting the SQL statement into an AST according to the abstract syntax tree AST conversion rule corresponding to the type of the SQL statement in S202 may include:

[0047] A1: Parse the SQL statement into a stream of SQL statement words.

[0048] An SQL statement is a string of characters. Through a grammar rule parser corresponding to the type of the SQL statement, the word stream of the SQL statement corresponding to the SQL statement can be identified. The word stream of the SQL statement includes multiple words. For example, for the SQL statement "select age from table", through parsing, a word stream including 4 words "select, age, from, table" can be obtained. The grammar rule parser can be an SQL statement parsing tool in practical applications.

[0049] A2: Match the words in the word stream of the SQL statement with the abstract syntax tree (AST) transformation rules corresponding to the type of the SQL statement to determine the node types of the words and the node hierarchy relationships among the words.

[0050] A3: Convert the SQL statement into an AST according to the node types of the words and the node hierarchy relationships among the words.

[0051] Matching the words in the word stream of the SQL statement with the corresponding AST transformation rules can obtain which type of nodes in the AST each word belongs to and what the node hierarchy relationships of these nodes are. Assembling these words according to the node types and the corresponding node hierarchy relationships can obtain the AST corresponding to the SQL statement. For example, for an SQL statement of the Mysql type "select age from table", where "age" is an expression node, "table" is an expression node, "select" is a Select block node, and "from" is a From block node, then the age expression node belongs to the Select block node, the table expression node belongs to the From block node, and the Select block node and the From block node belong to the MysqlStatement node, thus establishing the AST of this SQL statement.

[0052] See Figure 3 as shown, which shows a schematic diagram of the process of converting an SQL statement into an AST in practical applications.

[0053] For the input of different types of SQL statements, use their corresponding grammar rule parsers to identify each word in the SQL statement, form a word stream of the SQL statement, and then use their corresponding ASTBuilders to assemble these words into the AST designed currently. The corresponding AST transformation rules are stored in the ASTBuilder. When it is necessary to adapt to a new type of SQL statement, only the corresponding grammar rule parser and ASTBuilder need to be implemented. Finally, different types of SQL statements use the corresponding ASTBuilders to construct a unified AST. For example, to obtain an SQL statement of the Mysql type, use the Mysql grammar rule parser to parse the SQL statement into a word stream of the SQL statement, input the word stream of the SQL statement into the Mysql ASTBuilder, and convert the SQL statement into an AST. The same process applies to other types of SQL statements, which will not be elaborated here.

[0054] In this way, in the embodiment of this application, different statement nodes are constructed for different types of SQL statements in the AST. Each type of SQL statement is directly parsed into the corresponding statement node during parsing. At the same time, relatively independent statements and syntactic features are encapsulated into block nodes, and different block node combinations are used to fill different statement nodes. Finally, various basic expressions are encapsulated into expression nodes, and expression node combinations are used to fill the expression nodes themselves and block nodes. It realizes a combination method where the upper-layer AST nodes process different grammars, and the lower-layer AST nodes are filled as general nodes, thus solving the compatibility problem of different types of SQL statements on the AST.

[0055] S203: Find the first target node belonging to the aggregate expression among the expression nodes of the AST.

[0056] During the implementation of the differential privacy algorithm, it is necessary to calculate the sensitivity of the internal nodes belonging to the aggregate expression. To implement the differential privacy algorithm, a list of aggregate expressions can be set in advance, and then nodes belonging to the aggregate expression are found among the expression nodes of the AST as the first target node. For example, if it is pre-set that the differential privacy algorithm needs to be executed for the sum expression, then the sum expression is an aggregate expression, and the sum expression node is found among the various expression nodes of the AST as the first target node.

[0057] Since the first target node belongs to an aggregation expression, it will also include internal nodes. The first target node can include first-level internal nodes or multiple-level internal nodes. For example, in the SQL statement "sum(age)", it is converted into a sum expression node and an age expression node in the AST. The sum expression node is the first target node, and its internal node is the age expression node. Another example is that in the SQL statement "sum(id + age)", it is converted into a sum expression node, an addition expression node, an id expression node, and an age expression node in the AST tree. The sum expression node is the first target node, its internal node is the addition expression node, and the internal nodes of the addition expression node are the id expression node and the age expression node.

[0058] S204: Call the sensitivity calculation function of the internal nodes of the first target node to obtain the sensitivity of the internal nodes of the first target node, and the sensitivity of the internal nodes of the first target node is used to perform the differential privacy algorithm on the first target node.

[0059] After determining the first target node, the internal nodes of the first target node can be determined through the AST. In the embodiments of the present application, corresponding sensitivity calculation functions are preset for the internal nodes of the first target node. According to the execution logic of the sensitivity calculation function, the sensitivity of the internal nodes of the first target node can be obtained, so as to perform the differential privacy algorithm on the first target node by using the sensitivity of the internal nodes of the target node.

[0060] In a possible implementation, the specific implementation of S204 calling the sensitivity calculation function of the internal nodes of the first target node to obtain the sensitivity of the internal nodes of the first target node may include:

[0061] Call the sensitivity calculation function of the internal nodes of the first target node to obtain the metadata information of the internal nodes of the first target node, and calculate the sensitivity of the internal nodes of the first target node by using the metadata information; the metadata information is obtained by querying the data table through the SQL statement.

[0062] When calculating the sensitivity of the internal nodes of the first target node, the metadata information of the internal nodes of the first target node needs to be utilized, and this metadata information can be queried from the data table corresponding to the internal node. Specifically, the metadata information may include the data type, maximum value, minimum value, data occurrence frequency, etc. in the data table corresponding to the internal node. For example, based on the above example, from sum(age), it can be known that the sum expression node is the first target node, and the corresponding internal node is the age expression node. The age expression node queries the age (age) column in the data table, and the metadata information of the age expression node can be obtained from the data table, including the data type, maximum value, minimum value, etc. of this column in the data table. Then, when calling the sensitivity calculation function of the age expression node, the sensitivity of the age expression node can be calculated using the metadata information of the age expression node, and thus the differential privacy algorithm can be executed on the query result corresponding to the sum expression node according to the sensitivity of the age expression node.

[0063] In some possible implementation manners, since the first target node may include multiple levels of internal nodes, the specific implementation of calling the sensitivity calculation function of the internal nodes of the first target node, obtaining the metadata information of the internal nodes of the first target node, and calculating the sensitivity of the internal nodes of the first target node using the metadata information may include:

[0064] Call the sensitivity calculation function of the first-level internal node of the target node to obtain the metadata information of the second-level internal node of the target node, and calculate the sensitivity of the first-level internal node of the target node using the metadata information of the second-level internal node of the target node.

[0065] That is, when the first target node includes multiple levels of internal nodes, the second-level internal node can be understood as the next-level node of the first internal node. Then, by calling the sensitivity calculation function of the first-level internal node and obtaining the metadata information of the next-level internal node (i.e., the second internal node) of the first-level internal node, the sensitivity of the first-level internal node can be calculated.

[0066] When the first target node includes internal nodes of three levels or more, the sensitivity calculation function of the penultimate-level internal node can be called to obtain the metadata information of the last-level internal node, and the sensitivity of the penultimate-level internal node can be calculated using the metadata information of the last-level internal node. The sensitivity of the penultimate-level internal node can be used as the metadata information of the penultimate-level internal node. Then, continue to call the sensitivity calculation function of the internal node at the level above the penultimate-level internal node, and calculate the sensitivity of the internal node at the level above the penultimate-level internal node using the metadata information of the penultimate-level internal node. And so on, finally, the sensitivity of the internal node at the next level of the first target node can be obtained, so as to perform the differential privacy algorithm on the query result of the first target node.

[0067] For example, based on the above example, for sum(id + age), the sum expression node is the first target node, the addition expression node is the first-level internal node, and the id expression node and the age expression node are the second-level internal nodes. Call the sensitivity calculation function of the addition expression node to obtain the metadata information of the id expression node and the age expression node. According to the pre-set sensitivity calculation function of the addition expression node, add the minimum values corresponding to the id expression node and the age expression node as the minimum value of the addition expression node, and add the maximum values corresponding to the id expression node and the age expression node as the maximum value of the addition expression node, and calculate the sensitivity of the addition expression node.

[0068] Another example is the sum(power(salary, 2)) part in the SQL statement. The sum expression node is the first target node, its first-level internal node is the power (exponent calculation) expression node, and the second-level internal node is the salary (salary) expression node. Call the sensitivity calculation function of the power expression node to obtain the metadata information of the salary expression node. According to the pre-set sensitivity calculation function of the power expression node, when the minimum value corresponding to the salary expression node is non-negative, square the minimum value as the minimum value of the power expression node, and square the maximum value corresponding to the salary expression node as the maximum value of the power expression node; when the maximum value corresponding to the salary expression node is non-positive, square the maximum value as the minimum value of the power expression node, and square the minimum value corresponding to the salary expression node as the maximum value of the power expression node; when the minimum value corresponding to the salary expression node is negative and the maximum value is positive, the minimum value of the power expression node is 0, and the larger of the squares of the minimum value and the maximum value corresponding to the salary expression node is used as the maximum value of the power expression node to complete the sensitivity calculation of the power expression node.

[0069] In the embodiments of the present application, the expression nodes that need to calculate sensitivity are pre-encapsulated with sensitivity calculation logic, and the specific logic varies according to different expression nodes. Based on this, the differential privacy result output of the first target node is realized.

[0070] Based on the descriptions of S201 - S204, the embodiments of the present application have pre-established AST conversion rules corresponding to different SQL statement types, which can be compatible with different types of SQL statements and convert SQL statements into ASTs. The AST is represented by a three-level node structure of statement nodes, block nodes, and expression nodes. Then, in the expression nodes of the AST, the first target node belonging to the aggregation expression that needs to execute the differential privacy algorithm is determined, and the sensitivity calculation function of the internal nodes of the first target node is called to calculate the sensitivity of the internal nodes of the first target node. The sensitivity of the internal nodes of the first target node can be used to execute the differential privacy algorithm for the first target node. Thus, the execution of the differential privacy algorithm is realized after the input of the SQL statement.

[0071] Based on the above embodiments, in order to calculate the sensitivity of the internal nodes of the first target node, it is necessary to query the metadata information of the corresponding database, data table, data column, etc. from the data table corresponding to the internal nodes of the first target node. In order to improve the efficiency of obtaining metadata information and reduce the number of database queries, the embodiments of the present application can pre-bind the metadata information with the expression nodes in the AST.

[0072] In a possible implementation manner, based on the above embodiments, the embodiments of the present application may further include:

[0073] B1: Search for the second target node of a preset type in the expression nodes of the AST.

[0074] The second target node can be understood as an expression node that may need to obtain metadata information. There are three types of second target nodes in the AST, namely table type, column type, and Map expression type. The second target node of table type means that this expression node needs to query the data table, the second target node of column type means that this expression node needs to query the data column, and the second target node of Map expression type means that this expression node needs to query the Map expression. That is, search for the second target node of a preset type in each expression node of the AST, and the preset types are table type, column type, and Map expression type.

[0075] B2: Obtain the metadata information in the data table corresponding to the second target node according to the execution order of the SQL statement.

[0076] According to the execution order of the SQL statement, query the corresponding data table, data column or corresponding node of the second target node, so as to obtain the metadata information of the second target node. For example, for the SQL statement select name,sum(age)as sa,float_params{'_slot_param_1'}as fp1 from table1, where table1 is parsed as the second target node of table type, name and age are parsed as the second target nodes of column type, and float_params{'_slot_param_1'} is parsed as the second target node of Map expression type.

[0077] According to the execution order of the SQL statement, as in the above example, the table1 expression node in the From block node first obtains the metadata information, and then the three expression nodes in the Select block node obtain the metadata information.

[0078] In a possible implementation, when the second target node is of table type, the metadata information in the data table corresponding to the second target node is the metadata information of the corresponding table in the data table corresponding to the second target node;

[0079] When the second target node is of column type, the metadata information in the database corresponding to the second target node is the metadata information of the corresponding column in the data table corresponding to the second target node;

[0080] When the second target node is of Map expression type, the metadata information in the data table corresponding to the second target node is the metadata information of the corresponding node in the data table corresponding to the second target node.

[0081] In the embodiment of the present application, when the second target node is of table type, query the metadata information of the data table corresponding to the second target node (including the metadata information of all columns of the data table). When the second target node is of column type, query the metadata information of the data column corresponding to the second target node. When the second target node is of Map expression type, query the metadata information of the corresponding node in the data table corresponding to the second target node.

[0082] B3: Bind the metadata information corresponding to the second target node to the second target node in the AST.

[0083] Finally, bind the metadata information of each second target node to the second target node, so that when the metadata information of the second target node needs to be obtained, it can be directly obtained from the AST without querying the database again.

[0084] In a possible implementation, the specific implementation of obtaining the sensitivity of the internal nodes of the first target node by invoking the sensitivity calculation function of the internal nodes of the first target node in S204 may include:

[0085] Invoke the sensitivity calculation function of the internal nodes of the first target node, obtain the metadata information of the internal nodes of the first target node from the AST, and calculate the sensitivity of the internal nodes of the first target node using the metadata information; the internal nodes of the first target node match the second target node.

[0086] After the metadata information is bound in the AST, when it is necessary to obtain the metadata information of the internal nodes of the first target node, if the internal node belongs to the second target node, that is, the metadata information is bound, the metadata information of the internal node can be directly obtained from the AST without querying the database, improving the implementation efficiency.

[0087] Based on the method for processing SQL statements provided in the above method embodiments, the embodiments of the present application also provide a device for processing SQL statements, which will be described below with reference to the accompanying drawings.

[0088] See Figure 4 As shown, this figure is a schematic structural diagram of a device for processing SQL statements provided by the embodiments of the present application. As Figure 4 As shown, the device for processing SQL statements includes:

[0089] A first acquisition unit 401, configured to acquire an SQL statement;

[0090] A conversion unit 402, configured to convert the SQL statement into an AST according to the abstract syntax tree AST conversion rule corresponding to the type of the SQL statement; the node types of the AST include statement nodes, block nodes, and expression nodes, the statement nodes include at least one block node, and the block nodes include at least one expression node;

[0091] A first search unit 403, configured to search for a first target node belonging to an aggregate expression among the expression nodes of the AST;

[0092] An invocation unit 404, configured to invoke the sensitivity calculation function of the internal nodes of the first target node to obtain the sensitivity of the internal nodes of the first target node, and the sensitivity of the internal nodes of the first target node is used to execute the differential privacy algorithm for the first target node.

[0093] In a possible implementation, the conversion unit includes:

[0094] A parsing subunit, configured to parse the SQL statement into an SQL statement word stream;

[0095] A matching subunit, configured to match words in the word stream of the SQL statement with the abstract syntax tree (AST) transformation rules corresponding to the type of the SQL statement, and determine the node types of the words and the node hierarchical relationships between the words;

[0096] A conversion subunit, configured to convert the SQL statement into an AST according to the node types of the words and the node hierarchical relationships between the words.

[0097] In a possible implementation manner, the calling unit is specifically configured to:

[0098] Call the sensitivity calculation function of the internal node of the first target node, obtain the metadata information of the internal node of the first target node, and calculate the sensitivity of the internal node of the first target node by using the metadata information; the metadata information is obtained by querying a data table through the SQL statement.

[0099] In a possible implementation manner, when the first target node includes multiple levels of internal nodes, the calling unit specifically includes:

[0100] Call the sensitivity calculation function of the first-level internal node of the target node, obtain the metadata information of the second-level internal node of the target node, and calculate the sensitivity of the first-level internal node of the target node by using the metadata information of the second-level internal node of the target node.

[0101] In a possible implementation manner, the apparatus further includes:

[0102] A second search unit, configured to search for a second target node of a preset type in the expression nodes of the AST;

[0103] A second obtaining unit, configured to obtain the metadata information in the data table corresponding to the second target node according to the execution order of the SQL statement;

[0104] A binding unit, configured to bind the metadata information corresponding to the second target node to the second target node in the AST.

[0105] In a possible implementation manner, the preset type is a table type, a column type, and a Map expression type;

[0106] When the second target node is of the table type, the metadata information in the data table corresponding to the second target node is the metadata information of the corresponding table in the data table corresponding to the second target node;

[0107] When the second target node is of column type, the metadata information in the database corresponding to the second target node is the metadata information of the corresponding columns in the data table corresponding to the second target node;

[0108] When the second target node is of Map expression type, the metadata information in the data table corresponding to the second target node is the metadata information of the corresponding nodes in the data table corresponding to the second target node.

[0109] In a possible implementation manner, the calling unit is specifically configured to:

[0110] Call the sensitivity calculation function of the internal node of the first target node, obtain the metadata information of the internal node of the first target node from the AST, and calculate the sensitivity of the internal node of the first target node by using the metadata information; the internal node of the first target node matches the second target node.

[0111] Based on the SQL statement processing method provided in the foregoing method embodiments, the present application further provides an electronic device, including: one or more processors; a storage device storing one or more programs thereon, when the one or more programs are executed by the one or more processors, enabling the one or more processors to implement the SQL statement processing method described in any of the foregoing embodiments.

[0112] Next, referring to Figure 5 , which shows a schematic structural diagram of an electronic device 1300 suitable for implementing the embodiments of the present application. The terminal device in the embodiments of the present application may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (portable android devices, tablet computers), PMPs (Portable Media Players), in-vehicle terminals (such as in-vehicle navigation terminals), etc., and fixed terminals such as digital TVs (televisions), desktop computers, etc. Figure 5 The electronic device shown is only an example and should not impose any limitation on the functions and usage scope of the embodiments of the present application.

[0113] As Figure 5As shown, the electronic device 1300 may include a processing device (such as a central processing unit, a graphics processing unit, etc.) 1301, which may perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1302 or a program loaded from a storage device 1306 into a random access memory (RAM) 1303. In the RAM 1303, various programs and data required for the operation of the electronic device 1300 are also stored. The processing device 1301, the ROM 1302, and the RAM 1303 are connected to each other through a bus 1304. An input / output (I / O) interface 1305 is also connected to the bus 1304.

[0114] Generally, the following devices may be connected to the I / O interface 1305: an input device 1306 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 1307 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 1306 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1309. The communication device 1309 may allow the electronic device 1300 to communicate with other devices wirelessly or wiredly to exchange data. Although Figure 5 the electronic device 1300 with various devices is shown, it should be understood that it is not required to implement or have all the shown devices. Instead, more or fewer devices may be implemented or had.

[0115] Specifically, according to an embodiment of the present application, the process described above with reference to the flowchart may be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes program codes for executing the method shown in the flowchart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication device 1309, or installed from the storage device 1306, or installed from the ROM 1302. When the computer program is executed by the processing device 1301, the above functions defined in the method of the embodiment of the present application are executed.

[0116] The electronic device provided by the embodiment of the present application and a method for processing an SQL statement provided by the above embodiment belong to the same inventive concept. Technical details not described in detail in this embodiment may be referred to the above embodiment, and this embodiment has the same beneficial effects as the above embodiment.

[0117] Based on the method for processing an SQL statement provided by the above method embodiment, an embodiment of the present application provides a computer-readable medium, on which a computer program is stored, wherein the program, when executed by a processor, implements the method for processing an SQL statement as described in any of the above embodiments.

[0118] It should be noted that the above-mentioned computer-readable medium in this application can be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of the computer-readable storage medium can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this application, the computer-readable storage medium can be any tangible medium that contains or stores a program, and this program can be used by or in combination with an instruction execution system, apparatus, or device. And in this application, the computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, in which the computer-readable program code is carried. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium can also be any computer-readable medium other than the computer-readable storage medium, and this computer-readable signal medium can send, propagate, or transmit a program for use by or in combination with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted by any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0119] In some embodiments, the client and the server can communicate using any currently known or future-developed network protocol such as HTTP (HyperText Transfer Protocol), and can be interconnected with digital data communication in any form or medium (e.g., a communication network). Examples of communication networks include local area networks ("LAN"), wide area networks ("WAN"), the Internet (e.g., the Internet), and end-to-end networks (e.g., ad hoc end-to-end networks), as well as any currently known or future-developed networks.

[0120] The above-mentioned computer-readable medium can be included in the above-mentioned electronic device; or it can exist separately without being assembled into the electronic device.

[0121] The above-mentioned computer-readable medium carries one or more programs, and when the one or more programs are executed by the electronic device, the electronic device is caused to execute the processing method of the above SQL statement.

[0122] Computer program code for performing the operations of the embodiments of the present application may be written in one or more programming languages or combinations thereof. The above-mentioned programming languages include, but are not limited to, object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, executed as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., by connecting through the Internet using an Internet service provider).

[0123] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagram may represent a module, a program segment, or a part of code that contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than marked in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and combinations of blocks in the block diagram and / or flowchart, may be implemented by a dedicated hardware-based system for performing the specified functions or operations, or may be implemented by a combination of dedicated hardware and computer instructions.

[0124] The units involved in the embodiments described in the present application may be implemented in software or in hardware. Among them, the name of the unit / module does not constitute a limitation to the unit itself in some cases. For example, the first acquisition unit may also be described as the "first acquisition module".

[0125] The functions described above in this document may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGA), application specific integrated circuits (ASIC), application specific standard products (ASSP), system on a chip (SOC), complex programmable logic devices (CPLD), and so on.

[0126] In the context of the embodiments of the present application, a machine-readable medium may be a tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of the machine-readable storage medium would include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0127] According to one or more embodiments of the present application, [Example 1] provides a method for processing SQL statements, the method comprising:

[0128] Obtain an SQL statement;

[0129] According to the abstract syntax tree (AST) conversion rule corresponding to the type of the SQL statement, convert the SQL statement into an AST; the node types of the AST include statement nodes, block nodes, and expression nodes, the statement nodes include at least one block node, and the block nodes include at least one expression node;

[0130] In the expression nodes of the AST, find a first target node belonging to an aggregate expression;

[0131] Call the sensitivity calculation function of the internal nodes of the first target node to obtain the sensitivity of the internal nodes of the first target node, and the sensitivity of the internal nodes of the first target node is used to execute the differential privacy algorithm for the first target node.

[0132] According to one or more embodiments of the present application, [Example 2] provides a method for processing SQL statements, and converting the SQL statement into an AST according to the abstract syntax tree (AST) conversion rule corresponding to the type of the SQL statement, comprising:

[0133] Parse the SQL statement into an SQL statement word stream;

[0134] Match the words in the SQL statement word stream with the abstract syntax tree (AST) conversion rule corresponding to the type of the SQL statement to determine the node types of the words and the node hierarchy relationship between the words;

[0135] Convert the SQL statement into an AST according to the node type of the word and the node hierarchy relationship between each word.

[0136] According to one or more embodiments of the present application, [Example 3] provides a method for processing an SQL statement. The method of calling the sensitivity calculation function of the internal node of the first target node to obtain the sensitivity of the internal node of the first target node includes:

[0137] Call the sensitivity calculation function of the internal node of the first target node, obtain the metadata information of the internal node of the first target node, and calculate the sensitivity of the internal node of the first target node by using the metadata information; the metadata information is obtained by querying the data table through the SQL statement.

[0138] According to one or more embodiments of the present application, [Example 4] provides a method for processing an SQL statement. When the first target node includes multiple levels of internal nodes, the method of calling the sensitivity calculation function of the internal node of the first target node, obtaining the metadata information of the internal node of the first target node, and calculating the sensitivity of the internal node of the first target node by using the metadata information includes:

[0139] Call the sensitivity calculation function of the first-level internal node of the target node, obtain the metadata information of the second-level internal node of the target node, and calculate the sensitivity of the first-level internal node of the target node by using the metadata information of the second-level internal node of the target node.

[0140] According to one or more embodiments of the present application, [Example 5] provides a method for processing an SQL statement. The method further includes:

[0141] Find a second target node of a preset type in the expression node of the AST;

[0142] Obtain the metadata information in the data table corresponding to the second target node according to the execution order of the SQL statement;

[0143] Bind the metadata information corresponding to the second target node to the second target node in the AST.

[0144] According to one or more embodiments of the present application, [Example 6] provides a method for processing an SQL statement. The preset types are table type, column type, and Map expression type;

[0145] When the second target node is of table type, the metadata information in the data table corresponding to the second target node is the metadata information of the corresponding table in the data table corresponding to the second target node;

[0146] When the second target node is of the column type, the metadata information in the database corresponding to the second target node is the metadata information of the corresponding columns in the data table corresponding to the second target node;

[0147] When the second target node is of the Map expression type, the metadata information in the data table corresponding to the second target node is the metadata information of the corresponding nodes in the data table corresponding to the second target node.

[0148] According to one or more embodiments of the present application, [Example Seven] provides a method for processing SQL statements. Invoking the sensitivity calculation function of the internal node of the first target node to obtain the sensitivity of the internal node of the first target node includes:

[0149] Invoking the sensitivity calculation function of the internal node of the first target node, obtaining the metadata information of the internal node of the first target node from the AST, and calculating the sensitivity of the internal node of the first target node by using the metadata information; the internal node of the first target node matches the second target node.

[0150] According to one or more embodiments of the present application, [Example Eight] provides a device for processing SQL statements. The device includes:

[0151] A first acquisition unit, configured to acquire an SQL statement;

[0152] A conversion unit, configured to convert the SQL statement into an AST according to the abstract syntax tree AST conversion rule corresponding to the type of the SQL statement; the node types of the AST include statement nodes, block nodes, and expression nodes, the statement nodes include at least one block node, and the block nodes include at least one expression node;

[0153] A first search unit, configured to search for a first target node belonging to an aggregate expression among the expression nodes of the AST;

[0154] A calling unit, configured to call the sensitivity calculation function of the internal node of the first target node to obtain the sensitivity of the internal node of the first target node, and the sensitivity of the internal node of the first target node is used to execute the differential privacy algorithm for the first target node.

[0155] According to one or more embodiments of the present application, [Example Nine] provides a device for processing SQL statements. The conversion unit includes:

[0156] A parsing subunit, configured to parse the SQL statement into an SQL statement word stream;

[0157] A matching subunit, configured to match words in the word stream of the SQL statement with the abstract syntax tree (AST) conversion rules corresponding to the type of the SQL statement, and determine the node types of the words and the node hierarchical relationships between the words;

[0158] A conversion subunit, configured to convert the SQL statement into an AST according to the node types of the words and the node hierarchical relationships between the words.

[0159] According to one or more embodiments of the present application, [Example Ten] provides a processing device for an SQL statement. Specifically, the calling unit is configured to:

[0160] Call the sensitivity calculation function of the internal node of the first target node, obtain the metadata information of the internal node of the first target node, and calculate the sensitivity of the internal node of the first target node by using the metadata information; the metadata information is obtained by querying a data table through the SQL statement.

[0161] According to one or more embodiments of the present application, [Example Eleven] provides a processing device for an SQL statement. When the first target node includes multiple levels of internal nodes, the calling unit specifically includes:

[0162] Call the sensitivity calculation function of the first-level internal node of the target node, obtain the metadata information of the second-level internal node of the target node, and calculate the sensitivity of the first-level internal node of the target node by using the metadata information of the second-level internal node of the target node.

[0163] According to one or more embodiments of the present application, [Example Twelve] provides a processing device for an SQL statement. The device further includes:

[0164] A second search unit, configured to search for a second target node of a preset type in the expression nodes of the AST;

[0165] A second acquisition unit, configured to acquire the metadata information in the data table corresponding to the second target node according to the execution order of the SQL statement;

[0166] A binding unit, configured to bind the metadata information corresponding to the second target node to the second target node in the AST.

[0167] According to one or more embodiments of the present application, [Example Thirteen] provides a processing device for an SQL statement. The preset type is a table type, a column type, and a Map expression type;

[0168] When the second target node is of the table type, the metadata information in the data table corresponding to the second target node is the metadata information of the corresponding table in the data table corresponding to the second target node;

[0169] When the second target node is of the column type, the metadata information in the database corresponding to the second target node is the metadata information of the corresponding column in the data table corresponding to the second target node;

[0170] When the second target node is of the Map expression type, the metadata information in the data table corresponding to the second target node is the metadata information of the corresponding node in the data table corresponding to the second target node.

[0171] According to one or more embodiments of the present application, [Example Fourteen] provides a processing device for SQL statements. The calling unit is specifically configured to:

[0172] Call the sensitivity calculation function of the internal node of the first target node, obtain the metadata information of the internal node of the first target node from the AST, and calculate the sensitivity of the internal node of the first target node by using the metadata information; the internal node of the first target node matches the second target node.

[0173] According to one or more embodiments of the present application, [Example Fifteen] provides a processing device for SQL statements, including: a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the processing method of the SQL statement described in any one of [Example One] to [Example Seven] is implemented.

[0174] According to one or more embodiments of the present application, [Example Sixteen] provides a computer-readable storage medium, characterized in that instructions are stored in the computer-readable storage medium. When the instructions run on a terminal device, the terminal device is caused to execute the processing method of the SQL statement described in any one of [Example One] to [Example Seven].

[0175] It should be noted that the various embodiments in this specification are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. The same or similar parts among the various embodiments can be referred to each other. For the systems or devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple, and the relevant parts can be referred to the description of the method part.

[0176] It should be understood that in this application, "at least one (item)" means one or more, and "a plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that there can be three relationships. For example, "A and / or B" can mean: only A exists, only B exists, and both A and B exist at the same time. Among them, A and B can be singular or plural. The character " / " generally means that the associated objects before and after are in an "or" relationship. "At least one (one) of the following" or its similar expression refers to any combination of these items, including any combination of single item (one) or plural items (ones). For example, at least one (one) of a, b, or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.

[0177] It should also be noted that in this article, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or also includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "including one..." does not exclude the existence of additional identical elements in the process, method, article or device including the said element.

[0178] The steps of the method or algorithm described in connection with the embodiments disclosed herein can be implemented directly in hardware, a software module executed by a processor, or a combination of both. The software module can be placed in a random access memory (RAM), memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, register, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the technical field.

[0179] The above description of the disclosed embodiments enables those skilled in the art to implement or use this application. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for processing SQL statements of a Structured Query Language, characterized in that, The method includes: Obtain an SQL statement; Convert the SQL statement into an Abstract Syntax Tree (AST) according to the AST conversion rules corresponding to the type of the SQL statement; the node types of the AST include statement nodes, block nodes, and expression nodes, the statement nodes include at least one block node, and the block nodes include at least one expression node; the AST conversion rules for each type of SQL statement are established based on the nodes in the AST included in the SQL statement of this type and the node hierarchical relationships between the various nodes; Find a first target node belonging to an aggregate expression among the expression nodes of the AST; Call the sensitivity calculation function of the internal nodes of the first target node to obtain the sensitivity of the internal nodes of the first target node, and the sensitivity of the internal nodes of the first target node is used to perform a differential privacy algorithm for the first target node.

2. The method according to claim 1, characterized in that, The step of converting the SQL statement into an AST according to the AST conversion rules corresponding to the type of the SQL statement includes: Parse the SQL statement into a word stream of the SQL statement; Match the words in the word stream of the SQL statement with the AST conversion rules corresponding to the type of the SQL statement to determine the node types of the words and the node hierarchical relationships between the various words; Convert the SQL statement into an AST according to the node types of the words and the node hierarchical relationships between the various words.

3. The method according to claim 1, wherein The step of calling the sensitivity calculation function of the internal nodes of the first target node to obtain the sensitivity of the internal nodes of the first target node includes: Call the sensitivity calculation function of the internal nodes of the first target node to obtain the metadata information of the internal nodes of the first target node, and calculate the sensitivity of the internal nodes of the first target node by using the metadata information; the metadata information is obtained by querying a data table through the SQL statement.

4. The method according to claim 3, wherein When the first target node includes multiple levels of internal nodes, the step of calling the sensitivity calculation function of the internal nodes of the first target node to obtain the metadata information of the internal nodes of the first target node and calculating the sensitivity of the internal nodes of the first target node by using the metadata information includes: Call the sensitivity calculation function of the first-level internal nodes of the target node to obtain the metadata information of the second-level internal nodes of the target node, and calculate the sensitivity of the first-level internal nodes of the target node by using the metadata information of the second-level internal nodes of the target node.

5. The method according to any one of claims 1-4, characterized in that The method further includes: Find a second target node of a preset type among the expression nodes of the AST; Obtain the metadata information in the data table corresponding to the second target node according to the execution order of the SQL statement; Bind the metadata information corresponding to the second target node to the second target node in the AST.

6. The method according to claim 5, characterized in that, The preset type is table type, column type, and Map expression type; When the second target node is of the table type, the metadata information in the data table corresponding to the second target node is the metadata information of the corresponding table in the data table corresponding to the second target node; When the second target node is of the column type, the metadata information in the database corresponding to the second target node is the metadata information of the corresponding column in the data table corresponding to the second target node; When the second target node is of the Map expression type, the metadata information in the data table corresponding to the second target node is the metadata information of the corresponding node in the data table corresponding to the second target node.

7. The method according to claim 5, wherein The calling the sensitivity calculation function of the internal node of the first target node to obtain the sensitivity of the internal node of the first target node includes: Calling the sensitivity calculation function of the internal node of the first target node, obtaining the metadata information of the internal node of the first target node from the AST, and calculating the sensitivity of the internal node of the first target node by using the metadata information; the internal node of the first target node matches the second target node.

8. A processing device for Structured Query Language (SQL) statements, characterized in that, The device includes: A first acquisition unit, configured to acquire an SQL statement; A conversion unit, configured to convert the SQL statement into an AST according to the abstract syntax tree AST conversion rule corresponding to the type of the SQL statement; the node types of the AST include statement nodes, block nodes, and expression nodes, the statement nodes include at least one block node, and the block nodes include at least one expression node; the AST conversion rule of each type of SQL statement is established based on the nodes included in the AST of this type of SQL statement and the node hierarchy relationship between each node; A first search unit, configured to search for a first target node belonging to an aggregate expression among the expression nodes of the AST; A calling unit, configured to call the sensitivity calculation function of the internal node of the first target node to obtain the sensitivity of the internal node of the first target node, and the sensitivity of the internal node of the first target node is used to execute the differential privacy algorithm for the first target node.

9. A processing device for Structured Query Language (SQL) statements, characterized in that Includes: A memory, a processor, and a computer program stored on the memory and executable on the processor, and when the processor executes the computer program, the processing method of the SQL statement according to any one of claims 1-7 is implemented.

10. A computer-readable storage medium, characterized in that, Instructions are stored in the computer-readable storage medium, and when the instructions are run on a terminal device, the terminal device is caused to execute the processing method of the SQL statement according to any one of claims 1-7.

Citation Information

Patent Citations

  • Method and device for data desensitization, storage medium and computer equipment

    CN111191276A