WO2015027425A1 - 存储数据的方法和装置 - Google Patents

存储数据的方法和装置 Download PDF

Info

Publication number
WO2015027425A1
WO2015027425A1 PCT/CN2013/082544 CN2013082544W WO2015027425A1 WO 2015027425 A1 WO2015027425 A1 WO 2015027425A1 CN 2013082544 W CN2013082544 W CN 2013082544W WO 2015027425 A1 WO2015027425 A1 WO 2015027425A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
format
row identifier
distributed database
data object
Prior art date
Application number
PCT/CN2013/082544
Other languages
English (en)
French (fr)
Inventor
毕杰山
智伟
Original Assignee
华为技术有限公司
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 华为技术有限公司 filed Critical 华为技术有限公司
Priority to EP13892411.3A priority Critical patent/EP3023885B1/en
Priority to CN201611186259.5A priority patent/CN106649708A/zh
Priority to CN201380001160.1A priority patent/CN103703467B/zh
Priority to PCT/CN2013/082544 priority patent/WO2015027425A1/zh
Priority to CA2921616A priority patent/CA2921616C/en
Priority to JP2016537067A priority patent/JP6225261B2/ja
Priority to BR112016004490A priority patent/BR112016004490B8/pt
Priority to KR1020167005763A priority patent/KR101720602B1/ko
Publication of WO2015027425A1 publication Critical patent/WO2015027425A1/zh
Priority to US15/054,519 priority patent/US9589004B2/en
Priority to US15/411,657 priority patent/US10331642B2/en

Links

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/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • 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/22Indexing; Data structures therefor; Storage structures
    • G06F16/221Column-oriented storage; Management thereof
    • 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/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2264Multidimensional index structures
    • 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/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2272Management thereof
    • 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/2455Query execution
    • 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/2455Query execution
    • G06F16/24553Query execution of query operations
    • G06F16/24562Pointer or reference processing operations
    • 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/28Databases characterised by their database models, e.g. relational or object models
    • 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/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/289Object oriented databases

Definitions

  • the present invention relates to the field of information technology and, more particularly, to a method and apparatus for storing data. Background technique
  • KeyValue type distributed database is highly scalable and robust as a distributed column storage database and has been widely used in more and more systems.
  • KeyValue can be a large amount of data, for example: used to store web page address information, used to store call log information, used to store online log information, and so on. It provides fast queries based on the row key of the data record (RowKey), regardless of the amount of data. It dynamically expands physical nodes when current storage usage reaches a certain threshold.
  • Embodiments of the present invention provide a method and apparatus for storing data, which can improve the efficiency of querying data.
  • the first aspect provides a method for storing data, including: determining the same column attribute of at least two data objects to be stored in a distributed database of a KeyValue type; determining each of the at least two data objects a format of a row identifier in the KeyValue type distributed database, wherein the format of the row identifier includes the same column attribute and a data object identifier, and the data object identifier of the different data object in the at least two data objects is in the row
  • the locations in the identified format are the same and are located after the same column attribute; determining the value of the row identifier of each data record of each data object according to the determined format of the row identifier of each data object; KeyValue The value of the row identifier of each data record stored in the type distributed database and the data record of each of the data records, wherein the value of the row identifier of each data record is recorded as the data in the KeyValue type distributed database.
  • Primary index The value of the row identifier of each data record stored in
  • the method further includes: sorting, according to the value of the row identifier of each data record, each data record in a first order, and making all data of the at least two data objects
  • the records form a clustered table.
  • the first sequence is a lexicographical order.
  • the method further includes: receiving a data request, the data request indicating the at least two data objects The data record is queried or obtained; according to the format of the row identifier, constructing query information for querying in the KeyValue type distributed database, wherein the query information includes the same column attribute; according to the query information, exporting the KeyValue
  • the primary index in a type distributed database contains a data record of the query information.
  • determining each of the at least two data objects The format of the row identifier of the object in the KeyValue type distributed database, comprising: specifying a first prefix of the row identifier in the KeyValue type distributed database for the at least two data objects, wherein the first prefix is a constant; Determining, in a format of the row identifier of the first data object of the at least two data objects, the first prefix, the same column attribute, and a data object identifier of the first data object; or determining the at least two data objects
  • the format of the row identifier of the second data object in the second data object includes the first prefix, the same column attribute, the data object identifier of the second data object, and the column attribute of the second data object can distinguish the second data object The column properties of all data records.
  • the query information includes the first prefix and the same column attribute.
  • the method further includes: determining that any one of the at least two data objects is in the
  • the format of the secondary index in the KeyValue type distributed database is a second prefix, a second attribute and the same column attribute, wherein the second attribute is a column different from the same attribute in the column attribute of the any data object. Attribute, the second prefix is a constant different from the first prefix; according to any one The format of the secondary index of the data object determines the secondary index of the any one of the data objects;
  • the secondary index of any one of the data objects is stored in the KeyValue type distributed database.
  • the fields in the format of the row identifier are set The separator, or, each of the fields has a fixed length.
  • a second aspect provides an apparatus for storing data, including: a determining module, configured to determine the same column attribute of at least two data objects to be stored in a key value type KeyValue type distributed database, and determine the at least two data The format of the row identifier of each data object in the object in the KeyValue type distributed database, wherein the format of the row identifier includes the same column attribute and data object identifier, different data objects in the at least two data objects Data object identifier is located in the same format as the row identifier and is located after the same column attribute, and each data record of each data object is determined according to the determined format of the row identifier of each data object.
  • a storage module configured to store, in the KeyValue type distributed database, a value of the row identifier of each data record and the data record, wherein the value of the row identifier of each data record is used as the value
  • Each piece of data is recorded in the primary index of the KeyValue type distributed database.
  • the storage module is further configured to sort each data record in a first order for the value of the row identifier of each data record, so that the at least two data objects are All data records form a clustered table.
  • the first sequence is a lexicographic order.
  • the apparatus further includes: a receiving module, configured to receive a data request, where the data request indicates the at least The data record in the two data objects is queried or obtained; the query module is configured to construct query information for querying in the KeyValue type distributed database according to the format of the row identifier, where the query information includes the same column Attribute, according to the query information, exporting the data record of the key index of the KeyValue type in the distributed database containing the query information.
  • a receiving module configured to receive a data request, where the data request indicates the at least The data record in the two data objects is queried or obtained
  • the query module is configured to construct query information for querying in the KeyValue type distributed database according to the format of the row identifier, where the query information includes the same column Attribute, according to the query information, exporting the data record of the key index of the KeyValue type in the distributed database containing the query information.
  • the determining module is specifically configured to be the at least two The data object specifies a first prefix of the row identifier in the KeyValue type distributed database, wherein the first prefix is a constant, and determining a format of the row identifier of the first data object of the at least two data objects includes the first a prefix, the same column attribute, and the number of the first data object Or determining, according to the object identifier, a format of the row identifier of the second data object of the at least two data objects, the first prefix, the same column attribute, the data object identifier of the second data object, and the second The column attributes of the data object can distinguish the column attributes of all data records of the second data object.
  • the query information includes the first prefix and the same column attribute.
  • the determining module is further configured to: determine that any one of the at least two data objects is distributed in the KeyValue type
  • the format of the secondary index in the database is a second prefix, a second attribute and the same column attribute, wherein the second attribute is a column attribute different from the same attribute in the column attribute of the any data object, the first The second prefix is a constant different from the first prefix, and the secondary index of the any one of the data objects is determined according to the format of the secondary index of the any data object; the storage module is further used in the distributed database of the KeyValue type. Stores the secondary index of any of the data objects.
  • each of the fields has a fixed length.
  • the method and apparatus for storing data can implement multiple data by storing an associated data object in a KeyValue type distributed database in a format including a row identifier of the same column attribute.
  • Objects perform associative queries, which can improve the efficiency of querying data.
  • FIG. 1 is a schematic flowchart of a method of storing data according to an embodiment of the present invention.
  • FIG. 2 is a schematic flowchart of a method of determining a format of a row identifier according to an embodiment of the present invention.
  • 3 is a schematic flowchart of a method for storing data according to another embodiment of the present invention.
  • FIG. 4 is a schematic flowchart of a method for storing data according to still another embodiment of the present invention.
  • FIG. 5 is a schematic block diagram of an apparatus for storing data according to an embodiment of the present invention.
  • FIG. 6 is a schematic block diagram of an apparatus for storing data according to another embodiment of the present invention.
  • FIG. 7 is a schematic structural diagram of an apparatus for storing data according to an embodiment of the present invention. detailed description
  • the data object is a data table (also referred to as a table) or a type of data having a data table format.
  • the data of this type may be call record data or online record data, and the like.
  • the following embodiments will be described by taking a data table as an example.
  • FIG. 1 shows a schematic flow diagram of a method 100 of storing data in accordance with an embodiment of the present invention.
  • the method of Figure 1 is performed by a device that stores data.
  • the method 100 includes:
  • S120 Determine a format of a row identifier of each of the at least two data objects in the KeyValue type distributed database, where the format of the row identifier includes the same column attribute and a data object identifier, the at least two The data object identifiers of the different data objects in the data objects are in the same position in the format of the row identifier and are located after the same column attribute;
  • S140 Store, in the KeyValue type distributed database, a value of a row identifier of each data record and each data record, where a value of the row identifier of each data record is recorded as the key data type in the KeyValue type.
  • the primary index in a distributed database is a distributed database.
  • the device for storing data when multiple (ie, at least two) data objects are associated, that is, when multiple data objects have the same column attribute, in order to facilitate the association query of multiple data objects, the device for storing data will Multiple data objects are stored in a table in a distributed database of KeyValue types.
  • the apparatus for storing data determines a format of a row identifier (eg, RowKey) of each data object in a KeyValue type distributed database based on the same column attribute, wherein the format of the row identifier includes The same column attribute and data object identifier, the data object identifiers of the different data objects of the at least two data objects are in the same position in the format of the row identifier and are located after the same column attribute.
  • the format of the row identifier of each data object includes the same column attribute to facilitate the query, and further includes a data object identifier corresponding to the data object to distinguish different data objects.
  • the data object identifiers of different data objects are in the same position in the format of the row identifier and are located after the same column attribute to keep the format of the row identifiers of the different data objects consistent.
  • the device storing the data determines the value of the row identifier of each data record in each data object according to the format of the determined row identifier, and stores the value of the row identifier of each data record in the KeyValue type distributed database and each A data record, wherein the value of the row identifier of each data record is recorded as a primary index of each data in a KeyValue type distributed database. Since the associated multiple data objects adopt a consistent row identifier format, when querying data, constructing query information according to the format of the row identifier, it is possible to perform association query on multiple data objects in one data table, thereby Can improve the efficiency of querying data.
  • the method for storing data in the embodiment of the present invention can perform association query on multiple data objects by storing the associated data objects in a KeyValue type distributed database in a format including row identifiers of the same column attribute. Thereby, the efficiency of querying data can be improved.
  • the row identifier is an identifier of each row of data.
  • the row identifier can be expressed as a RowKey, and can also be expressed as a Key.
  • the present invention is not limited thereto.
  • the following embodiment is described by taking a RowKey as an example. The present invention is only intended to assist those skilled in the art to better understand the embodiments of the present invention and not to limit the scope of the embodiments of the present invention.
  • the device storing the data determines the same column attribute of the at least two data objects to be stored in the KeyValue type distributed database.
  • Multiple data objects have the same column attribute, that is, multiple data objects.
  • the data object A is exemplified by Table 1 for recording student information, and its attribute information includes a column attribute such as a name (Name), a student number (Id), a gender (Sex), and a class (Dept).
  • Table 1 and Table 2 have Id columns, that is, Table 1 and Table 2 have the same column attribute Id, so Table 1 and Table 2 are the associated data objects.
  • the means for storing data determines the format of the row identification of each of the at least two data objects in the KeyValue type distributed database.
  • the format of the row identifier includes the same column attribute and data object identifier, and the data object identifiers of the different data objects in the at least two data objects are in the same position in the format of the row identifier and are located after the same column attribute.
  • each data object in order to improve the efficiency of querying data, each data object is not stored in a separate table, but multiple data objects are stored in a table according to a unified format. , thus implementing the associated query.
  • the format of the row identifier needs to be pre-configured.
  • the format of the RowKey is pre-designed, that is, which constituent elements of the RowKey are specified, and how the constituent elements are combined.
  • the constituent elements of the row identifier include: the same column attribute of at least two data objects and a data object identifier.
  • the same column attribute is used to store the at least two data objects associated with each other, the data object identifier being used to indicate which data object each row of data originated from.
  • the data object identifiers are located after the same column attribute, and the data object identifier of each data object has the same position in the format of the row identifier.
  • the data object identifiers of different data objects may be different constants for distinguishing different data objects.
  • S120 includes:
  • the first prefix of the row identifier in the KeyValue type distributed database is specified for the at least two data objects, where the first prefix is a constant;
  • the row identifier includes an identical prefix (denoted as the first prefix).
  • RowKey has the following format:
  • RowKey first prefix + same column attribute + data object identifier (+ other attributes).
  • the RowKey format uses the same first prefix and the same attribute, so that when data records are stored in the order of RowKey values, data records of different data objects can be stored adjacently (referred to as Clustered storage). Different data objects are distinguished by the data object identifier corresponding to each data object. In addition, when the same column attribute can distinguish all the data records of one data object (represented as the first data object), for example, the Id attribute in Table 1 can distinguish all the data records of Table 1, the RowKey format of the first data object.
  • the RowKey format also includes attributes of all of the other column attributes of the second data object that distinguish the data records of the second data object, for example, the No attribute of Table 2.
  • Tables 1 and 2 Take Tables 1 and 2 as an example. Their same column attributes are Id. For Table 1, Id is able to distinguish all the data records in Table 1. Therefore, the RowKey format of Table 1 can be:
  • a (first prefix) +Id+M (M is the data object identifier corresponding to Table 1).
  • a separator is set between each field in the format of the row identifier, or the respective field has a fixed length.
  • the "+" in the above RowKey format can be a separator.
  • each field in the RowKey format can be set to a fixed length, in which case the "+” does not actually exist.
  • the device storing the data determines the value of the row identifier of each data record of each data object according to the determined format of the row identifier of each data object.
  • the device storing the data determines the RowKey value of each data record in each data object according to the format of the determined RowKey.
  • the RowKey value is A0001M
  • the RowKey value is A0001N1, and so on.
  • the means for storing data stores the value of the row identifier of each data record and the each data record in the KeyValue type distributed database.
  • the value of the row identifier of each data record is recorded as the main index of the data in the KeyValue type distributed database.
  • the method 100 further includes:
  • the data records are stored in the KeyValue type distributed database in the order of the values of the row identifiers, so that the data records of the plurality of data objects form a cluster table.
  • the cluster table storage method can correspond to the range of the value of the row identifier, that is, the range of the value of the row identifier of a data record belongs to, and the extent in which the data record corresponds to the partition, thereby supporting the query by range.
  • the first order may be a lexicographic order, for example, each data record may be arranged in a KeyValue type distributed database in a lexicographic order of RowKey values.
  • the first order may also be other orders, for example, the size order, that is, the data may be sequentially stored in the order of the size of the RowKey value, the RowKey value is small, the RowKey value is large, or the RowKey value is large. Stored in the front, the RowKey value d, is stored in the back.
  • This embodiment of the present invention is not limited to the first order. For ease of description, the following embodiment will be described by taking the lexicographic order of RowKey values as an example.
  • Table 3 is stored in the KeyValue type distributed database in the lexicographic order of RowKey values.
  • the data records of the associated different data objects can be stored adjacently. , forming a cluster table.
  • the first data record in Table 3 is the first record of the original table 1
  • the second 2-4 records in Table 3 are the first 1-3 records of the original table 2.
  • These data records have the same Id is stored adjacently in a KeyValue type distributed database. The adjacent data storage speeds up the data access rate and further improves the query efficiency.
  • the method 100 further includes:
  • S160 Receive a data request, where the data request indicates querying or acquiring the data record in the at least two data objects.
  • the device storing the data upon receiving the data request for querying or acquiring the data record, the device storing the data constructs the query information according to the format of the row identifier, the query information includes the same column attribute, and then the device storing the data adopts the constructed The query information is queried to obtain a data record in which the primary index of the KeyValue type distributed database contains the query information.
  • the query information when the format of the row identifier includes the first prefix, the query information includes the first prefix and the same column attribute.
  • the obtained query results are shown in Table 4. In the query process, only need to query a table, complete the positioning of user data, student information and learning The student class information can be returned immediately after being stored adjacent to it.
  • the method for storing data in the embodiment of the present invention can store the associated data objects in clusters by storing the associated data objects in a KeyValue type distributed database in a format including row identifiers of the same column attribute.
  • the implementation of the association query in a data table can improve the efficiency of querying data.
  • the method 100 further includes:
  • the format of the secondary index of the data object of the at least two data objects in the KeyValue type distributed database is a second prefix, a second attribute and the same column attribute, wherein the second attribute is the A column attribute of a data object is different from a column attribute of the same attribute, and the second prefix is a constant different from the first prefix;
  • the secondary index of any one of the data objects is stored in the KeyValue type distributed database.
  • secondary index information may be constructed on the data object.
  • the primary index of the same data object and the data of the secondary index are stored in the same table, but the format of different row identifiers is used to implement data isolation in the same table.
  • the associated query can be completed through the secondary index information.
  • the format of the row identifier of the secondary index is the second prefix, the second attribute, and the same attribute.
  • the second prefix is different from the first prefix to achieve data isolation;
  • the second attribute is an attribute different from the same attribute to facilitate constructing query information based on the second attribute; the same attribute is used to associate with the primary index.
  • the main index RowKey format of Table 1 may be: A+Id+M; the main index of the table 2 may be of the following format: +Id+N+No;
  • the secondary index RowKey format of Table 1 can be: B+Name+Ido
  • Table 5 is stored in the KeyValue type distributed database in the lexicographic order of the RowKey values.
  • the column information may also be stored, for example, the individual key column information, which is not limited by the embodiment of the present invention.
  • the method for storing data in the embodiment of the present invention can provide a richer and more diverse query scenario for the user by storing the secondary index of the data object in the KeyValue type distributed database, thereby facilitating user query, thereby improving the efficiency of querying data. .
  • the format of the row identifiers of the plurality of data objects may also have other implementation manners.
  • the format of the row identifiers of different data objects may adopt different prefixes, or may not use a prefix.
  • Data records of different data objects can be stored adjacently by the same column attribute, and different data objects can be distinguished by the data object identifier corresponding to each data object.
  • the RowKey format of the first data object no longer includes other attributes; the same column attribute cannot distinguish one data.
  • the RowKey format of the second data object further includes attributes of all of the other column attributes of the second data object that distinguish the data records of the second data object.
  • Tables 1 and 2 Take Tables 1 and 2 as an example. Their same column attributes are Id. For Table 1, Id is able to distinguish all the data records in Table 1. Therefore, the RowKey format of Table 1 can be:
  • Table 6 is stored in the KeyValue type distributed database in the lexicographic order of the RowKey values.
  • RowKey adopts the following format:
  • RowKey the prefix corresponding to the data object) + the same column attribute (+ other attributes).
  • the RowKey format of the first data object no longer includes other attributes; the same column attribute cannot distinguish one data.
  • the RowKey format of the second data object further includes attributes of all of the other column attributes of the second data object that distinguish the data records of the second data object.
  • Tables 1 and 2 Take Tables 1 and 2 as an example. Their same column attributes are Id. For Table 1, Id is able to distinguish all the data records in Table 1. Therefore, the RowKey format of Table 1 can be:
  • Table 7 is stored in the KeyValue type distributed database in the lexicographic order of the RowKey values.
  • the size of the sequence numbers of the above processes does not mean the order of execution, and the order of execution of each process should be determined by its function and internal logic, and should not be taken to the embodiments of the present invention.
  • the implementation process constitutes any limitation.
  • the method for storing data can facilitate the management of the database and improve the efficiency of querying data by storing a plurality of data objects in a unified row identification format in a data table in a KeyValue type distributed database.
  • FIG. 5 shows a schematic block diagram of an apparatus 500 for storing data in accordance with an embodiment of the present invention.
  • the apparatus 500 includes:
  • a determining module 510 configured to determine the same column attribute of the at least two data objects to be stored in the key value KeyValue type distributed database, and determine each of the at least two data objects in the KeyValue type distributed database
  • the format of the row identifier in the line identifier wherein the format of the row identifier includes the same column attribute and the data object identifier, and the data object identifier of the different data object in the at least two data objects has the same position in the format of the row identifier
  • a storage module 520 configured to store, in the KeyValue type distributed database, a value of a row identifier of each data record and each data record, where a value of the row identifier of each data record is used as the data record The primary index in the KeyValue type distributed database.
  • the device 500 storing the data stores the plurality of data objects to facilitate the associated query of the plurality of data objects.
  • the KeyValue type is in a table of a distributed database.
  • the determining module 510 determines a format of a row identifier (eg, RowKey) of each data object in a KeyValue type distributed database based on the same column attribute, where the format of the row identifier includes the same column attribute and a data object identifier,
  • the data object identifiers of the different data objects of the at least two data objects are in the same position in the format of the row identifier and are located after the same column attribute.
  • the format of the row identifier of each data object includes the same column attribute to facilitate the query, and further includes a data object identifier corresponding to the data object to distinguish different data objects.
  • Data for different data objects The structure in which the object identifiers are in the same position in the format of the row identifier and are located after the same column attribute to keep the format of the row identifiers of the different data objects consistent.
  • the determination module 510 determines the value of the row identification for each data record in each data object based on the determined format of the row identification.
  • the storage module 520 stores the value of the row identifier of each data record and each data record in a KeyValue type distributed database, wherein the value of the row identifier of each data record is recorded as a data record in a KeyValue type distributed database.
  • Primary index Since the associated multiple data objects adopt a consistent row identifier format, when querying data, constructing query information according to the format of the row identifier, it is possible to perform association query on multiple data objects in one data table, thereby Can improve the efficiency of querying data.
  • the apparatus for storing data can implement association of multiple data objects by storing the associated data objects in a KeyValue type distributed database by using a plurality of data object formats including the same column attribute. Query, which can improve the efficiency of querying data.
  • the storage module 520 is further configured to: sort, according to the value of the row identifier of each data record, the data records in the first order, so that the at least two data are All data records of the object form a clustered table.
  • the first order is a dictionary order.
  • the determining module 510 is specifically configured to: specify, for the at least two data objects, a first prefix of a row identifier in the KeyValue type distributed database, where the first prefix is a constant, determining a format of the row identifier of the first data object of the at least two data objects, including the first prefix, the same column attribute, and a data object identifier of the first data object, or determining the at least two
  • the format of the row identifier of the second data object in the data object includes the first prefix, the same column attribute, the data object identifier of the second data object, and the column attribute of the second data object can distinguish the second The column attribute of all data records for the data object.
  • the apparatus 500 further includes: a receiving module 530, configured to receive a data request, where the data request indicates to query a data record in the at least two data objects. Or obtain;
  • the querying module 540 is configured to construct query information for querying in the KeyValue type distributed database according to the format of the row identifier, where the query information includes the same column attribute, and the KeyValue type distribution is derived according to the query information.
  • the primary index in the database contains the data record of the query information.
  • the query information includes the first prefix and the same column attribute.
  • the determining module 510 is further configured to: determine that the format of the secondary index of the data object of the at least two data objects in the KeyValue type distributed database is a second prefix. a second attribute and a same column attribute, wherein the second attribute is a column attribute different from the same attribute in a column attribute of the any data object, and the second prefix is a constant different from the first prefix, according to The format of the secondary index of any one of the data objects determines a secondary index of the any one of the data objects;
  • the storage module 520 is further configured to store a secondary index of the any of the data objects in the KeyValue type distributed database.
  • the device for storing data in the embodiment of the present invention can provide a richer and more diverse query scenario for the user by querying the secondary index of the data object in the KeyValue type distributed database, thereby facilitating user query, thereby improving the efficiency of querying data.
  • a separator is set between each field in the format of the row identifier, or the respective field has a fixed length.
  • the apparatus 500 for storing data may correspond to an apparatus for storing data in a method according to an embodiment of the present invention, and the above-described and other operations and/or functions of respective modules in the apparatus 500 for storing data are respectively
  • the corresponding processes of the various methods in FIG. 1 to FIG. 4 are implemented, and are not described here.
  • the device for storing data can conveniently manage the database and improve the efficiency of querying data by storing a plurality of data objects in a unified row identification format in a data table in a KeyValue type distributed database.
  • FIG. 7 shows a structure of an apparatus for storing data according to another embodiment of the present invention, comprising at least one processor 702 (for example, a CPU), at least one network interface 705 or other communication interface, a memory 706, and at least one communication bus 703. Used to implement connection communication between these devices.
  • the processor 702 is configured to execute executable modules, such as computer programs, stored in the memory 706.
  • the memory 706 may include a high speed random access memory (RAM: Random Access Memory) and may also include a non-volatile memory such as at least one disk memory.
  • a communication connection with at least one other network element is achieved by at least one network interface 705 (which may be wired or wireless).
  • the memory 706 stores the program 7061, and the program 7061 can be The processor 702 executes, and the program includes:
  • the method further includes:
  • each data record For each value of the row identifier of each data record, each data record is sorted in a first order such that all data records of the at least two data objects form a cluster table.
  • the first order is a lexicographic order.
  • the method further includes:
  • the data record of the primary index in the distributed database of the KeyValue type containing the query information is derived.
  • determining a format of a row identifier of each of the at least two data objects in the KeyValue type distributed database including:
  • the format of the row identifier of the second data object in the second data object includes the first prefix, the same column attribute, the data object identifier of the second data object, and the second data
  • the column attribute of the object distinguishes the column attributes of all data records of the second data object.
  • the query information includes the first prefix and the same column attribute.
  • the method further includes:
  • the format of the secondary index of the data object of the at least two data objects in the KeyValue type distributed database is a second prefix, a second attribute and the same column attribute, wherein the second attribute is the A column attribute of a data object is different from a column attribute of the same attribute, and the second prefix is a constant different from the first prefix;
  • the secondary index of any one of the data objects is stored in the KeyValue type distributed database.
  • a separator is set between each field in the format of the row identifier, or the respective field has a fixed length.
  • the embodiment of the present invention can implement multiple pairs by storing the associated data objects in a KeyValue type distributed database in a format including row identifiers of the same column attribute.
  • Data objects perform associative queries, which can improve the efficiency of querying data.
  • the term "and/or” is merely an association describing the associated object, indicating that there may be three relationships.
  • a and / or B can mean: A exists separately, there are A and B, and there are three cases of B alone.
  • the character "/" in this article generally indicates that the contextual object is an "or" relationship.
  • the disclosed systems, devices, and The method can be implemented in other ways.
  • the device embodiments described above are merely illustrative.
  • the division of the unit is only a logical function division.
  • there may be another division manner for example, multiple units or components may be combined or Can be integrated into another system, or some features can be ignored, or not executed.
  • the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interface, device or unit, or an electrical, mechanical or other form of connection.
  • the units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the objectives of the embodiments of the present invention.
  • each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
  • the above integrated unit can be implemented in the form of hardware or in the form of a software functional unit.
  • the integrated unit if implemented in the form of a software functional unit and sold or used as a standalone product, may be stored in a computer readable storage medium.
  • the technical solution of the present invention contributes in essence or to the prior art, or all or part of the technical solution may be embodied in the form of a software product stored in a storage medium.
  • a number of instructions are included to cause a computer device (which may be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention.
  • the foregoing storage medium includes: a U disk, a removable hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and the like, which can store program codes. .

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Computational Linguistics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明公开了一种存储数据的方法和装置。该方法包括:确定待存储到Key Value类型分布式数据库中的至少两个数据对象的相同的列属性;确定该至少两个数据对象中的每个数据对象在Key Value类型分布式数据库中的行标识的格式,该行标识的格式包括该相同的列属性和数据对象标识,不同数据对象的数据对象标识在该行标识的格式中的位置相同且位于该相同的列属性之后;根据每个数据对象的行标识的格式,确定每个数据对象的每条数据记录的行标识的值;在Key Value类型分布式数据库中存储每条数据记录的行标识的值和每条数据记录,该每条数据记录的行标识的值作为该每条数据记录在Key Value类型分布式数据库中的主索引。本发明实施例的存储数据的方法和装置,能够提高查询数据的效率。

Description

存储数据的方法和装置 技术领域
本发明涉及信息技术领域,并且更具体地,涉及存储数据的方法和装置。 背景技术
键值 ( KeyValue )类型分布式数据库作为分布式列存储数据库具有高可 伸缩性和鲁棒性, 已经在越来越多的***中得到了广泛的使用。 KeyValue 单但可能是海量的数据, 例如: 用来存储网页地址信息, 用来存储通话记录 信息,用来存储上网记录信息,等等。它能够根据数据记录的行键(RowKey ) 提供快速的查询, 无关数据量的大小。 它能够在当前的存储空间使用率达到 一定阈值的时候动态的扩充物理节点。
在企业现有数据库应用中, 通常关联很多个用户数据表, 这些数据表的 大小不一, 并且表与表之间的数据可能存在内在的关联。 而基于稀疏矩阵的 KeyValue类型的分布式数据库适合存放大数据量表,如果原样将这些表导入 到 KeyValue类型分布式数据库中, 则存在过多的小表, 不仅难以实现跨表 的关联查询, 而且会增加管理上的复杂度。 也就是说, 当将传统应用中的数 据迁移到 KeyValue类型的分布式数据库中, 为了完成用户表与用户表之间 的关联查询, 需要查询不同的表, 不断进行数据定位导致效率低下。 发明内容
本发明实施例提供了一种存储数据的方法和装置, 能够提高查询数据的 效率。
第一方面, 提供了一种存储数据的方法, 包括: 确定待存储到 KeyValue 类型分布式数据库中的至少两个数据对象的相同的列属性; 确定该至少两个 数据对象中的每个数据对象在该 KeyValue类型分布式数据库中的行标识的 格式, 其中, 该行标识的格式包括该相同的列属性和数据对象标识, 该至少 两个数据对象中的不同数据对象的数据对象标识在该行标识的格式中的位 置相同且位于该相同的列属性之后;根据确定的该每个数据对象的该行标识 的格式,确定该每个数据对象的每条数据记录的行标识的值; 在该 KeyValue 类型分布式数据库中存储该每条数据记录的行标识的值和该每条数据记录, 其中, 该每条数据记录的行标识的值作为该每条数据记录在该 KeyValue类 型分布式数据库中的主索引。
在第一种可能的实现方式中, 该方法还包括: 针对该每条数据记录的行 标识的值, 按照第一顺序对该每条数据记录进行排序, 使该至少两个数据对 象的所有数据记录形成聚簇表。
结合第一方面的第一种可能的实现方式, 在第二种可能的实现方式中, 该第一顺序为字典顺序。
结合第一方面或第一方面的第一或二种可能的实现方式,在第三种可能 的实现方式中, 该方法还包括: 接收数据请求, 该数据请求指示对该至少两 个数据对象中的数据记录进行查询或获取; 根据该行标识的格式, 构造在该 KeyValue类型分布式数据库中进行查询的查询信息, 其中, 该查询信息包括 该相同的列属性; 根据该查询信息, 导出该 KeyValue类型分布式数据库中 主索引包含该查询信息的数据记录。
结合第一方面或第一方面的第一至三种可能的实现方式中的任一种可 能的实现方式, 在第四种可能的实现方式中, 确定该至少两个数据对象中的 每个数据对象在该 KeyValue类型分布式数据库中的行标识的格式, 包括: 为该至少两个数据对象指定在该 KeyValue类型分布式数据库中的行标识的 第一前缀, 其中, 该第一前缀为常量; 确定该至少两个数据对象中的第一数 据对象的该行标识的格式包括该第一前缀、该相同的列属性和该第一数据对 象的数据对象标识; 或者, 确定该至少两个数据对象中的第二数据对象的该 行标识的格式包括该第一前缀、 该相同的列属性、 该第二数据对象的数据对 象标识和该第二数据对象的列属性中能区分该第二数据对象的所有数据记 录的列属性。
结合第一方面的第四种可能的实现方式, 在第五种可能的实现方式中, 该查询信息包括该第一前缀和该相同的列属性。
结合第一方面的第四或五种可能的实现方式,在第六种可能的实现方式 中, 该方法还包括: 确定该至少两个数据对象中任一个数据对象在该
KeyValue类型分布式数据库中的二级索引的格式为第二前缀,第二属性和该 相同的列属性, 其中, 该第二属性为该任一个数据对象的列属性中不同于该 相同属性的列属性, 该第二前缀为与该第一前缀不同的常量; 根据该任一个 数据对象的该二级索引的格式确定该任一个数据对象的二级索引; 在该
KeyValue类型分布式数据库中存储该任一个数据对象的二级索引。
结合第一方面或第一方面的第一至六种可能的实现方式中的任一种可 能的实现方式, 在第七种可能的实现方式中, 该行标识的格式中的各个字段 之间设置分隔符, 或者, 该各个字段具有固定长度。
第二方面, 提供了一种存储数据的装置, 包括: 确定模块, 用于确定待 存储到键值 KeyValue类型分布式数据库中的至少两个数据对象的相同的列 属性, 确定该至少两个数据对象中的每个数据对象在该 KeyValue类型分布 式数据库中的行标识的格式, 其中, 该行标识的格式包括该相同的列属性和 数据对象标识,该至少两个数据对象中的不同数据对象的数据对象标识在该 行标识的格式中的位置相同且位于该相同的列属性之后,根据确定的该每个 数据对象的该行标识的格式,确定该每个数据对象的每条数据记录的行标识 的值; 存储模块, 用于在该 KeyValue类型分布式数据库中存储该每条数据 记录的行标识的值和该每条数据记录, 其中, 该每条数据记录的行标识的值 作为该每条数据记录在该 KeyValue类型分布式数据库中的主索引。
在第一种可能的实现方式中, 该存储模块还用于, 针对该每条数据记录 的行标识的值, 按照第一顺序对该每条数据记录进行排序, 使该至少两个数 据对象的所有数据记录形成聚簇表。
结合第二方面的第一种可能的实现方式, 在第二种可能的实现方式中, 该第一顺序为字典顺序。
结合第二方面或第二方面的第一或二种可能的实现方式,在第三种可能 的实现方式中, 该装置还包括: 接收模块, 用于接收数据请求, 该数据请求 指示对该至少两个数据对象中的数据记录进行查询或获取; 查询模块, 用于 根据该行标识的格式, 构造在该 KeyValue类型分布式数据库中进行查询的 查询信息, 其中, 该查询信息包括该相同的列属性, 根据该查询信息, 导出 该 KeyValue类型分布式数据库中主索引包含该查询信息的数据记录。
结合第二方面或第二方面的第一至三种可能的实现方式中的任一种可 能的实现方式, 在第四种可能的实现方式中, 该确定模块具体用于, 为该至 少两个数据对象指定在该 KeyValue类型分布式数据库中的行标识的第一前 缀, 其中, 该第一前缀为常量, 确定该至少两个数据对象中的第一数据对象 的该行标识的格式包括该第一前缀、该相同的列属性和该第一数据对象的数 据对象标识, 或者, 确定该至少两个数据对象中的第二数据对象的该行标识 的格式包括该第一前缀、 该相同的列属性、 该第二数据对象的数据对象标识 和该第二数据对象的列属性中能区分该第二数据对象的所有数据记录的列 属性。
结合第二方面的第四种可能的实现方式, 在第五种可能的实现方式中, 该查询信息包括该第一前缀和该相同的列属性。
结合第二方面的第四或五种可能的实现方式,在第六种可能的实现方式 中, 该确定模块还用于, 确定该至少两个数据对象中任一个数据对象在该 KeyValue类型分布式数据库中的二级索引的格式为第二前缀,第二属性和该 相同的列属性, 其中, 该第二属性为该任一个数据对象的列属性中不同于该 相同属性的列属性, 该第二前缀为与该第一前缀不同的常量, 根据该任一个 数据对象的该二级索引的格式确定该任一个数据对象的二级索引; 该存储模 块还用于在该 KeyValue类型分布式数据库中存储该任一个数据对象的二级 索引。
结合第二方面或第二方面的第一至六种可能的实现方式中的任一种可 能的实现方式, 在第七种可能的实现方式中, 该行标识的格式中的各个字段 之间设置分隔符, 或者, 该各个字段具有固定长度。
基于上述技术方案, 本发明实施例的存储数据的方法和装置, 通过将相 关联的数据对象采用包括相同的列属性的行标识的格式存储到 KeyValue类 型分布式数据库中, 可以实现对多个数据对象进行关联查询, 从而能够提高 查询数据的效率。 附图说明
为了更清楚地说明本发明实施例的技术方案, 下面将对本发明实施例中 所需要使用的附图作筒单地介绍, 显而易见地, 下面描述中的附图仅仅是本 发明的一些实施例, 对于本领域普通技术人员来讲, 在不付出创造性劳动的 前提下, 还可以根据这些附图获得其他的附图。
图 1是根据本发明实施例的存储数据的方法的示意性流程图。
图 2是根据本发明实施例的确定行标识的格式的方法的示意性流程图。 图 3是根据本发明另一实施例的存储数据的方法的示意性流程图 图 4是根据本发明又一实施例的存储数据的方法的示意性流程图 图 5是根据本发明实施例的存储数据的装置的示意性框图。
图 6是根据本发明另一实施例的存储数据的装置的示意性框图。
图 7是根据本发明实施例的存储数据的装置的结构示意图。 具体实施方式
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行 清楚、 完整地描述, 显然, 所描述的实施例是本发明的一部分实施例, 而不 是全部实施例。 基于本发明中的实施例, 本领域普通技术人员在没有作出创 造性劳动的前提下所获得的所有其他实施例, 都应属于本发明保护的范围。
本发明实施例的技术方案可以应用于 KeyValue类型分布式数据库。 在本发明实施例中, 数据对象为数据表(也筒称为表)或者具有数据表 格式的一类数据。 例如, 该类数据可以是通话记录数据或者上网记录数据, 等等。 为了描述方便, 下述实施例将以数据表为例进行说明。
图 1示出了根据本发明实施例的存储数据的方法 100的示意性流程图。 图 1的方法由存储数据的装置执行。 如图 1所示, 该方法 100包括:
S110, 确定待存储到 KeyValue类型分布式数据库中的至少两个数据对 象的相同的列属性;
S120, 确定该至少两个数据对象中的每个数据对象在该 KeyValue类型 分布式数据库中的行标识的格式, 其中, 该行标识的格式包括该相同的列属 性和数据对象标识, 该至少两个数据对象中的不同数据对象的数据对象标识 在该行标识的格式中的位置相同且位于该相同的列属性之后;
S130, 根据确定的该每个数据对象的该行标识的格式, 确定该每个数据 对象的每条数据记录的行标识的值;
S140, 在该 KeyValue类型分布式数据库中存储该每条数据记录的行标 识的值和该每条数据记录, 其中, 该每条数据记录的行标识的值作为该每条 数据记录在该 KeyValue类型分布式数据库中的主索引。
在本发明实施例中, 在多个(即至少两个)数据对象相关联时, 即多个 数据对象具有相同的列属性时, 为了方便对多个数据对象的关联查询, 存储 数据的装置将多个数据对象存储到 KeyValue类型分布式数据库的一个表中。 存储数据的装置基于该相同的列属性确定每个数据对象在 KeyValue类型分 布式数据库中的行标识(如 RowKey ) 的格式, 其中, 该行标识的格式包括 该相同的列属性和数据对象标识 , 该至少两个数据对象中的不同数据对象的 数据对象标识在该行标识的格式中的位置相同且位于该相同的列属性之后。 也就是说, 每个数据对象的行标识的格式都包括该相同的列属性以便于查 询, 另外, 还包括与数据对象对应的数据对象标识以区别不同数据对象。 不 同数据对象的数据对象标识在行标识的格式中的位置相同且位于相同的列 属性之后以使不同数据对象的行标识的格式保持相一致的结构。 然后, 存储 数据的装置根据确定的行标识的格式确定每个数据对象中的每条数据记录 的行标识的值, 再在 KeyValue类型分布式数据库中存储每条数据记录的行 标识的值和每条数据记录, 其中, 每条数据记录的行标识的值作为每条数据 记录在 KeyValue类型分布式数据库中的主索引。 由于相关联的多个数据对 象采用了一致的行标识的格式, 这样, 在查询数据时, 按照行标识的格式构 造查询信息, 可以实现在一个数据表中对多个数据对象进行关联查询, 从而 能够提高查询数据的效率。
因此, 本发明实施例的存储数据的方法, 通过将相关联的数据对象采用 包括相同的列属性的行标识的格式存储到 KeyValue类型分布式数据库中, 可以实现对多个数据对象进行关联查询, 从而能够提高查询数据的效率。
应理解, 在本发明实施例中, 行标识为每一行数据的标识。 行标识可以 表述为 RowKey, 也可以表述为 Key, 本发明对此并不限定。 为了描述方便, 下述实施例以 RowKey为例进行说明。 子只是为了帮助本领域技术人员更好地理解本发明实施例, 而非限制本发明 实施例的范围。
在 S110中, 存储数据的装置确定待存储到 KeyValue类型分布式数据库 中的至少两个数据对象的相同的列属性
多个数据对象具有相同的列属性即多个数据对象相关联。
例如, 数据对象 A, 以记录学生信息的表 1为例, 其属性信息包括姓名 ( Name ), 学号 ( Id ), 性别 ( Sex ), 班级 ( Dept )等列 ( Column )属性。
表 1
RowKey Columns
Id Name Id Sex Dept t t t
0001 张三 0001 Male 3班 , , , 0002 李四 0002 Male 3班 ...
0003 王五 0003 Female 3班 • · · 数据对象 B ,以记录学生选课信息的表 2为例,其属性信息包括编号( No 学号 (Id ), 课程 ( course )等列属性。
表 2
Figure imgf000009_0001
表 1和表 2都有 Id列, 也就是说, 表 1和表 2有相同的列属性 Id, 因 此, 表 1和表 2为相关联的数据对象。
在 S120中, 存储数据的装置确定该至少两个数据对象中的每个数据对 象在该 KeyValue类型分布式数据库中的行标识的格式。
该行标识的格式包括该相同的列属性和数据对象标识,该至少两个数据 对象中的不同数据对象的数据对象标识在该行标识的格式中的位置相同且 位于该相同的列属性之后。
具体而言, 在本发明实施例中, 为了提高查询数据的效率, 并不将每个 数据对象采用一个独立的表进行保存, 而是将多个数据对象按照统一的的格 式存储到一个表中, 由此实现关联查询。 为了实现将多个数据对象的存储到 一个表中, 需要预先配置行标识的格式, 以预先设计 RowKey的格式为例, 即预先指明 RowKey是由哪些组成元素, 以及组成元素如何组合。 在本实施 例中, 行标识的组成元素包含: 至少两个数据对象的相同的列属性以及数据 对象标识。 该相同的列属性用于将该至少两个数据对象关联存储起来, 该数 据对象标识用于表示每行数据来源于哪个数据对象。 其中, 数据对象标识位 于相同的列属性之后,每个数据对象的数据对象标识在行标识的格式中的位 置相同。 具体地, 不同数据对象的数据对象标识可以为不同的常量, 用来区 分不同的数据对象。 在本发明实施例中, 可选地, 如图 2所示, S120包括:
5121 , 为该至少两个数据对象指定在该 KeyValue类型分布式数据库中 的行标识的第一前缀, 其中, 该第一前缀为常量;
5122 ,确定该至少两个数据对象中的第一数据对象的该行标识的格式包 括该第一前缀、 该相同的列属性和该第一数据对象的数据对象标识; 或者,
5123 ,确定该至少两个数据对象中的第二数据对象的该行标识的格式包 括该第一前缀、 该相同的列属性、 该第二数据对象的数据对象标识和该第二 数据对象的列属性中能区分该第二数据对象的所有数据记录的列属性。
具体而言, 在本实施例中, 行标识中包含一个相同的前缀(表示为第一 前缀 )。 以 RowKey为例, 即 RowKey采用如下格式:
RowKey =第一前缀 +相同的列属性 +数据对象标识( +其他属性 )。
在本实施例中, 对于不同数据对象, RowKey格式采用相同的第一前缀 和相同属性, 这样, 在按照 RowKey值的顺序存放数据记录时, 不同的数据 对象的数据记录能够相邻存放(称为聚簇存放)。 再通过每个数据对象对应 的数据对象标识区分不同的数据对象。 另外, 在该相同的列属性能够区分一 个数据对象(表示为第一数据对象) 的所有数据记录时, 例如, 表 1 中 Id 属性能够区分表 1的所有数据记录,第一数据对象的 RowKey格式不再包括 其他属性; 在该相同属性不能区分一个数据对象(表示为第二数据对象)的 所有数据记录时, 例如, 表 2中 Id属性不能区分表 2的所有数据记录, 第 二数据对象的 RowKey格式还要包括第二数据对象的其他列属性中能区分 该第二数据对象的所有数据记录的属性, 例如, 表 2的 No属性。
以表 1和表 2为例, 它们的相同的列属性为 Id。 对于表 1 , Id能够区分 表 1的所有数据记录, 因此, 表 1的 RowKey格式可以为:
A (第一前缀 ) +Id+M ( M为表 1对应的数据对象标识)。
对于表 2, Id不能区分表 2的所有数据记录, No能区分表 2的所有数 据记录, 因此, 表 2的 RowKey格式可以为:
A (第一前缀) +Id+N ( N为表 2对应的数据对象标识) +No。
在本发明实施例中, 可选地, 该行标识的格式中的各个字段之间设置分 隔符, 或者, 该各个字段具有固定长度。
也就是说, 上述 RowKey格式中的 "+" 可以为分隔符。 或者, RowKey 格式的各个字段可以设置固定长度, 在这种情况下 "+" 实际并不存在。 在 S130中, 存储数据的装置根据确定的该每个数据对象的该行标识的 格式, 确定该每个数据对象的每条数据记录的行标识的值。
具体地, 以 RowKey为例, 存储数据的装置根据确定的 RowKey的格式 确定每个数据对象中的每条数据记录的 RowKey值。
例如, 对于数据对象 A中的第一条数据记录, RowKey值为 A0001M; 对于数据对象 B中的第一条数据记录, RowKey值为 A0001N1 , 以此类推。
在 S140中,存储数据的装置在该 KeyValue类型分布式数据库中存储该 每条数据记录的行标识的值和该每条数据记录。
该每条数据记录的行标识的值作为该每条数据记录在该 KeyValue类型 分布式数据库中的主索引。
在本发明实施例中, 可选地, 如图 3所示, 该方法 100还包括:
S150, 针对该每条数据记录的行标识的值, 按照第一顺序对该每条数据 记录进行排序, 使该至少两个数据对象的所有数据记录形成聚簇表。
本发明实施例按行标识的值的顺序将数据记录存放到 KeyValue类型分 布式数据库中, 使多个数据对象的数据记录形成聚簇表。 这种聚簇表存放方 式能够将行标识的值的范围与分区对应, 即一条数据记录的行标识的值属于 哪个范围,该数据记录就在哪个范围对应的分区,因而可以支持按范围查询。
该第一顺序可以是字典顺序, 例如, 可以按 RowKey值的字典顺序将每 条数据记录在 KeyValue类型分布式数据库中排列。 该第一顺序还可以是其 他顺序, 例如, 大小顺序, 即可以按照 RowKey值的大小顺序依次存放数据 ¾录, RowKey值小的存放在前, RowKey值大的存放在后, 或者, RowKey 值大的存放在前, RowKey值 d、的存放在后。 本发明实施例对该第一顺序并 不限定。 为了便于描述, 下述实施例将以 RowKey值的字典顺序为例进行说 明。
以表 1和表 2为例, 按照 RowKey值的字典顺序在 KeyValue类型分布 式数据库中存放得到表 3。
表 3
RowKey Columns
RowKey = A+Id+... Name Id Sex Dept No Course
A0001M 张三 0001 Male 3班
A0001N1 0001 1 English A0001N2 0001 2 Chinese
A0001N3 0001 3 Math
A0002M 李四 0002 Male 3班
A0002N4 0002 4 English
A0002N5 0002 5 Math
A0003M 王五 0003 Female 3班
A0003N6 0003 6 English
(包含斜线的列, 表示本行数据无此列, 在存储上不占据任何空间, 下同) 采用本发明实施例的存储数据的方法,相关联的不同数据对象的数据记 录可以相邻存放, 形成聚簇表。 例如, 表 3中的第 1条数据记录为原表 1的 第 1条记录, 表 3中的第 2-4条记录为原表 2的第 1-3条记录, 这些数据记 录因为有相同的 Id而在 KeyValue类型分布式数据库中被相邻存放。 通过相 邻存放可以加快数据访问速率, 进一步提高查询效率。
下面描述对按照上述存储方法得到的数据表进行查询的实施方式。
在本发明实施例中, 可选地, 如图 4所示, 该方法 100还包括:
S160, 接收数据请求, 该数据请求指示对该至少两个数据对象中的数据 记录进行查询或获取;
S170, 根据该行标识的格式, 构造在该 KeyValue类型分布式数据库中 进行查询的查询信息, 其中, 该查询信息包括该相同的列属性;
S180, 根据该查询信息, 导出该 KeyValue类型分布式数据库中主索引 包含该查询信息的数据记录。
具体而言, 在接收到查询或获取数据记录的数据请求时, 存储数据的装 置根据行标识的格式, 构造查询信息, 该查询信息要包括相同的列属性, 然 后, 存储数据的装置采用构造的查询信息进行查询, 得到 KeyValue类型分 布式数据库中主索引包含该查询信息的数据记录。
可选地, 在行标识的格式包括第一前缀时, 该查询信息包括该第一前缀 和该相同的列属性。
例如, 当通过学生学号(Id=0001 )来获取学生信息和学生选课信息时, 可以构造查询信息: A0001 , 通过范围查询即可在表 3中查询得到学生学号 ( Id=0001 ) 的学生信息和学生选课信息。 得到的查询结果如表 4所示。 在 查询过程中, 仅需要查询一张表, 完成一次用户数据的定位, 学生信息和学 生选课信息相邻存放可以快速返回。
表 4
Figure imgf000013_0001
因此, 本发明实施例的存储数据的方法, 通过将相关联的数据对象采用 包括相同的列属性的行标识的格式存储到 KeyValue类型分布式数据库中, 可以将相关联的数据对象聚簇存放到一个数据表中, 实现在一个数据表中进 行关联查询, 从而能够提高查询数据的效率。
在本发明实施例中, 可选地, 该方法 100还包括:
确定该至少两个数据对象中任一个数据对象在该 KeyValue类型分布式 数据库中的二级索引的格式为第二前缀,第二属性和该相同的列属性,其中, 该第二属性为该任一个数据对象的列属性中不同于该相同属性的列属性, 该 第二前缀为与该第一前缀不同的常量;
根据该任一个数据对象的该二级索引的格式确定该任一个数据对象的 二级索引;
在该 KeyValue类型分布式数据库中存储该任一个数据对象的二级索引。 具体而言, 为了满足复杂查询场景, 可以对数据对象构建二级索引信息。 同 一个数据对象的主索引与二级索引的数据存放在同一个表中,但采用不同的 行标识的格式, 实现在同一个表内的数据隔离。 同时可以通过二级索引信息 完成关联查询。 二级索引的行标识的格式为第二前缀, 第二属性和该相同属 性。 第二前缀不同于第一前缀以实现数据隔离; 该第二属性为不同于该相同 属性的属性, 以便于根据该第二属性构造查询信息; 该相同属性用于与主索 引相关联。
例如, 在将数据对象表 1和数据对象表 2存储到 KeyValue类型分布式 数据库中时, 表 1的主索引 RowKey格式可以为: A+Id+M; 表 2的主索引 RowKey格式可以为: A+Id+N+No; 表 1的二级索引 RowKey格式可以为: B+Name+Ido 这样, 按照 RowKey值的字典顺序在 KeyValue类型分布式数 据库中存放得到表 5。 表 5
Figure imgf000014_0001
应理解, 与二级索引 RowKey对应的各列中, 也可以存储列信息, 例如 个别关键的列信息, 本发明实施例对此并不限定。
当通过学生姓名 (Name=张三)来获取学生信息和学生选课信息时, 可 以构造查询信息: B张三, 通过范围查询即可在表 5中查询得到完整的二级 索引 RowKey信息: B张三 0001。 解析二级索引 RowKey, 得到 Id=0001。 再构造查询信息: A0001 , 进行再次查询即可在表 5中得到学生信息和学生 选课信息。 这样便于在用户只知道 Name不知道 Id时进行查询。
因此, 本发明实施例的存储数据的方法, 通过在 KeyValue类型分布式 数据库中存储数据对象的二级索引, 可以提供给用户更丰富多样的查询场 景, 方便用户查询, 从而能够提高查询数据的效率。
在本发明实施例中, 多个数据对象的行标识的格式还可以有其他实现方 式, 例如, 不同数据对象的行标识的格式可以采用不同的前缀, 或者, 不使 用前缀。
例如, 不使用前缀时, RowKev采用如下格式: RowKey =相同的列属性 +数据对象标识( +其他属性)。
通过相同的列属性实现不同的数据对象的数据记录能够相邻存放,再通 过每个数据对象对应的数据对象标识区分不同的数据对象。 另外, 在该相同 的列属性能够区分一个数据对象(表示为第一数据对象)的所有数据记录时, 第一数据对象的 RowKey格式不再包括其他属性;在该相同的列属性不能区 分一个数据对象(表示为第二数据对象)的所有数据记录时, 第二数据对象 的 RowKey格式还要包括第二数据对象的其他列属性中能区分该第二数据 对象的所有数据记录的属性。
以表 1和表 2为例, 它们的相同的列属性为 Id。 对于表 1 , Id能够区分 表 1的所有数据记录, 因此, 表 1的 RowKey格式可以为:
Id+M。
对于表 2, Id不能区分表 2的所有数据记录, No能区分表 2的所有数 据记录, 因此, 表 2的 RowKey格式可以为:
Figure imgf000015_0001
这样, 按照 RowKey值的字典顺序在 KeyValue类型分布式数据库中存 放得到表 6。
表 6
Figure imgf000015_0002
当通过学生学号 (Id=0001 ) 来获取学生信息和学生选课信息时, 可以 构造查询信息: 0001 , 通过范围查询即可查询得到学生学号 (Id=0001 ) 学 生信息和学生选课信息。 在查询过程中, 仅需要查询一张表, 完成一次用户 数据的定位, 学生信息和学生选课信息相邻存放可以快速返回。 不同数据对象采用不同的前缀时, RowKey采用如下格式:
RowKey =数据对象对应的前缀) +相同的列属性( +其他属性)。
不同的数据对象采用不同的前缀实现不同数据对象的分区存放。 另外, 在该相同的列属性能够区分一个数据对象(表示为第一数据对象)的所有数 据记录时, 第一数据对象的 RowKey格式不再包括其他属性; 在该相同的列 属性不能区分一个数据对象(表示为第二数据对象)的所有数据记录时, 第 二数据对象的 RowKey格式还要包括第二数据对象的其他列属性中能区分 该第二数据对象的所有数据记录的属性。
以表 1和表 2为例, 它们的相同的列属性为 Id。 对于表 1 , Id能够区分 表 1的所有数据记录, 因此, 表 1的 RowKey格式可以为:
A+Id。
对于表 2, Id不能区分表 2的所有数据记录, No能标识表 2的所有数 据记录, 因此, 表 2的 RowKey格式可以为:
B+Id+No o
这样, 按照 RowKey值的字典顺序在 KeyValue类型分布式数据库中存 放得到表 7。
表 7
RowKey Columns
RowKey=A(B)+Id+... Name Id Sex Dept No Course
A0001 张三 0001 Male 3班
A0002 李四 0002 Male 3班
A0003 王五 0003 Female 3班
(如下数据属于其它数据分区, 此行用来表示与上面数据分区的隔离, 无实际数据)
B00011 0001 1 English
B00012 0001 2 Chinese
B00013 0001 3 Math
B00024 0002 4 English
B00025 0002 5 Math
B00036 0003 6 English 通过不同数据对象的 RowKey格式采用不同的前缀,可以实现不同数据 对象在 KeyValue类型分布式数据库中的分区存放。
应理解, 在本发明的各种实施例中, 上述各过程的序号的大小并不意味 着执行顺序的先后, 各过程的执行顺序应以其功能和内在逻辑确定, 而不应 对本发明实施例的实施过程构成任何限定。
本发明实施例的存储数据的方法,通过将多个数据对象按照统一的行标 识的格式存储到 KeyValue类型分布式数据库中的一个数据表中, 能够方便 数据库的管理, 提高查询数据的效率。
上文详细描述了根据本发明实施例的存储数据的方法, 下面将描述根据 本发明实施例的存储数据的装置。
图 5示出了根据本发明实施例的存储数据的装置 500的示意性框图。如 图 5所示, 该装置 500包括:
确定模块 510,用于确定待存储到键值 KeyValue类型分布式数据库中的 至少两个数据对象的相同的列属性,确定该至少两个数据对象中的每个数据 对象在该 KeyValue类型分布式数据库中的行标识的格式, 其中, 该行标识 的格式包括该相同的列属性和数据对象标识, 该至少两个数据对象中的不同 数据对象的数据对象标识在该行标识的格式中的位置相同且位于该相同的 列属性之后, 根据确定的该每个数据对象的该行标识的格式, 确定该每个数 据对象的每条数据记录的行标识的值;
存储模块 520,用于在该 KeyValue类型分布式数据库中存储该每条数据 记录的行标识的值和该每条数据记录, 其中, 该每条数据记录的行标识的值 作为该每条数据记录在该 KeyValue类型分布式数据库中的主索引。
在多个(即至少两个)数据对象相关联时, 即多个数据对象具有相同的 列属性时, 为了方便对多个数据对象的关联查询, 存储数据的装置 500将多 个数据对象存储到 KeyValue类型分布式数据库的一个表中。 确定模块 510 基于该相同的列属性确定每个数据对象在 KeyValue类型分布式数据库中的 行标识(如 RowKey ) 的格式, 其中, 该行标识的格式包括该相同的列属性 和数据对象标识, 该至少两个数据对象中的不同数据对象的数据对象标识在 该行标识的格式中的位置相同且位于该相同的列属性之后。 也就是说, 每个 数据对象的行标识的格式都包括该相同的列属性以便于查询, 另外, 还包括 与数据对象对应的数据对象标识以区别不同数据对象。 不同数据对象的数据 对象标识在行标识的格式中的位置相同且位于相同的列属性之后以使不同 数据对象的行标识的格式保持相一致的结构。 然后, 确定模块 510根据确定 的行标识的格式确定每个数据对象中的每条数据记录的行标识的值。存储模 块 520在 KeyValue类型分布式数据库中存储每条数据记录的行标识的值和 每条数据记录, 其中, 每条数据记录的行标识的值作为每条数据记录在 KeyValue类型分布式数据库中的主索引。由于相关联的多个数据对象采用了 一致的行标识的格式, 这样, 在查询数据时, 按照行标识的格式构造查询信 息, 可以实现在一个数据表中对多个数据对象进行关联查询, 从而能够提高 查询数据的效率。
因此, 本发明实施例的存储数据的装置, 通过将相关联的数据对象采用 包括相同的列属性的对多个数据对象格式存储到 KeyValue类型分布式数据 库中, 可以实现对多个数据对象进行关联查询, 从而能够提高查询数据的效 率。
在本发明实施例中, 可选地, 该存储模块 520还用于, 针对该每条数据 记录的行标识的值, 按照第一顺序对该每条数据记录进行排序, 使该至少两 个数据对象的所有数据记录形成聚簇表。
在本发明实施例中, 可选地, 该第一顺序为字典顺序。
在本发明实施例中, 可选地, 该确定模块 510具体用于, 为该至少两个 数据对象指定在该 KeyValue类型分布式数据库中的行标识的第一前缀, 其 中, 该第一前缀为常量, 确定该至少两个数据对象中的第一数据对象的该行 标识的格式包括该第一前缀、该相同的列属性和该第一数据对象的数据对象 标识, 或者, 确定该至少两个数据对象中的第二数据对象的该行标识的格式 包括该第一前缀、 该相同的列属性、 该第二数据对象的数据对象标识和该第 二数据对象的列属性中能区分该第二数据对象的所有数据记录的列属性。
在本发明实施例中, 可选地, 如图 6所示, 该装置 500还包括: 接收模块 530, 用于接收数据请求, 该数据请求指示对该至少两个数据 对象中的数据记录进行查询或获取;
查询模块 540, 用于根据该行标识的格式, 构造在该 KeyValue类型分布 式数据库中进行查询的查询信息, 其中, 该查询信息包括该相同的列属性, 根据该查询信息, 导出该 KeyValue类型分布式数据库中主索引包含该查询 信息的数据记录。 可选地, 在行标识的格式包括第一前缀时, 该查询信息包括该第一前缀 和该相同的列属性。
在本发明实施例中, 可选地, 该确定模块 510还用于, 确定该至少两个 数据对象中任一个数据对象在该 KeyValue类型分布式数据库中的二级索引 的格式为第二前缀, 第二属性和该相同的列属性, 其中, 该第二属性为该任 一个数据对象的列属性中不同于该相同属性的列属性, 该第二前缀为与该第 一前缀不同的常量,根据该任一个数据对象的该二级索引的格式确定该任一 个数据对象的二级索引;
该存储模块 520还用于在该 KeyValue类型分布式数据库中存储该任一 个数据对象的二级索引。
本发明实施例的存储数据的装置, 通过在 KeyValue类型分布式数据库 中存储数据对象的二级索引, 可以提供给用户更丰富多样的查询场景, 方便 用户查询, 从而能够提高查询数据的效率。
在本发明实施例中, 可选地, 该行标识的格式中的各个字段之间设置分 隔符, 或者, 该各个字段具有固定长度。
根据本发明实施例的存储数据的装置 500可对应于根据本发明实施例的 的方法中的存储数据的装置, 并且存储数据的装置 500中的各个模块的上述 和其它操作和 /或功能分别为了实现图 1至图 4中的各个方法的相应流程,为 了筒洁, 在此不再赘述。
本发明实施例的存储数据的装置,通过将多个数据对象按照统一的行标 识的格式存储到 KeyValue类型分布式数据库中的一个数据表中, 能够方便 数据库的管理, 提高查询数据的效率。
图 7示出了本发明另一个实施例提供的存储数据的装置的结构, 包括至 少一个处理器 702 (例如 CPU ), 至少一个网络接口 705或者其他通信接口, 存储器 706, 和至少一个通信总线 703 , 用于实现这些装置之间的连接通信。 处理器 702用于执行存储器 706中存储的可执行模块, 例如计算机程序。 存 储器 706可能包含高速随机存取存储器 ( RAM: Random Access Memory ), 也可能还包括非不稳定的存储器( non- volatile memory ), 例如至少一个磁盘 存储器。 通过至少一个网络接口 705 (可以是有线或者无线) 实现与至少一 个其他网元之间的通信连接。
在一些实施方式中, 存储器 706存储了程序 7061 , 程序 7061可以被处 理器 702执行, 这个程序包括:
确定待存储到 KeyValue类型分布式数据库中的至少两个数据对象的相 同的列属性;
确定该至少两个数据对象中的每个数据对象在该 KeyValue类型分布式 数据库中的行标识的格式, 其中, 该行标识的格式包括该相同的列属性和数 据对象标识, 该至少两个数据对象中的不同数据对象的数据对象标识在该行 标识的格式中的位置相同且位于该相同的列属性之后;
根据确定的该每个数据对象的该行标识的格式,确定该每个数据对象的 每条数据记录的行标识的值;
在该 KeyValue类型分布式数据库中存储该每条数据记录的行标识的值 和该每条数据记录, 其中, 该每条数据记录的行标识的值作为该每条数据记 录在该 KeyValue类型分布式数据库中的主索引。
可选地, 还包括:
针对该每条数据记录的行标识的值,按照第一顺序对该每条数据记录进 行排序, 使该至少两个数据对象的所有数据记录形成聚簇表。
可选地, 该第一顺序为字典顺序。
可选地, 还包括:
接收数据请求, 该数据请求指示对该至少两个数据对象中的数据记录进 行查询或获取;
根据该行标识的格式, 构造在该 KeyValue类型分布式数据库中进行查 询的查询信息, 其中, 该查询信息包括该相同的列属性;
根据该查询信息, 导出该 KeyValue类型分布式数据库中主索引包含该 查询信息的数据记录。
可选地, 确定该至少两个数据对象中的每个数据对象在该 KeyValue类 型分布式数据库中的行标识的格式, 包括:
为该至少两个数据对象指定在该 KeyValue类型分布式数据库中的行标 识的第一前缀, 其中, 该第一前缀为常量;
确定该至少两个数据对象中的第一数据对象的该行标识的格式包括该 第一前缀、 该相同的列属性和该第一数据对象的数据对象标识; 或者, 确定该至少两个数据对象中的第二数据对象的该行标识的格式包括该 第一前缀、 该相同的列属性、 该第二数据对象的数据对象标识和该第二数据 对象的列属性中能区分该第二数据对象的所有数据记录的列属性。
可选地, 该查询信息包括该第一前缀和该相同的列属性。
可选地, 还包括:
确定该至少两个数据对象中任一个数据对象在该 KeyValue类型分布式 数据库中的二级索引的格式为第二前缀,第二属性和该相同的列属性,其中, 该第二属性为该任一个数据对象的列属性中不同于该相同属性的列属性, 该 第二前缀为与该第一前缀不同的常量;
根据该任一个数据对象的该二级索引的格式确定该任一个数据对象的 二级索引;
在该 KeyValue类型分布式数据库中存储该任一个数据对象的二级索引。 可选地, 该行标识的格式中的各个字段之间设置分隔符, 或者, 该各个 字段具有固定长度。
从本发明实施例提供的以上技术方案可以看出,本发明实施例通过将相 关联的数据对象采用包括相同的列属性的行标识的格式存储到 KeyValue类 型分布式数据库中, 可以实现对多个数据对象进行关联查询, 从而能够提高 查询数据的效率。
应理解, 在本发明实施例中, 术语 "和 /或"仅仅是一种描述关联对象的 关联关系, 表示可以存在三种关系。 例如, A和 /或 B, 可以表示: 单独存在 A, 同时存在 A和 B, 单独存在 B这三种情况。 另外, 本文中字符 "/" , 一 般表示前后关联对象是一种 "或" 的关系。
本领域普通技术人员可以意识到, 结合本文中所公开的实施例描述的各 示例的单元及算法步骤, 能够以电子硬件、 计算机软件或者二者的结合来实 现, 为了清楚地说明硬件和软件的可互换性, 在上述说明中已经按照功能一 般性地描述了各示例的组成及步骤。这些功能究竟以硬件还是软件方式来执 行, 取决于技术方案的特定应用和设计约束条件。 专业技术人员可以对每个 特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超 出本发明的范围。
所属领域的技术人员可以清楚地了解到, 为了描述的方便和筒洁, 上述 描述的***、 装置和单元的具体工作过程, 可以参考前述方法实施例中的对 应过程, 在此不再赘述。
在本申请所提供的几个实施例中, 应该理解到, 所揭露的***、 装置和 方法, 可以通过其它的方式实现。 例如, 以上所描述的装置实施例仅仅是示 意性的, 例如, 所述单元的划分, 仅仅为一种逻辑功能划分, 实际实现时可 以有另外的划分方式, 例如多个单元或组件可以结合或者可以集成到另一个 ***, 或一些特征可以忽略, 或不执行。 另外, 所显示或讨论的相互之间的 耦合或直接耦合或通信连接可以是通过一些接口、装置或单元的间接耦合或 通信连接, 也可以是电的, 机械的或其它的形式连接。
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作 为单元显示的部件可以是或者也可以不是物理单元, 即可以位于一个地方, 或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或 者全部单元来实现本发明实施例方案的目的。
另外, 在本发明各个实施例中的各功能单元可以集成在一个处理单元 中, 也可以是各个单元单独物理存在, 也可以是两个或两个以上单元集成在 一个单元中。 上述集成的单元既可以采用硬件的形式实现, 也可以采用软件 功能单元的形式实现。
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销 售或使用时, 可以存储在一个计算机可读取存储介质中。 基于这样的理解, 本发明的技术方案本质上或者说对现有技术做出贡献的部分, 或者该技术方 案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在 一个存储介质中, 包括若干指令用以使得一台计算机设备(可以是个人计算 机, 服务器, 或者网络设备等)执行本发明各个实施例所述方法的全部或部 分步骤。 而前述的存储介质包括: U盘、 移动硬盘、 只读存储器(ROM, Read-Only Memory )、 随机存取存储器 ( RAM, Random Access Memory )、 磁碟或者光盘等各种可以存储程序代码的介质。
以上所述, 仅为本发明的具体实施方式, 但本发明的保护范围并不局限 于此, 任何熟悉本技术领域的技术人员在本发明揭露的技术范围内, 可轻易 想到各种等效的修改或替换, 这些修改或替换都应涵盖在本发明的保护范围 之内。 因此, 本发明的保护范围应以权利要求的保护范围为准。

Claims

权利要求
1. 一种存储数据的方法, 其特征在于, 包括:
确定待存储到键值 KeyValue类型分布式数据库中的至少两个数据对象 的相同的列属性;
确定所述至少两个数据对象中的每个数据对象在所述 KeyValue类型分 布式数据库中的行标识的格式, 其中, 所述行标识的格式包括所述相同的列 属性和数据对象标识,所述至少两个数据对象中的不同数据对象的数据对象 标识在所述行标识的格式中的位置相同且位于所述相同的列属性之后; 根据确定的所述每个数据对象的所述行标识的格式,确定所述每个数据 对象的每条数据记录的行标识的值;
在所述 KeyValue类型分布式数据库中存储所述每条数据记录的行标识 的值和所述每条数据记录, 其中, 所述每条数据记录的行标识的值作为所述 每条数据记录在所述 KeyValue类型分布式数据库中的主索引。
2. 根据权利要求 1所述的方法, 其特征在于, 所述方法还包括: 针对所述每条数据记录的行标识的值,按照第一顺序对所述每条数据记 录进行排序, 使所述至少两个数据对象的所有数据记录形成聚簇表。
3. 根据权利要求 2所述的方法, 其特征在于, 所述第一顺序为字典顺 序。
4. 根据权利要求 1至 3中任一项所述的方法, 其特征在于, 所述方法 还包括:
接收数据请求, 所述数据请求指示对所述至少两个数据对象中的数据记 录进行查询或获取;
根据所述行标识的格式, 构造在所述 KeyValue类型分布式数据库中进 行查询的查询信息, 其中, 所述查询信息包括所述相同的列属性;
根据所述查询信息, 导出所述 KeyValue类型分布式数据库中主索引包 含所述查询信息的数据记录。
5. 根据权利要求 1至 4中任一项所述的方法, 其特征在于, 所述确定 所述至少两个数据对象中的每个数据对象在所述 KeyValue类型分布式数据 库中的行标识的格式, 包括:
为所述至少两个数据对象指定在所述 KeyValue类型分布式数据库中的 行标识的第一前缀, 其中, 所述第一前缀为常量; 确定所述至少两个数据对象中的第一数据对象的所述行标识的格式包 括所述第一前缀、 所述相同的列属性和所述第一数据对象的数据对象标识; 或者,
确定所述至少两个数据对象中的第二数据对象的所述行标识的格式包 括所述第一前缀、 所述相同的列属性、 所述第二数据对象的数据对象标识和 所述第二数据对象的列属性中能区分所述第二数据对象的所有数据记录的 列属性。
6. 根据权利要求 5所述的方法, 其特征在于, 所述查询信息包括所述 第一前缀和所述相同的列属性。
7. 根据权利要求 5或 6所述的方法, 其特征在于, 所述方法还包括: 确定所述至少两个数据对象中任一个数据对象在所述 KeyValue类型分 布式数据库中的二级索引的格式为第二前缀, 第二属性和所述相同的列属 性, 其中, 所述第二属性为所述任一个数据对象的列属性中不同于所述相同 属性的列属性, 所述第二前缀为与所述第一前缀不同的常量;
根据所述任一个数据对象的所述二级索引的格式确定所述任一个数据 对象的二级索引;
在所述 KeyValue类型分布式数据库中存储所述任一个数据对象的二级 索引。
8. 根据权利要求 1至 7中任一项所述的方法, 其特征在于, 所述行标 识的格式中的各个字段之间设置分隔符,或者,所述各个字段具有固定长度。
9. 一种存储数据的装置, 其特征在于, 包括:
确定模块, 用于确定待存储到键值 KeyValue类型分布式数据库中的至 少两个数据对象的相同的列属性,确定所述至少两个数据对象中的每个数据 对象在所述 KeyValue类型分布式数据库中的行标识的格式, 其中, 所述行 标识的格式包括所述相同的列属性和数据对象标识, 所述至少两个数据对象 中的不同数据对象的数据对象标识在所述行标识的格式中的位置相同且位 于所述相同的列属性之后,根据确定的所述每个数据对象的所述行标识的格 式, 确定所述每个数据对象的每条数据记录的行标识的值;
存储模块, 用于在所述 KeyValue类型分布式数据库中存储所述每条数 据记录的行标识的值和所述每条数据记录, 其中, 所述每条数据记录的行标 识的值作为所述每条数据记录在所述 KeyValue类型分布式数据库中的主索 引。
10. 根据权利要求 9所述的装置, 其特征在于, 所述存储模块还用于, 针对所述每条数据记录的行标识的值,按照第一顺序对所述每条数据记录进 行排序, 使所述至少两个数据对象的所有数据记录形成聚簇表。
11. 根据权利要求 10所述的装置, 其特征在于, 所述第一顺序为字典 顺序。
12. 根据权利要求 9至 11 中任一项所述的装置, 其特征在于, 所述装 置还包括:
接收模块, 用于接收数据请求, 所述数据请求指示对所述至少两个数据 对象中的数据记录进行查询或获取;
查询模块, 用于根据所述行标识的格式, 构造在所述 Key Value类型分 布式数据库中进行查询的查询信息, 其中, 所述查询信息包括所述相同的列 属性, 根据所述查询信息, 导出所述 KeyValue类型分布式数据库中主索引 包含所述查询信息的数据记录。
13. 根据权利要求 9至 12中任一项所述的装置, 其特征在于, 所述确 定模块具体用于, 为所述至少两个数据对象指定在所述 KeyValue类型分布 式数据库中的行标识的第一前缀, 其中, 所述第一前缀为常量, 确定所述至 少两个数据对象中的第一数据对象的所述行标识的格式包括所述第一前缀、 所述相同的列属性和所述第一数据对象的数据对象标识, 或者, 确定所述至 少两个数据对象中的第二数据对象的所述行标识的格式包括所述第一前缀、 所述相同的列属性、所述第二数据对象的数据对象标识和所述第二数据对象 的列属性中能区分所述第二数据对象的所有数据记录的列属性。
14. 根据权利要求 13所述的装置, 其特征在于, 所述查询信息包括所 述第一前缀和所述相同的列属性。
15. 根据权利要求 13或 14所述的装置, 其特征在于, 所述确定模块还 用于, 确定所述至少两个数据对象中任一个数据对象在所述 KeyValue类型 分布式数据库中的二级索引的格式为第二前缀, 第二属性和所述相同的列属 性, 其中, 所述第二属性为所述任一个数据对象的列属性中不同于所述相同 属性的列属性, 所述第二前缀为与所述第一前缀不同的常量, 根据所述任一 个数据对象的所述二级索引的格式确定所述任一个数据对象的二级索引; 所述存储模块还用于在所述 KeyValue类型分布式数据库中存储所述任 一个数据对象的二级索引。
16. 根据权利要求 9至 15中任一项所述的装置, 其特征在于, 所述行 标识的格式中的各个字段之间设置分隔符, 或者, 所述各个字段具有固定长 度。
17. 一种计算机, 其特征在于, 包括: 处理器、 存储器、 总线和通信接 口;
所述存储器用于存储计算机执行指令, 所述处理器与所述存储器通过 所述总线连接, 当所述计算机运行时, 所述处理器执行所述存储器存储的 所述计算机执行指令, 以使所述计算机执行权利要求 1-8 中任意一项所述 的方法。
18. 一种计算机可读介质, 其特征在于, 包括计算机执行指令, 当计 算机的处理器执行所述计算机执行指令时, 所述计算机执行权利要求 1-8 中任意一项所述的方法。
PCT/CN2013/082544 2013-08-29 2013-08-29 存储数据的方法和装置 WO2015027425A1 (zh)

Priority Applications (10)

Application Number Priority Date Filing Date Title
EP13892411.3A EP3023885B1 (en) 2013-08-29 2013-08-29 Method and device for storing data
CN201611186259.5A CN106649708A (zh) 2013-08-29 2013-08-29 存储数据的方法和装置
CN201380001160.1A CN103703467B (zh) 2013-08-29 2013-08-29 存储数据的方法和装置
PCT/CN2013/082544 WO2015027425A1 (zh) 2013-08-29 2013-08-29 存储数据的方法和装置
CA2921616A CA2921616C (en) 2013-08-29 2013-08-29 Data storage method and apparatus
JP2016537067A JP6225261B2 (ja) 2013-08-29 2013-08-29 データを記憶する方法及び装置
BR112016004490A BR112016004490B8 (pt) 2013-08-29 2013-08-29 Aparelho e método de armazenamento de dados
KR1020167005763A KR101720602B1 (ko) 2013-08-29 2013-08-29 데이터를 저장하기 위한 방법 및 장치
US15/054,519 US9589004B2 (en) 2013-08-29 2016-02-26 Data storage method and apparatus
US15/411,657 US10331642B2 (en) 2013-08-29 2017-01-20 Data storage method and apparatus

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2013/082544 WO2015027425A1 (zh) 2013-08-29 2013-08-29 存储数据的方法和装置

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US15/054,519 Continuation US9589004B2 (en) 2013-08-29 2016-02-26 Data storage method and apparatus

Publications (1)

Publication Number Publication Date
WO2015027425A1 true WO2015027425A1 (zh) 2015-03-05

Family

ID=50363919

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2013/082544 WO2015027425A1 (zh) 2013-08-29 2013-08-29 存储数据的方法和装置

Country Status (8)

Country Link
US (2) US9589004B2 (zh)
EP (1) EP3023885B1 (zh)
JP (1) JP6225261B2 (zh)
KR (1) KR101720602B1 (zh)
CN (2) CN106649708A (zh)
BR (1) BR112016004490B8 (zh)
CA (1) CA2921616C (zh)
WO (1) WO2015027425A1 (zh)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112835938A (zh) * 2021-02-23 2021-05-25 百度在线网络技术(北京)有限公司 数据处理方法、装置、电子设备和计算机可读存储介质
CN112835901A (zh) * 2021-02-01 2021-05-25 长沙市到家悠享家政服务有限公司 文件存储方法及装置、计算机设备、计算机可读存储介质
CN113360776A (zh) * 2021-07-19 2021-09-07 西南大学 基于跨表数据挖掘的科技资源推荐方法

Families Citing this family (23)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106649708A (zh) * 2013-08-29 2017-05-10 华为技术有限公司 存储数据的方法和装置
CN105095268A (zh) * 2014-05-12 2015-11-25 深圳市同洲电子股份有限公司 结构化数据的存取方法以及装置
CN108897761B (zh) * 2014-05-27 2023-01-13 华为技术有限公司 一种聚簇存储方法及装置
CN104102711B (zh) * 2014-07-15 2017-12-01 中国联合网络通信集团有限公司 一种HBase数据库存储上网记录的方法和***
US9836507B2 (en) * 2014-09-17 2017-12-05 Futurewei Technologies, Inc. Method and system for adaptively building a column store database from a temporal row store database based on query demands
US10671594B2 (en) 2014-09-17 2020-06-02 Futurewei Technologies, Inc. Statement based migration for adaptively building and updating a column store database from a row store database based on query demands using disparate database systems
CN104408150A (zh) * 2014-12-03 2015-03-11 天津南大通用数据技术股份有限公司 一种适应多种数据库数据格式的数据导入导出方法及装置
CN106326305A (zh) * 2015-06-30 2017-01-11 星环信息科技(上海)有限公司 一种数据文件的存储和查询方法及设备
CN105354255B (zh) * 2015-10-21 2018-01-02 华为技术有限公司 数据查询方法和装置
CN105630934A (zh) * 2015-12-23 2016-06-01 浪潮电子信息产业股份有限公司 一种数据统计方法及***
CN105653611B (zh) * 2015-12-24 2019-08-20 深圳市汇朗科技有限公司 分表分页排序查询方法及装置
CN105740405B (zh) 2016-01-29 2020-06-26 华为技术有限公司 存储数据的方法和装置
CN107463512B (zh) * 2017-06-26 2020-11-13 上海高顿教育培训有限公司 分布式高速存储***的数据更新方法
CN107832389B (zh) * 2017-10-31 2020-12-25 新华三大数据技术有限公司 数据管理方法及装置
CN108681563B (zh) * 2018-04-28 2021-08-27 新疆熙菱信息技术股份有限公司 基于一表多用户的服务发布及访问***
CN110647517B (zh) * 2018-06-11 2022-06-24 北京神州泰岳软件股份有限公司 一种表格数据结构的处理方法和装置
CN108920725B (zh) * 2018-08-02 2020-08-04 网宿科技股份有限公司 一种对象存储的方法及对象存储网关
CN109101641B (zh) * 2018-08-20 2022-09-23 联想(北京)有限公司 表格处理方法、装置、***和介质
CN109918472A (zh) * 2019-02-27 2019-06-21 北京百度网讯科技有限公司 存储和查询数据的方法、装置、设备和介质
CN111723245B (zh) * 2019-03-18 2024-04-26 阿里巴巴集团控股有限公司 数据存储***中建立不同类型存储对象关联关系的方法
CN110297832B (zh) * 2019-07-01 2021-12-24 联想(北京)有限公司 一种时序数据存储方法及装置、时序数据查询方法及装置
CN111324605B (zh) * 2020-01-22 2020-11-10 北京东方金信科技有限公司 数据库中数据混合存储动态调整方法及应用
CN112465294B (zh) * 2020-10-21 2023-08-22 郑州大学第一附属医院 基于审计结果的医院药品智能供货方法及装置

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101198953A (zh) * 2005-05-13 2008-06-11 Abb研究有限公司 产生实物资产的唯一表示
CN102193917A (zh) * 2010-03-01 2011-09-21 ***通信集团公司 一种数据处理和查询方法和装置

Family Cites Families (35)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5295256A (en) * 1990-12-14 1994-03-15 Racal-Datacom, Inc. Automatic storage of persistent objects in a relational schema
JPH0567159A (ja) 1991-09-10 1993-03-19 Nec Software Kansai Ltd 表形式データ処理装置
JPH0736756A (ja) * 1993-07-21 1995-02-07 Hitachi Ltd オブジェクト管理方式
US5878411A (en) * 1997-06-27 1999-03-02 International Business Machines Corporation Dependent object class and subclass mapping to relational data store
US5995973A (en) * 1997-08-29 1999-11-30 International Business Machines Corporation Storing relationship tables identifying object relationships
JP2001518670A (ja) * 1997-09-26 2001-10-16 オントス,インコーポレイテッド オブジェクト指向ソフトウエアを有するリレーショナルデータベースを使用するための目的モデルマッピングおよびランタイムエンジン
US6112207A (en) * 1997-10-31 2000-08-29 Oracle Corporation Apparatus and method which features linearizing attributes of an information object into a string of bytes for object representation and storage in a database system
US6385618B1 (en) * 1997-12-22 2002-05-07 Sun Microsystems, Inc. Integrating both modifications to an object model and modifications to a database into source code by an object-relational mapping tool
US6360223B1 (en) * 1997-12-22 2002-03-19 Sun Microsystems, Inc. Rule-based approach to object-relational mapping strategies
US6094649A (en) * 1997-12-22 2000-07-25 Partnet, Inc. Keyword searches of structured databases
US6374256B1 (en) * 1997-12-22 2002-04-16 Sun Microsystems, Inc. Method and apparatus for creating indexes in a relational database corresponding to classes in an object-oriented application
US6122639A (en) * 1997-12-23 2000-09-19 Cisco Technology, Inc. Network device information collection and change detection
US6769124B1 (en) 1998-07-22 2004-07-27 Cisco Technology, Inc. Persistent storage of information objects
US6341289B1 (en) * 1999-05-06 2002-01-22 International Business Machines Corporation Object identity and partitioning for user defined extents
US6754670B1 (en) 1999-12-17 2004-06-22 International Business Machines Corporation Mapping relational tables to object oriented classes
US6591275B1 (en) * 2000-06-02 2003-07-08 Sun Microsystems, Inc. Object-relational mapping for tables without primary keys
JP2004534981A (ja) 2000-11-29 2004-11-18 ラファイエット・ソフトウェア・インコーポレーテッド データベース・システムでデータを編成し、問合せを処理する方法、およびそのような方法を実施するためのデータベース・システムおよびソフトウェア製品
EP1211610A1 (en) * 2000-11-29 2002-06-05 Lafayette Software Inc. Methods of organising data and processing queries in a database system
EP1217541A1 (en) * 2000-11-29 2002-06-26 Lafayette Software Inc. Method of processing queries in a database system, and database system and software product for implementing such method
JP2005234612A (ja) 2001-05-07 2005-09-02 I-Ze Communications Inc データベースの統合
US20030154197A1 (en) * 2002-02-13 2003-08-14 Permutta Technologies Flexible relational data storage method and apparatus
US7103588B2 (en) 2003-05-05 2006-09-05 International Business Machines Corporation Range-clustered tables in a database management system
US7203712B2 (en) * 2004-02-26 2007-04-10 International Business Machines Corporation Algorithm to find LOB value in a relational table after key columns have been modified
JP2006065467A (ja) 2004-08-25 2006-03-09 Hitachi Ltd データ抽出定義情報生成装置およびデータ抽出定義情報生成方法
US7493313B2 (en) 2004-09-17 2009-02-17 Microsoft Corporation Durable storage of .NET data types and instances
US7865888B1 (en) * 2004-12-21 2011-01-04 Zenprise, Inc. Systems and methods for gathering deployment state for automated management of software application deployments
US20080059492A1 (en) * 2006-08-31 2008-03-06 Tarin Stephen A Systems, methods, and storage structures for cached databases
US8458191B2 (en) * 2010-03-15 2013-06-04 International Business Machines Corporation Method and system to store RDF data in a relational store
WO2012074529A1 (en) 2010-12-03 2012-06-07 Hewlett-Packard Development Company, L.P. Systems and methods for performing a nested join operation
JP5727258B2 (ja) * 2011-02-25 2015-06-03 ウイングアーク1st株式会社 分散型データベースシステム
CN107451225B (zh) * 2011-12-23 2021-02-05 亚马逊科技公司 用于半结构化数据的可缩放分析平台
CN103116625A (zh) * 2013-01-31 2013-05-22 重庆大学 一种基于Hadoop的海量RDF数据分布式查询处理方法
GB2513329A (en) * 2013-04-23 2014-10-29 Ibm Method and system for scoring data in a database
US10235391B2 (en) * 2013-06-18 2019-03-19 Change Healthcare Holdings, Llc Method and apparatus for implementing dynamic database traversal
CN106649708A (zh) * 2013-08-29 2017-05-10 华为技术有限公司 存储数据的方法和装置

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101198953A (zh) * 2005-05-13 2008-06-11 Abb研究有限公司 产生实物资产的唯一表示
CN102193917A (zh) * 2010-03-01 2011-09-21 ***通信集团公司 一种数据处理和查询方法和装置

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
See also references of EP3023885A4 *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112835901A (zh) * 2021-02-01 2021-05-25 长沙市到家悠享家政服务有限公司 文件存储方法及装置、计算机设备、计算机可读存储介质
CN112835938A (zh) * 2021-02-23 2021-05-25 百度在线网络技术(北京)有限公司 数据处理方法、装置、电子设备和计算机可读存储介质
CN113360776A (zh) * 2021-07-19 2021-09-07 西南大学 基于跨表数据挖掘的科技资源推荐方法

Also Published As

Publication number Publication date
JP6225261B2 (ja) 2017-11-01
KR101720602B1 (ko) 2017-03-29
BR112016004490B8 (pt) 2022-08-23
US10331642B2 (en) 2019-06-25
CA2921616A1 (en) 2015-03-05
US9589004B2 (en) 2017-03-07
US20160179856A1 (en) 2016-06-23
KR20160040282A (ko) 2016-04-12
JP2016534456A (ja) 2016-11-04
CN103703467A (zh) 2014-04-02
CN106649708A (zh) 2017-05-10
EP3023885A1 (en) 2016-05-25
EP3023885B1 (en) 2019-10-30
EP3023885A4 (en) 2016-06-29
US20170132260A1 (en) 2017-05-11
BR112016004490B1 (pt) 2020-11-10
CN103703467B (zh) 2017-02-08
CA2921616C (en) 2017-03-07

Similar Documents

Publication Publication Date Title
WO2015027425A1 (zh) 存储数据的方法和装置
US20200042507A1 (en) Information Processing Method and Apparatus
EP3522029A1 (en) Natural language search results for intent queries
WO2017096892A1 (zh) 索引构建方法、查询方法及对应装置、设备、计算机存储介质
WO2019127299A1 (zh) 数据查询方法、电子设备及存储介质
JP2016534456A5 (zh)
CN110110006A (zh) 数据管理方法及相关产品
WO2017161540A1 (zh) 数据查询的方法、数据对象的存储方法和数据***
CN104063501B (zh) 基于hdfs的副本平衡方法
CN106599091B (zh) 基于键值存储的rdf图结构存储和索引方法
CN108536808A (zh) 一种基于Spark计算框架的数据获取方法和装置
WO2013107031A1 (zh) 基于评论信息确定视频质量参数的方法、装置和***
CN103856462A (zh) 一种会话的管理方法及***
CN110119396A (zh) 数据管理方法及相关产品
CN110765158A (zh) 分页查询方法、***和装置
CN110134698A (zh) 数据管理方法及相关产品
WO2023197865A1 (zh) 一种信息存储方法及装置
WO2016180186A1 (zh) 语义数据的存储方法及装置
WO2016169322A1 (zh) 数据库的查询方法和装置、计算机存储介质
CN109101595B (zh) 一种信息查询方法、装置、设备及计算机可读存储介质
CN107203550B (zh) 一种数据处理方法和数据库服务器
CN110119427B (zh) 数据管理方法及相关产品
CN109063201B (zh) 一种基于混合存储方案的impala在线交互式查询方法
CN110110007A (zh) 数据管理方法及相关产品
JP6397105B2 (ja) データを記憶する方法及び装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 13892411

Country of ref document: EP

Kind code of ref document: A1

WWE Wipo information: entry into national phase

Ref document number: 2013892411

Country of ref document: EP

ENP Entry into the national phase

Ref document number: 2921616

Country of ref document: CA

ENP Entry into the national phase

Ref document number: 2016537067

Country of ref document: JP

Kind code of ref document: A

NENP Non-entry into the national phase

Ref country code: DE

ENP Entry into the national phase

Ref document number: 20167005763

Country of ref document: KR

Kind code of ref document: A

REG Reference to national code

Ref country code: BR

Ref legal event code: B01A

Ref document number: 112016004490

Country of ref document: BR

ENP Entry into the national phase

Ref document number: 112016004490

Country of ref document: BR

Kind code of ref document: A2

Effective date: 20160229