SQL query method, intelligent device and storage medium

By obtaining the connection relationship between the query engine and the preset database and the mapping relationship between the data sources, the problem of low data query efficiency in the existing technology is solved, the effect of quickly obtaining query results is achieved, and the threshold for data analysis is lowered.

CN119357221APending Publication Date: 2025-01-24NIO TECH ANHUI CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411463695.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-18
Publication Date
2025-01-24

AI Technical Summary

Technical Problem

The query efficiency corresponding to existing data query methods is low, especially when users who lack professional knowledge use Presto to query cross-data source, the overall efficiency is low and takes longer.

Method used

Provide a SQL query method. By obtaining the connection relationship between the query engine and the preset database, loading the data source of the preset database, obtaining the mapping relationship between the query engine and the data source, and based on the first SQL query request and mapping Relations get the query results.

Benefits of technology

Through the preloaded default database and the mapping relationship between the query engine and the data source, the query results corresponding to the SQL query request can be quickly obtained, which lowers the threshold for data analysis across data sources and improves query efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119357221A_ABST
    Figure CN119357221A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computers, particularly provides an SQL query method, intelligent equipment and a storage medium, and aims to solve the technical problem of relatively low query efficiency corresponding to an existing data query method. In order to achieve the purpose, the SQL query method comprises the steps that a connection relation between a query engine and a preset database is obtained; loading a data source of a preset database based on the connection relationship; obtaining a mapping relationship between the query engine and a data source of a preset database; obtaining a first SQL query request; the query result is obtained based on the first SQL query request and the mapping relation, the purpose of rapid query is achieved, and the threshold of cross-data-source data analysis is lowered.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and specifically provides an SQL query method, an intelligent device and a storage medium. Background Art

[0002] When performing data analysis, the data to be analyzed usually comes from various storage systems, such as traditional relational databases (Mysql, SQLServer, Oracle), files (Excel, CSV), online tables, distributed analytical databases (StarRocks, ClickHouse), etc. The data between various data sources are not interoperable, the data query methods are also different, and the SQL syntax of different databases is also inconsistent.

[0003] Presto is a data analysis engine that supports cross-data source queries and supports various common data sources. Data analysis through Presto requires a certain understanding of Presto, and the corresponding process of accessing data sources as a prerequisite for data analysis is also relatively complicated. Therefore, for users who lack professional knowledge, the overall efficiency of directly using Presto to query across data sources is relatively low and it takes a long time.

[0004] To this end, this application proposes a new SQL query solution. Summary of the invention

[0005] In order to overcome the above defects, the present application is proposed to provide a solution or at least partially solve the technical problem of low query efficiency corresponding to the existing data query method. The present application provides a SQL query method, an intelligent device and a storage medium.

[0006] In a first aspect, the present application provides a SQL query method, the method comprising:

[0007] Obtaining the connection relationship between the query engine and the preset database;

[0008] Loading the data source of the preset database based on the connection relationship;

[0009] Acquire a mapping relationship between the query engine and a data source of the preset database;

[0010] Get the first SQL query request;

[0011] A query result is obtained based on the first SQL query request and the mapping relationship.

[0012] In a specific implementation of the present application, the step of obtaining a connection relationship between the query engine and the preset database includes:

[0013] Obtaining the data source type, data source name and address information corresponding to the preset database;

[0014] A connection relationship between a query engine and a preset database is obtained based on the data source type, the data source name and the address information.

[0015] In a specific implementation of the present application, the obtaining of a mapping relationship between the query engine and a data source of the preset database includes:

[0016] Obtaining the data source type corresponding to the preset database;

[0017] The data source of the preset database is mapped to the hierarchical structure of the query engine based on the data source type to obtain a mapping relationship between the query engine and the data source.

[0018] In a specific implementation of the present application, when the data source type of the preset database is a structured data storage format, before obtaining the mapping relationship between the query engine and the data source of the preset database, the method further includes:

[0019] Parsing the preset database to obtain field information of each database table in the preset database;

[0020] Creating a database table of a distributed database based on the field information;

[0021] The data source in the database is written into the database table corresponding to the distributed database.

[0022] In a specific implementation of the present application, the obtaining of query results based on the first SQL query request and the mapping relationship includes:

[0023] Acquire data source information in the first SQL query request based on the first SQL query request;

[0024] identifying the type of the data source based on the data source information;

[0025] Determine a second SQL query request based on the type of the data source and the mapping relationship;

[0026] Obtain query results based on the second SQL query request.

[0027] In a specific implementation of the present application, the acquiring the data source information in the first SQL query request based on the first SQL query request includes:

[0028] Parsing the first SQL query request to obtain an execution plan in the first SQL query request;

[0029] Metadata is extracted from the execution plan to obtain data source information in the first SQL query request.

[0030] In a specific implementation of the present application, parsing the first SQL query request to obtain an execution plan in the first SQL query request includes:

[0031] Using a lexical analyzer to identify keywords and identifiers in the first SQL query request;

[0032] Using a syntax analyzer to perform syntax construction on the keywords and the identifiers to generate a syntax tree;

[0033] A compiler is used to compile and parse the syntax tree to obtain the execution plan.

[0034] In a specific implementation of the present application, the first SQL query request includes a queried data source object, the data source object includes a data source name, a library name and a table name, and the data source name, the library name and the table name are connected with a separator.

[0035] In a second aspect, a smart device is provided, comprising:

[0036] at least one processor;

[0037] and, a memory communicatively coupled to the at least one processor;

[0038] Wherein, a computer program is stored in the memory, and the computer program is the aforementioned SQL query method when executed by the at least one processor.

[0039] In a third aspect, a computer-readable storage medium is provided, wherein a plurality of program codes are stored in the computer-readable storage medium, wherein the program codes are suitable for being loaded and run by a processor to execute any of the aforementioned SQL query methods.

[0040] The above one or more technical solutions of this application have at least one or more of the following Beneficial effects:

[0041] The SQL query method provided in the present application first obtains the connection relationship between the query engine and the preset database; loads the data source of the preset database based on the connection relationship; obtains the mapping relationship between the query engine and the data source of the preset database; obtains the first SQL query request; and obtains the query result based on the first SQL query request and the mapping relationship. Through the pre-loaded preset database and the mapping relationship between the query engine and the data source of the preset database, the query result corresponding to the first SQL query request can be quickly obtained, so that business personnel who are only familiar with simple SQL syntax can also complete professional data analysis work, thereby lowering the threshold for cross-data source data analysis and improving query efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] The disclosure of the present application will become more easily understood with reference to the accompanying drawings. It is easy for those skilled in the art to understand that these drawings are only for illustrative purposes and are not intended to limit the scope of protection of the present application. In addition, similar numbers in the drawings are used to represent similar components, among which:

[0043] Figure 1 This is a flowchart of the main steps of the SQL query method according to an embodiment of the present application;

[0044] Figure 2 This is a schematic diagram of adding a MySql database in one embodiment of the present application;

[0045] Figure 3 is a schematic diagram of adding an online form in one embodiment of the present application;

[0046] Figure 4 This is a schematic diagram of adding an Excel file in one embodiment of the present application;

[0047] Figure 5 It is a flowchart of obtaining the corresponding relationship between Mysql and the hierarchical structure in one embodiment of the present application;

[0048] Figure 6 It is a flowchart of obtaining the correspondence between the online form and the hierarchical structure in one embodiment of the present application;

[0049] Figure 7 It is a schematic diagram of a process of transferring data in a structured data storage format to a distributed database in one embodiment of the present application;

[0050] Figure 8 This is a query flow diagram in one embodiment of the present application;

[0051] Fig. 9 It is a schematic diagram of the main structural block diagram of a SQL query device according to an embodiment of the present application;

[0052] Fig.10 It is a schematic diagram of the structure of an electronic device in one embodiment of the present application. DETAILED DESCRIPTION

[0053] Some embodiments of the present application are described below with reference to the accompanying drawings. Those skilled in the art should understand that these embodiments are only used to explain the technical principles of the present application and are not intended to limit the protection scope of the present application.

[0054] In the description of the present application, "module" and "processor" may include hardware, software or a combination of the two. A module may include hardware circuits, various suitable sensors, communication ports, memory, and may also include software parts, such as program code, or a combination of software and hardware. The processor may be a central processing unit, a microprocessor, an image processor, a digital signal processor or any other suitable processor. The processor has data and / or signal processing functions. The processor may be implemented in software, hardware or a combination of the two. Non-temporary computer-readable storage media include any suitable medium that can store program code, such as a disk, a hard disk, an optical disk, a flash memory, a read-only memory, a random access memory, etc. The term "A and / or B" means all possible combinations of A and B, such as only A, only B or A and B. The term "at least one A or B" or "at least one of A and B" has a similar meaning to "A and / or B" and may include only A, only B or A and B. The singular terms "one" and "the" may also include plural forms.

[0055] Currently, for users who lack professional knowledge, the overall efficiency of directly using Presto to query data across data sources is relatively low and it takes a long time.

[0056] To this end, the present application proposes a SQL query method, an intelligent device and a storage medium.

[0057] See attached Figure 1 , Figure 1 It is a flowchart of the main steps of the SQL query method according to an embodiment of the present application.

[0058] like Figure 1 As shown, the SQL query method in the embodiment of the present application mainly includes the following steps S10 to S50.

[0059] Step S10: Acquire the connection relationship between the query engine and the preset database.

[0060] The query engine is mainly used to process and analyze data query requests. Its core function is to parse the query statements (usually SQL or other query languages) submitted by users or applications, execute the necessary data retrieval and processing logic, and return the query results. The design goal of the query analysis engine is to efficiently process complex queries, including but not limited to data filtering, aggregation, sorting, grouping and other operations. For example, Impala, Presto, etc. can be used as examples of query engines.

[0061] The preset database can be a database that the user wants to add to the query engine and perform data query analysis. The preset database can be a relational database (Mysql, SQLServer, Oracle), a file in a structured data storage format (Excel, CSV), an online table (such as Feishu Table), a distributed analytical database (StarRocks, ClickHouse), etc.

[0062] The connection relationship is a connection relationship between the query engine and the preset database, and based on this relationship, the preset database can be added to the query engine.

[0063] The connection relationship may be obtained by the user through a front-end interface input, or may be a preset connection relationship, and there is no specific limitation on this.

[0064] Step S20: loading a preset database based on the connection relationship.

[0065] The preset database can be loaded into the query engine according to the connection relationship between the query engine and the preset database.

[0066] Step S30: Acquire a mapping relationship between the query engine and a data source of a preset database.

[0067] The mapping relationship refers to the mapping relationship between the data source of the preset database and the hierarchical structure of the query engine.

[0068] Step S40: Obtain a first SQL query request.

[0069] Step S50: Obtain query results based on the first SQL query request and the mapping relationship.

[0070] Based on the above steps S10 to S50, first obtain the connection relationship between the query engine and the preset database; load the data source of the preset database based on the connection relationship; obtain the mapping relationship between the query engine and the data source of the preset database; obtain the first SQL query request; obtain the query result based on the first SQL query request and the mapping relationship. Through the pre-loaded preset database and the mapping relationship between the query engine and the data source of the preset database, the query result corresponding to the first SQL query request can be quickly obtained, so that business personnel who are only familiar with simple SQL syntax can also complete professional data analysis work, thereby lowering the threshold for cross-data source data analysis and improving query efficiency.

[0071] In order to make the purpose, technical solution and advantages of the present application clearer, the SQL query method of the present application is described in detail below with reference to the accompanying drawings and embodiments, taking Presto as an example of the query engine. It should be understood by those skilled in the art that the embodiments described herein are only used to explain the present application, and are not used to limit the SQL query method of the present application to use Presto as the query engine.

[0072] The above steps S10 to S50 are further explained below.

[0073] Specifically, the above step S10 can be implemented through the following steps S101 to S102.

[0074] Step S101: obtaining the data source type, data source name and address information corresponding to the preset database.

[0075] The data source type can be a relational database (such as MySQL, SQL Server, Oracle), a file in a structured data storage format (Excel, CSV), an online table (such as Feishu Table), or a distributed analytical database (StarRocks, ClickHouse), etc.

[0076] A data source name is a data structure that contains the information needed to connect to a specific database.

[0077] The address information is the specific address information that can connect to a specific database, such as a server, port, URL address, etc.

[0078] Step S102: obtaining a connection relationship between the query engine and a preset database based on the data source type, data source name and address information.

[0079] Specifically, the data source type, data source name and address information together constitute the connection relationship between the query engine and the preset database.

[0080] Specifically, Figure 2It can be used as an example to add a data source corresponding to a MySql database. Figure 3 As an example of adding an online form, Figure 4 This can be used as an example to add an Excel file.

[0081] The above is a further description of step S10 , and the following is a further description of step S30 .

[0082] Specifically, before executing step S30, the connectivity of the preset database added to the query engine may be verified in advance, and subsequent steps may be executed when the preset database is connected, which is beneficial to improving query efficiency.

[0083] Specifically, the above step S30 can be implemented through the following steps S301 to S302.

[0084] Step S301: Obtain the data source type corresponding to the preset database.

[0085] The data source type can be a relational database (such as MySQL, SQL Server, Oracle), a file (Excel, CSV), an online table (such as Feishu Table), or a distributed analytical database (StarRocks, ClickHouse), etc.

[0086] Step S302: Mapping the data source of the preset database to the hierarchical structure of the query engine based on the data source type to obtain a mapping relationship between the query engine and the data source.

[0087] The hierarchical structure of the query engine includes catalog, database instance (schema) and data table instance (table).

[0088] Catalog can be understood as the highest level organizational unit, representing a data source or a collection of databases. It physically points to an external data source and is accessed through Presto's Connector. A Catalog can contain multiple Schemas, allowing users to switch and query between different data sources.

[0089] Schema is under Catalog, and Schema is used to further organize Tables. It can be seen as a namespace or a logical grouping within the database to help manage related Tables.

[0090] Table is the lowest level unit in Presto's hierarchy, which directly contains the structured definition of data and the data itself. Table defines the column name, data type, and possible constraints of the data.

[0091] Specifically, different types of databases can be mapped to different hierarchical structures of Presto. For example, Figure 5 As shown, relational databases (MySQL, SQL Server, Oracle), taking MySQL as an example, can be registered as a catalog of Presto.

[0092] All online table data share a Presto catalog, which is system-level. Each Feishu table corresponds to a schema in the catalog, and a sheet in a Feishu table corresponds to a table in the schema. For example, Figure 6 As shown in the figure, after the user initiates a request to create a data source, the system obtains the sheet id of Feishu based on the URL of Feishu, and then creates a schema under the Catalog in Presto based on the Sheet id.

[0093] Specifically, the mapping relationship between the query engine and the data source can be the corresponding relationship between the data source of the preset database and the hierarchical structure of the query engine. After mapping the data source of the preset database to the hierarchical structure of the query engine, the mapping relationship between the query engine and the data source is obtained.

[0094] In a specific embodiment of the present application, when the data source type of the preset database is a structured data storage format, before obtaining the mapping relationship between the query engine and the data source of the preset database, the method also includes: parsing the preset database to obtain field information of each database table in the preset database; creating a database table of a distributed database based on the field information; and writing the data source in the database into the database table corresponding to the distributed database.

[0095] The structured data storage format can be structured data formats such as Excel and CSV.

[0096] A distributed database is a database system that distributes data across a computer network in multiple physical locations. Each node has a partial or full copy of the database management system and manages its own local database. These scattered databases are interconnected through the network to form a logically unified and physically distributed large database. For example, StarRocks can be used as an example of a distributed database.

[0097] Data in files in structured data storage formats such as Excel and CSV is not conducive to subsequent cross-data source queries. In order to improve the efficiency of subsequent queries, the data source data of files in structured data storage formats such as Excel and CSV needs to be transferred to StarRocks. The data of each worksheet in each electronic storage file will be stored in a StarRocks table, where CSV can be regarded as a file with only one sheet. Subsequent Excel and CSV queries are converted into queries on the system StarRocks library table through mapping relationships.

[0098] Specifically, if Figure 7 As shown, after the user initiates a request to add a data source such as Excel or Csv, the system first parses the file uploaded by the user, parses the field information in each Sheet (including field name and field type), and then creates a StarRocks table corresponding to the Sheet based on the field information, and then writes the data into the StarRocks table. Finally, the mapping information between the Excel or Csv worksheet (Sheet) and the StarRocks library table and the basic information of the data source are saved. In this way, it is avoided to query data directly in data sources such as Excel or Csv, which is conducive to improving the efficiency of subsequent queries.

[0099] The above is a further description of step S30 , and the following is a further description of step S40 .

[0100] In a specific implementation of the present application, the first SQL query request includes a data source name, a library name, and a table name, and the data source name and the library name, as well as the library name and the table name are connected with a separator.

[0101] The query request may be obtained by a user input through a front-end interface, wherein a preset rule of the first SQL query request is pre-set to improve query efficiency. Specifically, the data source object in the first SQL query request may include a data source name, a library name, and a table name, and the data source name and the library name, and the library name and the table name are connected by a separator.

[0102] For example, Mysql, SQLServer, Oracle, StarRocks and other data sources use the data source name wrapped in square brackets to specify the data source to be queried, and then connect the specific library name and table name through ".". For example, as shown below:

[0103] select

[0104] *

[0105] from

[0106] [Mysql data source name].Mysql library name.Mysql table name

[0107] For example, a user has a Mysql data source named "sales platform", a database named "car" in the data source, and a table named "order" in the database. Then the first SQL query request for querying data in the table can be:

[0108] select

[0109] *

[0110] from

[0111] [Sales platform].car.Order

[0112] Excel and CSV data sources use the data source name enclosed in square brackets to specify the data source for the query, and then connect the specific worksheet name with "." after the Excel data source name, as shown below:

[0113] select

[0114] *

[0115] from

[0116] [Excel data source name].Sheet name

[0117] Assume that the user has an Excel data source named "Coupons", and there is a worksheet named "Auto Coupons" in the data source. Then the SQL to query the data in the worksheet "Auto Coupons" is:

[0118] select

[0119] *

[0120] from

[0121] [Coupon].Car Coupons

[0122] Feishu table data source uses the data source name wrapped in square brackets to specify the data source for the query, and then connects the specific worksheet name with "." after the data source name, as shown below:

[0123] select

[0124] *

[0125] from

[0126] [Feishu table data source].Sheet name

[0127] Assume that there is a Feishu table data source named "Customer", and there is a Sheet named "Automobile Customer" in the data source. Then the SQL to query the data in the "Automobile Customer" worksheet is:

[0128] select

[0129] *

[0130] from

[0131] [Customer].Automotive Customer

[0132] The above data source example queries are all simple single data source queries. Different data sources can be combined in any unlimited number for associated queries. For example, for the above Mysql data source named "Sales Platform", Excel data source named "Coupon" and Feishu Table data source named "Customer", the following cross-data source query can be performed:

[0133] select

[0134] *

[0135] from

[0136] [Sales platform].car.Order as sale

[0137] left join

[0138] [Coupon].Car couponsticket on sale.ticket_id=ticker.id

[0139] leftjoin

[0140] [Customer].CarCustomerascustomeronsale.customer_id=customer.id

[0141] In this way, by presetting the rules of the first SQL query request, the user can quickly and accurately obtain the query result, which is conducive to improving the query efficiency.

[0142] The above is a further description of step S40 , and the following is a further description of step S50 .

[0143] Specifically, step S50 can be implemented through the following steps S501-S504.

[0144] Step S501: obtaining data source information in the first SQL query request based on the first SQL query request.

[0145] In a specific implementation of the present application, obtaining the data source information in the first SQL query request based on the first SQL query request includes: parsing the first SQL query request to obtain an execution plan in the first SQL query request; extracting metadata from the execution plan to obtain the data source information in the first SQL query request. The parsing of the first SQL query request to obtain the execution plan in the first SQL query request includes: using a lexical analyzer to identify keywords and identifiers in the first SQL query request; using a syntax analyzer to perform syntax construction on the keywords and the identifiers to generate a syntax tree; using a compiler to compile and parse the syntax tree to obtain the execution plan.

[0146] Specifically, the execution plan not only contains the execution steps, but also contains information about the data sources involved in the query, such as table names, column names, etc. By analyzing the execution plan, you can extract these metadata and understand what data the query will operate on and how to operate the data.

[0147] Data source information refers to the location and description of the specific database table, view, or other data storage referred to in the SQL query request. This step is the basis for subsequent data processing and access, ensuring that the query engine can locate the correct data storage location to read or modify data.

[0148] Specifically, in the process of obtaining the execution plan in the first SQL query request, the lexical analyzer is first used to identify keywords and identifiers. Lexical analysis is the first stage of processing SQL queries, also known as the scanning stage. The lexical analyzer reads the SQL query string and breaks it into a series of meaningful elements, which are called lexical units (tokens). Lexical units include keywords (such as SELECT, FROM, WHERE, etc.), identifiers (table names, column names, etc.), operators (=, <, >, etc.) and special symbols (parentheses, commas, etc.). This step helps the system understand the basic components of the query.

[0149] Secondly, the syntax analyzer is used to build the syntax of keywords and identifiers to generate a syntax tree. The syntax analyzer will parse the sequence of lexical units according to the SQL syntax rules and check whether they are combined according to the correct syntax rules. This process is usually achieved by building an abstract syntax tree (AST). AST is a tree structure that intuitively shows the structure of the SQL query, including the various parts of the query and their relationships, such as the SELECT clause, FROM clause, WHERE conditions, etc.

[0150] Finally, the compiler is used to compile and parse the syntax tree to obtain an execution plan. After the syntax tree is generated, the system will further analyze the tree, which may involve query optimization. The compiler or query optimizer will decide how to execute the query most efficiently based on the syntax tree and the metadata of the database (such as table structure, index information, etc.). This decision-making process includes selecting the best data access path, determining the appropriate connection algorithm, etc., and finally generating an execution plan. The execution plan is a detailed sequence of steps that indicates how to retrieve the required data from the database, including but not limited to the table access order, the index used, etc.

[0151] Step S502: Identify the type of data source based on the data source information.

[0152] Specifically, the type of the specific data source corresponding to the first SQL query request is identified according to the data information obtained after parsing.

[0153] Step S503: Determine a second SQL query request based on the type of the data source and the mapping relationship.

[0154] Specifically, according to the type and mapping relationship of the data source, the data source name and the library table name in the first SQL query request are replaced with an SQL request that Presto can recognize, so as to obtain a second SQL query request.

[0155] For JDBC data sources such as MySQL, SQL Server, Oracle, and StarRocks, you can directly replace the data source name. Specifically, query the corresponding Presto Catalog based on the data source name, and then replace "[data source name]" with the Catalog name.

[0156] For example, a user uses a MySQL data source named "Sales Platform" across data sources SQL as shown below

[0157] select

[0158] *

[0159] from

[0148] [Sales platform].car.Order

[0149] By querying the data source "sales platform" corresponding to the catalog name "catalog_mysql_1234", we can get the final SQL request as follows

[0150] select

[0151] *

[0152] from

[0153] catalog_mysql_1234.car.Order

[0160] For file type data sources such as Excel and Csv, in addition to replacing the data source name, you also need to replace the library table name corresponding to the Sheet. Specifically, find the Sheet name connected to the data source in SQL, then find the StarRocks library table information corresponding to the Sheet, and finally replace the data source name and Sheet name respectively.

[0161] For example, the user uses an Excel data source named "Coupon" across data sources SQL, and there is a Sheet named "Auto Coupon" in the data source, as shown below

[0162] select

[0163] *

[0164] from

[0165] [Coupon].Car Coupons

[0166] The StarRocks data source storing file data has been registered in Presto, and the catalog is catalog_file. By querying the data source "Coupon" Sheet "Car Coupon" corresponding to the library table is "file_db.file_1234", so the final SQL can be obtained as follows:

[0167] select

[0168] *

[0169] from

[0170] catalog_file.file_db.file_1234

[0171] For Feishu table data sources, first query the corresponding Schema from the data source management module based on the data source name, and then replace "[data source name]" with the catalog name and schema name. For example, a user uses a Feishu table data source named "Customer" across data source SQL, and there is a Sheet named "Automotive Customer" in the data source, as shown below:

[0172] select

[0173] *

[0174] from

[0175] [Customer].Automotive Customer

[0176] The Lark application of the system has been registered in Presto, and the catalog is catalog_lark. Through the data source management module, the schema corresponding to the data source "customer" is queried and the name is "schema_1234", so the final SQL can be obtained as follows:

[0177] select

[0178] *

[0179] from

[0180] catalog_lark.schema_1234

[0181] Step S504: Obtain query results based on the second SQL query request.

[0182] The query function of Presto is used to query the second SQL query request to obtain the query result.

[0183] In one embodiment of the present application, Figure 8 As shown, when it is determined that the used data source does not exist in the Presto engine, the data source is added to the Presto engine, and further query is performed through the SQL cross-data source query method to obtain the query result.

[0171] It should be pointed out that although the various steps in the above embodiments are described in a specific order, those skilled in the art can understand that in order to achieve the effect of the present application, different steps do not have to be executed in such an order. They can be executed simultaneously (in parallel) or in other orders. These changes are within the scope of protection of the present application.

[0172] Furthermore, the present application also provides a SQL query device.

[0173] See attached Fig. 9 , Fig. 9 It is a main structural block diagram of a SQL query device according to an embodiment of the present application.

[0174] like Fig. 9 As shown, the SQL query device in the embodiment of the present application mainly includes a first acquisition module 11, a loading module 12, a second acquisition module 13, a third acquisition module 14 and a fourth acquisition module 15. In some embodiments, one or more of the first acquisition module 11, the loading module 12, the second acquisition module 13, the third acquisition module 14 and the fourth acquisition module 15 can be combined into one module.

[0175] In some embodiments, the first acquisition module 11 may be configured to acquire a connection relationship between the query engine and a preset database.

[0176] The loading module 12 may be configured to load the preset database based on the connection relationship.

[0177] The second acquisition module 13 may be configured to acquire a mapping relationship between the query engine and a data source of the preset database.

[0178] The third acquisition module 14 may be configured to acquire a first SQL query request.

[0179] The fourth acquisition module 15 may be configured to acquire a query result based on the first SQL query request and the mapping relationship.

[0180] In one implementation, the description of the specific implementation functions can refer to step S10 to step S50.

[0181] The above SQL query device is used to execute Figure 1 The SQL query method embodiment shown in the figure has similar technical principles, technical problems solved and technical effects produced. Technical personnel in this technical field can clearly understand that for the convenience and conciseness of description, the specific working process and related instructions of the SQL query device can refer to the contents described in the embodiment of the SQL query method, which will not be repeated here.

[0182] It is understood by those skilled in the art that all or part of the processes in the method for implementing the above-mentioned embodiment of the present application can also be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable storage medium may include: any entity or device, medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory, random access memory, electrical carrier signal, telecommunication signal and software distribution medium, etc. that can carry the computer program code.

[0183] Furthermore, the present application also provides an intelligent device, which may include at least one processor; and a memory connected to the at least one processor; wherein a computer program is stored in the memory, and when the computer program is executed by the at least one processor, the SQL query method described in any of the above embodiments is implemented. Fig.10 As shown, Fig.10 exemplarily shows the structure of a smart device, which includes a processor 100 and a memory 200.

[0184] Furthermore, the present application also provides a computer-readable storage medium. In a computer-readable storage medium embodiment according to the present application, the computer-readable storage medium can be configured to store a program for executing the SQL query method of the above method embodiment, and the program can be loaded and run by the processor to implement the above SQL query method. For ease of explanation, only the parts related to the embodiment of the present application are shown. For specific technical details not disclosed, please refer to the method part of the embodiment of the present application. The computer-readable storage medium can be a memory device formed by various electronic devices. Optionally, the computer-readable storage medium in the embodiment of the present application is a non-temporary computer-readable storage medium.

[0185] Further, it should be understood that since the setting of each module is only for illustrating the functional units of the device of the present application, the physical devices corresponding to these modules may be the processor itself, or a part of the software in the processor, a part of the hardware, or a part of the combination of software and hardware. Therefore, the number of each module in the figure is only schematic.

[0186] It is understood by those skilled in the art that each module in the device can be adaptively split or merged. Such splitting or merging of specific modules will not cause the technical solution to deviate from the principle of the present application, and therefore, the technical solutions after splitting or merging will fall within the protection scope of the present application.

[0187] The relevant user personal information that may be involved in the various embodiments of this application is strictly in accordance with the requirements of laws and regulations, following the principles of legality, legitimacy and necessity, based on the reasonable purposes of business scenarios, to process the personal information that users actively provide during the use of products / services or generated due to the use of products / services, as well as the personal information obtained with the user's authorization.

[0188] The user personal information processed by this application will vary depending on the specific product / service scenario, and will be based on the specific scenario in which the user uses the product / service. It may involve the user's account information, device information, driving information, vehicle information or other related information. The applicant will treat the user's personal information and its processing with a high degree of diligence.

[0189] This application attaches great importance to the security of user personal information and has taken reasonable and feasible security protection measures that meet industry standards to protect user information and prevent personal information from being accessed, disclosed, used, modified, damaged or lost without authorization.

[0190] So far, the technical solutions of the present application have been described in conjunction with the specific implementations shown in the accompanying drawings, but it is easy for those skilled in the art to understand that the protection scope of the present application is obviously not limited to these specific implementations. Without departing from the principles of the present application, those skilled in the art can make equivalent changes or substitutions to the relevant technical features, and the technical solutions after these changes or substitutions will fall within the protection scope of the present application.

Claims

1. A SQL query method, characterized in that: The method comprises: Obtaining the connection relationship between the query engine and the preset database; Loading the data source of the preset database based on the connection relationship; Acquire a mapping relationship between the query engine and a data source of the preset database; Get the first SQL query request; A query result is obtained based on the first SQL query request and the mapping relationship.

2. The SQL query method according to claim 1, characterized in that: The obtaining of the connection relationship between the query engine and the preset database includes: Obtaining the data source type, data source name and address information corresponding to the preset database; A connection relationship between a query engine and a preset database is obtained based on the data source type, the data source name and the address information.

3. The SQL query method according to claim 1, characterized in that: The obtaining of a mapping relationship between the query engine and a data source of the preset database includes: Obtaining the data source type corresponding to the preset database; The data source of the preset database is mapped to the hierarchical structure of the query engine based on the data source type to obtain a mapping relationship between the query engine and the data source.

4. The SQL query method according to claim 1, characterized in that: When the data source type of the preset database is a structured data storage format, before obtaining the mapping relationship between the query engine and the data source of the preset database, the method further includes: Parsing the preset database to obtain field information of each database table in the preset database; Creating a database table of a distributed database based on the field information; The data source in the database is written into the database table corresponding to the distributed database.

5. The SQL query method according to claim 1, characterized in that: The obtaining the query result based on the first SQL query request and the mapping relationship includes: Acquire data source information in the first SQL query request based on the first SQL query request; identifying the type of the data source based on the data source information; Determine a second SQL query request based on the type of the data source and the mapping relationship; Obtain query results based on the second SQL query request.

6. The SQL query method according to claim 5, characterized in that: The acquiring the data source information in the first SQL query request based on the first SQL query request includes: Parsing the first SQL query request to obtain an execution plan in the first SQL query request; Metadata is extracted from the execution plan to obtain data source information in the first SQL query request.

7. The SQL query method according to claim 6, characterized in that: The parsing the first SQL query request to obtain an execution plan in the first SQL query request includes: Using a lexical analyzer to identify keywords and identifiers in the first SQL query request; Using a syntax analyzer to perform syntax construction on the keywords and the identifiers to generate a syntax tree; A compiler is used to compile and parse the syntax tree to obtain the execution plan.

8. The SQL query method according to claim 1, characterized in that: The first SQL query request includes a data source name, a library name, and a table name. The data source name and the library name, and the library name and the table name are connected by a separator.

9. A smart device, characterized in that: include: at least one processor; and, a memory communicatively coupled to the at least one processor; The memory stores a computer program, and when the computer program is executed by the at least one processor, the SQL query method according to any one of claims 1 to 8 is implemented.

10. A computer-readable storage medium storing a plurality of program codes, characterized in that: The program code is suitable for being loaded and run by a processor to execute the SQL query method according to any one of claims 1 to 8.