CN112084250A - Data storage method, data query method and electronic equipment - Google Patents

Data storage method, data query method and electronic equipment Download PDF

Info

Publication number
CN112084250A
CN112084250A CN202010967820.3A CN202010967820A CN112084250A CN 112084250 A CN112084250 A CN 112084250A CN 202010967820 A CN202010967820 A CN 202010967820A CN 112084250 A CN112084250 A CN 112084250A
Authority
CN
China
Prior art keywords
codes
code
stored
data
target node
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010967820.3A
Other languages
Chinese (zh)
Inventor
殷振威
吕寒冰
黄武君
朱伟进
陈桂军
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Fortune Investment Group Co ltd
Original Assignee
Shenzhen Fortune Investment Group Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Fortune Investment Group Co ltd filed Critical Shenzhen Fortune Investment Group Co ltd
Priority to CN202010967820.3A priority Critical patent/CN112084250A/en
Publication of CN112084250A publication Critical patent/CN112084250A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/25Integrating or interfacing systems involving database management systems
    • G06F16/258Data format conversion from or to a database
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2458Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
    • G06F16/2471Distributed queries
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Abstract

The application provides a data storage method, a data query method and electronic equipment, which are used for acquiring data to be stored and codes to be stored of items to be processed, wherein the codes to be stored are preset according to the categories of the items to be processed and preset modes. And then converting the codes to be stored into corresponding category codes in the preset mode, wherein the codes of the items belonging to the same category correspond to the same category codes. And finally, determining a target node for storing the codes according to the class codes, storing the codes to be stored to the target node, and storing the data to be stored in a storage area associated with the codes to be stored. Therefore, the codes of the same category of items can be converted into the same category codes, the single codes are stored in the same node, and subsequently, when the query is carried out, the data of all items in the category to which the codes belong can be obtained based on the codes to be queried.

Description

Data storage method, data query method and electronic equipment
Technical Field
The application relates to the technical field of computer application, in particular to a data storage method, a data query method and electronic equipment.
Background
In the big data era, daily applications often involve storage of data and querying of data. For some non-relational databases, the SQL statements and the indexes are not supported, and only simple single-value storage can be processed, so that only a single-value query function can be correspondingly performed when the application is queried. At present, the data storage mode adopted by the system leads to one-to-one query in the query mode, the mode is not friendly, and the operation is simple but tedious. In such a manner, a complete query list needs to be provided, otherwise, complete query data is difficult to obtain, and the defects of high maintenance cost and the like exist.
Disclosure of Invention
The application aims to provide a data storage method, a data query method and an electronic device, which can improve the storage and query efficiency and reduce the maintenance cost.
The embodiment of the application can be realized as follows:
in a first aspect, an embodiment of the present application provides a data storage method, where the method includes:
acquiring data to be stored and codes to be stored of items to be processed, wherein the codes to be stored are preset according to the category of the items to be processed and a preset mode;
converting the codes to be stored into corresponding category codes in the preset mode, wherein the codes of the items belonging to the same category correspond to the same category codes;
and determining a target node for storing the codes according to the class codes, storing the codes to be stored to the target node, and storing the data to be stored in a storage area associated with the codes to be stored.
In an optional embodiment, the step of converting the code to be stored into the class code corresponding to the preset mode includes:
detecting whether the format of the code to be stored meets the preset format requirement, and if not, performing format conversion processing on the code to be stored;
and accumulating the characters contained in the codes to be stored which meet the requirements of the preset format to obtain the corresponding class codes in the preset mode.
In an alternative embodiment, the step of determining a target node for storing codes according to the class code includes:
detecting whether a tree structure containing a plurality of nodes has a target node corresponding to the category code;
and if not, creating a target node corresponding to the category code in the tree structure.
In an optional embodiment, the step of storing the code to be stored in the target node includes:
detecting whether the target node has a residual storage space;
if the target node does not have the residual storage space, acquiring the node number of the target node, and determining a storage module corresponding to the node number in a data engine library according to the node number;
and storing the codes stored in the target node into the determined storage module, deleting the codes stored in the target node, and storing the codes to be stored into the target node.
In an optional embodiment, the step of storing the code to be stored in the target node further includes:
after the codes are stored in the data engine library, the flag bit of the target node is set to be in a set state, and the flag bit represents that the operation of storing the codes in the target node into the data engine library is executed in the set state.
In a second aspect, an embodiment of the present application provides a data query method, where the method includes:
acquiring a code to be queried;
when the code to be inquired is a category code corresponding to the category of the item, determining a target node corresponding to the code to be inquired, wherein the codes of the items belonging to the same category correspond to the same category code;
and querying the target node to obtain a stored code, and acquiring data associated with the code from a data engine library according to the obtained code, wherein the obtained data is data corresponding to all items belonging to the same category and corresponding to the category code.
In an alternative embodiment, the method further comprises:
when the code to be inquired is the code of the corresponding item, detecting whether the code to be inquired meets the requirement of a preset format, and if not, performing format conversion processing on the code to be inquired;
accumulating characters contained in the code to be inquired which meets the requirements of the preset format so as to convert the code to be inquired into a category code corresponding to the category of the item.
In an alternative embodiment, the step of querying the target node to obtain the stored code comprises:
detecting a flag bit of the target node, and acquiring a code stored in a corresponding storage module of the data engine library according to a node number of the target node when the state of the flag bit indicates that the operation of inputting the code from the target node to the data engine library is executed;
combining the code stored in the target node with the code obtained from the data engine repository.
In an optional embodiment, when there are a plurality of codes to be queried, the querying the target node to obtain the stored codes includes:
determining a target node corresponding to one of a plurality of codes to be queried as an initial target node;
and traversing the target nodes corresponding to the codes to be inquired from the initial target nodes according to a preset sequence to obtain the codes stored in the target nodes.
In an alternative embodiment, the step of querying the target node to obtain the stored codes includes:
and detecting whether a reverse order request is obtained or not, and if the reverse order request is obtained, sequentially obtaining each code from the rear to the front according to the writing time of the code stored in the target node.
In a third aspect, an embodiment of the present application provides an electronic device, including: the system comprises a processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, when an electronic device runs, the processor is communicated with the storage medium through the bus, and the processor executes the machine-readable instructions to execute the steps of the method according to any one of the preceding implementation modes.
The beneficial effects of the embodiment of the application include, for example:
the embodiment of the application provides a data storage method, a data query method and electronic equipment, which are used for acquiring to-be-stored data and to-be-stored codes of to-be-processed items, wherein the to-be-stored codes are preset according to the categories of the to-be-processed items and preset modes. And then converting the codes to be stored into corresponding category codes in the preset mode, wherein the codes of the items belonging to the same category correspond to the same category codes. And finally, determining a target node for storing the codes according to the class codes, storing the codes to be stored to the target node, and storing the data to be stored in a storage area associated with the codes to be stored. Therefore, the codes of the same category of items can be converted into the same category codes, the single codes are stored in the same node, and subsequently, when the query is carried out, the data of all items in the category to which the codes belong can be obtained based on the codes to be queried.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are required to be used in the embodiments will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered as limiting the scope, and for those skilled in the art, other related drawings can be obtained from the drawings without inventive effort.
Fig. 1 is a block diagram of an electronic device according to an embodiment of the present disclosure;
FIG. 2 is a flowchart of a data storage method according to an embodiment of the present disclosure;
fig. 3 is a schematic structural diagram of a tree structure provided in an embodiment of the present application;
fig. 4 is a flowchart of a format conversion processing method in the data storage method according to the embodiment of the present application;
fig. 5 is a flowchart of a storage space detection method in the data storage method according to the embodiment of the present application;
FIG. 6 is another flow chart of a data storage method according to an embodiment of the present disclosure;
FIG. 7 is a flowchart of a data query method provided in an embodiment of the present application;
fig. 8 is a flowchart of a code obtaining method in the data query method according to the embodiment of the present application;
FIG. 9 is another flowchart of a data query method according to an embodiment of the present application;
FIG. 10 is a flowchart of a data query method according to an embodiment of the present application;
FIG. 11 is a functional block diagram of a data storage device according to an embodiment of the present application;
fig. 12 is a functional block diagram of a data query device according to an embodiment of the present application.
Icon: 110-a processor; 120-a memory; 130-a communication module.
Detailed Description
Under the Fabric architecture, when a user queries for data, the query request is submitted to a world state database module for processing. While there are two types of implementation in the Fabric world state module: a Level DB engine, a Couch DB engine and a third-party cache fastcache. The KV single-machine embedded database has high random writing and sequential reading/writing performances, but the random reading performance is general. The key (query key) and the value (query value) are both arbitrary byte arrays, support memory and persistent storage, provide basic operation interfaces such as Put (), Get (), Delete (), Batch () and the like, and support Batch atomic operations and the like. However, the system is a non-relational database, does not support SQL statements and indexes, brings inconvenience to processing and development of a business end, and can only process simple single-value query functions.
For example, in one application scenario, for the query of the commodity information of the e-commerce platform, each specific commodity belongs to a certain category, for example, the large category may be fruits, food, shoes, beverages, and the like. However, in daily life, the goods are not generally classified for data storage according to such a large category, and the data storage is generally performed according to specific brands such as brand a, brand B, brand C and the like under the category of shoes. However, under the level DB architecture of the current Fabric world state, it is often difficult to satisfy such a query requirement.
Under the current architecture, if a type of data needs to be queried from a database, a user needs to provide enough query key values, that is, the number of the provided query key values needs to be as large as that of the data to be queried, so that a one-to-one query mode is formed. The query mode is very unfriendly, the operation is simple but tedious, a user is required to provide a complete query key value, and otherwise complete query data cannot be obtained. Causing the defects of high maintenance cost, easy error recording and the like.
Based on the research findings, the application provides a data storage method and a data query method, the codes of the items belonging to the same category are converted in a preset mode to correspond to the mode of the codes of the same category, so that the codes of the items of the same category are stored in the same node, and then all data of the items in one category can be queried and obtained only by providing the category codes or obtaining the category codes based on the provided codes during subsequent query. The query is not required to be carried out in a one-to-one mode, so that the storage and query efficiency is improved, and the maintenance cost is reduced.
In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments. The components of the embodiments of the present application, generally described and illustrated in the figures herein, can be arranged and designed in a wide variety of different configurations.
Thus, the following detailed description of the embodiments of the present application, presented in the accompanying drawings, is not intended to limit the scope of the claimed application, but is merely representative of selected embodiments of the 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.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures. It should be noted that the features of the embodiments of the present application may be combined with each other without conflict.
Referring to fig. 1, a block diagram of an electronic device provided in the embodiment of the present application is shown, where the electronic device may include, but is not limited to, a computer, a server, and other devices. The electronic device may be loaded with a Fabric architecture, including a database engine (level DB engine).
The electronic device may include a memory 120, a processor 110, and a communication module 130. The memory 120, the processor 110 and the communication module 130 are electrically connected to each other directly or indirectly to realize data transmission or interaction. For example, the components may be electrically connected to each other via one or more communication buses or signal lines.
The memory 120 is used for storing programs or data. The Memory 120 may be, but is not limited to, a Random Access Memory (RAM), a Read Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Read-Only Memory (EPROM), an electrically Erasable Read-Only Memory (EEPROM), and the like.
The processor 110 is used for reading/writing data or programs stored in the memory 120 and executing the data storage method and/or the data query method provided by any embodiment of the present application.
The communication module 130 is used for establishing a communication connection between the electronic device and another communication terminal through a network, and for transceiving data through the network.
It should be understood that the configuration shown in fig. 1 is merely a schematic configuration diagram of an electronic device, which may also include more or fewer components than shown in fig. 1, or have a different configuration than shown in fig. 1. The components shown in fig. 1 may be implemented in hardware, software, or a combination thereof.
Referring to fig. 2, fig. 2 is a flowchart illustrating a data storage method according to an embodiment of the present application, where the data storage method can be executed by the electronic device shown in fig. 1. It should be understood that, in other embodiments, the order of some steps in the data storage method of this embodiment may be interchanged according to actual needs, or some steps may be omitted or deleted. The detailed steps of the data storage method are described below.
Step S210, obtaining data to be stored and codes to be stored of items to be processed, wherein the codes to be stored are preset according to the category of the items to be processed and the preset mode.
Step S220, converting the code to be stored into a category code corresponding to the preset mode, wherein the codes of the items belonging to the same category correspond to the same category code.
Step S230, determining a target node for storing the code according to the category code, storing the code to be stored to the target node, and storing the data to be stored in a storage area associated with the code to be stored.
In this embodiment, for example, storage of commodity data, storage of running data, and storage of some other information related to a large amount of data can be realized. The items to be processed may be, for example, a certain commodity category, such as a certain brand of shoes, a certain brand of hat, a jacket, and the like. Where each item has a corresponding code, such as a model of shoe under a certain brand of footwear, the corresponding model may be the code for that item. Also, in daily management, each item corresponds to relevant data such as the location where the item is placed, the date of shipment, the amount of inventory, and so forth.
In order to conveniently and conveniently inquire the related data of the items in the following process, the related data needs to be stored when the items are managed, and the corresponding codes can be understood as indexes for inquiring the corresponding data.
In this embodiment, for convenience of implementing subsequent query on data of an item of a certain category, rather than performing only one-to-one query, codes of items of different categories may be set in advance, so that codes of items in the same category can meet certain requirements. For example, codes of items of the same category can be converted to codes of the same category after a certain conversion.
Therefore, when the data of the project is stored, after the data to be stored and the codes to be stored of the project to be processed are obtained, the codes to be stored can be converted into the corresponding class codes.
In addition, in the present embodiment, the tree structure may be a B + tree structure by constructing a tree structure including a plurality of nodes to store the relevant codes of the items. The codes to be stored are sorted and managed through the B + tree structure, the stability and the order of the codes can be ensured, and the insertion and the modification of the codes have stable logarithmic time complexity.
The B + tree structure in this embodiment is mainly characterized by the definitions of non-leaf nodes and leaf nodes, where the non-leaf nodes use the obtained category codes as indexes, and the data field of the non-leaf nodes is empty, and the data field of the leaf nodes is non-empty, and can store specific uplink coding information. An architectural diagram of a B + tree structure is schematically shown in fig. 3.
After the category code corresponding to the code of the item to be processed is obtained, a target node for storing the code may be determined from the tree structure, where the determined target node may include a non-leaf node and a leaf node connected to the non-leaf node, the non-leaf node is mainly used for positioning, and the leaf node connected to the non-leaf node may be used for storing the code to be stored. After the code to be stored is stored in the target node, the data to be stored is correspondingly stored in the storage area associated with the code to be stored. The data to be stored may be stored in a data engine library (level DB engine).
Therefore, the codes of the items under the same category can be stored in the same node, and in the follow-up inquiry process, no matter whether the obtained single code or category code is obtained, the node in which the codes of all the items under the category are stored can be positioned, so that all the data under the category can be inquired, and the inquiry efficiency is improved.
In the present embodiment, in order to facilitate the accuracy of the conversion between the single code and the category code, please refer to fig. 4, the conversion between the code and the category code can be implemented as follows:
step S221, detecting whether the format of the code to be stored meets a preset format requirement, if not, executing step S222, and if so, directly executing the following step S223.
Step S222, performing format conversion processing on the code to be stored.
Step S223, accumulating the characters included in the codes to be stored that meet the requirement of the preset format to obtain the corresponding category codes in the preset mode.
In this embodiment, since the codes used in daily life may include characters, but not all of them are simple numbers, a conversion scheme between 16-ary codes and category codes is mainly used for conversion. Therefore, after the codes to be stored are obtained, whether the format of the codes to be stored meets the preset format requirement, namely whether the format is a 16-system format can be detected. If the format of the code to be stored is not the 16-ary format, conversion processing is required to convert the code into the 16-ary format.
After the conversion into the 16-system format, the characters contained in the codes to be stored are accumulated to obtain the category codes. For example, if the obtained code to be stored is ab3fc46, each character is converted into a corresponding 10-ary number, and then the corresponding conversion form is as follows:
16 carry system 10 system of
a 10
b 11
3 3
f 15
c 12
4 4
6 6
As shown above, the obtained category code is 10+11+3+15+12+4+6, i.e. the corresponding node in the tree structure is located according to the obtained category code 61.
As is apparent from the above description, the codes of the items in the same category can be converted into the same category codes, and for example, if the category code set in a certain category is 50, the setting needs to be performed according to a certain rule when setting the codes of the respective items in the category. For example, the codes of the next three items in the category can be ab4f82, ab4f73, and ab4f64, and the following results can be obtained by the above conversion method:
ab4f82=>Sum=a+b+4+f+8+2=50
ab4f73=>Sum=a+b+4+f+7+3=50
ab4f64=>Sum=a+b+4+f+6+4=50
that is, the codes of the three items in the category can be converted into the same category code 50, so that the codes of the three items can be stored in the target node located by using the category code 50 as an index.
In this embodiment, when the target node is located from the tree structure according to the category code, it is further required to first detect whether there is a target node corresponding to the category code in the tree structure including a plurality of nodes, and if not, it is required to first create a target node corresponding to the category code in the tree structure. Therefore, the problem of errors in coding storage can be avoided.
In this embodiment, considering that the storage space of each node is limited, in order to avoid that the codes that need to be stored subsequently cannot be successfully written in the case of an excessive number of codes, please refer to fig. 5, when performing code storage, the following steps may be performed:
step S231, detecting whether the target node has a remaining storage space, if not, executing the following step S232, and if so, directly storing the storage code into the target node.
Step S232, obtaining the node number of the target node, and determining a storage module corresponding to the node number in a data engine library according to the node number.
Step S233, storing the codes stored in the target node into the determined storage module, deleting the codes stored in the target node, and storing the codes to be stored into the target node.
In this embodiment, each node in the tree structure has a maximum uplink data value dataMaxNum, which is the maximum length of writable data. When the data stored in the node reaches the maximum uplink data value, the node will not have the remaining storage space, and at this time, the status of the flag bit is FULL of the node for indicating whether the data is FULL may be True, i.e., indicating that the current data is FULL.
In this case, the node number uuid of the node, which is the unique ID of the node, can be obtained. The data engine library is provided with a storage module, the storage module in the data engine library and each node can have an incidence relation, and under the condition that data in a certain node is stored fully, the data in the node can be transferred to the data engine library for storage.
In order to ensure that the stored codes are stored in time sequence, the codes stored in the target node can be stored in a storage module corresponding to the target node in the data engine library, and the codes stored in the target node, namely the codes transferred to the data engine library, are deleted. At this time, the state of the flag bit is FULL of the target node for indicating whether the data is FULL may be set to False, i.e., indicating that the current data is not FULL.
Therefore, the problem of limited storage space of the node can be solved by combining the data engine library and the node for coding storage, and complete coded data can be obtained from the corresponding node and the storage module corresponding to the node when the code needs to be inquired and obtained subsequently.
In this embodiment, in order to obtain whether the code in a certain node is written into the data engine library in the subsequent query, after the code is stored into the data engine library from the target node, the flag bit of the target node is set to be in a set state, and the flag bit represents that the operation of storing the code in the target node into the data engine library is performed in the set state.
In addition, when the codes are stored in the target node, if the target node has a remaining storage space, the codes to be stored may be added to the array in the target node.
In this embodiment, since the data engine library has a certain requirement on the format of the stored data, when the code stored in the target node is stored in the data engine library, the code may be compressed, for example, json compression or protobuf compression, and then the compressed code is written into the data engine library.
In order to clearly understand the data storage method provided in this embodiment, please refer to fig. 6, which will briefly describe an overall process of the data storage method provided in this embodiment as follows:
step S301, acquiring codes to be stored and data to be stored;
step S302, detecting whether the code to be stored is in the 16-ary format, if not, executing step S303, and if so, executing step S304.
Step S303, carrying out format conversion on the code to be stored;
step S304, accumulating characters contained in the codes to be stored to obtain corresponding class codes;
step S305, storing the data to be stored into a storage area of a data engine library corresponding to the code to be stored;
step S306, detecting whether a target node corresponding to the category code exists in the tree structure, if not, executing step S307, and if so, executing step S308;
step S307, creating a target node corresponding to the category code in the tree structure;
step S308, positioning a target node according to the category codes;
step S309, detecting whether the target node has the remaining storage space, if not, executing the step S310 to the step S313, and if so, jumping to the step S313;
step S310, compressing the codes stored in the target node;
step S311, storing the compressed code stored in the target node into a data engine library, and setting the flag bit of the target node to be in a set state;
step S312, deleting the codes stored in the target node;
and step 313, storing the code to be stored in the target node.
In the data storage method provided in this embodiment, the codes of the items belonging to the same category may be set so that the codes of the items belonging to the same category correspond to the codes belonging to the same category, and the codes of the items belonging to the same category are further stored in the same node. Therefore, during subsequent query, the relevant data of all items belonging to the same category can be obtained by providing conditions in single query, one-to-one query is not needed, the query efficiency is improved, and the maintenance cost is reduced.
In addition, an embodiment of the present application further provides a data query method corresponding to the data storage method, please refer to fig. 7, and fig. 7 illustrates a flowchart of the data query method provided in the embodiment of the present application, where the data query method may be executed by the electronic device illustrated in fig. 1. It should be understood that, in other embodiments, the order of some steps in the data query method of this embodiment may be interchanged according to actual needs, or some steps may be omitted or deleted. The detailed steps of the data query method are described below.
Step S410, acquiring a code to be queried.
Step S420, when the code to be queried is a category code corresponding to a category of an item, determining a target node corresponding to the code to be queried, where codes of items belonging to the same category correspond to the same category code.
Step S430, querying the target node to obtain a stored code, and obtaining data associated with the code from a data engine library according to the obtained code, wherein the obtained data is data corresponding to all items belonging to the same category and corresponding to the category code.
In this embodiment, when a user performs data query, the user may input a relevant code to be queried, where the code to be queried may be a category code corresponding to an item category, may be a category code corresponding to one item category, or may be a category code corresponding to multiple item categories, that is, a category code in a range is included. In addition, the code to be queried may also be a code corresponding to a single item, and likewise, may be a code corresponding to one item, or may also be a code corresponding to multiple items, that is, multiple codes within a range.
The codes of the items belonging to the same category correspond to the codes of the same category, so that if the acquired code to be queried input by the user is the code of the corresponding item, the code can be converted into the category code.
In order to ensure the accuracy of conversion between codes and category codes, it may be first detected whether the code to be queried meets a preset format requirement, for example, whether the code to be queried is a 16-ary number. If the code to be queried is not in the 16-system format, format conversion processing is firstly carried out on the code to be queried so as to convert the code to be queried into the 16-system format.
After the code to be inquired meeting the preset format requirement is obtained, accumulating characters contained in the code to be inquired so as to convert the code to be inquired into a category code corresponding to the category of the item.
As can be seen from the above, the codes of the items in the same category correspond to the codes in the same category, for example, the codes of the items in a certain category can be ab4f82, ab4f73, and ab4f64, and the characters of the codes are accumulated to obtain the following category codes:
ab4f82=>Sum=a+b+4+f+8+2=50
ab4f73=>Sum=a+b+4+f+7+3=50
ab4f64=>Sum=a+b+4+f+6+4=50
on the basis, the target node in the tree structure can be positioned according to the obtained category codes. Therefore, whether the obtained category code corresponding to the item category or the code corresponding to the item is obtained, the same target node can be positioned.
In addition, in a possible scenario, if the node corresponding to the category code is not found in the tree structure, the empty information may be fed back to inform the user that the corresponding code information is not stored, and then the process is ended.
In this embodiment, the tree structure includes a plurality of nodes, each node may be configured to store a code, and the tree structure may be a B + tree structure. After the target node is located, the target node may be queried to obtain the stored code, and data associated with the code may be retrieved from the data engine repository based on the obtained code.
Therefore, because the codes of the same category of items are all stored in the same node, when the query is performed, the codes of all items in the category can be queried and obtained when the category code of a certain category of item to be queried is provided or the code of a certain item in the category is provided, so that the related data of all items in the category can be obtained, one-to-one query is not needed, and the query efficiency is improved.
It should be noted that the data query method of the present embodiment corresponds to the data storage method of the foregoing embodiment, and therefore, reference may be made to the related description in the data storage method of the foregoing embodiment for details in this embodiment, which is not described herein any more.
In this embodiment, considering that the space for storing the codes in the nodes is limited, when the codes are stored, the data may be transferred when the data in the nodes are full, and therefore, with reference to fig. 8, when the codes are obtained based on the query of the target node, the following method may be implemented:
step S431, detecting a flag bit of the target node, and when the status of the flag bit indicates that an operation of entering a code from the target node to the data engine library is performed, acquiring the code stored in the flag bit from a corresponding storage module of the data engine library according to the node number of the target node.
Step S432, combining the code stored in the target node with the code obtained from the data engine library.
In this embodiment, each node in the tree structure has an associated attribute, such as a flag stored, and the status of the flag stored may indicate whether an operation of storing the code stored in the node into the data engine library is performed during data storage. For example, when the status of the flag stored is True, it indicates that an operation of storing a code into the data engine library has been performed, and when the status of the flag stored is False, it indicates that an operation of storing a code into the data engine library has not been performed.
Therefore, if the status of the flag stored is True, the code needs to be searched in the database of the data engine. In this embodiment, each node has a node number uuid, and the node number is a unique ID of each node. The storage modules in the data engine library may correspond to the respective nodes, and thus, the codes stored therein may be obtained from the corresponding storage modules of the data engine library based on the node numbers of the target nodes.
And combining the codes acquired from the target node and the codes acquired from the data engine library to obtain complete coding information.
In this embodiment, since the data engine library has a certain requirement on the stored data format, the code to be stored needs to be compressed and then stored. Thus, when the code is retrieved from the data engine repository, the retrieved code may be decoded first and then combined with the code obtained from the target node.
After the complete encoding information is obtained, an associated interface of the data engine library, such as a Batch interface, may be called, so as to obtain the data corresponding to the encoding stored in the data engine library.
As can be seen from the above, the code to be queried obtained from the user may be a single code, such as a single code corresponding to the item or a single code corresponding to the category of the item, or may be a code to be queried in a range. I.e. a query of information within a certain range can be made.
Therefore, if there are a plurality of codes to be queried, when code query is performed, nodes corresponding to each code to be queried in the plurality of codes to be queried are all target nodes, and in order to obtain codes according to a sequence required by a user, it is determined that a target node corresponding to one code to be queried in the plurality of codes to be queried is an initial target node. For example, a target node corresponding to a first one of the plurality of codes to be queried may be used as an initial target node, or a target node corresponding to a last one of the plurality of codes to be queried may be used as an initial target node.
And traversing the target nodes corresponding to the codes to be inquired from the initial target node according to a preset sequence to obtain the codes stored in the target nodes. For example, when the initial target node is a node corresponding to the first code to be queried, the corresponding target nodes may be sequentially traversed according to the sequence from front to back of the plurality of codes to be queried, and the codes stored therein are obtained. For another example, when the initial target node is a node corresponding to the last code to be queried, the corresponding target nodes may be sequentially traversed according to the sequence from the back to the front of the plurality of codes to be queried, and the codes stored therein are obtained.
In addition, in this embodiment, the codes stored in the respective nodes are stored in chronological order, and considering that a user may have a need to query from the most recently stored data when querying data, it may be detected whether to obtain a reverse order request for a single node, and if the reverse order request is obtained, the codes are sequentially obtained in chronological order from the back to the front according to the writing time of the code stored in the target node.
In addition, if a requirement that paging needs to be performed is obtained, the coding array stored in the node may be cut off, and then coding acquisition may be performed in segments.
The data query method in this embodiment can be roughly divided into a query based on a single code to be queried and a query based on a plurality of codes (i.e., ranges) to be queried. In order to facilitate those skilled in the art to understand the data query method provided in this embodiment, the following describes the overall flow of query execution in two ways.
Referring to fig. 9, when the code to be queried is single, the query of data can be implemented by the following steps:
step S501, obtaining a code to be inquired;
step S502, detecting whether the code to be inquired is a category code, if not, executing the following steps S503 and S504, and if so, executing the following step S505;
step S503, detecting whether the code to be inquired is in the 16-system format, if not, converting the code to be inquired into the 16-system format;
step S504, accumulating the characters contained in the code to be inquired to obtain the corresponding category code;
step S505, detecting whether a target node corresponding to the category code exists in the tree structure, if not, executing step S506, and if so, executing step S507;
step S506, feeding back a null result and finishing the query process;
step S507, locating to a target node, and detecting whether a flag stored of the target node is true, if not, performing step S508, and if true, performing step S509 and step S510;
step S508, inquiring the target node to obtain the stored code;
step S509, determining a corresponding storage module in the data engine library according to the node number of the target node;
step S510, the stored codes are obtained from the corresponding storage modules in the data engine base and combined with the codes obtained from the target nodes;
step S511, obtaining corresponding data from the data engine base according to the obtained codes;
step S512, the obtained data is decoded to be fed back to the user.
The above process is a process of obtaining corresponding data according to a single code to be queried, and in this embodiment, the related data of all items belonging to a single category can be obtained through querying according to a single category code or a single code provided by a user, so that the querying efficiency is improved, and the maintenance cost is reduced.
In addition, referring to fig. 10, when there are a plurality of codes to be queried, that is, when querying related data of items in a certain range, the following method can be implemented:
step S601, obtaining codes to be inquired, wherein the codes to be inquired are a first code to be inquired and a last code to be inquired in a specified range;
step S602, detecting whether the first code to be queried and the last code to be queried are class codes, if not, executing step S603 and step S604, and if so, executing step S605;
step S603, detecting whether the first code to be inquired and the last code to be inquired are in a 16-system format, and if not, converting the codes into the 16-system format;
step S604, accumulating the characters contained in the first code to be inquired and the last code to be inquired to obtain the corresponding category codes;
step S605, detecting whether the tree structure has a target node corresponding to two category codes, if not, executing step S606, and if so, executing step S607;
step S606, feeding back a null result and finishing the query process;
step S607, positioning to two target nodes corresponding to the two kinds of codes, detecting whether the flag bit stored of each target node is true, if not, executing step S608, if true, executing step S609, and step S610;
step S608, traversing the two target nodes and the nodes between the two target nodes to obtain stored codes;
step S609, positioning to a storage module corresponding to the two target nodes in the data engine library;
step S610, traversing the two positioned storage modules and the storage module between the two positioned storage modules to obtain stored codes, and combining the codes with the codes obtained by traversing the target node;
step S611, obtaining corresponding data from a data engine base according to the obtained codes;
step S612, decoding the obtained data to feed back to the user.
By the method, the query of the items in a certain range can be realized, and the query efficiency is further improved.
According to the data storage method and the data query method provided by the embodiment, under the condition that the performance of the Fabric world state in the levelDB mode is not affected, a B + cache structure pool is constructed through the characteristics of order, stability, low height and the like of a B + tree structure, the uplink coding information of the user is sorted, a simple and effective division is performed, and meanwhile, the conditional query of the sorting and paging functions is supported. The cost of maintaining the data in multiple parts under the chain is solved for the service development end, although the data is uplink, and the realization of the ordinary condition query function of the service in the Fabric world state level DB mode is also expanded.
In addition, corresponding to the data storage method in the foregoing embodiment, an embodiment of the present application further provides a data storage device, please refer to fig. 11, where the data storage device includes:
the system comprises a first acquisition module, a second acquisition module and a third acquisition module, wherein the first acquisition module is used for acquiring data to be stored and codes to be stored of items to be processed, and the codes to be stored are preset according to the category of the items to be processed and a preset mode;
the conversion module is used for converting the codes to be stored into the corresponding category codes in the preset mode, wherein the codes of the items belonging to the same category correspond to the same category codes;
and the storage module is used for determining a target node for storing the codes according to the class codes, storing the codes to be stored to the target node, and storing the data to be stored into a storage area associated with the codes to be stored.
The detailed processes executed by the modules in the data storage device are not repeated herein, and reference may be made to the foregoing explanation of the data storage method.
In addition, corresponding to the data query method in the foregoing embodiment, an embodiment of the present application further provides a data query device, please refer to fig. 12, where the data query device includes:
the second acquisition module is used for acquiring the code to be inquired;
the determining module is used for determining a target node corresponding to the code to be inquired when the code to be inquired is a category code corresponding to the category of the item, wherein the codes of the items belonging to the same category correspond to the same category code;
and the query module is used for querying the target node to obtain the stored codes and acquiring data related to the codes from a data engine library according to the obtained codes, wherein the obtained data are data corresponding to all items belonging to the same category and corresponding to the category codes.
The detailed processes executed by the modules in the data query apparatus are not repeated here, and reference may be made to the explanation of the data query method above.
In summary, the data storage method, the data query method, and the electronic device provided in the embodiments of the present application obtain the to-be-stored data and the to-be-stored code of the to-be-processed item, where the to-be-stored code is preset according to the category to which the to-be-processed item belongs and in a preset manner. And then converting the codes to be stored into corresponding category codes in the preset mode, wherein the codes of the items belonging to the same category correspond to the same category codes. And finally, determining a target node for storing the codes according to the class codes, storing the codes to be stored to the target node, and storing the data to be stored in a storage area associated with the codes to be stored. Therefore, the codes of the same category of items can be converted into the same category codes, the single codes are stored in the same node, and subsequently, when the query is carried out, the data of all items in the category to which the codes belong can be obtained based on the codes to be queried.
The above description is only for the specific embodiments of the present application, but the scope of the present application is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present application should be covered within the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (11)

1. A method of data storage, the method comprising:
acquiring data to be stored and codes to be stored of items to be processed, wherein the codes to be stored are preset according to the category of the items to be processed and a preset mode;
converting the codes to be stored into corresponding category codes in the preset mode, wherein the codes of the items belonging to the same category correspond to the same category codes;
and determining a target node for storing the codes according to the class codes, storing the codes to be stored to the target node, and storing the data to be stored in a storage area associated with the codes to be stored.
2. The data storage method according to claim 1, wherein the step of converting the code to be stored into the corresponding class code in the preset mode comprises:
detecting whether the format of the code to be stored meets the preset format requirement, and if not, performing format conversion processing on the code to be stored;
and accumulating the characters contained in the codes to be stored which meet the requirements of the preset format to obtain the corresponding class codes in the preset mode.
3. The data storage method of claim 1, wherein the step of determining a target node for storing codes based on the class code comprises:
detecting whether a tree structure containing a plurality of nodes has a target node corresponding to the category code;
and if not, creating a target node corresponding to the category code in the tree structure.
4. The data storage method of claim 1, wherein the step of storing the code to be stored to the target node comprises:
detecting whether the target node has a residual storage space;
if the target node does not have the residual storage space, acquiring the node number of the target node, and determining a storage module corresponding to the node number in a data engine library according to the node number;
and storing the codes stored in the target node into the determined storage module, deleting the codes stored in the target node, and storing the codes to be stored into the target node.
5. The data storage method of claim 4, wherein the step of storing the code to be stored to the target node further comprises:
after the codes are stored in the data engine library, the flag bit of the target node is set to be in a set state, and the flag bit represents that the operation of storing the codes in the target node into the data engine library is executed in the set state.
6. A method for data query, the method comprising:
acquiring a code to be queried;
when the code to be inquired is a category code corresponding to the category of the item, determining a target node corresponding to the code to be inquired, wherein the codes of the items belonging to the same category correspond to the same category code;
and querying the target node to obtain a stored code, and acquiring data associated with the code from a data engine library according to the obtained code, wherein the obtained data is data corresponding to all items belonging to the same category and corresponding to the category code.
7. The data query method of claim 6, further comprising:
when the code to be inquired is the code of the corresponding item, detecting whether the code to be inquired meets the requirement of a preset format, and if not, performing format conversion processing on the code to be inquired;
accumulating characters contained in the code to be inquired which meets the requirements of the preset format so as to convert the code to be inquired into a category code corresponding to the category of the item.
8. The data query method of claim 6, the step of querying the target node for a stored code comprising:
detecting a flag bit of the target node, and acquiring a code stored in a corresponding storage module of the data engine library according to a node number of the target node when the state of the flag bit indicates that the operation of inputting the code from the target node to the data engine library is executed;
combining the code stored in the target node with the code obtained from the data engine repository.
9. The data query method of claim 6, wherein, when there are a plurality of codes to be queried, the step of querying the target node to obtain the stored codes comprises:
determining a target node corresponding to one of a plurality of codes to be queried as an initial target node;
and traversing the target nodes corresponding to the codes to be inquired from the initial target nodes according to a preset sequence to obtain the codes stored in the target nodes.
10. The data query method of claim 6, wherein the codes stored in the target node are sorted in chronological order of storage, and the step of querying the target node to obtain the stored codes comprises:
and detecting whether a reverse order request is obtained or not, and if the reverse order request is obtained, sequentially obtaining each code from the rear to the front according to the writing time of the code stored in the target node.
11. An electronic device, comprising: a processor, a storage medium and a bus, the storage medium storing machine-readable instructions executable by the processor, the processor and the storage medium communicating via the bus when the electronic device is operating, the processor executing the machine-readable instructions to perform the steps of the method of any one of claims 1 to 5 or the method of any one of claims 6 to 10.
CN202010967820.3A 2020-09-15 2020-09-15 Data storage method, data query method and electronic equipment Pending CN112084250A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010967820.3A CN112084250A (en) 2020-09-15 2020-09-15 Data storage method, data query method and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010967820.3A CN112084250A (en) 2020-09-15 2020-09-15 Data storage method, data query method and electronic equipment

Publications (1)

Publication Number Publication Date
CN112084250A true CN112084250A (en) 2020-12-15

Family

ID=73737104

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010967820.3A Pending CN112084250A (en) 2020-09-15 2020-09-15 Data storage method, data query method and electronic equipment

Country Status (1)

Country Link
CN (1) CN112084250A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113031877A (en) * 2021-04-12 2021-06-25 中国移动通信集团陕西有限公司 Data storage method, device, equipment and medium
CN113536188A (en) * 2021-09-16 2021-10-22 统信软件技术有限公司 Data storage method, data query method, computing device and storage medium

Citations (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104199927A (en) * 2014-09-03 2014-12-10 腾讯科技(深圳)有限公司 Data processing method and device
CN104298681A (en) * 2013-07-18 2015-01-21 华为技术有限公司 Data storage method and device
CN104750855A (en) * 2015-04-16 2015-07-01 成都睿峰科技有限公司 Method and device for optimizing big data storage
CN106228165A (en) * 2016-07-27 2016-12-14 维沃移动通信有限公司 A kind of method of photo classification and mobile terminal
CN107092686A (en) * 2017-04-24 2017-08-25 浙江宇视科技有限公司 A kind of file management method and device based on cloud storage platform
CN109271361A (en) * 2018-08-13 2019-01-25 华东计算技术研究所(中国电子科技集团公司第三十二研究所) Distributed storage method and system for massive small files
CN109408509A (en) * 2018-10-15 2019-03-01 北京金山云网络技术有限公司 Date storage method, device and computer equipment
CN109542965A (en) * 2018-11-07 2019-03-29 平安医疗健康管理股份有限公司 A kind of data processing method, electronic equipment and storage medium
CN109799948A (en) * 2017-11-17 2019-05-24 航天信息股份有限公司 A kind of date storage method and device
CN110110153A (en) * 2018-01-24 2019-08-09 北京京东尚科信息技术有限公司 A kind of method and apparatus of node searching
CN110737663A (en) * 2019-10-15 2020-01-31 腾讯科技(深圳)有限公司 data storage method, device, equipment and storage medium
CN110879807A (en) * 2018-09-06 2020-03-13 Sap欧洲公司 File format for quickly and efficiently accessing data
CN111367916A (en) * 2020-03-04 2020-07-03 浙江大华技术股份有限公司 Data storage method and device
CN111427959A (en) * 2020-03-27 2020-07-17 北京贝斯平云科技有限公司 Data storage method and device

Patent Citations (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104298681A (en) * 2013-07-18 2015-01-21 华为技术有限公司 Data storage method and device
CN104199927A (en) * 2014-09-03 2014-12-10 腾讯科技(深圳)有限公司 Data processing method and device
CN104750855A (en) * 2015-04-16 2015-07-01 成都睿峰科技有限公司 Method and device for optimizing big data storage
CN106228165A (en) * 2016-07-27 2016-12-14 维沃移动通信有限公司 A kind of method of photo classification and mobile terminal
CN107092686A (en) * 2017-04-24 2017-08-25 浙江宇视科技有限公司 A kind of file management method and device based on cloud storage platform
CN109799948A (en) * 2017-11-17 2019-05-24 航天信息股份有限公司 A kind of date storage method and device
CN110110153A (en) * 2018-01-24 2019-08-09 北京京东尚科信息技术有限公司 A kind of method and apparatus of node searching
CN109271361A (en) * 2018-08-13 2019-01-25 华东计算技术研究所(中国电子科技集团公司第三十二研究所) Distributed storage method and system for massive small files
CN110879807A (en) * 2018-09-06 2020-03-13 Sap欧洲公司 File format for quickly and efficiently accessing data
CN109408509A (en) * 2018-10-15 2019-03-01 北京金山云网络技术有限公司 Date storage method, device and computer equipment
CN109542965A (en) * 2018-11-07 2019-03-29 平安医疗健康管理股份有限公司 A kind of data processing method, electronic equipment and storage medium
CN110737663A (en) * 2019-10-15 2020-01-31 腾讯科技(深圳)有限公司 data storage method, device, equipment and storage medium
CN111367916A (en) * 2020-03-04 2020-07-03 浙江大华技术股份有限公司 Data storage method and device
CN111427959A (en) * 2020-03-27 2020-07-17 北京贝斯平云科技有限公司 Data storage method and device

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113031877A (en) * 2021-04-12 2021-06-25 中国移动通信集团陕西有限公司 Data storage method, device, equipment and medium
CN113031877B (en) * 2021-04-12 2024-03-08 中国移动通信集团陕西有限公司 Data storage method, device, equipment and medium
CN113536188A (en) * 2021-09-16 2021-10-22 统信软件技术有限公司 Data storage method, data query method, computing device and storage medium

Similar Documents

Publication Publication Date Title
US8799229B2 (en) Searchable archive
US7672930B2 (en) System and methods for facilitating a linear grid database with data organization by dimension
US9020910B2 (en) Storing tables in a database system
CN108292315A (en) Data in storage and retrieval data cube
CN103733195A (en) Managing storage of data for range-based searching
KR20090075885A (en) Managing storage of individually accessible data units
CN111506559A (en) Data storage method and device, electronic equipment and storage medium
CN105488201A (en) Log inquiry method and system
CN112084250A (en) Data storage method, data query method and electronic equipment
CN113704243A (en) Data analysis method, data analysis device, computer device, and storage medium
CN105144157A (en) System and method for compressing data in database
CN110807080A (en) Commodity coding method and device
CN114328981B (en) Knowledge graph establishing and data acquiring method and device based on mode mapping
CN114356851A (en) Data file storage method and device, electronic equipment and storage medium
CN111611250A (en) Data storage device, data query method, data query device, server and storage medium
CN109739854A (en) A kind of date storage method and device
CN112527824B (en) Paging query method, paging query device, electronic equipment and computer-readable storage medium
US7882114B2 (en) Data processing method and data processing program
CN110362540B (en) Data storage and visitor number acquisition method and device
CN112347355A (en) Data processing method, device, server and storage medium
CN111813773A (en) Power grid meter reading data storage method, uploading method, device and storage device
CN111723122A (en) Method, device and equipment for determining association rule between data and readable storage medium
CN111552703B (en) Data processing method and device
CN116263770A (en) Method, device, terminal equipment and medium for storing business data based on database
CN114564501A (en) Database data storage and query methods, devices, equipment and medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination