Disclosure of Invention
In view of this, embodiments of the present invention provide data query methods and apparatuses, and the method implements lightweight data query frameworks, and can freely and quickly transform the dimensionality of data query while ensuring the timeliness of data query.
To achieve the above object, according to aspects of the embodiment of the present invention, there is provided a data query method, including parsing a data query request from a data request end to obtain configuration information of a database to be queried, creating a data query task according to the configuration information of the database to be queried to query the database to be queried, and returning a query result to the data request end.
Optionally, creating a data query task according to the database configuration information to be queried includes: and assembling query sentences according to the database configuration information to be queried so as to obtain query results through a database query method.
Optionally, the database configuration information to be queried at least includes: the database address to be inquired, the database name to be inquired and the inquiry logic information.
Optionally, the database configuration information to be queried further includes: the number of the sub-libraries, the number of the sub-tables of each sub-library and the name of each sub-table; the database address to be inquired is a branch database address to be inquired, and the name of the database to be inquired is a branch database name to be inquired;
creating a data query task according to the configuration information of the database to be queried so as to query the database to be queried, wherein the data query task comprises the following steps: determining the number of times of circular query according to the number of the sub-libraries and the number of the sub-tables of each sub-library so as to circularly execute the following steps: assembling a current query statement to be executed according to the name of the current sub-library to be queried, the name of the current sub-table to be queried and query logic information; according to the current query statement to be executed, obtaining a current query result through a database query method and adding the result to a query result set;
returning the query result to the data request end comprises: and when the circular query is completed, returning the query result set to the data request end.
Optionally, the database configuration information to be queried further includes a callback task class name and a callback method name; returning the query result to the data request end comprises: and returning the query result to the data request end according to the callback task class name and the callback method name.
To achieve the above object, according to another aspect of the embodiment of the present invention, there is provided a data query apparatus, including a parameter parsing module configured to parse a data query request from a data request end to obtain database configuration information to be queried, a database access module configured to create a data query task according to the database configuration information to be queried to query a database to be queried, and a result returning module configured to return a query result to the data request end.
Optionally, the database access module is further configured to: and assembling query sentences according to the database configuration information to be queried so as to obtain query results through a database query method.
Optionally, the database configuration information to be queried at least includes: the database address to be inquired, the database name to be inquired and the inquiry logic information.
Optionally, the database configuration information to be queried further includes: the number of the sub-libraries, the number of the sub-tables of each sub-library and the name of each sub-table; the database address to be inquired is a branch database address to be inquired, and the name of the database to be inquired is a branch database name to be inquired;
the database access module is further configured to: determining the number of times of circular query according to the number of the sub-libraries and the number of the sub-tables of each sub-library so as to circularly execute the following steps: assembling a current query statement to be executed according to the name of the current sub-library to be queried, the name of the current sub-table to be queried and query logic information; according to the current query statement to be executed, obtaining a current query result through a database query method and adding the result to a query result set;
the result returning module is further configured to: and when the circular query is completed, returning the query result set to the data request end.
Optionally, the database configuration information to be queried further includes a callback task class name and a callback method name;
the result returning module is further configured to: and returning the query result to the data request end according to the callback task class name and the callback method name.
To achieve the above object, according to yet another aspect of the present invention, there is provided electronic devices, including processors or a plurality of processors, and a storage device for storing programs, which when the programs or the plurality of programs are executed by the processors, make the processors or the plurality of processors implement the data query method of the present invention.
To achieve the above object, according to aspects of the embodiment of the present invention, computer-readable media are provided, on which computer programs are stored, which when executed by a processor implement the data query method of the embodiment of the present invention.
The embodiments in the invention have the advantages or beneficial effects that the technical means of analyzing the data query request from the data request end to obtain the configuration information of the database to be queried, creating the data query task according to the configuration information of the database to be queried to query the database to be queried and returning the query result to the data request end is adopted, so that lightweight data query frameworks are realized, and data can be queried flexibly in real time.
The effect of step of the above non-conventional alternative is described below in conjunction with the detailed description.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Fig. 1 is a schematic diagram of a main flow of a data query method according to an embodiment of the present invention, as shown in fig. 1, the method includes:
step S101: and analyzing the data query request from the data request terminal to obtain the configuration information of the database to be queried.
The database configuration information to be queried at least comprises: the database address to be inquired, the database name to be inquired and the inquiry logic information. The query logic information includes a keyword of an SQL query statement (structured query Language) having a specific logic. The data request end can be a service system or a service party needing to inquire data.
In an optional embodiment, the database configuration information to be queried further includes a database access user name and a database access password for accessing the database.
Step S102: and creating a data query task according to the configuration information of the database to be queried so as to query the database to be queried.
JDBC (Java data base Connectivity ) is Java API (Application Programming Interface) for executing SQL statements (structured query Language), which provides system access to multiple relational databases and consists of sets of classes and interfaces written in Java Language (Java is object oriented Programming Language).
Specifically, the step may include the following steps:
and assembling query sentences according to the database configuration information to be queried so as to obtain query results through a database query method.
The method comprises the steps of acquiring a database address to be queried, a database name to be queried and query logic information, assembling query statements according to the database address to be queried, the database name to be queried and the query logic information, and executing a JDBC.
Step S103: and returning the query result to the data request end.
In an optional embodiment, the database configuration information to be queried further includes a callback task class name and a callback method name. And returning the query result to the data request end according to the callback task class name and the callback method name.
In the embodiment, after a data query request from a data request terminal is received, a callback task can be created to return a query result to the data request terminal after the query result is obtained, and in Java, a task is an object, and classes need to be defined for the task in order to create the task.
Among them, RPC (remote procedure Call) -remote procedure call, which is protocols that request services from remote computer programs over a network without knowledge of the underlying network technology.
The data query method of the embodiment of the invention can query the database in real time according to the data query request of the data request terminal, does not need an offline data wide table, and ensures the timeliness of data query; for the data request end, a data query framework does not need to be maintained, the dimensionality of data query can be freely and flexibly changed, and the problems and the labor are saved; the database is directly inquired by using a database inquiry method, so that overtime limit caused by inquiry by using a third-party management platform is avoided.
In an optional embodiment, when the data to be queried is stored in the sub-repository sub-table, the database configuration information to be queried may further include: the database number, the database address to be inquired, the database name to be inquired, the table number of each database and the name of each table.
Further to step , the method may further include:
determining the number of times of circular query according to the number of the sub-libraries and the number of the sub-tables of each sub-library so as to circularly execute the following steps:
assembling a current query statement to be executed according to the name of the current sub-library to be queried, the name of the current sub-table to be queried and query logic information;
and executing the current query statement to be executed by a database query method according to the current query statement to be executed, obtaining a current query result and adding the result to a query result set.
And when the cyclic query is completed, namely after all the sub-libraries and sub-tables related to the data query task are traversed, returning a query result set serving as a parameter of a callback task to the data request terminal.
The data query method of the embodiment of the invention obtains the database configuration information by analyzing the data query request, dynamically assembles the query statement, circularly executes the query statement to obtain the data result set, cooperates with the RPC management center to carry out callback processing, realizes lightweight data query frameworks, and provides an API (application programming interface) externally at the same time, thereby ensuring the timeliness and flexibility of data query.
Fig. 2 is a schematic diagram of a main flow of a data query method according to another embodiment of the present invention, as shown in fig. 2, the method includes:
step S201: and analyzing the data query request of the service calling party to obtain the configuration information of the database to be queried. As shown in table 1, the configuration information includes: the method comprises the following steps of database access address dbAddress, user name dbUser, password dbPassWord, database name dbName, database quantity dbCount, table quantity tableCount, table name tableName, query logic information sql, callback task class name invokeClassName and callback method name invokeMethod.
Table 1:
properties
|
Name of Chinese
|
dbAddress
|
Database access address
|
dbUser
|
Database access username
|
dbPassWord
|
Database access password
|
dbName
|
Database name
|
dbStartIndex
|
Library start suffix
|
dbEndIndex
|
End of library suffix
|
tableName
|
Table name
|
startNo
|
Table start suffix
|
endNo
|
End of Table suffix
|
invokeClassName
|
Callback task class name
|
invokeMethod
|
Callback method name
|
sql
|
Querying logical information |
Step S202: and using a variable m to indicate that the current sub-library to be queried is the mth sub-library, wherein m is a positive integer smaller than dbCount. The initial value of m is 0.
Step S203: and judging whether m is smaller than dbCount, if so, executing the step S204, and if not, ending the process.
Step S204: and using a variable n to represent that the sub-table to be queried currently is the nth sub-table of the sub-base to be queried currently, wherein n is a positive integer smaller than tableCount. The initial value of n is 0.
Step S205, judging whether n is less than tableCount, if yes, executing step S206, if no, indicating that all the sublists in the current sublibrary to be inquired have traversed, executing step S209 to add 1 to m so as to inquire sublibraries.
Step S206: and assembling the query statement to be executed according to the name of the current sub-library to be queried, the name of the current sub-table to be queried and the query logic information.
Step S207: and executing the JDBC.
And step S208, adding 1 to n, and returning to execute the step S205 to inquire the next branch tables in the branch library to be inquired currently.
Step S209, adding 1 to m to inquire the next sub-libraries.
According to the data query method, the database configuration information is obtained by analyzing the data query request, the query statement is dynamically assembled, the query statement is circularly executed to obtain the data result set, and the callback processing is performed in cooperation with the RPC management center, so that lightweight data query frameworks are realized, an API (application programming interface) is provided externally, the timeliness and flexibility of data query are guaranteed, the flexibility of marketing dispersion and complex data query is improved in the actual use process, a business party can concentrate on the analysis processing after the data query, and the overall efficiency of data analysis is improved.
Fig. 3 is a schematic diagram of main blocks of a data query apparatus 300 according to an embodiment of the present invention, as shown in fig. 3, the apparatus 300 includes:
the parameter analysis module 301 is configured to analyze a data query request from a data request end to obtain database configuration information to be queried;
a database access module 302, configured to create a data query task assembly query statement according to the database configuration information to be queried, so as to query the database to be queried;
and a result returning module 303, configured to return the query result to the data requesting end.
Optionally, the database access module 302 is further configured to:
and assembling query sentences according to the database configuration information to be queried so as to obtain query results through a database query method.
Optionally, the database configuration information to be queried at least includes: the database address to be inquired, the database name to be inquired and the inquiry logic information.
Optionally, the database configuration information to be queried further includes: the number of the sub-libraries, the number of the sub-tables of each sub-library and the name of each sub-table; the database address to be inquired is a branch database address to be inquired, and the name of the database to be inquired is a branch database name to be inquired;
the database access module 302 is further configured to:
determining the number of times of circular query according to the number of the sub-libraries and the number of the sub-tables of each sub-library so as to circularly execute the following steps:
assembling a current query statement to be executed according to the name of the current sub-library to be queried, the name of the current sub-table to be queried and query logic information;
executing the current query statement to be executed by a database query method according to the current query statement to be executed, obtaining a current query result and adding the result to a query result set;
the result returning module 303 is further configured to: and when the circular query is completed, returning the query result set to the data request end.
The database configuration information to be inquired also comprises a callback task class name and a callback method name;
the result returning module 303 is further configured to: and returning the query result to the data request end according to the callback task class name and the callback method name.
According to the data query device, the database configuration information is obtained by analyzing the data query request, the query statement is dynamically assembled, the query statement is circularly executed to obtain the data result set, and the callback processing is performed in cooperation with the RPC management center, so that lightweight data query frameworks are realized, an API (application programming interface) is provided externally, the timeliness and flexibility of data query are guaranteed, the flexibility of marketing dispersion and complex data query is improved in the actual use process, a business party can concentrate on the analysis processing after the data query, and the overall efficiency of data analysis is improved.
The device can execute the method provided by the embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method. For technical details that are not described in detail in this embodiment, reference may be made to the method provided by the embodiment of the present invention.
Fig. 4 shows an exemplary system architecture 400 of a data query method or data query device to which embodiments of the present invention may be applied.
As shown in fig. 4, the system architecture 400 may include terminal devices 401, 402, 403, a network 404, and a server 405. The network 404 serves as a medium for providing communication links between the terminal devices 401, 402, 403 and the server 405. Network 404 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use terminal devices 401, 402, 403 to interact with a server 405 over a network 404 to receive or send messages or the like. The terminal devices 401, 402, 403 may have various communication client applications installed thereon, such as shopping applications, web browser applications, search applications, instant messaging tools, mailbox clients, social platform software, and the like.
The terminal devices 401, 402, 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 405 may be a server that provides various services, such as a background management server that supports shopping websites browsed by users using the terminal devices 401, 402, and 403. The background management server may analyze and perform other processing on the received data such as the product information query request, and feed back a processing result (e.g., target push information and product information) to the terminal device.
It should be noted that the data query method provided by the embodiment of the present invention is generally executed by the server 405, and accordingly, the data query apparatus is generally disposed in the server 405.
It should be understood that the number of terminal devices, networks, and servers in fig. 4 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 5, therein is shown a schematic block diagram of a computer system 500 suitable for use with a terminal device embodying embodiments of the present invention, the terminal device shown in FIG. 5 is merely an example and should not impose any limitations on the functionality or scope of use of embodiments of the present invention.
As shown in fig. 5, the computer system 500 includes a Central Processing Unit (CPU)501 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)502 or a program loaded from a storage section 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data necessary for the operation of the system 500 are also stored. The CPU 501, ROM 502, and RAM 503 are connected to each other via a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
The following components are connected to the I/O interface 505: an input portion 506 including a keyboard, a mouse, and the like; an output portion 507 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 508 including a hard disk and the like; and a communication section 509 including a network interface card such as a LAN card, a modem, or the like. The communication section 509 performs communication processing via a network such as the internet. The driver 510 is also connected to the I/O interface 505 as necessary. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as necessary, so that a computer program read out therefrom is mounted into the storage section 508 as necessary.
For example, the embodiments of the present disclosure include computer program products comprising a computer program embodied on a computer readable medium, the computer program containing program code for performing the method illustrated by the flow chart.
A more specific example of a computer readable storage medium may include, but is not limited to, an electrical connection having or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures, for example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved, and it may also be noted that each block of the block diagrams or flowchart illustrations, and combinations of blocks in the block diagrams or flowchart illustrations, may be implemented by special purpose hardware-based systems that perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The described modules can also be arranged in a processor, for example, kinds of processors comprise a sending module, an acquisition module, a determination module and a processing module, wherein the names of the modules do not form a limitation to the unit per se in some cases, for example, the sending module can also be described as a module for sending a picture acquisition request to a connected server.
As another aspect, the present invention also provides computer readable media, which may be contained in the devices described in the above embodiments, or may exist separately and not be assembled into the devices, the computer readable media carrying or more programs, which when executed by devices, cause the devices to comprise:
analyzing a data query request from a data request terminal to obtain database configuration information to be queried;
creating a data query task according to the configuration information of the database to be queried so as to query the database to be queried;
and returning the query result to the data request end.
According to the technical scheme, the database configuration information is obtained by analyzing the data query request, the query statement is dynamically assembled, the query statement is circularly executed to obtain the data result set, and the callback processing is performed in cooperation with the RPC management center, so that lightweight data query frameworks are realized, an API (application programming interface) is provided externally, the timeliness and flexibility of data query are guaranteed, the flexibility of marketing dispersion and complex data query is improved in the actual use process, a business party can concentrate on the analysis processing after the data query, and the overall efficiency of data analysis is improved.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.