A query logic visualization method, device, electronic device and storage medium
By converting SQL query statements into abstract syntax trees and dividing them into dimensions, measurements and filtering conditions, and converting them into logical display controls for visual display, it solves the problem that users find it difficult to judge the correctness of SQL statements generated by LLM, and realizes the intuitive display of SQL query logic and the transparency of data analysis.
Patent Information
- Application Number
- CN202411940598.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-26
- Publication Date
- 2025-04-04
AI Technical Summary
In the prior art, the SQL query statement generated by the LLM may not match the user's actual query intention, making it difficult for users to judge their correctness, especially for users who do not have SQL knowledge.
By converting SQL query statements into abstract syntax trees, data selection information, filter condition information and result grouping information are determined, and they are divided into dimension fields, measurement fields and filter condition fields, which are converted into logical display controls, and are displayed in areas in the logical display page according to dimensions, measurements and filter conditions.
It realizes the visual display of the dimensions, measurements and filtering conditions of SQL query statements in the form of controls, so that users can determine the query logic of SQL query statements without deep SQL knowledge, and improves the transparency and interpretability of data analysis.
Smart Images

Figure CN119759941A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of computer technology, and in particular to a query logic visualization method, device, electronic device, and storage medium. Background Art
[0002] With the development of Large Language Models (LLM), LLM-based natural language to database structured query language (SQL) conversion technology has made a major breakthrough. This technology enables ordinary users to generate SQL statements through natural language, thereby realizing data exploration and analysis.
[0003] In the prior art, when data needs to be queried from a database, LLM can generate corresponding SQL query statements based on the user's natural language, execute the generated SQL query statements and display the corresponding query results. However, the SQL query statements generated by LLM may not match the user's actual query intentions, and if the user does not have SQL-related knowledge, he or she cannot judge their correctness. Summary of the invention
[0004] The present invention provides a query logic visualization method, device, electronic device and storage medium, which can visualize the query dimensions, metrics and screening conditions corresponding to the SQL query statement in the form of controls.
[0005] In a first aspect, an embodiment of the present invention provides a query logic visualization method, including:
[0006] Obtaining an SQL query statement, converting the SQL query statement into a corresponding abstract syntax tree, and determining data selection information, screening condition information, and result grouping information in the abstract syntax tree;
[0007] According to the result grouping information, the fields included in the data selection information are divided into dimension fields and metric fields;
[0008] According to a preset conversion method, the dimension field, the metric field, and the filtering condition field included in the filtering condition information are converted into corresponding logical display controls respectively;
[0009] A logic display page is displayed, wherein the logic display page includes the query results of each of the logic display controls and the SQL query statement, and each of the logic display controls is displayed in different regions according to the dimension, metric and filter condition.
[0010] In a second aspect, an embodiment of the present invention provides a query logic visualization device, including:
[0011] A first processing module is used to obtain an SQL query statement, convert the SQL query statement into a corresponding abstract syntax tree, and determine data selection information, screening condition information and result grouping information in the abstract syntax tree;
[0012] A second processing module, configured to divide the fields included in the data selection information into dimension fields and metric fields according to the result grouping information;
[0013] A third processing module is used to convert the dimension field, the metric field, and the filtering condition field included in the filtering condition information into corresponding logical display controls according to a preset conversion method;
[0014] The fourth processing module is used to display a logic display page, which includes the query results of each of the logic display controls and the SQL query statement, and each of the logic display controls is displayed in different regions according to dimensions, metrics and filtering conditions.
[0015] In a third aspect, an embodiment of the present invention provides an electronic device, including:
[0016] at least one processor; and
[0017] a memory communicatively connected to the at least one processor; wherein,
[0018] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can perform the method according to the first aspect.
[0019] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in the first aspect.
[0020] The technical solution of the embodiment of the present invention determines data selection information, filtering condition information and result grouping information according to the abstract syntax tree of the SQL query statement, determines the dimension field, metric field and filtering condition field based on the determined information, converts the determined fields into corresponding logic display controls, and displays each control in a region on the logic display page according to the dimension, metric and filtering condition. The query dimensions, metrics and filtering conditions corresponding to the SQL query statement are visually displayed in the form of controls, and the user does not need to have deep SQL knowledge, and can determine the query logic of the SQL query statement through the visually displayed controls.
[0021] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0023] Figure 1 is a flowchart of a query logic visualization method provided according to the first embodiment of the present invention;
[0024] Figure 2 is a schematic diagram of a logic display page provided according to the first embodiment of the present invention;
[0025] Figure 3 is a flowchart of a query logic visualization method provided according to Embodiment 2 of the present invention;
[0026] Figure 4 is a structural diagram of a query logic visualization device provided according to Embodiment 3 of the present invention;
[0027] Figure 5 It is a schematic diagram of the structure of an electronic device implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0028] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0029] It should be noted that the terms "first", "second", etc. in the present invention are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0030] Embodiment 1
[0031] Figure 1 This is a flowchart of a query logic visualization method provided according to Embodiment 1 of the present invention. This embodiment is applicable to the case of visualizing the query logic of SQL query statements. The method can be executed by a query logic visualization device, which can be implemented in the form of software and / or hardware and integrated in an electronic device. Further, the electronic device includes but is not limited to: a computer, a laptop, etc.
[0032] like Figure 1 As shown, the method includes:
[0033] S110: Obtain an SQL query statement, convert the SQL query statement into a corresponding abstract syntax tree, and determine data selection information, screening condition information, and result grouping information in the abstract syntax tree.
[0034] The SQL query statement may be a structured query language statement used to query data in a database. There is no limitation on the method of obtaining the SQL query statement. For example, the LLM may obtain the user's need to query data from the database. The need may be in the form of natural language, and the LLM converts the natural language into an SQL query statement. The type of data that the user needs to query from the database is subject to actual application needs.
[0035] In the embodiment of the present invention, the SQL query statement can be understood as a SELECT statement, which means data selection and can be used to retrieve data from one or more tables in a database. The SELECT statement can include one or more of the following SQL keywords, which are not specifically limited:
[0036] SELECT: This is a keyword used to specify which columns you want to select from the table as query results;
[0037] AS: a keyword used to rename columns or expressions in query results to make the query results more readable;
[0038] FROM: a keyword indicating the source of data, indicating the table to be queried;
[0039] WHERE: a keyword used to add filtering conditions to filter out data that meets specific standards. The filtering conditions are the conditions for filtering data in the table.
[0040] GROUP BY: a keyword used to group query results according to the values of one or more columns, usually used with aggregate functions (such as sum, average, etc.);
[0041] HAVING: It is a keyword used to further filter the grouped data. When used with GROUP BY, it is equivalent to conditionally filtering the grouped results again.
[0042] ORDER BY: This is the keyword used to sort the query results. You can specify one or more columns and the sorting method (such as ascending or descending);
[0043] LIMIT: A keyword used to limit the number of rows returned by a query. You can specify a specific number of rows as the maximum number of rows returned by the query.
[0044] In this step, based on obtaining the SQL query statement, the SQL query statement can be parsed by the SQL parser, the nodes of the abstract syntax tree are constructed according to the results of the syntax analysis, and the constructed nodes are connected to form a tree structure. In the abstract syntax tree, the keywords included in the SQL query statement can be represented as nodes of a specific type, such as SELECT corresponding to the selection node, listing the selected columns; FROM corresponding to the from node, specifying the data source; WHERE corresponding to the condition node, specifying the filtering condition, etc. Among them, the abstract syntax tree can be a structured representation of the SQL query statement, presenting the various components of the SQL query statement and their interrelationships through a tree structure.
[0045] In the case of determining the abstract syntax tree corresponding to the SQL query statement, the information of the node corresponding to the SELECT keyword in the abstract syntax tree can be used as data selection information; the information of the node corresponding to the WHERE keyword in the abstract syntax tree can be used as screening condition information; the information of the node corresponding to the GROUP BY keyword in the abstract syntax tree can be used as result grouping information. The data selection information can be information indicating the columns or expressions included in the query result; the screening condition information can be information indicating the screening condition of the query; and the result grouping information can be information indicating how to group the query result.
[0046] For example, the SQL query statement may be “SELECT area as "region", avg(salary) as "income (average)" FROM employee WHERE sex = 'male' and year(salary_date) = 2024 GROUP BY area ORDER BY avg(salary) LIMIT 1000”.
[0047] In the abstract syntax tree corresponding to the above SQL query statement, the node corresponding to SELECT contains two parts, "area", which is the region, and "avg(salary)", which is the average salary. "area" is named as the region and "avg(salary)" is named as the income (average) as the query result for output; the node corresponding to FROM points to the table named "employee", which is the employee table, indicating that the data comes from this table; there are two filtering conditions under the node corresponding to WHERE, the first one is "sex='male'", which means that only records with male gender are selected, and the second one is "year(salary_date)=2024", which means that the salary date is 2024. These two filtering conditions are AND logic; the node corresponding to GROUP BY points to "area", indicating that the query results need to be grouped by "area"; the node corresponding to ORDER BY points to "avg(salary)", indicating that the query results will be sorted in ascending order according to "avg(salary)"; the node corresponding to LIMIT points to 1000, indicating that the upper limit of the number of query results returned is 1000.
[0048] In the abstract syntax tree corresponding to the above SQL query statement, "area" and "avg(salary)" corresponding to the SELECT keyword are used as data selection information; "sex='male'" and "year(salary_date)=2024" corresponding to the WHERE keyword are used as screening condition information; and "area" corresponding to the GROUP BY keyword is used as result grouping information.
[0049] S120. Divide the fields included in the data selection information into dimension fields and metric fields according to the result grouping information.
[0050] Dimension fields can be fields that indicate query dimensions corresponding to SQL query statements. Query dimensions can be understood as dimensions for grouping query results, usually referring to non-numeric data, such as regions. Metric fields can be fields that indicate query metrics corresponding to SQL query statements, usually numeric data, mainly used for quantitative analysis, such as salary. Dimension fields do not need to be directly involved in mathematical operations, but are used to provide context for metric fields; metric fields are the core of data analysis.
[0051] In one embodiment, according to the result grouping information, the fields included in the data selection information are divided into dimension fields and metric fields, including: among the fields included in the data selection information, the fields included in the result grouping information are determined as dimension fields, and the fields other than the dimension fields are determined as metric fields.
[0052] That is, among the fields included in the data selection information, the fields that appear in the result grouping information are determined as dimension fields, and the other fields except the dimension fields are determined as metric fields.
[0053] For example, the data selection information includes two fields, "area" and "avg(salary)", and the result grouping information includes the "area" field. Then, the "area" in the data selection information is used as the dimension field, and the "avg(salary)" in the data selection information is used as the measurement field.
[0054] S130. According to a preset conversion method, the dimension field, the metric field, and the filtering condition field included in the filtering condition information are respectively converted into corresponding logical display controls.
[0055] The filter condition field may be a field indicating the filter condition of the query corresponding to the SQL query statement, and each filter condition may be used as a filter condition field. For example, the filter condition field may be "sex = 'male'" included in the filter condition information, and the filter condition field may be "year (salary_date) = 2024" included in the filter condition information, and the two filter condition fields are logically ANDed.
[0056] The logic display control can be a control for displaying the query logic of an SQL query statement. The query logic can include the query dimensions, metrics, and filter conditions of the SQL query statement. The query dimensions correspond to dimension fields, the query metrics correspond to metric fields, and the query filter conditions correspond to filter condition fields.
[0057] The logic display control can be a field type control or an SQL fragment type control. Among them, the field type control can be a control of the type displayed as a field, that is, the content displayed by the control is in the form of a field; the SQL fragment type control can be a control of the type displayed as an SQL fragment, that is, the content displayed by the control is in the form of an SQL fragment, and the SQL fragment is a partial fragment in the SQL query statement. The SQL fragment in the SQL fragment type control can be editable.
[0058] The preset conversion method can be a preset method for converting dimension fields, metric fields, and filter condition fields into corresponding logical display controls. In actual applications, different conversion methods can be preset for dimension fields, metric fields, and filter condition fields, and the preset conversion method can set what kind of field content a certain field contains before it can be converted into a field type control.
[0059] In this step, for any field among the dimension field, measure field and filter condition field, you can use the corresponding preset conversion method to determine whether a field can be converted into a field type control; if so, convert it into a field type control, and when converting it to a field type control, you can convert the SQL description in the field into the corresponding natural language, logical operators, etc. as the name of the control to display; otherwise, convert it into an SQL fragment type control, and when converting it to an SQL fragment type control, the entire field can be directly displayed as the name of the control.
[0060] For example, the logical display control corresponding to the dimension field "area" is a field type control, and the name displayed by the logical display control is "region"; the logical display control corresponding to the metric field "avg(salary)" is a field type control, and the name displayed by the logical display control is "income (average)"; the logical display control corresponding to the filter condition field "sex='male'" is a field type control, and the name displayed by the logical display control is "gender: equal to male"; the logical display control corresponding to the filter condition field "year(salary_date)=2024" is a SQL fragment type control, and the name displayed by the logical display control is "year(salary_date)=2024".
[0061] It should be noted that, in the embodiment of the present invention, when S110 determines the abstract syntax tree corresponding to the SQL query statement, the abstract syntax tree can be parsed and converted into the configuration of the corresponding domain-specific language (DSL), and then the DSL configuration is converted into a logic display control. That is, the conversion between the abstract syntax tree and the front-end logic display control is undertaken by DSL, and the core processing logic of the DSL conversion includes the part of determining the data selection information, the screening condition information and the result grouping information in the abstract syntax tree in S110, and the parts of S120 and S130.
[0062] In the DSL configuration, you can configure which nodes in the abstract syntax tree are used as data selection information, which nodes are used as filtering condition information, and which nodes are used as result grouping information; based on the result grouping information, you can configure which nodes in the nodes corresponding to the data selection information are used as dimension fields and which nodes are used as metric fields; you can configure which nodes in the nodes included in the filtering condition information are used as the same filtering condition field, as well as the logical relationship between the filtering condition fields.
[0063] S140: Display a logic display page, wherein the logic display page includes the query results of each of the logic display controls and the SQL query statement, and each of the logic display controls is displayed in different regions according to the dimension, metric, and filter condition.
[0064] In the embodiment of the present invention, when an SQL query statement is obtained, on the one hand, the SQL query statement can be executed to obtain the corresponding query result; on the other hand, S110 to S130 can be executed to determine the logical display controls corresponding to the dimension field, the metric field, and the filter condition field. The execution order of the above two aspects is not limited. When both of the above two aspects are executed, S140 can be executed.
[0065] In this step, the query results of the SQL query statement can be displayed on the logic display page; the three areas divided by dimension, measure and filter condition can also be displayed on the logic display page, and the logic display control obtained by converting the dimension field is displayed in the area corresponding to the dimension, the logic display control obtained by converting the measure field is displayed in the area corresponding to the measure, and the logic display control obtained by converting the filter condition field is displayed in the area corresponding to the filter condition. In the logic display page, there is no limitation on the display positions of the query results of the SQL query statement and the above three areas.
[0066] The query results of the SQL query statement can be displayed in the form of a table or a graph in the logic display page, such as a line graph, a pie chart, a scatter plot, a heat map, a rose chart, etc., which are not limited here.
[0067] Figure 2 It is a schematic diagram of a logic display page provided according to the first embodiment of the present invention. In the logic display page, the upper part displays multiple logic display controls, wherein the dimension area displays the logic display control corresponding to the dimension field, namely "region", the metric area displays the logic display control corresponding to the metric field, namely "income (average)", and the filter area displays the logic display control corresponding to the filter condition field, namely "gender: equal to male" and "year (salary_date) = 2024"; the lower part displays the query results of the SQL query statement in the form of a table, namely, the income (average) of region one is 115,000, and the income (average) of region two is 12,000.
[0068] pass Figure 2 The combination of the dimension area, measure area, and filter area in the table can show the query logic of the SQL query statement. That is, with "gender: equal to male" and "year(salary_date) = 2024" as the filter conditions, the average income is counted according to different regions as the statistical dimension. That is, the average income of men in each region in 2024 is counted.
[0069] The technical solution of the embodiment of the present invention determines data selection information, filtering condition information and result grouping information according to the abstract syntax tree of the SQL query statement, determines the dimension field, metric field and filtering condition field based on the determined information, converts the determined fields into corresponding logic display controls, and displays each control in a region on the logic display page according to the dimension, metric and filtering condition. The query dimensions, metrics and filtering conditions corresponding to the SQL query statement are visually displayed in the form of controls, and the user does not need to have deep SQL knowledge, and can determine the query logic of the SQL query statement through the visually displayed controls.
[0070] In one embodiment, the method further comprises:
[0071] Determining result sorting information in the abstract syntax tree;
[0072] Determine a field in the data selection information that is consistent with a field included in the result sorting information;
[0073] In the logic display control obtained by the consistent field conversion, the sorting configuration information corresponding to the result sorting information is visually displayed.
[0074] When the abstract syntax tree corresponding to the SQL query statement is determined, the information of the node corresponding to the ORDER BY keyword in the abstract syntax tree can be used as the result sorting information. The result sorting information can be information indicating the sorting of the query results. Exemplarily, "avg(salary)" corresponding to the ORDER BY keyword in the example of the above SQL query statement is used as the result sorting information, and the corresponding sorting method is ascending sorting.
[0075] Determine the field in the data selection information that is consistent with the field included in the result sorting information, that is, the "avg(salary)" field in the data selection information, that is, the metric field included in the data selection information.
[0076] In the logic display control obtained by converting the metric field, the sorting configuration information corresponding to the result sorting information is visually displayed. The sorting configuration information may be information indicating the sorting method. Exemplarily, in response to a click operation on the metric control in the logic display page, a pop-up window is displayed: the sorting method is ascending.
[0077] In one embodiment, the method further comprises:
[0078] Determining query result restriction information in the abstract syntax tree;
[0079] The query result restriction information is displayed on the logic display page.
[0080] When the abstract syntax tree corresponding to the SQL query statement is determined, the information of the node corresponding to the LIMIT keyword in the abstract syntax tree can be used as query result restriction information. The query result restriction information can be information indicating restriction on the query result, such as the maximum number of rows of the returned query result is 1000.
[0081] Display query result limit information to the logical display page, such as Figure 2 The maximum number of rows displayed in the logic display page shown is 1000.
[0082] Embodiment 2
[0083] Figure 3 It is a flowchart of a query logic visualization method provided according to the second embodiment of the present invention. This embodiment is based on the above-mentioned first embodiment, and further refines the conversion of the dimension field, the metric field, and the filter condition field included in the filter condition information into corresponding logic display controls according to the preset conversion method. Among them, the preset conversion method includes a first conversion method and a second conversion method; the logic display control is a field type control or an SQL fragment type control.
[0084] like Figure 3 As shown, the method includes:
[0085] S110: Obtain an SQL query statement, convert the SQL query statement into a corresponding abstract syntax tree, and determine data selection information, screening condition information, and result grouping information in the abstract syntax tree.
[0086] S120. Divide the fields included in the data selection information into dimension fields and metric fields according to the result grouping information.
[0087] S131. According to a first conversion method, convert the dimension field and the metric field into corresponding logical display controls respectively.
[0088] In one embodiment, the first conversion method includes:
[0089] In the case where the target field does not include a function but only includes a field, converting the target field into the field type control; wherein the target field is the dimension field or the metric field;
[0090] In the case where the target field includes a function and a field, determining whether the included function is within the function range supported by the visual display, if so, converting the target field into the field type control, otherwise, converting the target field into the SQL fragment type control;
[0091] In the case where the target field includes sub-query logic, the target field is converted into the SQL fragment type control.
[0092] In the abstract syntax tree corresponding to the SQL query statement, the nodes corresponding to the SELECT keyword are parsed, and each node is traversed in order to determine the node corresponding to the target field; if the nodes corresponding to the target field are all composed of simple fields, the target field is converted into a field type control, such as parsing the dimension field "area" into the field type control "region"; if the node corresponding to the target field contains functions plus fields, it is determined whether the included functions are within the function range supported by the visualization display. The function range supported by the visualization can be predetermined. If so, the target field is converted into a field type control, such as parsing the metric field "avg(salary)" into the field type control "income (average)", otherwise the target field is converted into an SQL fragment type control; if the node corresponding to the target field contains complex logic such as subqueries, the target field is converted into an SQL fragment type control.
[0093] S132: According to the second conversion method, the filtering condition field included in the filtering condition information is converted into a corresponding logic display control.
[0094] In one embodiment, the second conversion method includes:
[0095] Determine whether the screening condition field supports conversion to the field type control, if supported, convert it to the field type control, if not supported, convert it to the SQL fragment type control; wherein the conditions supporting conversion include at least one of the following:
[0096] The screening condition fields are multiple and the multiple fields correspond and are logical;
[0097] The filter condition field is a plurality of AND logical OR logical corresponding to a single field;
[0098] The screening condition field is a string type field, and the screening conditions corresponding to the screening condition field include equal to, contain, do not contain, start with, end with, is empty, and is not empty;
[0099] The screening condition field is a numerical type field, and the screening conditions corresponding to the screening condition field include greater than, less than, greater than or equal to, less than or equal to, equal to, not equal to, is empty, and is not empty;
[0100] The filtering condition field is a date type field, and the filtering conditions corresponding to the filtering condition field include fixed date, dynamic date, and filtering by date granularity.
[0101] In the abstract syntax tree corresponding to the SQL query statement, parse the nodes corresponding to the WHERE keyword, perform in-order traversal on each node, determine the node corresponding to the filter condition field; and determine whether the node corresponding to the filter condition field supports conversion to a field type control.
[0102] In the conditions that support conversion, the following are judged: the filter condition field is multiple and the multiple fields correspond and logically, that is, the filter condition is multiple conditions for multiple fields, and the multiple conditions are AND logically; the filter condition field is multiple and logically or logically corresponding to a single field, that is, the filter condition is multiple conditions for a single field, and the multiple conditions can be AND logically or OR logically; the filter condition field is a string type field, that is, the filter condition field is a field composed of strings; the filter condition field is a numeric type field, that is, the filter condition field is a field composed of numeric values; the filter condition field is a date type field, that is, the filter condition field is a field composed of dates.
[0103] In the embodiment of the present invention, the filtering condition information includes the filtering condition fields "sex='male'" and "year(salary_date)=2024", the filtering condition fields are multiple conditions for multiple fields, and the multiple conditions are AND logic, so the two fields can be parsed as controls respectively; "sex='male'" is a string type field, and the filtering condition includes equals, so it is parsed as a field type control "sex: equals male"; "year(salary_date)=2024" is a field of year function plus date type, which is not within the scope of the above-mentioned support for conversion to field type controls, so it is parsed as an SQL fragment type control "year(salary_date)=2024".
[0104] S140: Display a logic display page, wherein the logic display page includes the query results of each of the logic display controls and the SQL query statement, and each of the logic display controls is displayed in different regions according to the dimension, metric, and filter condition.
[0105] The technical solution of the embodiment of the present invention converts dimension fields, metric fields, and filter condition fields into corresponding logic display controls through a specific conversion method, focusing on explaining the logic and intention behind SQL queries. Displaying the query logic in the form of visual controls helps users intuitively understand the data analysis process; it can not only lower the SQL learning threshold, but also improve the transparency and explainability of data analysis, aiming to provide a more intuitive, easy-to-understand and powerful data analysis tool.
[0106] Embodiment 3
[0107] Figure 4is a schematic diagram of the structure of a query logic visualization device provided according to Embodiment 3 of the present invention. This embodiment is applicable to the case of visualizing the query logic of SQL query statements. Figure 4 As shown, the specific structure of the device includes:
[0108] The first processing module 41 is used to obtain an SQL query statement, convert the SQL query statement into a corresponding abstract syntax tree, and determine data selection information, screening condition information and result grouping information in the abstract syntax tree;
[0109] A second processing module 42 is used to divide the fields included in the data selection information into dimension fields and metric fields according to the result grouping information;
[0110] The third processing module 43 is used to convert the dimension field, the metric field and the filtering condition field included in the filtering condition information into corresponding logical display controls respectively according to a preset conversion method;
[0111] The fourth processing module 44 is used to display a logic display page, which includes the query results of each of the logic display controls and the SQL query statement, and each of the logic display controls is displayed in different regions according to the dimension, metric and filter condition.
[0112] The query logic visualization device provided in this embodiment obtains SQL query statements through the first processing module, converts the SQL query statements into corresponding abstract syntax trees, and determines data selection information, filtering condition information and result grouping information in the abstract syntax tree; divides the fields included in the data selection information into dimension fields and metric fields according to the result grouping information through the second processing module; converts the dimension fields, the metric fields and the filtering condition fields included in the filtering condition information into corresponding logic display controls according to a preset conversion method through the third processing module; and displays a logic display page through the fourth processing module, the logic display page includes the query results of each logic display control and the SQL query statement, and each logic display control is displayed in different areas according to the dimension, metric and filtering condition. The query dimensions, metrics and filtering conditions corresponding to the SQL query statement are visually displayed in the form of controls, and users do not need to have deep SQL knowledge, and can determine the query logic of the SQL query statement through the visually displayed controls.
[0113] Furthermore, the second processing module 42 is specifically configured to:
[0114] Among the fields included in the data selection information, the fields included in the result grouping information are determined as dimension fields, and the fields other than the dimension fields are determined as metric fields.
[0115] Furthermore, the third processing module 43 is specifically used for:
[0116] According to the first conversion method, the dimension field and the metric field are respectively converted into corresponding logical display controls;
[0117] According to the second conversion method, the filtering condition field included in the filtering condition information is converted into a corresponding logic display control;
[0118] Among them, the preset conversion method includes the first conversion method and the second conversion method; the logic display control is a field type control or an SQL fragment type control.
[0119] Furthermore, the first conversion method includes:
[0120] In the case where the target field does not include a function but only includes a field, converting the target field into the field type control; wherein the target field is the dimension field or the metric field;
[0121] In the case where the target field includes a function and a field, determining whether the included function is within the function range supported by the visual display, if so, converting the target field into the field type control, otherwise, converting the target field into the SQL fragment type control;
[0122] In the case where the target field includes sub-query logic, the target field is converted into the SQL fragment type control.
[0123] Furthermore, the second conversion method includes:
[0124] Determine whether the screening condition field supports conversion to the field type control, if supported, convert it to the field type control, if not supported, convert it to the SQL fragment type control; wherein the conditions supporting conversion include at least one of the following:
[0125] The screening condition fields are multiple and the multiple fields correspond and are logical;
[0126] The filter condition field is a plurality of AND logical OR logical corresponding to a single field;
[0127] The screening condition field is a string type field, and the screening conditions corresponding to the screening condition field include equal to, contain, do not contain, start with, end with, is empty, and is not empty;
[0128] The screening condition field is a numerical type field, and the screening conditions corresponding to the screening condition field include greater than, less than, greater than or equal to, less than or equal to, equal to, not equal to, is empty, and is not empty;
[0129] The filtering condition field is a date type field, and the filtering conditions corresponding to the filtering condition field include fixed date, dynamic date, and filtering by date granularity.
[0130] Furthermore, the device also includes:
[0131] A first determining module, configured to determine result sorting information in the abstract syntax tree;
[0132] A second determination module, used to determine a field in the data selection information that is consistent with a field included in the result sorting information;
[0133] The first display module is used to visually display the sorting configuration information corresponding to the result sorting information in the logic display control obtained by the consistent field conversion.
[0134] Furthermore, the device also includes:
[0135] A third determination module, used to determine query result restriction information in the abstract syntax tree;
[0136] The second display module is used to display the query result restriction information on the logic display page.
[0137] The query logic visualization device provided in the embodiment of the present invention can execute the query logic visualization method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0138] Embodiment 4
[0139] Figure 5 Schematic diagram of the structure of the electronic device implementing the embodiment of the present invention. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0140] like Figure 5As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0141] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0142] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as the query logic visualization method.
[0143] In some embodiments, the query logic visualization method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the query logic visualization method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the query logic visualization method in any other appropriate manner (e.g., by means of firmware).
[0144] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0145] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0146] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, 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 foregoing.
[0147] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0148] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0149] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0150] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0151] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A query logic visualization method, characterized in that: include: Obtaining an SQL query statement, converting the SQL query statement into a corresponding abstract syntax tree, and determining data selection information, screening condition information, and result grouping information in the abstract syntax tree; According to the result grouping information, the fields included in the data selection information are divided into dimension fields and metric fields; According to a preset conversion method, the dimension field, the metric field, and the filtering condition field included in the filtering condition information are converted into corresponding logical display controls respectively; A logic display page is displayed, wherein the logic display page includes the query results of each of the logic display controls and the SQL query statement, and each of the logic display controls is displayed in different regions according to the dimension, metric and filter condition.
2. The method according to claim 1, characterized in that According to the result grouping information, the fields included in the data selection information are divided into dimension fields and metric fields, including: Among the fields included in the data selection information, the fields included in the result grouping information are determined as dimension fields, and the fields other than the dimension fields are determined as metric fields.
3. The method according to claim 1, characterized in that According to a preset conversion method, the dimension field, the metric field, and the filter condition field included in the filter condition information are respectively converted into corresponding logical display controls, including: According to the first conversion method, the dimension field and the metric field are respectively converted into corresponding logical display controls; According to the second conversion method, the filtering condition field included in the filtering condition information is converted into a corresponding logic display control; Among them, the preset conversion method includes the first conversion method and the second conversion method; the logic display control is a field type control or an SQL fragment type control.
4. The method according to claim 3, characterized in that The first conversion method includes: In the case where the target field does not include a function but only includes a field, converting the target field into the field type control; wherein the target field is the dimension field or the metric field; In the case where the target field includes a function and a field, determining whether the included function is within the function range supported by the visual display, if so, converting the target field into the field type control, if not, converting the target field into the SQL fragment type control; In the case where the target field includes sub-query logic, the target field is converted into the SQL fragment type control.
5. The method according to claim 3, characterized in that: The second conversion method includes: Determine whether the screening condition field supports conversion to the field type control, if supported, convert it to the field type control, if not supported, convert it to the SQL fragment type control; wherein the conditions supporting conversion include at least one of the following: The screening condition fields are multiple and the multiple fields correspond and are logical; The filter condition field is a plurality of AND logical OR logical corresponding to a single field; The screening condition field is a string type field, and the screening conditions corresponding to the screening condition field include equal to, contain, do not contain, start with, end with, is empty, and is not empty; The screening condition field is a numerical type field, and the screening conditions corresponding to the screening condition field include greater than, less than, greater than or equal to, less than or equal to, equal to, not equal to, is empty, and is not empty; The filtering condition field is a date type field, and the filtering conditions corresponding to the filtering condition field include fixed date, dynamic date, and filtering by date granularity.
6. The method according to claim 1, characterized in that Also includes: Determining result sorting information in the abstract syntax tree; Determine a field in the data selection information that is consistent with a field included in the result sorting information; In the logic display control obtained by the consistent field conversion, the sorting configuration information corresponding to the result sorting information is visually displayed.
7. The method according to claim 1, characterized in that Also includes: Determining query result restriction information in the abstract syntax tree; The query result restriction information is displayed on the logic display page.
8. A query logic visualization device, characterized in that: include: A first processing module is used to obtain an SQL query statement, convert the SQL query statement into a corresponding abstract syntax tree, and determine data selection information, screening condition information and result grouping information in the abstract syntax tree; A second processing module, configured to divide the fields included in the data selection information into dimension fields and metric fields according to the result grouping information; A third processing module is used to convert the dimension field, the metric field, and the filtering condition field included in the filtering condition information into corresponding logical display controls according to a preset conversion method; The fourth processing module is used to display a logic display page, which includes the query results of each of the logic display controls and the SQL query statement, and each of the logic display controls is displayed in different regions according to dimensions, metrics and filtering conditions.
9. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can perform the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.