Data query method and device, storage medium and computing equipment
By extracting metadata from the database and building a visual tree structure, query statements are automatically generated, which solves the problem in the existing technology that users need to write their own query statements, and improves the flexibility and convenience of data query.
Patent Information
- Application Number
- CN202410502697.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-24
- Publication Date
- 2024-08-23
AI Technical Summary
In the existing technology, users need to write their own query statements, which results in a high threshold for use, and the query system is limited to predefined models and cannot meet complex and changing query requirements.
By extracting table metadata and field metadata from the database's metadata, a visual tree structure is constructed, allowing users to select target metadata and configure query conditions, and automatically generate query statements.
It reduces the need for users to write query statements, improves the flexibility and convenience of data query, and adapts to complex and changing query needs.
Smart Images

Figure CN118535594A
Abstract
Description
Technical Field
[0001] The embodiments of the present disclosure relate to the field of computer technology, and more specifically, the embodiments of the present disclosure relate to a data query method, apparatus, storage medium and computing device. Background Art
[0002] This section is intended to provide a background or context to the embodiments of the present disclosure. No description herein is admitted to be prior art by virtue of its inclusion in this section.
[0003] In the related art, when users conduct data query, they need to write query statements by themselves, which requires users to have relevant knowledge. Therefore, for users who do not have relevant knowledge, the threshold for use is relatively high. Summary of the invention
[0004] In a first aspect of the embodiments of the present disclosure, a data query method is provided. Applicable to a query system connected to a database, the method comprising:
[0005] Extracting table metadata and field metadata related to a data table in the database from the metadata of the database;
[0006] Acquire target metadata for data query selected from the table metadata and field metadata and query conditions configured for the target metadata;
[0007] A query statement for database query is generated according to the target metadata and the query condition, and data is queried from the database using the query statement.
[0008] Optionally, the table metadata includes a subject and a table type of the data table, and the table type includes a dimension table and a fact table;
[0009] Wherein, the dimension table includes a table recording dimension fields, and the fact table includes a table recording metric fields; the dimension fields include offline fields in the data table; and the metric fields include numerical fields in the data table;
[0010] The field metadata includes metadata corresponding to the dimension fields of the dimension table records and metadata corresponding to the metric fields of the fact table records.
[0011] Optionally, after extracting table metadata and field metadata related to a data table in the database from the metadata of the database, the method further includes:
[0012] Obtaining the dimension table and fact table of the table metadata, and further obtaining the dimension fields and metric fields of the dimension table and fact table records;
[0013] The acquired subject of the dimension table and the subject of the fact table are used as first-level nodes, and the dimension fields of the dimension table records and the metric fields of the fact table records are used as second-level nodes under the first-level nodes to construct a visual tree structure;
[0014] The acquiring target metadata selected from the table metadata and the field metadata for data query and the query condition configured for the target metadata includes:
[0015] In response to a configuration operation performed by a user on a secondary node in the visualized tree structure, a target dimension field and a target metric field corresponding to the secondary node of the configuration operation are obtained;
[0016] Matching target metadata corresponding to the target dimension field and the target metric field from the field metadata;
[0017] The query condition configured by the configuration operation is used as a query condition for the target metadata.
[0018] Optionally, the query condition includes condition screening and / or aggregation mode;
[0019] Among them, conditional filtering is used to set conditions for the selected dimension field or measure field to determine the data query scope;
[0020] The aggregation method is used to set the aggregation method for the metric field to perform statistical analysis on the queried data.
[0021] Optionally, the query statement includes an SQL statement, and generating a query statement for database query according to the target metadata and the query condition includes:
[0022] If the target dimension field is located in one dimension table, and the target metric field is located in one fact table, the first writing rule is executed, and the first writing rule includes writing the target dimension field and the target metric field into the initial SQL statement, and splicing the where filter condition and the aggregation method in the initial SQL statement;
[0023] If the target dimension field is located in at least two dimension tables, and the target metric field is located in one fact table, a second write rule is executed, wherein the second write rule includes concatenating the primary key of each dimension table associated with the foreign key of the fact table in the initial SQL statement, and executing the first write rule after concatenation;
[0024] If the target dimension field is located in at least two dimension tables and the target metric field is located in at least two fact tables, a third write rule is executed, wherein the third write rule includes executing the second write rule for each fact table and concatenating a union all in the initial SQL statement for aggregating the associated results of each fact table associated dimension table.
[0025] Optionally, before extracting table metadata related to a data table in the database from the metadata of the database, the method further includes:
[0026] Sending authentication information to the database for access authentication through an access interface provided by the database, so as to establish a connection with the database after the authentication is passed;
[0027] After the connection is successful, the metadata of the database is read from the storage location in the database for storing metadata, and the read metadata is stored locally;
[0028] The step of extracting table metadata and field metadata related to a data table in the database from metadata of the database includes:
[0029] Table metadata and field metadata related to the data table in the database are extracted from the metadata of the database stored locally.
[0030] Optionally, after querying data from the database using the database query language, the method further includes:
[0031] Visualize the query results.
[0032] Optionally, before using the database query language to query data from the database, the method further includes:
[0033] In response to a query request configured with a visualization type, querying data from the database using the database query language;
[0034] The visual display of the query results includes:
[0035] The query results are converted into a table report of the visualization type and then output for display.
[0036] Optionally, the database includes a distributed database.
[0037] Optionally, the distributed database includes an OLAP database.
[0038] In a second aspect of the embodiments of the present disclosure, a data query device is provided, which is applied to a query system connected to a database, and the device includes:
[0039] An extraction unit, extracting table metadata and field metadata related to a data table in the database from the metadata of the database;
[0040] An acquisition unit, which acquires target metadata selected from the table metadata and the field metadata for data query and a query condition configured for the target metadata;
[0041] The query unit generates a query statement for database query according to the target metadata and the query condition, and uses the query statement to query data from the database.
[0042] Optionally, the table metadata includes a subject and a table type of the data table, and the table type includes a dimension table and a fact table;
[0043] Wherein, the dimension table includes a table recording dimension fields, and the fact table includes a table recording metric fields; the dimension fields include offline fields in the data table; and the metric fields include numerical fields in the data table;
[0044] The field metadata includes metadata corresponding to the dimension fields of the dimension table records and metadata corresponding to the metric fields of the fact table records.
[0045] Optionally, after the extraction unit, the method further includes:
[0046] A construction unit is configured to obtain a dimension table and a fact table of the table metadata, and further obtain dimension fields and metric fields recorded in the dimension table and the fact table; the obtained subject of the dimension table and the subject of the fact table are used as first-level nodes, and the dimension fields recorded in the dimension table and the metric fields recorded in the fact table are used as second-level nodes under the first-level nodes to construct a visual tree structure;
[0047] The acquisition unit further includes: in response to a user's configuration operation on a secondary node in the visualized tree structure, acquiring a target dimension field and a target metric field corresponding to the secondary node of the configuration operation; matching target metadata corresponding to the target dimension field and the target metric field from the field metadata; and using the query condition configured by the configuration operation as a query condition for the target metadata.
[0048] Optionally, the query condition includes condition screening and / or aggregation mode;
[0049] Among them, conditional filtering is used to set conditions for the selected dimension field or measure field to determine the data query scope;
[0050] The aggregation method is used to set the aggregation method for the metric field to perform statistical analysis on the queried data.
[0051] Optionally, the query statement includes an SQL statement, and when the query unit generates a query statement for database query according to the target metadata and the query condition, the query unit further includes:
[0052] The first generating subunit executes a first writing rule if the target dimension field is located in one dimension table and the target metric field is located in one fact table. The first writing rule includes writing the target dimension field and the target metric field into an initial SQL statement and splicing a where filter condition and an aggregation method into the initial SQL statement.
[0053] The second generating subunit executes a second writing rule if the target dimension field is located in at least two dimension tables and the target metric field is located in one fact table, wherein the second writing rule includes concatenating the primary key of each dimension table associated with the foreign key of the fact table in the initial SQL statement and executing the first writing rule after concatenation;
[0054] The third generating subunit executes a third writing rule if the target dimension field is located in at least two dimension tables and the target metric field is located in at least two fact tables. The third writing rule includes executing the second writing rule for each fact table and concatenating a unionall in an initial SQL statement for aggregating the associated results of each fact table associated dimension table.
[0055] Optionally, before the extraction unit, it also includes:
[0056] A connection unit, which sends authentication information to the database for access authentication through an access interface provided by the database, so as to establish a connection with the database after the authentication is passed;
[0057] The storage unit, after the connection is successful, reads the metadata of the database from the storage location in the database for storing metadata, and stores the read metadata locally;
[0058] The extracting unit further includes extracting table metadata related to the data table in the database from the metadata of the database stored locally.
[0059] Optionally, after the query unit, the following is further included:
[0060] The display unit displays the query results visually.
[0061] Optionally, before the query unit uses the database query language to query data from the database, the query unit further includes, in response to a query request configured with a visualization type, using the database query language to query data from the database;
[0062] The display unit further includes converting the query results into a table report of the visualization type and then outputting it for display.
[0063] Optionally, the database includes a distributed database.
[0064] Optionally, the distributed database includes an OLAP database.
[0065] In a third aspect of the embodiments of the present disclosure, a computer-readable storage medium is provided, comprising:
[0066] When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the data query method as described in any of the preceding items.
[0067] In a fourth aspect of the embodiments of the present disclosure, there is provided a computing device, comprising:
[0068] processor;
[0069] a memory for storing instructions executable by the processor;
[0070] Wherein, the processor is configured to execute the executable instructions to implement the data query method as described in any of the preceding items.
[0071] According to the data query solution provided by the embodiment of the present disclosure, by reading the metadata of the database and extracting the table metadata and field metadata, the user can select the target metadata and query conditions for data query, and then automatically generate query statements corresponding to the target metadata and query conditions. Since the user does not need to write the query statement by himself, the usage threshold is low. BRIEF DESCRIPTION OF THE DRAWINGS
[0072] The above and other objects, features and advantages of the exemplary embodiments of the present disclosure will become readily understood by reading the detailed description below with reference to the accompanying drawings. In the accompanying drawings, several embodiments of the present disclosure are shown in an exemplary and non-limiting manner, in which:
[0073] Figure 1 The system architecture diagram applicable to data query provided by the present disclosure is schematically shown;
[0074] Figure 2 The following schematically shows a data query method provided by the present disclosure;
[0075] Figure 3 The schematic diagram of metadata acquisition provided by the present disclosure is schematically shown;
[0076] Figure 4 The schematic diagram of metadata processing provided by the present disclosure is schematically shown;
[0077] Figure 5 The schematic diagram of the visualization interface provided by the present disclosure is schematically shown;
[0078] Figure 6 The medium schematic diagram provided by the present disclosure is schematically shown;
[0079] Figure 7 The following schematically shows a data query device provided by the present disclosure;
[0080] Figure 8 The schematic diagram of the computing device provided by the present disclosure is schematically shown.
[0081] In the drawings, the same or corresponding reference numerals represent the same or corresponding parts. DETAILED DESCRIPTION
[0082] The principles and spirit of the present disclosure will be described below with reference to several exemplary embodiments. It should be understood that these embodiments are provided only to enable those skilled in the art to better understand and implement the present disclosure, and are not intended to limit the scope of the present disclosure in any way. On the contrary, these embodiments are provided to make the present disclosure more thorough and complete, and to fully convey the scope of the present disclosure to those skilled in the art.
[0083] Those skilled in the art will appreciate that the embodiments of the present disclosure may be implemented as a system, device, apparatus, method or computer program product. Therefore, the present disclosure may be specifically implemented in the following forms, namely: complete hardware, complete software (including firmware, resident software, microcode, etc.), or a combination of hardware and software.
[0084] According to an embodiment of the present disclosure, a data query method, a computer-readable storage medium, an apparatus, and a computing device are proposed.
[0085] It should be understood herein that any number of elements in the drawings is for illustration rather than limitation, and any naming is only for distinction rather than having any limiting meaning.
[0086] The principle and spirit of the present disclosure are explained in detail below with reference to several representative embodiments of the present disclosure.
[0087] The data involved in the present disclosure may be data authorized by the user or fully authorized by all parties. The collection, dissemination, and use of the data shall comply with the requirements of relevant national laws and regulations. The implementation methods / examples of the present disclosure may be combined with each other.
[0088] In the present disclosure, metadata may refer to data that describes data, such as the structure, derivative logic, usage rights, etc. of the data.
[0089] As mentioned above, in the related technologies, users need to write query statements by themselves to query data, which requires users to have relevant knowledge. Therefore, for users who do not have relevant knowledge, the threshold for use is relatively high.
[0090] In addition, the query system in the related technology generally predefines a fixed query model (fixing the dimension fields and measurement fields to be queried), and the user's query and analysis are usually limited to the predefined model, and the predefined model may not meet the user's complex and changing query needs. SUMMARY OF THE INVENTION
[0092] The present disclosure aims to provide a data query solution, which reads the metadata of the database and extracts the table metadata and field metadata, so that users can select target metadata and query conditions for data query, and then automatically generate query statements corresponding to the target metadata and query conditions. Since users do not need to write query statements themselves, the usage threshold is low.
[0093] On the other hand, users can flexibly select the target metadata (dimensional fields, metric fields) and query conditions for data query without being restricted by predefined query models, thereby improving the flexibility and convenience of data query.
[0094] After introducing the basic principles of the present disclosure, various non-limiting embodiments of the present disclosure are described in detail below.
[0095] Application Scenario Overview
[0096] The database of the present disclosure may include a distributed database; the distributed database may include an OLAP (Online Analytical Processing) database.
[0097] First reference Figure 1 A system architecture diagram suitable for data query is shown. In the system architecture diagram, a query system connected to a database is included, and the query system can further include a metadata processing module, a metadata storage module, a visualization module, a query statement generation module and a query statement execution module.
[0098] Wherein, the metadata processing module is used to obtain metadata of the database.
[0099] Exemplarily, the metadata processing module may connect to a database through an access interface (API) provided by the database, thereby acquiring metadata of the database.
[0100] The metadata storage module may be used to extract table metadata and field metadata related to the data table based on the metadata of the database acquired by the metadata processing module, and store the extracted table metadata and field metadata locally.
[0101] The visualization module can visualize the table metadata and field metadata stored locally by the metadatabase storage module for the user to select from.
[0102] Exemplarily, the visualization module can construct a graphical interface, which can display all selectable metadata in a tree structure, and support click, drag and search, etc.
[0103] The query statement generating module is used to automatically generate a query statement according to the target metadata selected by the user and the query conditions configured for the target metadata after the user confirms the selection result.
[0104] Exemplarily, if the selectable metadata displayed in the above graphical interface is a tree structure constructed with corresponding nodes, then after the user confirms the selection result, the corresponding target metadata is matched from the locally stored metadata according to the node selected by the user.
[0105] The query statement execution module is used to submit the query statement generated by the query statement generation module to the database for query through the query interface provided by the database. If the query fails, an error message is returned; if the query succeeds, a query result can be returned.
[0106] The present disclosure reads the metadata of the database to mark the table metadata and field metadata representing the dimension and measure, and provides them to the user through a graphical interface for flexible selection. Based on the user's selection, a query statement is automatically generated to execute data query in the database.
[0107] Exemplary Methods
[0108] Combine the following Figure 1 The application scenario shown is shown in Figure 4 To describe the method of data query according to the exemplary embodiment of the present disclosure. It should be noted that the above application scenarios are only shown to facilitate understanding of the spirit and principle of the present disclosure, and the embodiments of the present disclosure are not limited in this respect. On the contrary, the embodiments of the present disclosure can be applied to any applicable scenario.
[0109] like Figure 4 As shown, the data query method can be applied to a query system connected to a database, and the method includes:
[0110] Step 410: extracting table metadata and field metadata related to a data table in the database from metadata of the database.
[0111] In the present disclosure, the metadata of the database may be obtained by the query system from the docked database.
[0112] Combine the following Figure 3 The schematic diagram of metadata acquisition is shown in FIG. Figure 3 As shown, the query system can connect to the database and obtain the metadata of the database after the connection is successful.
[0113] Exemplarily, the query system may first send authentication information to the database through an access interface provided by the database for access authentication, so as to establish a connection with the database after the authentication is passed.
[0114] The authentication information may include a user name and password for access, and the database verifies whether the user name and password are correct to determine whether the authentication is successful.
[0115] After the connection is successful, Figure 3 As shown, the query system may then read the metadata of the database from a storage location in the database for storing metadata, and store the read metadata locally.
[0116] The local storage may be a storage device such as a local database of a query system.
[0117] In the present disclosure, since metadata is stored in a specific table, view or file directory of a database, such as an OLAP-type database, Greenplum metadata is stored in the system directory of the master node, which contains the definition of database objects, such as metadata of tables, views, indexes, users, etc. For another example, Hive metadata is stored in HiveMetastore;
[0118] Therefore, by pre-adapting the metadata reading positions and reading information of different types of databases, the query system can obtain the metadata of the database from the database that needs to perform data query.
[0119] After the query system stores the read metadata locally, the above step 410 may be executed.
[0120] Please combine the following Figure 4 Schematic diagram of metadata processing as shown. Figure 4 The query system reads metadata of a database from local storage, and extracts table metadata and field metadata related to a data table in the database from the metadata of the database stored locally.
[0121] In an exemplary embodiment, the table metadata may include a subject and a table type of a data table, and the table type may include a dimension table and a fact table;
[0122] The dimension table may include a table recording dimension fields; the fact table may include a table recording metric fields; the dimension fields may include offline fields in the data table; the metric fields may include numerical fields in the data table;
[0123] The field metadata may include metadata corresponding to dimension fields of the dimension table records and metadata corresponding to metric fields of the fact table records.
[0124] The dimensions, measures, dimension tables and fact tables in this disclosure are all definitions in the data warehouse. The dimension table is the observation angle of the data. It is represented by a field in the data table. The value of the field is a discrete value. For example, date, region, gender, etc. are all dimensions. Dimensions are usually used to describe, classify and organize data to facilitate data analysis and decision support.
[0125] The metric is the measurement angle of the data, which is also represented by a field in the database table. The value of the field is numeric and is used to measure and count attributes, such as sales, cost, number of users, etc. Metrics are usually used to measure and analyze data to facilitate data decision support and business optimization.
[0126] The dimension table records the dimension fields. The dimension table usually contains descriptive information about the business entities in the data warehouse, such as customers, products, time, location, etc.
[0127] The fact table is a table that records measurement fields. The fact table usually contains measurement data about the business process, such as sales volume, sales revenue, cost, etc.
[0128] like Figure 4 As shown, after the table metadata and field metadata are extracted, they can also be manually confirmed by the configuration management module. If there are omissions in the extraction or the original metadata is missing, they can be manually supplemented and the missing information can be summarized to form table building specifications.
[0129] Step 420: Acquire target metadata selected from the table metadata and field metadata for data query and query conditions configured for the target metadata.
[0130] After the table metadata and field metadata related to the data table in the database are extracted, the user can select target metadata for data query and query conditions configured for the target metadata.
[0131] In an exemplary embodiment, after extracting the table metadata and field metadata related to the data table in the database, the following may also be included:
[0132] Obtaining the dimension table and fact table of the table metadata, and further obtaining the dimension fields and metric fields of the dimension table and fact table records;
[0133] The acquired subject of the dimension table and the subject of the fact table are used as first-level nodes, and the dimension fields recorded in the dimension table and the metric fields recorded in the fact table are used as second-level nodes under the first-level nodes to construct a visual tree structure.
[0134] Accordingly, the above step 420 may further include:
[0135] In response to a configuration operation performed by a user on a secondary node in the visualized tree structure, a target dimension field and a target metric field corresponding to the secondary node of the configuration operation are obtained;
[0136] Matching target metadata corresponding to the target dimension field and the target metric field from the field metadata;
[0137] The query condition configured by the configuration operation is used as a query condition for the target metadata.
[0138] In the present disclosure, the extracted table metadata and field metadata may be visualized, that is, the visualized tree structure constructed above may be displayed on a visualization interface.
[0139] Below Figure 5 Taking an exemplary visualization interface shown as an example, the visualization interface can be divided into a to-be-selected area, a selected area, and a query result display area.
[0140] The waiting area is used to display metadata that constitutes a tree structure, that is, to display all selectable dimension fields and metric fields in a tree structure. When displaying, the subject of the dimension table and fact table is the first-level node, and the dimension field and metric field under the first-level node are the second-level nodes. Each second-level node represents a dimension or metric, and the information of each node can include the subject, name, description, etc. In addition, a search function is provided, and users can quickly locate the relevant dimension field or metric field by entering keywords.
[0141] The selected area is used to display the dimension fields and metric fields selected by the user from the waiting area. For example, the user can operate in the visual interface through a mouse or a touch screen to select a node. For example, the user can click a node to select it to the "selected area"; or drag a node to move it to the "selected area".
[0142] At the same time, the node of "Selected Area" supports the configuration of query conditions.
[0143] Wherein, the query conditions include condition screening and / or aggregation methods;
[0144] Conditional filtering is used to set conditions for the selected dimension field or measure field to determine the data query scope;
[0145] The aggregation method is used to set the aggregation method for the metric field to perform statistical analysis on the queried data. The statistical analysis method may include counting, deduplication counting, summing, averaging, maximum value, minimum value, median, etc.
[0146] After the user confirms the dimension fields and metric fields selected in the "Selected Area", the target metadata corresponding to these selected dimension fields and metric fields can be matched from the locally stored metadata to obtain specific table names, field names, primary and foreign keys and other information, so as to automatically generate query statements based on this information.
[0147] Step 430: Generate a query statement for database query according to the target metadata and the query condition, and use the query statement to query data from the database.
[0148] The present disclosure can pre-configure a generation rule for automatically generating a query statement, so that after acquiring the target metadata and the corresponding query conditions, a query statement for database query is automatically generated.
[0149] In an exemplary embodiment, taking a query statement such as an SQL statement as an example, the query statement generated by generating rules may be as follows:
[0150] Scenario 1: If the target dimension field is located in one dimension table, and the target metric field is located in one fact table, the first write rule is executed, and the first write rule includes writing the target dimension field and the target metric field into the initial SQL statement, and splicing the where filter condition and aggregation method in the initial SQL statement;
[0151] In this scenario 1, the target dimension and target measure selected by the user are the fields after select in SQL, the conditional screening set by the user is the where condition in SQL, the aggregation method set by the user is the aggregation function of the corresponding field after select in SQL, and the field for which the user has not set the aggregation method is the field after group by in SQL. The pseudo code is as follows:
[0152]
[0153] In addition, if the user does not set an aggregation method for any measure, the selection is performed directly without an aggregation function or group by. The pseudo code is as follows:
[0154]
[0155]
[0156] Scenario 2: If the target dimension field is located in at least two dimension tables, and the target metric field is located in one fact table, the second write rule is executed, and the second write rule includes concatenating the primary key of each dimension table associated with the foreign key of the fact table in the initial SQL statement, and executing the first write rule after concatenation;
[0157] In scenario 2, the primary keys of each dimension table and the corresponding foreign keys of the fact table are concatenated in SQL, and then the where conditions and aggregation logic are concatenated. The fact table is used as the primary table for association, that is, the table after from in SQL, and the dimension table appears after the join keyword.
[0158] In the first case, if the conditional filtering set by the user involves the dimension table field, an inner join is used to associate the dimension table, and a subquery is used to filter the dimension table first. The splicing of the where condition and the aggregation logic refers to "Scenario 1". The pseudo code is as follows:
[0159]
[0160]
[0161] In the second case, if the conditional filter set by the user does not involve the dimension table field, the dimension table is left-joined. The pseudo code is as follows:
[0162]
[0163] If the dimension selected by the user involves multiple dimension tables, the dimension tables are associated and spliced in the same way as in the first and second cases. The pseudo code is as follows:
[0164]
[0165]
[0166] Scenario 3: If the target dimension field is located in at least two dimension tables, and the target metric field is located in at least two fact tables, the third write rule is executed, and the third write rule includes executing the second write rule for each fact table, and concatenating a union all in the initial SQL statement for aggregating the associated results of each fact table associated with the dimension table.
[0167] In scenario 3, each fact table is associated with the corresponding dimension table (same as scenario 2), and then the results of each association are unioned and aggregated. The pseudo code is as follows:
[0168]
[0169]
[0170]
[0171] Through the above embodiment, a query statement can be automatically generated according to the target metadata and the query condition, and then the query statement can be used to query data from the database.
[0172] After the query statement is executed, the query system will obtain the query results returned by the database.
[0173] In an exemplary embodiment, after querying data from the database using the database query language, the method may further include:
[0174] Visualize the query results.
[0175] Through visual display, the present disclosure can intuitively discover the patterns and trends of data by comparing the measurement values of different dimensions, thereby improving the user experience.
[0176] In an exemplary embodiment, before querying data from the database using the database query language, the method further includes:
[0177] In response to a query request configured with a visualization type, querying data from the database using the database query language;
[0178] The visual display of the query results includes:
[0179] The query results are converted into a table report of the visualization type and then output for display.
[0180] In the present disclosure, the visualization interface also supports configuring visualization types, so that after the query system obtains the query results returned by the database, the query results can be converted into reports of the configured visualization type and then output for display. Exemplarily, the visualization types may include tables, charts, dashboards, etc., and users can select different report formats according to their needs.
[0181] Exemplary Media
[0182] After introducing the method of the exemplary embodiment of the present disclosure, next, refer to Figure 6 A medium according to an exemplary embodiment of the present disclosure is described.
[0183] In this exemplary embodiment, the above method can be implemented by a program product, such as a portable compact disk read-only memory (CD-ROM) and including program code, and can be run on a device, such as a personal computer. However, the program product of the present disclosure is not limited thereto, and in this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus, or a device.
[0184] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable 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.
[0185] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0186] The program code contained on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RE, etc., or any suitable combination of the foregoing.
[0187] Program code for performing the operations of the present disclosure may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as C or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user computing device, partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., using an Internet service provider to connect through the Internet).
[0188] In summary, the present disclosure may provide a computer-readable storage medium. When instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device may be enabled to execute the aforementioned data query method embodiment.
[0189] Exemplary Devices
[0190] After introducing the medium of the exemplary embodiment of the present disclosure, next, reference is made to Figure 7 A device according to an exemplary embodiment of the present disclosure is described.
[0191] Figure 7 The block diagram of a data query device according to an embodiment of the present disclosure is schematically shown, corresponding to the aforementioned Figure 2 The method embodiment shown is applied to a query system connected to a database, and the device includes:
[0192] An extraction unit 810 extracts table metadata and field metadata related to a data table in the database from metadata in the database;
[0193] An acquiring unit 820 acquires target metadata for data query selected from the table metadata and the field metadata and a query condition configured for the target metadata;
[0194] The query unit 830 generates a query statement for database query according to the target metadata and the query condition, and uses the query statement to query data from the database.
[0195] Optionally, the table metadata includes a subject and a table type of the data table, and the table type includes a dimension table and a fact table;
[0196] Wherein, the dimension table includes a table recording dimension fields, and the fact table includes a table recording metric fields; the dimension fields include offline fields in the data table; and the metric fields include numerical fields in the data table;
[0197] The field metadata includes metadata corresponding to the dimension fields of the dimension table records and metadata corresponding to the metric fields of the fact table records.
[0198] Optionally, after the extracting unit 810, the method further includes:
[0199] The construction unit 811 obtains the dimension table and the fact table of the table metadata, and further obtains the dimension fields and the metric fields of the dimension table and the fact table records; takes the obtained subject of the dimension table and the subject of the fact table as the first-level node, and takes the dimension fields of the dimension table records and the metric fields of the fact table records as the second-level nodes under the first-level node, to construct a visual tree structure;
[0200] The acquisition unit 820 further includes: in response to a user's configuration operation on a secondary node in the visualized tree structure, acquiring a target dimension field and a target metric field corresponding to the secondary node of the configuration operation; matching target metadata corresponding to the target dimension field and the target metric field from the field metadata; and using the query condition configured by the configuration operation as a query condition for the target metadata.
[0201] Optionally, the query condition includes condition screening and / or aggregation mode;
[0202] Among them, conditional filtering is used to set conditions for the selected dimension field or measure field to determine the data query scope;
[0203] The aggregation method is used to set the aggregation method for the metric field to perform statistical analysis on the queried data.
[0204] Optionally, the query statement includes an SQL statement, and when the query unit 830 generates a query statement for database query according to the target metadata and the query condition, the query unit 830 further includes:
[0205] The first generating subunit 831 executes a first writing rule if the target dimension field is located in one dimension table and the target metric field is located in one fact table. The first writing rule includes writing the target dimension field and the target metric field into an initial SQL statement and splicing a where filter condition and an aggregation method into the initial SQL statement.
[0206] The second generating subunit 833 executes a second writing rule if the target dimension field is located in at least two dimension tables and the target metric field is located in one fact table, wherein the second writing rule includes concatenating the primary key of each dimension table associated with the foreign key of the fact table in the initial SQL statement and executing the first writing rule after concatenation;
[0207] The third generating subunit 835 executes a third writing rule if the target dimension field is located in at least two dimension tables and the target metric field is located in at least two fact tables. The third writing rule includes executing the second writing rule for each fact table and concatenating a union all in the initial SQL statement for aggregating the association results of each fact table associated with the dimension table.
[0208] Optionally, before the extracting unit 810, the method further includes:
[0209] The connection unit 801 sends the authentication information to the database for access authentication through the access interface provided by the database, so as to establish a connection with the database after the authentication is passed;
[0210] The storage unit 803 reads the metadata of the database from the storage location for storing metadata in the database after the connection is successful, and stores the read metadata locally;
[0211] The extracting unit 810 further includes extracting table metadata related to the data table in the database from the metadata of the database stored locally.
[0212] Optionally, after the query unit 830, the method further includes:
[0213] The display unit 840 displays the query results visually.
[0214] Optionally, before the query unit 830 uses the database query language to query data from the database, it further includes: in response to a query request configured with a visualization type, querying data from the database using the database query language;
[0215] The display unit 840 further includes converting the query result into a table report of the visualization type and then outputting it for display.
[0216] Optionally, the database includes a distributed database.
[0217] Optionally, the distributed database includes an OLAP database.
[0218] Exemplary Computing Devices
[0219] After introducing the method, medium and apparatus of the exemplary embodiments of the present disclosure, next, reference is made to Figure 8 A computing device according to an exemplary embodiment of the present disclosure is described.
[0220] Figure 8 The computing device 1500 shown is merely an example and should not bring any limitation to the functionality and scope of use of the embodiments of the present disclosure.
[0221] like Figure 8As shown, computing device 1500 is in the form of a general computing device. Components of computing device 1500 may include, but are not limited to: at least one processing unit 1501, at least one storage unit 1502, and a bus 1503 connecting different system components (including processing unit 1501 and storage unit 1502).
[0222] The bus 1503 includes a data bus, a control bus, and an address bus.
[0223] The storage unit 1502 may include a readable medium in the form of a volatile memory, such as a random access memory (RAM) 15021 and / or a cache memory 15022 , and may further include a readable medium in the form of a non-volatile memory, such as a read-only memory (ROM) 15023 .
[0224] The storage unit 1502 may also include a program / utility 15025 having a set (at least one) of program modules 15024, such program modules 15024 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0225] The computing device 1500 may also communicate with one or more external devices 1504 (eg, a keyboard, pointing device, etc.).
[0226] Such communication may be performed via input / output (I / O) interface 1505. In addition, computing device 1500 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via network adapter 1506. Figure 8 As shown, network adapter 1506 communicates with other modules of computing device 1500 via bus 1503. It should be understood that, although not shown in the figure, other hardware and / or software modules can be used in conjunction with computing device 1500, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0227] Through Figure 8 The computing device 1500 shown can implement the aforementioned data query method. More specifically, the storage unit 1502 stores instructions executable by the processing unit 1501. When the processing unit 1501 executes the instructions, the aforementioned data query method is implemented.
[0228] It should be noted that although several units / modules or sub-units / modules of the data query device are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, according to an embodiment of the present disclosure, the features and functions of two or more units / modules described above can be embodied in one unit / module. Conversely, the features and functions of one unit / module described above can be further divided into multiple units / modules to be embodied.
[0229] In addition, although the operations of the disclosed method are described in a specific order in the drawings, this does not require or imply that the operations must be performed in this specific order, or that all the operations shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.
[0230] Although the spirit and principle of the present disclosure have been described with reference to several specific embodiments, it should be understood that the present disclosure is not limited to the disclosed specific embodiments, and the division of various aspects does not mean that the features in these aspects cannot be combined to benefit, and such division is only for the convenience of expression. The present disclosure is intended to cover various modifications and equivalent arrangements included in the spirit and scope of the attached claims.
Claims
1. A data query method, applied to a query system connected to a database, the method comprising: Extracting table metadata and field metadata related to a data table in the database from the metadata of the database; Acquire target metadata for data query selected from the table metadata and field metadata and query conditions configured for the target metadata; A query statement for database query is generated according to the target metadata and the query condition, and data is queried from the database using the query statement.
2. According to the method of claim 1, the table metadata includes the subject and table type of the data table, and the table type includes a dimension table and a fact table; in, The dimension table includes a table for recording dimension fields, and the fact table includes a table for recording metric fields; the dimension fields include offline fields in the data table; and the metric fields include numerical fields in the data table; The field metadata includes metadata corresponding to the dimension fields of the dimension table records and metadata corresponding to the metric fields of the fact table records.
3. The method according to claim 2, after extracting table metadata and field metadata related to the data table in the database from the metadata of the database, further comprises: Obtaining the dimension table and fact table of the table metadata, and further obtaining the dimension fields and metric fields of the dimension table and fact table records; The acquired subject of the dimension table and the subject of the fact table are used as first-level nodes, and the dimension fields of the dimension table records and the metric fields of the fact table records are used as second-level nodes under the first-level nodes to construct a visual tree structure; The acquiring target metadata selected from the table metadata and the field metadata for data query and the query condition configured for the target metadata includes: In response to a configuration operation performed by a user on a secondary node in the visualized tree structure, a target dimension field and a target metric field corresponding to the secondary node of the configuration operation are obtained; Matching target metadata corresponding to the target dimension field and the target metric field from the field metadata; The query condition configured by the configuration operation is used as a query condition for the target metadata.
4. The method according to claim 3, wherein the query condition includes condition screening and / or aggregation mode; in, Conditional filtering is used to set conditions for the selected dimension field or measure field to determine the data query scope; The aggregation method is used to set the aggregation method for the metric field to perform statistical analysis on the queried data.
5. According to the method of claim 4, the query statement comprises an SQL statement, and the generating of the query statement for database query according to the target metadata and the query condition comprises: If the target dimension field is located in one dimension table, and the target metric field is located in one fact table, the first writing rule is executed, and the first writing rule includes writing the target dimension field and the target metric field into the initial SQL statement, and splicing the where filter condition and the aggregation method in the initial SQL statement; If the target dimension field is located in at least two dimension tables, and the target metric field is located in one fact table, a second write rule is executed, wherein the second write rule includes concatenating the primary key of each dimension table associated with the foreign key of the fact table in the initial SQL statement, and executing the first write rule after concatenation; If the target dimension field is located in at least two dimension tables and the target metric field is located in at least two fact tables, a third write rule is executed, wherein the third write rule includes executing the second write rule for each fact table and concatenating a union all in the initial SQL statement for aggregating the associated results of each fact table associated dimension table.
6. The method according to claim 1, before extracting table metadata related to a data table in the database from the metadata of the database, further comprises: Sending authentication information to the database for access authentication through an access interface provided by the database, so as to establish a connection with the database after the authentication is passed; After the connection is successful, the metadata of the database is read from the storage location in the database for storing metadata, and the read metadata is stored locally; The step of extracting table metadata and field metadata related to a data table in the database from metadata of the database includes: Table metadata and field metadata related to the data table in the database are extracted from the metadata of the database stored locally.
7. The method according to claim 1, after querying data from the database using the database query language, further comprises: Visualize the query results.
8. A data query device, applied to a query system connected to a database, the device comprising: An extraction unit, extracting table metadata and field metadata related to a data table in the database from the metadata of the database; An acquisition unit, which acquires target metadata selected from the table metadata and the field metadata for data query and a query condition configured for the target metadata; The query unit generates a query statement for database query according to the target metadata and the query condition, and uses the query statement to query data from the database.
9. A computer-readable storage medium, comprising: When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the data query method according to any one of claims 1 to 7.
10. A computing device comprising: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the executable instructions to implement the data query method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Metadata self-discovery-based data query interface automatic generation method and system
CN110083650A
Data modeling method and device, computer readable medium and electronic device
CN110674117A
Data query method and device, equipment and storage medium
CN114153852A
Data query method and device, electronic equipment and storage medium
CN116795860A
Cited By
Method and equipment for adding filtering condition for SQL (Structured Query Language) query statement
CN119149573A
Evidence chain node data query method and device, equipment and storage medium
CN119248832A
Low-code-based data index query statement generation method and device
CN120670456A
