Cross-database data query method, device and equipment
1. A cross-repository data query method, the method comprising:
according to an input data set and a query instruction set, querying a plurality of databases to obtain a first target data set, wherein the input data set comprises batch data sets to be queried;
querying the plurality of databases according to the first target data set and the query instruction set to obtain a second target data set;
and associating the first target data set with the second target data set according to the mapping relation to generate a third target data set.
2. The cross-repository data query method according to claim 1, wherein the mapping relationship comprises an association relationship of the first target data set with a second target data set.
3. The cross-repository data query method according to claim 2, wherein the association relationship is obtained when querying the second target data set according to the first target data set and the query instruction set.
4. The cross-repository data query method according to claim 1, wherein the query instruction set comprises a plurality of query instructions, and each query instruction queries one database.
5. The cross-repository data query method according to claim 4, wherein the querying a plurality of databases according to the input data set and the query instruction set to obtain the first target data set comprises:
according to the input data set and each query instruction, querying each database to obtain a sub-target data set, wherein the sub-target data set comprises a part of data sets in the first target data set;
and generating the first target data set according to the sub-target data sets and the connection instruction of each database.
6. The cross-repository data query method according to claim 5, wherein the generating the first target data set according to the sub-target data sets and join instruction of each of the databases comprises:
converting the data set in each sub-target data set into a standard data set according to a preset format;
and generating a first target data set according to the standard data set in each sub-target data set.
7. The cross-repository data query method according to any one of claims 1 to 6, wherein querying a plurality of databases according to the input data set and the query instruction set to obtain the first target data set comprises:
generating a character string to be queried according to an input data set and a merging instruction, wherein the character string to be queried comprises the data set to be queried in the input data set;
and querying in a plurality of databases according to the character string to be queried and the query instruction set to obtain a first target data set.
8. The cross-repository data query method according to any one of claims 1-6, further comprising:
the external data set is loaded by a load instruction to obtain an input data set.
9. A cross-repository data querying device, the device comprising:
the system comprises a first query module, a second query module and a third query module, wherein the first query module is used for querying a plurality of databases according to an input data set and a query instruction set to obtain a first target data set, and the input data set comprises a batch of data sets to be queried;
the second query module is used for querying the plurality of databases according to the first target data set and the query instruction set to obtain a second target data set;
and the generating module is used for associating the first target data set with the second target data set according to the mapping relation to generate a third target data set.
10. A server, characterized in that the server comprises: a memory, a processor;
the memory is used for storing a computer program; the processor is used for realizing the cross-database data query method according to any one of claims 1 to 8 according to the computer program stored in the memory.
11. A computer-readable storage medium, in which a computer program is stored, which, when being executed by a processor, is adapted to carry out a cross-repository data query method according to any one of claims 1-8.
12. A computer program product, characterized in that the computer program product comprises a computer program which, when being executed by a processor, implements the cross-repository data query method according to any one of claims 1-8.
Background
The distributed system has a high degree of cohesion and transparency. The distributed system realizes the dynamic allocation of tasks by using general physical and logical resources, thereby improving the processing efficiency of the data set. In a distributed transformation of an IT system, multiple original systems may be integrated into one distributed system. The plurality of original systems may correspond to a plurality of databases.
Currently, when a system includes multiple databases, an engineer is usually required to manage the multiple databases in a one-by-one operation manner for one database operation. For example, when the database operation is a data query, an engineer needs to edit a plurality of database query instructions to query the plurality of databases one by one, thereby implementing the data query operation.
However, the query method for multiple databases described above has a problem that the query process is complicated, and the database query efficiency is low.
Disclosure of Invention
The application provides a cross-database data query method, a cross-database data query device and cross-database data query equipment, which are used for solving the problem of low database query efficiency in the prior art.
In a first aspect, the present application provides a cross-database data query method, including:
according to an input data set and a query instruction set, querying a plurality of databases to obtain a first target data set, wherein the input data set comprises batch data sets to be queried;
querying the plurality of databases according to the first target data set and the query instruction set to obtain a second target data set;
and associating the first target data set with the second target data set according to the mapping relation to generate a third target data set.
Optionally, the mapping relationship comprises an association relationship of the first target data set and a second target data set.
Optionally, the association relationship is obtained when the second target data set is queried according to the first target data set and the query instruction set.
Optionally, the query instruction set includes a plurality of query instructions, and each query instruction queries one database.
Optionally, the querying a plurality of databases according to the input data set and the query instruction set to obtain a first target data set includes:
according to the input data set and each query instruction, querying each database to obtain a sub-target data set, wherein the sub-target data set comprises a part of data sets in the first target data set;
and generating the first target data set according to the sub-target data sets and the connection instruction of each database.
Optionally, the generating the first target data set according to the sub-target data sets and join instruction of each of the databases includes:
converting the data set in each sub-target data set into a standard data set according to a preset format;
and generating a first target data set according to the standard data set in each sub-target data set.
Optionally, the querying a plurality of databases according to the input data set and the query instruction set to obtain a first target data set includes:
generating a character string to be queried according to an input data set and a merging instruction, wherein the character string to be queried comprises the data set to be queried in the input data set;
and querying in a plurality of databases according to the character string to be queried and the query instruction set to obtain a first target data set.
Optionally, the method further comprises:
the external data set is loaded by a load instruction to obtain an input data set.
In a second aspect, the present application provides a cross-database data query apparatus, including:
the system comprises a first query module, a second query module and a third query module, wherein the first query module is used for querying a plurality of databases according to an input data set and a query instruction set to obtain a first target data set, and the input data set comprises a batch of data sets to be queried;
the second query module is used for querying the plurality of databases according to the first target data set and the query instruction set to obtain a second target data set;
and the generating module is used for associating the first target data set with the second target data set according to the mapping relation to generate a third target data set.
Optionally, the mapping relationship comprises an association relationship of the first target data set and a second target data set.
Optionally, the association relationship is obtained when the second target data set is queried according to the first target data set and the query instruction set.
Optionally, the query instruction set includes a plurality of query instructions, and each query instruction queries one database.
Optionally, the first query module includes:
the first query submodule is used for querying each database according to the input data set and each query instruction to obtain a sub-target data set, and the sub-target data set comprises a part of data sets in the first target data set;
and the first generation submodule is used for generating the first target data set according to the sub-target data sets and the connection instruction of each database.
Optionally, the first generating sub-module is specifically configured to convert the data set in each of the sub-target data sets into a standard data set according to a preset format; and generating a first target data set according to the standard data set in each sub-target data set.
Optionally, the first query module includes:
the second generation submodule is used for generating a character string to be queried according to an input data set and a merging instruction, wherein the character string to be queried comprises the data set to be queried in the input data set;
and the second query submodule is used for querying in a plurality of databases according to the character string to be queried and the query instruction set to obtain a first target data set.
Optionally, the apparatus further comprises:
and the loading module is used for loading the external data set through the loading instruction to obtain the input data set.
In a third aspect, the present application provides a server, comprising: a memory and a processor;
the memory is used for storing program instructions; the processor is configured to invoke program instructions in the memory to perform the cross-library data query method of the first aspect and any one of the possible designs of the first aspect.
In a fourth aspect, the present application provides a readable storage medium, in which execution instructions are stored, and when the execution instructions are executed by at least one processor of the server, the server executes the cross-library data query method in any one of the possible designs of the first aspect and the first aspect.
In a fifth aspect, the present application provides a computer program product comprising a computer program that, when executed by a processor, implements the cross-library data query method of the first aspect and any one of the possible designs of the first aspect.
According to the cross-database data query method, a query instruction set is generated according to database information, and the query instruction set comprises a plurality of query instructions; acquiring an input data set, wherein the input data set can comprise a batch of data sets to be queried; according to the input data set and the query instruction set, querying a plurality of databases to obtain a first target data set; taking the first target data set obtained by query as an input data set for query; according to the first target data set and the query instruction set, querying a plurality of databases to obtain a second target data set; and the first target data set and the second target data set are correlated according to the mapping relation to generate a third target data set, so that the complexity of storing the intermediate data set in the multi-library query process is reduced, and the query efficiency of cross-library query is improved.
Drawings
In order to more clearly illustrate the technical solutions in the present application or the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise.
Fig. 1 is a flowchart of a cross-database data query method according to an embodiment of the present application;
FIG. 2 is a flowchart of another cross-database data query method according to an embodiment of the present application;
fig. 3 is a flowchart of another cross-database data query method according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of a cross-database data query apparatus according to an embodiment of the present application;
fig. 5 is a schematic hardware structure diagram of a server according to an embodiment of the present application.
Detailed Description
To make the purpose, technical solutions and advantages of the present application clearer, the technical solutions in the present application will be clearly and completely described below with reference to the drawings in the present application, and it is obvious that the described embodiments are some, but not all embodiments of the present application. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The terms "first," "second," "third," "fourth," and the like in the description and in the claims of the present application and in the above-described drawings are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It should be understood that the data sets so used are interchangeable under appropriate circumstances such that the embodiments of the application described herein are, for example, capable of operation in sequences other than those illustrated or otherwise described herein.
Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
A distributed system is an integrated system with a high degree of cohesion and transparency. The distributed system includes a plurality of servers. The distributed system realizes the dynamic allocation of tasks in a plurality of servers by using general physical and logical resources, thereby improving the processing efficiency of the data set. In an IT system of a bank, in order to improve the data set processing efficiency of the IT system, the IT system is transformed into a distributed system. Before modification, a plurality of original systems can be included in the IT system. Also, the plurality of original systems may correspond to a plurality of databases. Because each database contains a large number of data sets, the integration of the databases has the problem that the migration of the data sets is complicated. Moreover, after all the data sets are stored in the same database, the reading and writing of the data sets are limited by the reading and writing efficiency of the database, and the use efficiency of the data sets is inevitably lower than that of distributed storage. Therefore, how to implement cross-database query of a data set for the plurality of databases becomes an urgent problem to be solved.
Currently, the cross-library operation is usually implemented by engineers by operating the databases therein one by one. When the database operation is data query, an engineer needs to edit a plurality of database query instructions for each data set to be queried, and query the plurality of databases one by one, thereby implementing the data query operation. The current query of the database mainly comprises a single-library query and a multi-library query. The single-library query refers to a query operation that the server can directly query in the database according to the data set to be queried to obtain a result. For example, when the data query is a single-library query, it may include database 1, database 2, database 3, data set to be queried a, and target data set B. An engineer needs to write three database query instructions of the data set a to be queried, so as to realize the operation of querying the target data set B from the three databases.
The multi-library query refers to a query operation that the server can query to obtain a result only after obtaining at least one intermediate result according to the query of the data to be queried. Two-library queries are the simplest query approach in multi-library queries. The two-database query mode may include that the server queries the database according to the data set a to be queried to obtain an intermediate data set B. And then, the server queries the database according to the intermediate data set B to obtain a target data set C. For example, when the database 1, the database 2, the database 3, the data set a to be queried, and the target data set C are included, an engineer needs to write an intermediate result 1, an intermediate result 2, and an intermediate result 3 of the data set a to be queried in the database 1, the database 2, and the database 3. The intermediate result 1, the intermediate result 2 and the intermediate result 3 may each include an intermediate data set B. An engineer needs to write three database query instructions according to the intermediate result 1, the intermediate result 2 and the intermediate result 3, so that query operations of the three intermediate results in the three databases are realized. The query operation may result in 9 query results, including query result 11, query result 12, query result 13, query result 21, query result 22, query result 23, query result 31, query result 32, and query result 33. Among them, query result 11, query result 12, query result 13, query result 21, query result 22, query result 23, query result 31, query result 32, and query result 33 may respectively include target dataset C.
In the above query process, the database 1, the database 2 and the database 3 may be different databases. Such as SQL Server, Oracle, DB2, Foxpro, Access, MySQL, etc. Alternatively, the databases may include both relational and non-relational databases. Thus, for multi-library queries, the saving of intermediate results can become cumbersome. The complexity of the intermediate results also leads to a reduction in query efficiency and a reduction in query accuracy as the number of databases involved increases, as the number of intermediate result queries in a multi-library query increases.
In order to solve the problems, the application provides a cross-database data query method. The cross-database data Query method mainly comprises an operation Query Language (OPQL). The OPQL language is a database query language proposed by engineers for the technical problems of the present application. Five basic instructions may be included in the database query language. The five basic commands are OPQL _ EXEC, OPQL _ MAP, OPQL _ LOAD, OPQL _ JOIN, and OPQL _ CONCAT, respectively. The classification and function of the above five basic instructions can be as shown in table 1:
TABLE 1
Based on the five basic instructions, the method and the device also store the connection information of different databases in a centralized manner. The engineer can realize the connection of all databases according to the centrally stored database connection information. The application also assigns a database Identification (ID) and a database Name (Name) to each database. Wherein a database Identification (ID) uniquely corresponds to a database. In the single-library query process, the server can realize the query of a data set to be queried in a database through the query instruction OPQL _ EXEC. The query instruction includes 4 parameters. The 4 parameters are respectively database identification, SQL statement template, SQL parameter and result set name. In the multi-library query process, one multi-library query can be split into one or more two-library queries. A two-pool query may be split into multiple single-pool queries.
The server can store the intermediate data sets into a temporary data set with a uniform format when a plurality of intermediate data sets are obtained through one single-base query. And the server performs the second single-library query according to the temporary data set, so as to realize the second two-library query. The server can implement the linkage of the intermediate data sets of the respective databases obtained by querying through a linkage instruction OPQL _ MAP. The binding process includes normalizing the query results of the various databases to a uniform format and storing the uniform format query results in a dataset table. After the multi-library query is completed, the server can also associate a plurality of intermediate data sets into a target data set according to the mapping relation of the intermediate data sets through a mapping instruction OPQL _ JOIN.
During the database query, the input data set may be a batch data set. The input dataset includes a dataset to be queried. The server can LOAD the input data set by using a LOAD instruction OPQL _ LOAD, so that the import of the batch data set to be inquired is realized. The server may also use the merge instruction OPQL _ CONCAT to sort the data set to be queried in the input data set into a string for subsequent querying. Or, the server may also use the merge instruction OPQL _ CONCAT to arrange the target data set obtained by the query into a character string for subsequent storage.
The technical solution of the present application will be described in detail below with specific examples. The following several specific embodiments may be combined with each other, and details of the same or similar concepts or processes may not be repeated in some embodiments.
In the present application, a server is used as an execution subject to execute the cross-database data query method of the following embodiments. Specifically, the execution body may be a hardware device of the server, or a software application in the server, or a computer-readable storage medium on which the software application implementing the following embodiment is installed, or code of the software application implementing the following embodiment.
Fig. 1 shows a flowchart of a cross-database data query method according to an embodiment of the present application. As shown in fig. 1, with a server as an execution subject, the method of this embodiment may include the following steps:
s101, according to the input data set and the query instruction set, a first target data set is obtained by querying in a plurality of databases, wherein the input data set comprises batch data sets to be queried.
In this embodiment, the server may generate the query instruction set according to the database information. The query instruction set includes a plurality of query instructions. Each query instruction corresponds to one query operation of one database. The server obtains an input data set. The input dataset may include a batch of datasets to be queried. The server can query the data set to be queried in each database by taking the data set to be queried as a parameter of a query instruction.
Wherein, a query instruction OPQL _ EXEC can be as follows:
OPQL_EXEC('RS1','DS000000000000004364',"select CARD_NO,CARD_ID,CUSTOMER_NO,CONTRACT_ID from card where CARD_NO in#1",OPQL_CONCAT('RS0','CARD_NO'));
the OPQL _ EXEC includes 4 parameters. Where RS1 is the first target data set. Where DS000000000000004364 is a database Identification (ID). Wherein, the "select CARD _ NO, CARD _ ID, CUSTOMER _ NO, CONTRACT _ ID from CARD word CARD _ NO in #1" is the SQL statement template. The SQL parameters are OPQL _ CONCAT ('RS0', 'CARD _ NO'). In the SQL parameters, OPQL _ CONCAT is a merge instruction. Where RS0 is the input data set. The merge instruction OPQL _ CONCAT is used to retrieve the data set CARD _ NO to be queried in the input data set. The data set to be queried CARD _ NO is a CARD number. The card number will be replaced at SQL statement template # 1. The SQL statement template is used to search the database DS000000000000004364 for a data set whose CARD _ NO coincides with the data set CARD _ NO to be queried. When the server retrieves the data set of which the CARD _ NO is the data set CARD _ NO to be queried in the database DS 00000000004364, the server outputs the four fields of the CARD _ NO, the CARD _ ID, the curstor _ NO and the controlid of the data set to the first target data set. The four data sets may correspond to a card number, a card ID, a customer number, and an account ID, respectively.
In one example, when the input data set includes a batch of data sets to be queried, the server may input the data sets to be queried in the input data set as SQL parameters into the SQL statement template statement. For example, when 1000 user card numbers are included in the input data set, the server inputs the 1000 card numbers as SQL parameters into the SQL statement template statement. The server uses the query instruction OPQL _ EXEC to perform 1000 queries in the database DS000000000000004364 according to the 1000 SQL statement template statements, so as to obtain multiple data sets. Each data set comprises four fields of CARD _ NO, CARD _ ID, CUSTOMER _ NO and CONTRACT _ ID. The server stores the plurality of data sets in a first target data set.
The query instruction set may include a plurality of query instructions OPQL _ EXEC, and each query instruction OPQL _ EXEC includes a different SQL statement template. Alternatively, a different database statement template may also be included in each query instruction OPQL _ EXEC. Different SQL statement templates or database statement templates may include different database Identifiers (IDs), different query statements, and different sub-target data sets. Wherein the sub-target data set is a subset of the first target data set. The plurality of query instructions OPQL _ EXEC include the same input data set therein. The server may integrate the plurality of sub-target data sets into a first target data set RS1 set by means of join instructions.
And S102, inquiring in a plurality of databases according to the first target data set and the inquiry instruction set to obtain a second target data set.
In this embodiment, the server queries the first target data set as an input data set. The server may query the second target data set through the same query instruction set as S101 and a different input data set.
For example, after the server determines the account ID (controlid) from the first target data set, the server may query the account balance according to the account ID. The query instruction can be: OPQL _ EXEC ('RS2', 'DS000000000000004488', 'select CUSTOMER _ ID, CUSTOMER _ NO from CUSTOMER where CUSTOMER _ NO # 1', OPQL _ CONCAT ('RS1', 'CUSTOMER _ NO'));
where RS2 is the second target data set. Wherein DS000000000000004488 is a database Identification (ID). Wherein, the "select CUSTOMER _ ID, CUSTOMER _ NO from CUSTOMER where CUSTOMER _ NO in #1" is the SQL statement template. This SQL statement template is used to search the database DS000000000000004488 for a data set in which CUSTOMER _ NO coincides with CUSTOMER _ NO in the first target data set RS 1. When the server retrieves a data set in the database DS000000000000004488 for which the CUSTOMER _ NO coincides with the CUSTOMER _ NO in the first target data set RS1, the server outputs both fields of the CUSTOMER _ ID, CUSTOMER _ NO of the piece of data set into the second target data set RS 2. The two fields correspond to the account ID and balance, respectively.
S103, associating the first target data set with the second target data set according to the mapping relation to generate a third target data set.
In this embodiment, after the server determines the first target data set RS1 according to the input data set RS0, the server queries the first target data set RS1 to obtain a second target data set RS 2. For example, the server queries the database for a second target data set RS2 using the account ID (CUSTOMER _ NO) in the first target data set RS 1. Therefore, the server can determine the association relationship between the first target data set RS1 and the second target data set RS2 according to the account ID (CUSTOMER _ NO). The server can determine the mapping relation between the first target data set RS1 and the second target data set RS2 according to the association relation. The mapping is used to correspond one of the first target data sets RS1 to one of the second target data sets RS 2. The server generates a third target data set RS3 according to the mapping relation.
The association process may be implemented by a mapping function OPQL _ JOIN, and the implementation process may include:
OPQL_JOIN('RS3','RS1','RS2','CUSTOMER_NO=CUSTOMER_NO');
wherein RS1 is the first target data set, RS2 is the second target data set, and RS3 is the third target data set. Wherein the mapping condition includes CUSTOMER _ NO ═ CUSTOMER _ NO. That is, if and only if CUSTOMER _ NO in RS1 is the same as CUSTOMER _ NO in RS2, the server determines that a mapping relationship exists between the two data sets, and merges the two data sets into one data set. The merged data set is stored in RS 3.
According to the cross-database data query method, the server can generate a query instruction set according to the database information. The query instruction set includes a plurality of query instructions. The server obtains an input data set. The input dataset may include a batch of datasets to be queried. The server queries a plurality of databases according to the input data set and the query instruction set to obtain a first target data set. And the server takes the first target data set obtained by query as an input data set for query. And the server queries a plurality of databases according to the first target data set and the query instruction set to obtain a second target data set. And the server associates the first target data set with the second target data set according to the mapping relation to generate a third target data set. In the application, the server can realize one-time two-library query through the two-time single-library query. The server can also realize multi-library query through multiple two-library query. The server realizes multi-library query by using the basic instruction in the OPQL, reduces the complexity of intermediate data set storage, improves the query efficiency of cross-library query, and improves the query accuracy of cross-library query.
Fig. 2 is a flowchart illustrating another cross-database data query method according to an embodiment of the present application. On the basis of the embodiment shown in fig. 1, as shown in fig. 2, when the query instruction set includes a plurality of query instructions, each query instruction queries one database, and a server is used as an execution subject, the method of this embodiment may include the following steps:
s201, loading an external data set through a loading instruction to obtain an input data set.
In this embodiment, the server may load the external data set through the load instruction. And obtaining the input data set by the server after obtaining the external data set. The external data set may be a data set stored in a preset format. The external data set may include a variety of storage means. The server may set the load instruction according to the plurality of storage manners. The LOAD instruction OPQL _ LOAD may read the external data set by obtaining the address of the external data set, which in turn results in the input data set RS 0. The input data set may be in the form of a table. A plurality of fields may be included in the table. The data set to be queried is one or more fields in the input data set.
S202, according to the input data set and each query instruction, a sub-target data set is obtained by querying in each database, wherein the sub-target data set comprises a part of data sets in the first target data set.
In this embodiment, the server may generate the query instruction set according to the database information. The query instruction set includes a plurality of query instructions. Each query instruction corresponds to one query operation of one database. Wherein, the server determines the data set obtained from each database by each query instruction as the sub-target data set.
In one example, different sub-target datasets can have different dataset formats. The data set format may be determined according to the database to which the sub-target data set corresponds.
S203, generating a first target data set according to the sub-target data sets and the connection instruction of each database.
In this embodiment, the server may include a join instruction OPQL _ MAP. After the server obtains the plurality of sub-target data sets, the join instruction OPQL _ MAP may integrate the plurality of sub-target data sets into one data set, i.e. the first target data set. The parameters of the join command OPQL _ MAP may include a query command set. The join instruction OPQL _ MAP may integrate the respective query instruction query result sub-target data sets included in the parameters into one data set.
In an example, when the data sets in each sub-target data set have different data set formats, S203 may specifically include:
step 1, the server carries out format conversion operation on each sub-target data set according to a preset format. And the server converts the format of each sub-target data set into a preset format to obtain a standard data set.
And 2, putting the standard data set of each sub-target data set into one data set by the server, wherein the data set is the first target data set.
And S204, inquiring in a plurality of databases according to the first target data set and the inquiry instruction set to obtain a second target data set.
S205, associating the first target data set with the second target data set according to the mapping relation to generate a third target data set.
Steps S204 and S205 are similar to steps S102 and S103 in the embodiment of fig. 2, and are not described again in this embodiment.
According to the cross-database data query method, the server can load the external data set through the loading instruction. And obtaining the input data set by the server after obtaining the external data set. The server may generate a set of query instructions based on the database information. The query instruction set includes a plurality of query instructions. Each query instruction corresponds to one query operation of one database. Wherein, the server determines the data set obtained from each database by each query instruction as the sub-target data set. After the server obtains the plurality of sub-target data sets, the join instruction may integrate the plurality of sub-target data sets into one data set, i.e., the first target data set. And the server queries a plurality of databases according to the first target data set and the query instruction set to obtain a second target data set. And the server associates the first target data set with the second target data set according to the mapping relation to generate a third target data set. In the application, by using the connection instruction, the execution of the query instruction set is realized, and a plurality of sub-target data sets are integrated into one data set, so that the intermediate data set can be stored in one data set, the complexity of the intermediate data set is reduced, and the query efficiency of cross-library query is improved.
Fig. 3 is a flowchart illustrating a further cross-database data query method according to an embodiment of the present application. On the basis of the embodiments shown in fig. 1 and fig. 2, as shown in fig. 3, when the query instruction set includes a plurality of query instructions, each query instruction queries one database, and the server is used as an execution subject, the method of this embodiment may include the following steps:
s301, generating a character string to be queried according to the input data set and the merging instruction, wherein the character string to be queried comprises the data set to be queried in the input data set.
In this embodiment, after acquiring the input data set, the server acquires the data set to be queried from the input data set by using the merge instruction. For example, as shown by the query instruction, OPQL _ EXEC ('RS1', 'DS000000000000004364', 'select CARD _ NO, CARD _ ID, CUSTOMER _ NO, CONTRAT _ ID from CARD where CARD _ NO in # 1', OPQL _ CONCAT ('RS0', 'CARD _ NO')) includes a merge instruction. Before executing the query instruction, the server acquires the data set to be queried according to the merging instruction indicated by the SQL parameter. The merging instruction OPQL _ CONCAT is specifically configured to, after acquiring the data set to be queried in the input data set, generate a character string to be queried according to the data set to be queried. In the character string to be queried, two data sets to be queried are separated by a preset symbol. The preset symbol may be a symbol such as ","/", etc. For example, when a plurality of card numbers are included in the string to be queried, the string to be queried may be "6216920 xxxx1225, 6216920xxxx1226, 6216920xxxx1227, 6216920xxxx 1228".
S302, according to the character string to be queried and the query instruction set, a first target data set is obtained through query in a plurality of databases.
In this embodiment, after generating the character string to be queried, the server inputs the character string to be queried into the query instruction, thereby implementing batch query of the data set to be queried. For example, as shown by the query instruction, OPQL _ EXEC ('RS1', 'DS000000000000004364', 'select CARD _ NO, CARD _ ID, CUSTOMER _ NO, CONTRAT _ ID from CARD where CARD _ NO in # 1', OPQL _ CONCAT ('RS0', 'CARD _ NO')). The server generates a character string to be queried according to the merging instruction OPQL _ CONCAT ('RS0', 'CARD _ NO') indicated by the SQL parameter. The data set to be queried in the character string to be queried replaces the content #1 in the SQL statement template to generate a query statement corresponding to the data set to be queried, so that the data set to be queried is queried in batches.
And S303, inquiring in a plurality of databases according to the first target data set and the inquiry instruction set to obtain a second target data set.
And S304, associating the first target data set with the second target data set according to the mapping relation to generate a third target data set.
Steps S303 and S304 are similar to steps S102 and S103 in the embodiment of fig. 2, and are not described again in this embodiment.
According to the cross-database data query method, after the server obtains the input data set, the server obtains the data set to be queried from the input data set by using the merging instruction. And after acquiring the data set to be queried in the input data set, the merging instruction generates a character string to be queried according to the data set to be queried. And the server inputs the character string to be queried into a query instruction to realize batch query of the data set to be queried. And the server queries a plurality of databases according to the first target data set and the query instruction set to obtain a second target data set. And the server associates the first target data set with the second target data set according to the mapping relation to generate a third target data set. In the application, the merging instruction is used for converting the format of the data set to be queried into the character string to be queried, so that the data set to be queried in the input data set can be extracted and used, the use efficiency of the input data set is further improved, and the query efficiency of cross-library query is improved.
Fig. 4 shows a schematic structural diagram of a cross-database data query apparatus according to an embodiment of the present application, as shown in fig. 4, a cross-database data query apparatus 10 according to this embodiment is used to implement an operation corresponding to a server in any one of the method embodiments, where the cross-database data query apparatus 10 according to this embodiment includes:
the first query module 11 is configured to query the multiple databases according to the input data set and the query instruction set to obtain a first target data set, where the input data set includes batch data sets to be queried.
And the second query module 12 is configured to query the multiple databases to obtain a second target data set according to the first target data set and the query instruction set.
And the generating module 13 is configured to associate the first target data set with the second target data set according to the mapping relationship, and generate a third target data set.
In one example, the mapping relationship includes a first association of the input data set with a first target data set and a second association of the first target data set with a second target data set.
In one example, the first association is obtained when querying the first target data set based on the input data set and the query instruction set, and the second association is obtained when querying the second target data set based on the first target data set and the query instruction set.
In one example, when the query instruction set includes a plurality of query instructions, each query instruction being for querying one database, the first query module 11 may include:
the first query submodule 111 is configured to query each database according to the input data set and each query instruction to obtain a sub-target data set, where the sub-target data set includes a part of data sets in the first target data set.
The first generating sub-module 112 is configured to generate a first target data set according to the sub-target data sets and the join instruction of each database.
The first generating submodule is specifically configured to convert the data set in each sub-target data set into a standard data set according to a preset format. And generating a first target data set according to the standard data set in each sub-target data set.
In another example, the first query module 11 may further include:
the second generating sub-module 113 is configured to generate a to-be-queried character string according to the input data set and the merging instruction, where the to-be-queried character string includes a to-be-queried data set in the input data set.
And the second query submodule 114 is configured to query the multiple databases to obtain a first target data set according to the character string to be queried and the query instruction set.
In one example, the cross-database data query apparatus 10 further includes:
and the loading module 14 is used for loading the external data set through a loading instruction to obtain an input data set.
The cross-database data query device 10 provided in the embodiment of the present application may implement the above method embodiment, and specific implementation principles and technical effects thereof may refer to the above method embodiment, which is not described herein again.
Fig. 5 shows a hardware structure diagram of a server provided in an embodiment of the present application. As shown in fig. 5, the server 20 is configured to implement the operation corresponding to the server in any of the above method embodiments, where the server 20 of this embodiment may include: memory 21, processor 22.
A memory 21 for storing a computer program. The Memory 21 may include a Random Access Memory (RAM), a Non-Volatile Memory (NVM), at least one disk Memory, a usb disk, a removable hard disk, a read-only Memory, a magnetic disk or an optical disk.
A processor 22 for executing the computer program stored in the memory to implement the cross-database data query method in the above embodiments. Reference may be made in particular to the description relating to the method embodiments described above. The Processor 22 may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), or the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of a method disclosed in connection with the present invention may be embodied directly in a hardware processor, or in a combination of the hardware and software modules within the processor.
Alternatively, the memory 21 may be separate or integrated with the processor 22.
When memory 21 is a separate device from processor 22, server 20 may also include bus 23. The bus 23 is used to connect the memory 21 and the processor 22. The bus 23 may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, an Extended ISA (EISA) bus, or the like. The bus may be divided into an address bus, a data set bus, a control bus, etc. For ease of illustration, the buses in the figures of the present application are not limited to only one bus or one type of bus.
Optionally, the server may also include a communication interface 24. The communication interface 24 may be connected to the processor 21 via a bus 23. The communication interface 24 may be used to obtain an input data set from which the processor 21 will perform the cross-repository data query function via the cross-repository data query method described above.
The server provided in this embodiment may be used to execute the cross-database data query method, and the implementation manner and the technical effect thereof are similar, and this embodiment is not described herein again.
The present application also provides a computer-readable storage medium, in which a computer program is stored, and the computer program is used for implementing the methods provided by the above-mentioned various embodiments when being executed by a processor.
The computer-readable storage medium may be a computer storage medium or a communication medium. Communication media includes any medium that facilitates transfer of a computer program from one place to another. Computer storage media may be any available media that can be accessed by a general purpose or special purpose computer. For example, a computer readable storage medium is coupled to the processor such that the processor can read information from, and write information to, the computer readable storage medium. Of course, the computer readable storage medium may also be integral to the processor. The processor and the computer-readable storage medium may reside in an Application Specific Integrated Circuit (ASIC). Additionally, the ASIC may reside in user equipment. Of course, the processor and the computer-readable storage medium may also reside as discrete components in a communication device.
In particular, the computer-readable storage medium may be implemented by any type of volatile or non-volatile Memory device or combination thereof, such as Static Random-Access Memory (SRAM), Electrically-Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read-Only Memory (EPROM), Programmable Read-Only Memory (PROM), Read-Only Memory (ROM), magnetic Memory, flash Memory, magnetic disk, or optical disk. A storage media may be any available media that can be accessed by a general purpose or special purpose computer.
The present application also provides a computer program product comprising a computer program stored in a computer readable storage medium. The computer program can be read by at least one processor of the device from a computer-readable storage medium, and execution of the computer program by the at least one processor causes the device to implement the methods provided by the various embodiments described above.
Embodiments of the present application further provide a chip, where the chip includes a memory and a processor, where the memory is used to store a computer program, and the processor is used to call and run the computer program from the memory, so that a device in which the chip is installed executes the method in the above various possible embodiments.
In the several embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, a division of modules is merely a division of logical functions, and an actual implementation may have another division, for example, a plurality of modules may be combined or may be integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or modules, and may be in an electrical, mechanical or other form.
Wherein the modules may be physically separated, e.g. mounted at different locations of one device, or mounted on different devices, or distributed over multiple network elements, or distributed over multiple processors. The modules may also be integrated, for example, in the same device, or in a set of codes. The respective modules may exist in the form of hardware, or may also exist in the form of software, or may also be implemented in the form of software plus hardware. The method and the device can select part or all of the modules according to actual needs to achieve the purpose of the scheme of the embodiment.
When the respective modules are implemented as integrated modules in the form of software functional modules, they may be stored in a computer-readable storage medium. The software functional module is stored in a storage medium and includes several instructions to enable a computer device (which may be a personal computer, a server, or a network device) or a processor to execute some steps of the methods according to the embodiments of the present application.
It should be understood that, although the respective steps in the flowcharts in the above-described embodiments are sequentially shown as indicated by arrows, the steps are not necessarily performed sequentially as indicated by the arrows. The steps are not performed in the exact order shown and may be performed in other orders unless explicitly stated herein. Moreover, at least some of the steps in the figures may include multiple sub-steps or multiple stages that are not necessarily performed at the same time, but may be performed at different times, in different orders, and may be performed alternately or at least partially with respect to other steps or sub-steps of other steps.
Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit the same. Although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: it is also possible to modify the solutions described in the previous embodiments or to substitute some or all of them with equivalents. And the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present application.
- 上一篇:石墨接头机器人自动装卡簧、装栓机
- 下一篇:一种基于区块链的基金信息实时交互系统