Summary of the invention
The purpose of the present invention is to provide a kind of data export method of distributed big single table, device, equipment and readable deposit
Storage media exports efficiency to improve the data of big single table.
To achieve the above object, the embodiment of the invention provides following technical solutions:
A kind of data export method of distributed big single table, comprising:
Receive the request for the export data that client is sent;
Distributed data base is searched for by sphinx, and obtains the server identification and data subregion for meeting the request
ID;
Target data item corresponding with the request is obtained according to the server identification and the data partition id;
Destination document is written into the target data item and is exported to the client.
Wherein, the request for receiving the export data that client is sent, comprising:
The request is received by searchd, and sphinx configuration file is written into the corresponding querying condition of the request.
Wherein, it is described by sphinx search for distributed data base, and obtain meet the request server identification and
Data partition id, comprising:
The distributed data base is searched for according to the sphinx configuration file, and is obtained according to socket mode and meets institute
The Servers-all for stating request identifies and all data partition ids.
Wherein, described that number of targets corresponding with the request is obtained according to the server identification and the data partition id
According to item, comprising:
According to the server identification, the data partition id and preset target configuration file obtain in batches with it is described
Request corresponding target data item.
It is wherein, described that destination document is written into the target data item and is exported to before the client, further includes:
The target data item is sorted sequentially in time, and judges whether the item number of the target data item is more than pre-
If threshold value;
If so, filtering out preset quantity data strip according to time rule, the data strip filtered out is determined as described
Target data item.
It is wherein, described that destination document is written into the target data item, comprising:
When the format of the destination document is excel, call described in the target data item is written poi function one by one
Destination document.
It is wherein, described that destination document is written into the target data item and is exported to the client, further includes:
The destination document is shown in the client visibleization.
A kind of data guiding device of distributed big single table, comprising:
Receiving module, the request of the export data for receiving client transmission;
First obtains module, for searching for distributed data base by sphinx, and obtains the service for meeting the request
Device mark and data partition id;
Second obtains module, corresponding with the request for being obtained according to the server identification and the data partition id
Target data item;
Export module, for destination document to be written in the target data item and is exported to the client.
A kind of data equipment leading out of distributed big single table, comprising:
Memory, for storing computer program;
Processor realizes the number of the big single table of distribution described in above-mentioned any one when for executing the computer program
The step of according to deriving method.
A kind of readable storage medium storing program for executing is stored with computer program, the computer program quilt on the readable storage medium storing program for executing
Processor realizes the step of data export method of the big single table of distribution described in above-mentioned any one when executing.
By above scheme it is found that a kind of data export method of distributed big single table provided in an embodiment of the present invention, packet
It includes: receiving the request for the export data that client is sent;Distributed data base is searched for by sphinx, and obtains and is asked described in satisfaction
The server identification and data partition id asked;It is obtained and the request pair according to the server identification and the data partition id
The target data item answered;Destination document is written into the target data item and is exported to the client.
As it can be seen that the method is searched for by sphinx first when receiving the request of export data of client transmission
Distributed data base, and the server identification and data partition id for meeting the request are obtained, target data item is stored to determine
Server and corresponding data subregion;And then target data item is obtained according to server identification and data partition id, and by mesh
It marks data strip and destination document is written, export to client, so that user checks.Wherein, this method is inquired first meets request
Server and data subregion, since the data of return are only server identification and data partition id, data volume is smaller, therefore inquires effect
Rate is improved;And then target data item directly acquired according to server identification and data partition id, due to hard objectives
The storage location of data strip, thus the efficiency for obtaining data is also improved;Therefore the data export effect of big single table can be improved
Rate reduces the load of database;Distributed data base is searched for by sphinx simultaneously, the consumption of computer resource can be reduced,
Improve user experience.
Correspondingly, it a kind of data guiding device of distributed big single table provided in an embodiment of the present invention, equipment and readable deposits
Storage media similarly has above-mentioned technique effect.
Specific embodiment
Following will be combined with the drawings in the embodiments of the present invention, and technical solution in the embodiment of the present invention carries out clear, complete
Site preparation description, it is clear that described embodiments are only a part of the embodiments of the present invention, instead of all the embodiments.It is based on
Embodiment in the present invention, it is obtained by those of ordinary skill in the art without making creative efforts every other
Embodiment shall fall within the protection scope of the present invention.
The embodiment of the invention discloses data export method, device, equipment and the readable storages of a kind of distributed big single table
Medium exports efficiency to improve the data of big single table.
Referring to Fig. 1, a kind of data export method of distributed big single table provided in an embodiment of the present invention, comprising:
S101, the request for receiving the export data that client is sent;
S102, distributed data base is searched for by sphinx, and obtains the server identification and data subregion for meeting request
ID;
Specifically, sphinx is the full-text search engine based on SQL, full text is done in combination with MySQL, PostgreSQL and is searched
Rope, it can provide the function of search more professional than distributed data base itself, so that application program is easier to realize specialization.
Therefore, when searching for acquisition server identification and data partition id using sphinx, data search efficiency can be improved.Wherein, number
It is accessid according to partition id.
Data volume in distributed data base is million to ten million ranks, and data can be continually added to distribution at any time
Database.Generally, single table default in distributed data base saves trimestral data recently, and can be built as unit of day
Vertical data subregion;Each data subregion accordingly establishes a sphinx index, wherein the size of sphinx index is smaller, about
The 1/10 of former data subregion.Meanwhile every server in distributed data base has server identification, is denoted as POID.
Therefore, when receiving the request of export data of client transmission, distributed data can be searched for by sphinx
Library, and obtain the server identification and data partition id for meeting request, that is, determine target data item institute derived from the request requirement
The server of storage and corresponding data subregion.
S103, target data item corresponding with request is obtained according to server identification and data partition id;
After the server identification and data partition id for determining to meet export request of data, according to server identification sum number
Target data item is directly acquired according to partition id, so that the acquisition efficiency of data can be improved.It should be noted that distributed data base
In data generally stored with the format of data strip, therefore, when obtaining data therein, equally in the form of data strip into
Row obtains.
S104, destination document is written into target data item and is exported to client.
After getting target data item, the target data item that will acquire is written destination document and exports to client, with
Just user checks.Wherein, the format of destination document can be excel, csv or txt, naturally it is also possible to be facilitate user to check,
It edits, the document of the extended formatting of screening.Wherein it is possible to document template be preset, after getting target data item, by mesh
Mark data strip inserts the document template, to generate destination document.
As it can be seen that present embodiments providing a kind of data export method of distributed big single table, the method is receiving visitor
When the request for the export data that family end is sent, distributed data base is searched for by sphinx first, and obtain and meet the request
Server identification and data partition id, to determine the server and corresponding data subregion of storage target data item;And then root
Target data item is obtained according to server identification and data partition id, and destination document is written into target data item, is exported to client
End, so that user checks.
Wherein, this method inquires the server and data subregion for meeting request first, since the data of return are only to service
Device mark and data partition id, data volume is smaller, therefore search efficiency is improved;And then according to server identification and data point
Area ID directly acquires target data item, due to the storage location of hard objectives data strip, thus obtains the efficiency of data also
Raising is arrived;Therefore the data export efficiency that big single table can be improved, reduces the load of database;It is searched for simultaneously by sphinx
Distributed data base can reduce the consumption of computer resource, improve user experience.
The embodiment of the invention discloses the data export method of another distributed big single table, relative to a upper embodiment,
The present embodiment has made further instruction and optimization to technical solution.
Referring to fig. 2, the data export method of another distributed big single table provided in an embodiment of the present invention, comprising:
S201, the request that export data are received by searchd, and corresponding querying condition write-in sphinx will be requested to match
Set file;
S202, distributed data base is searched for according to sphinx configuration file, and obtain satisfaction request according to socket mode
Servers-all mark and all data partition ids;
In the present embodiment, the request for the export data that client is sent is received by searchd, and request is carried
Sphinx configuration file is written in querying condition, so that sphinx searches for distributed data base according to sphinx configuration file.Distribution
Server in formula database can be divided into application server and distributed server,
Wherein, for application server for interacting with user, user can be based on application management server Distributed Services
Device;Distributed server is for storing data.The quantity of application server is generally one, and the application service of redundancy will also be arranged
Device, in case of need;The quantity of distributed server is generally multiple, and application server and distributed server pass through
Socket establishes communication connection.Wherein, the interface of socket is the API based on TCP/IP network, can define many kinds of function and example
Journey.
Wherein, searchd is operation retrieval finger daemon, every server being pre-configured in distributed data base
On.The corresponding search for configuration information of request of export data is had recorded in sphinx configuration file, such as: it is required that the maximum returned
Number of data is generally indicated with max;Inquire the max-timeout time etc. of data.
Therefore, when the searchd of application server receives the request of the export data of client transmission, by request pair
The querying condition write-in sphinx configuration file answered, and monitor process is opened, and then sphinx configuration file is passed through into socket
It is forwarded to each distributed server;When searchd on each distributed server receives sphinx configuration file, foundation
Sphinx configuration file scans for, and after the completion of search, returns to server identification and data partition id that search obtains, searches at this time
What rope obtained is that the Servers-all mark for meeting request and all data partition ids can be obtained disposably to improve efficiency
Servers-all mark and all data partition ids.
S203, target data item corresponding with request is obtained according to server identification and data partition id;
S204, destination document is written into target data item and is exported to client.
It in the present embodiment, can be by server mark when application server obtains server identification and data partition id
Know and data partition id inserts temporary table, to obtain target data item corresponding with request according to the temporary table.Wherein,
The quantity of server identification and data partition id in temporary table can be preset, when the number of server identification and data partition id
When amount exceeds the setting of temporary table, server identification and data partition id can be obtained in batches.It should be noted that this reality
Applying example can be realized based on WEB application.
As it can be seen that present embodiments providing the data export method of another distributed big single table, the method passes through
Searchd receives request, and will request corresponding querying condition write-in sphinx configuration file, is searched according to sphinx configuration file
Rope distributed data base, and the Servers-all mark for meeting request and all data partition ids are obtained according to socket mode,
To determine the server and corresponding data subregion of storage target data item;And then according to server identification and data partition id
Target data item is obtained, and destination document is written into target data item, is exported to client, so that user checks.
Wherein, server and data subregion that this method is requested according to sphinx configuration file inquiry satisfaction, and according to
Socket mode obtains server identification and data partition id, since the data of acquisition are only server identification and data subregion
ID, data volume is smaller, therefore search efficiency is improved;And then target is directly acquired according to server identification and data partition id
Data strip, due to the storage location of hard objectives data strip, thus the efficiency for obtaining data is also improved;Therefore it can mention
The data of tall and big list table export efficiency, reduce the load of database;Distributed data base is searched for by sphinx simultaneously, can be subtracted
The consumption of few computer resource, improves user experience.
Based on above-mentioned any embodiment, it should be noted that described according to the server identification and the data subregion
ID obtains target data item corresponding with the request, comprising:
According to the server identification, the data partition id and preset target configuration file obtain in batches with it is described
Request corresponding target data item.
Specifically, can be screened according to preset target configuration file after getting server identification and data partition id
The server identification and data partition id got.Because having preset the max-thresholds limit of number of data in target configuration file
System, when the server identification and the corresponding number of data of data partition id got is greater than the max-thresholds of number of data, then
Target data item is obtained in batches;When the server identification and the corresponding number of data of data partition id got is not more than data
It is when the max-thresholds of item number, then disposable to obtain whole target data items.
Such as: assuming that the max-thresholds of number of data are 1000, then 1000 are returned to every time, when real data item number is less than
When 1000, then returned by practical item number." limit 0,1000 can be added after query statement;Limit 1001,2000 " is realized.
It is described that destination document is written into the target data item and is exported to the client based on above-mentioned any embodiment
Before, further includes:
The target data item is sorted sequentially in time, and judges whether the item number of the target data item is more than pre-
If threshold value;
If so, filtering out preset quantity data strip according to time rule, the data strip filtered out is determined as described
Target data item.
Specifically, can be screened according to time rule when the item number of the target data item got is more than preset threshold value
The data strip filtered out is determined as the target data item by preset quantity data strip out.It should be noted that client is wanted
The querying condition asked is generally the data generated the nearest time, therefore can erasing time data strip remote.
Based on above-mentioned any embodiment, it should be noted that described that destination document, packet is written in the target data item
It includes: when the format of the destination document is excel, calling poi function that the target is written in the target data item one by one
Document.
Specifically, poi function can be called in the following manner if indicating the item number for the data strip being written every time with m,
Such as: " Workbook wb=new SXSSFWorkbook (m) " can be controlled at this point, only m data is cached in memory
Memory usage processed.It should be noted that needing depositing target data item before destination document is written in target data item
It stores up IP address and character string type is converted to by unsigned int.Storage IP address of the target data item in distributed data base is nothing
Symbol integer needs to be converted to character string type after export.It wherein, can be by calling poi when destination document is excel format
Data strip is written in function.
Based on above-mentioned any embodiment, it should be noted that described that destination document is written in the target data item and is led
Out extremely after the client, further includes: show the destination document in the client visibleization.
Specifically, can show the destination document with visualization window after exporting destination document to client.Meanwhile
The destination document in distributed data base is deleted, to reduce memory usage.
A kind of data guiding device of distributed big single table provided in an embodiment of the present invention is introduced below, is hereafter retouched
The data export method of a kind of data guiding device for the distributed big single table stated and a kind of above-described distributed big single table
It can be cross-referenced.
Referring to Fig. 3, a kind of data guiding device of distributed big single table provided in an embodiment of the present invention, comprising:
Receiving module 301, the request of the export data for receiving client transmission;
First obtains module 302, for searching for distributed data base by sphinx, and obtains the clothes for meeting the request
Business device mark and data partition id;
Second obtains module 303, for being obtained and the request according to the server identification and the data partition id
Corresponding target data item;
Export module 304, for destination document to be written in the target data item and is exported to the client.
Wherein, the receiving module is specifically used for:
The request is received by searchd, and sphinx configuration file is written into the corresponding querying condition of the request.
Wherein, the first acquisition module is specifically used for:
The distributed data base is searched for according to the sphinx configuration file, and is obtained according to socket mode and meets institute
The Servers-all for stating request identifies and all data partition ids.
Wherein, the second acquisition module is specifically used for:
According to the server identification, the data partition id and preset target configuration file obtain in batches with it is described
Request corresponding target data item.
Wherein, further includes:
Judgment module for the target data item to sort sequentially in time, and judges the target data item
Whether item number is more than preset threshold value;
Screening module, for being screened according to time rule when the item number of the target data item is more than preset threshold value
The data strip filtered out is determined as the target data item by preset quantity data strip out.
Wherein, described to be specifically used for export module:
When the format of the destination document is excel, call described in the target data item is written poi function one by one
Destination document.
Wherein, further includes:
Display module, for showing the destination document in the client visibleization.
As it can be seen that present embodiments providing a kind of data guiding device of distributed big single table, comprising: receiving module, first
Obtain module, the second acquisition module and export module.Asking for the export data of client transmission is received by receiving module first
It asks;Then first module is obtained by sphinx search distributed data base, and obtain the server identification sum number for meeting request
According to partition id;And then second obtains module according to server identification and data partition id acquisition target data corresponding with request
Item;Target data item is written destination document and exported to client by last export module.Divide the work between such modules and closes
Make, Each performs its own functions, to improve the data export efficiency of efficiency data query and distributed big single table;Meanwhile meter can be reduced
The consumption of calculation machine resource improves user experience.
A kind of data equipment leading out of distributed big single table provided in an embodiment of the present invention is introduced below, is hereafter retouched
The data export method of a kind of data equipment leading out for the distributed big single table stated and a kind of above-described distributed big single table
And device can be cross-referenced.
Referring to fig. 4, the data equipment leading out of a kind of distributed big single table provided in an embodiment of the present invention, comprising:
Memory 401, for storing computer program;
Processor 402 realizes that distribution described in above-mentioned any embodiment is big single when for executing the computer program
The step of data export method of table.
A kind of readable storage medium storing program for executing provided in an embodiment of the present invention is introduced below, one kind described below is readable to deposit
Storage media can be cross-referenced with above-described a kind of data export method, device and the equipment of distributed big single table.
A kind of readable storage medium storing program for executing is stored with computer program, the computer program quilt on the readable storage medium storing program for executing
The step of data export method of the big single table of distribution as described in above-mentioned any embodiment is realized when processor executes.
Based on above-mentioned any embodiment, it should be noted that each threshold size involved in this specification can be identical,
It can be different.I.e. threshold size, which is based on practical situations, to be adjusted flexibly, therefore this specification is not specifically limited in this embodiment.
Based on above-mentioned any embodiment, exported in order to illustrate more clearly of the data of distributed big single table provided by the invention
Method is now listed below implementation steps:
Step 1, the complete web application of deployment, sphinx index service and database environment;
Sphinx.conf configuration file is written in querying condition by step 2, the querying condition according to web page;
The searchd service of step 3, server-side, is issued to other distributed servers for query condition information
Searchd service, and begin listening for;
Step 4, server-side searchd will be monitored after the data obtained is ranked up processing, and the interim table of database is written;Its
In, the interim table is for storage server mark (POID) and data partition id (accessid);
Step 5 obtains data according to the accessid and POID of interim table: obtaining and needs derived data, takes m every time
The data of (threshold value) item only save the data of this acquisition in memory;
Step 6, the data obtained to step 5 are processed, for example initial data is in database purchase IP address
Unsigned int needs to be converted into character string type herein;
Data after step 6 processing are written in excel step 7 one by one, by the poi function of calling excel, and with
M data is cached in memory by " Workbook wb=new SXSSFWorkbook (m) " statement;
Step 8, when step 7 processing after the completion of, judge whether database data obtains completely, i.e., judgement satisfaction currently look into
Whether the data of inquiry condition all get, if will not go to step 5 automatically completely;If data all obtain
It finishes, then generates excel file, and enter lower step 9;
The excel file that step 9, the downloading of web applications client generate, deletes the excel file of server-side after downloading.
So far, the implementation of the big single table data export excel method of the distribution applied based on web is completed.It needs to illustrate
It is that the present embodiment is not particularly limited the type and version of database, the platform of web application is also not particularly limited.
Each embodiment in this specification is described in a progressive manner, the highlights of each of the examples are with other
The difference of embodiment, the same or similar parts in each embodiment may refer to each other.
The foregoing description of the disclosed embodiments enables those skilled in the art to implement or use the present invention.
Various modifications to these embodiments will be readily apparent to those skilled in the art, as defined herein
General Principle can be realized in other embodiments without departing from the spirit or scope of the present invention.Therefore, of the invention
It is not intended to be limited to the embodiments shown herein, and is to fit to and the principles and novel features disclosed herein phase one
The widest scope of cause.