CN110704507B - Method and device for storing data and method and device for querying data - Google Patents

Method and device for storing data and method and device for querying data Download PDF

Info

Publication number
CN110704507B
CN110704507B CN201910924829.3A CN201910924829A CN110704507B CN 110704507 B CN110704507 B CN 110704507B CN 201910924829 A CN201910924829 A CN 201910924829A CN 110704507 B CN110704507 B CN 110704507B
Authority
CN
China
Prior art keywords
time
segment
sub
line segment
target
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.)
Active
Application number
CN201910924829.3A
Other languages
Chinese (zh)
Other versions
CN110704507A (en
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.)
Jingdong City Beijing Digital Technology Co Ltd
Original Assignee
Jingdong City Beijing Digital Technology 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 Jingdong City Beijing Digital Technology Co Ltd filed Critical Jingdong City Beijing Digital Technology Co Ltd
Priority to CN201910924829.3A priority Critical patent/CN110704507B/en
Publication of CN110704507A publication Critical patent/CN110704507A/en
Application granted granted Critical
Publication of CN110704507B publication Critical patent/CN110704507B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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/24Querying
    • G06F16/245Query processing
    • G06F16/2458Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
    • G06F16/2474Sequence data queries, e.g. querying versioned data

Landscapes

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

Abstract

Embodiments of the present disclosure disclose methods and apparatus for storing data. One embodiment of the method comprises: acquiring a time period of time period data to be stored as a target time period; determining a target time line segment to which a time starting point of a target time period belongs from a time line segment sequence, wherein the time line segment in the time line segment sequence corresponds to a mark in a mark set, the time line segment comprises a preset number of sub line segments obtained by dividing the time line segment in a preset mode, and the preset number of sub line segments corresponds to the preset number of sub marks; determining a target sub-line segment of which the time period indicated by the corresponding extension line segment comprises the target time period from a preset number of sub-line segments of the target time line segment; generating a time period mark corresponding to the target time period based on the mark corresponding to the target time line segment and the sub-mark corresponding to the target sub-line segment; and storing the time period mark and the time period data to be stored into a target database in an associated manner. This embodiment may save storage space.

Description

Method and device for storing data and method and device for querying data
Technical Field
Embodiments of the present disclosure relate to the field of computer technologies, and in particular, to a method and an apparatus for storing data and a method and an apparatus for querying data.
Background
The time period data corresponds to a time period attribute, which refers to data generated in the corresponding time period. In practice, the query of the time segment data refers to finding the time segment data in the database, where the corresponding time segment intersects with the query time segment, given a query time segment.
Currently, when storing time segment data, indexes can be respectively constructed for the start time and the end time corresponding to the time segment data, and then, when querying the time segment data, the time segment data meeting the intersection condition can be queried based on the start point and the end point of the query time segment.
Disclosure of Invention
The embodiment of the disclosure provides a method and a device for storing data and a method and a device for querying data.
In a first aspect, an embodiment of the present disclosure provides a method for storing data, the method including: acquiring a time period corresponding to time period data to be stored as a target time period; determining a time segment to which a time starting point of a target time segment belongs from a preset time segment sequence as the target time segment, wherein the time segment in the time segment sequence is used for indicating the time segment with the same time span, the time segment indicated by the target time segment comprises the time starting point, the time segment in the time segment sequence corresponds to a mark in a preset mark set, the time segment comprises a preset number of sub-segments obtained by dividing the time segment in a preset mode, and the preset number of sub-segments corresponds to a preset number of sub-marks; determining sub-line segments, which are indicated by corresponding extension line segments and comprise the target time period, from a preset number of sub-line segments of the target time line segment as target sub-line segments, wherein the extension line segments corresponding to the sub-line segments are obtained by extending the sub-line segments by preset times; generating a time period mark corresponding to the target time period based on the mark corresponding to the target time line segment and the sub-mark corresponding to the target sub-line segment; and storing the time period mark and the time period data to be stored into a target database in an associated manner.
In some embodiments, determining, from a preset sequence of timeline segments, a timeline segment to which the time start of the target time period belongs as the target timeline segment includes: performing difference calculation on the time starting point of the target time period and the time starting point of the time period indicated by the time line segment arranged at the head of the time line segment sequence to obtain a difference calculation result; carrying out quotient calculation on the difference calculation result and the time span corresponding to the time line segment to obtain a quotient calculation result; and selecting the time line segment arranged at the position indicated by the quotient finding result from the time line segment sequence as a target time line segment.
In some embodiments, the preset number of sub-segments of the timeline segment is obtained by: taking the time line segment as an initial sub-line segment, and executing the following dividing steps: dividing the initial sub-line segment into two sub-line segments by taking the central position of the initial sub-line segment as a reference; determining whether the number of the sub-line segments is a preset number; obtaining a preset number of sub-line segments in response to the preset number; and in response to the number not being the preset number, taking the latest obtained sub-line segment as the initial sub-line segment, and continuing to execute the dividing step.
In some embodiments, determining, from a preset number of sub-line segments of the target time line segment, a sub-line segment in which the time period indicated by the corresponding extension line segment includes the target time period as the target sub-line segment includes: and in response to that the time periods indicated by the extension line segments corresponding to the at least two sub-line segments in the preset number of sub-line segments of the target time line segment contain the target time period, selecting the sub-line segment with the shortest length from the at least two sub-line segments as the target sub-line segment.
In some embodiments, the target database is a non-relational database.
In a second aspect, an embodiment of the present disclosure provides a method for querying data, the method including: acquiring a query time period and a target database for querying time period data, wherein the target database is the target database described in any embodiment of the method described in the first aspect; determining a time line segment for querying time segment data from the time line segment sequence as a query line segment based on the time starting point and the time ending point of the query time segment; for the obtained query line segment, the following steps are performed: determining whether an intersection exists between a time period indicated by an extension line segment corresponding to the sub-line segment and the query time period for the sub-line segment in a preset number of sub-line segments included in the query line segment; in response to the intersection being present, determining the sub-line segment as a query sub-line segment; generating a query time segment mark corresponding to a query time segment based on the mark corresponding to the query line segment and the sub-mark corresponding to the query sub-line segment; and acquiring time period data corresponding to the generated query time period mark from the target database.
In a third aspect, an embodiment of the present disclosure provides an apparatus for storing data, the apparatus including: a first acquisition unit configured to acquire a time period corresponding to time period data to be stored as a target time period; the time segment determination method comprises a first determination unit, a second determination unit and a third determination unit, wherein the first determination unit is configured to determine a time segment to which a time starting point of a target time segment belongs from a preset time segment sequence as the target time segment, the time segment in the time segment sequence is used for indicating time segments with the same time span, the time segment indicated by the target time segment comprises the time starting point, the time segment in the time segment sequence corresponds to a mark in a preset mark set, the time segment comprises a preset number of sub-segments obtained by dividing the time segment in a preset manner, and the preset number of sub-segments corresponds to a preset number of sub-marks; the second determining unit is configured to determine sub-line segments, as target sub-line segments, of the time segments indicated by the corresponding extension line segments, wherein the time segments include the target time segments, and the extension line segments corresponding to the sub-line segments are obtained by extending the sub-line segments by preset times; the generating unit is configured to generate a time period mark corresponding to the target time period based on the mark corresponding to the target time line segment and the sub-mark corresponding to the target sub-line segment; and the storage unit is configured to store the time period mark and the time period data to be stored into the target database in an associated manner.
In a fourth aspect, an embodiment of the present disclosure provides an apparatus for querying data, the apparatus including: a second obtaining unit configured to obtain a query time period for querying time period data and a target database, wherein the target database is the target database described in any one of the embodiments of the method described in the first aspect; a third determination unit configured to determine a time segment for querying the time segment data from the time segment sequence as a query segment based on a time start point and a time end point of the query time segment; an execution unit configured to perform, for the obtained query line segment, the steps of: determining whether an intersection exists between a time period indicated by an extension line segment corresponding to the sub-line segment and the query time period for the sub-line segment in a preset number of sub-line segments included in the query line segment; in response to the intersection being present, determining the sub-line segment as a query sub-line segment; generating a query time segment mark corresponding to a query time segment based on the mark corresponding to the query line segment and the sub-mark corresponding to the query sub-line segment; and the third acquisition unit is configured to acquire the time period data corresponding to the generated query time period mark from the target database.
In a fifth aspect, an embodiment of the present disclosure provides an electronic device, including: one or more processors; a storage device having one or more programs stored thereon, which when executed by one or more processors, cause the one or more processors to implement the method of any of the embodiments of the methods described in the first and second aspects above.
In a sixth aspect, embodiments of the present disclosure provide a computer-readable medium on which a computer program is stored, which program, when executed by a processor, implements the method of any of the embodiments of the methods described in the first and second aspects above.
The method and the device for storing data provided by the embodiment of the disclosure are characterized in that a time period corresponding to time segment data to be stored is obtained as a target time period, then a time segment to which a time starting point of the target time period belongs is determined from a preset time segment sequence as a target time segment, wherein the time segment in the time segment sequence is used for indicating the time period with the same time span, the time period indicated by the target time segment comprises the time starting point, the time segment in the time segment sequence corresponds to a mark in a preset mark set, the time segment comprises a preset number of sub-segments obtained by dividing the time segment in a preset mode, the preset number of sub-segments corresponds to a preset number of sub-marks, and then a sub-segment indicated by a corresponding extension segment is determined from the preset number of sub-segments of the target time segment and comprises the target time period as the target sub-segment, the extension line segment corresponding to the sub-line segment is a line segment obtained by extending the sub-line segment by a preset multiple, then a time segment mark corresponding to a target time segment is generated based on a mark corresponding to the target time segment and a sub-mark corresponding to the target sub-line segment, and finally the time segment mark and the time segment data to be stored are stored in a target database in an associated mode, so that the time segment corresponding to the time segment data can be represented by a one-dimensional time segment mark determined based on a time segment sequence, and further, the storage space is saved when the time segment data and the corresponding time segment mark are stored in an associated mode.
The method and apparatus for querying data provided by the embodiments of the present disclosure obtain a query time segment and a target database for querying time segment data, where the target database is the target database described in any one of the embodiments of the method described in the above first aspect, then determine a time segment for querying time segment data from a time segment sequence as a query line segment based on a time start point and a time end point of the query time segment, and then execute the following steps for the obtained query line segment: determining whether an intersection exists between a time period indicated by an extension line segment corresponding to the sub-line segment and the query time period for the sub-line segment in a preset number of sub-line segments included in the query line segment; in response to the intersection being present, determining the sub-line segment as a query sub-line segment; and finally, acquiring time segment data corresponding to the generated query time segment mark from the target database, so that the query time segment data can be marked based on the one-dimensional time segment, and the query efficiency of the time segment data can be improved compared with the query time segment data based on a time starting point and a time ending point.
Drawings
Other features, objects and advantages of the disclosure will become more apparent upon reading of the following detailed description of non-limiting embodiments thereof, made with reference to the accompanying drawings in which:
FIG. 1 is an exemplary system architecture diagram in which one embodiment of the present disclosure may be applied;
FIG. 2 is a flow diagram for one embodiment of a method for storing data, according to the present disclosure;
FIG. 3 is a schematic diagram of one application scenario of a method for storing data in accordance with an embodiment of the present disclosure;
FIG. 4 is a flow diagram of yet another embodiment of a method for querying data according to the present disclosure;
FIG. 5 is a schematic diagram of one application scenario of a method for querying data, in accordance with an embodiment of the present disclosure;
FIG. 6 is a schematic block diagram illustrating one embodiment of an apparatus for storing data according to the present disclosure;
FIG. 7 is a schematic diagram illustrating one embodiment of an apparatus for querying data, according to the present disclosure;
FIG. 8 is a schematic structural diagram of a computer system suitable for use with the electronic device used to implement embodiments of the present disclosure.
Detailed Description
The present disclosure is described in further detail below with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the relevant invention and not restrictive of the invention. It should be noted that, for convenience of description, only the portions related to the related invention are shown in the drawings.
It should be noted that, in the present disclosure, the embodiments and features of the embodiments may be combined with each other without conflict. The present disclosure will be described in detail below with reference to the accompanying drawings in conjunction with embodiments.
Fig. 1 illustrates an exemplary system architecture 100 to which embodiments of the method for storing data, the apparatus for storing data, the method for querying data, or the apparatus for querying data of the present disclosure may be applied.
As shown in fig. 1, the system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 serves as a medium for providing communication links between the terminal devices 101, 102, 103 and the server 105. Network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The user may use the terminal devices 101, 102, 103 to interact with the server 105 via the network 104 to receive or send messages or the like. The terminal devices 101, 102, 103 may have various client applications installed thereon, such as a web browser application, a shopping-like application, a search-like application, an instant messaging tool, a mailbox client, social platform software, and the like.
The terminal apparatuses 101, 102, and 103 may be hardware or software. When the terminal devices 101, 102, 103 are hardware, they may be various electronic devices, including but not limited to smart phones, tablet computers, electronic book readers, MP3 players (Moving Picture Experts Group Audio Layer III, mpeg Audio Layer 3), MP4 players (Moving Picture Experts Group Audio Layer IV, mpeg Audio Layer 4), laptop portable computers, desktop computers, and the like. When the terminal apparatuses 101, 102, 103 are software, they can be installed in the electronic apparatuses listed above. It may be implemented as multiple pieces of software or software modules (e.g., multiple pieces of software or software modules to provide distributed services) or as a single piece of software or software module. And is not particularly limited herein.
The server 105 may be a server that provides various services, such as a data storage server that stores time period data to be stored transmitted by the terminal apparatuses 101, 102, 103. The data storage server can analyze and process the received data of the time period and the like corresponding to the time period data to be stored, and store the processing result and the data to be stored in a correlation mode.
It should be noted that the method for storing data provided by the embodiment of the present disclosure may be executed by the terminal devices 101, 102, and 103, or may be executed by the server 105, and accordingly, the apparatus for storing data may be disposed in the terminal devices 101, 102, and 103, or may be disposed in the server 105. In addition, the method for querying data provided by the embodiment of the present disclosure may be executed by the terminal devices 101, 102, and 103, or may be executed by the server 105, and accordingly, the apparatus for querying data may be disposed in the terminal devices 101, 102, and 103, or may be disposed in the server 105.
The server may be hardware or software. When the server is hardware, it may be implemented as a distributed server cluster formed by multiple servers, or may be implemented as a single server. When the server is software, it may be implemented as multiple pieces of software or software modules (e.g., multiple pieces of software or software modules used to provide distributed services), or as a single piece of software or software module. And is not particularly limited herein.
It should be understood that the number of terminal devices, networks, and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation. In the case where data used in storing time zone data or inquiring time zone data does not need to be acquired from a remote place, the above system architecture may not include a network but only a terminal device or a server.
With continued reference to FIG. 2, a flow 200 of one embodiment of a method for storing data in accordance with the present disclosure is shown. The method for storing data comprises the following steps:
step 201, acquiring a time period corresponding to the time period data to be stored as a target time period.
In this embodiment, an execution subject (for example, a server shown in fig. 1) of the method for storing data may obtain the time period data to be stored from a remote location or a local location by a wired connection manner or a wireless connection manner, and obtain a time period corresponding to the time period data to be stored as the target time period. The time period data to be stored is time period data to be stored. The time zone data is data generated in a certain time zone. The time period (i.e., the target time period) corresponding to the time period data to be stored is the time period for generating the time period data to be stored.
As an example, the time period data to be stored may be data generated when the user browses a webpage at 8:00 to 9:00, and the target time period is 8:00 to 9: 00.
In practice, the time period data is typically stored with its corresponding time period as a marker.
Step 202, determining a time line segment to which the time starting point of the target time period belongs from a preset time line segment sequence as a target time line segment.
In this embodiment, based on the target time period obtained in step 201, the execution subject may determine, from a preset time segment sequence, a time segment to which the time start point of the target time period belongs as the target time segment. Wherein, the time line segments in the time line segment sequence are used for indicating the time segments with the same time span.
By way of example, the timeline segment sequence includes three timeline segments, timeline segment 1, timeline segment 2, and timeline segment 3, timeline segment 1 may be used to indicate 3 months, 1 days 00:00-24: 00; timeline segment 2 may be used to indicate 3 months, 2 days 00:00-24: 00; time segment 3 may be used to indicate 3 months, 3 days 00:00-24:00, and each time segment is used to indicate one day, i.e., the time span of the time segments indicated by the time segment is the same, all being one day. In practice, the time span corresponding to the time line segment may also be a month, a year, or the like, and may be determined by a skilled person.
In practice, a continuous time segment may be segmented based on a time span to obtain a sequence of sub-time segments, and then the sub-time segments in the obtained sequence of sub-time segments are represented by a time segment to obtain a sequence of time segments. For example, the time span is one day, and based on the time span, 3 months are divided to obtain a sequence of sub-time periods of "3 months and 1 day; 3, month and 2 days; 3 months and 3 days; … … 3 month 31 day ". Then, representing the sub-time periods in the obtained sub-time period sequence by using the time line segments to obtain a time line segment sequence 'time line segment 1'; a time line segment 2; a time line segment 3; … … time line segment 31 ".
Note that points on the time line segment correspond to points in time in the indicated time period. The length of the timeline segment corresponds to the duration of the indicated time period. As an example, a time segment is 24cm long, the time segment indicates a time period of 3 months 1 days 00:00-24:00, and the midpoint of the time segment may correspond to 3 months 1 days 12: 00. Every 1cm of sub-line segments on the time line segment may correspond to 1 hour within 3 months and 1 day.
In practice, one of the two endpoints of the time line segment may be the starting point, and the other endpoint may be the ending point. The start of the timeline segment corresponds to the time start of the indicated time period and the end of the timeline segment corresponds to the time end of the indicated time period. The time end point corresponding to the end point of the previous time line segment in the time line segment sequence is the same as the time starting point corresponding to the starting point of the adjacent next time line segment.
In the present embodiment, the time period indicated by the target time line segment includes the time starting point of the target time period. By way of example, the timeline segment sequence includes three timeline segments, timeline segment 1, timeline segment 2, and timeline segment 3, timeline segment 1 being used to indicate 3 months, 1 days 00:00-24: 00; time segment 2 is used to indicate 3 months, 2 days 00:00-24: 00; timeline segment 3 is used to indicate 3 months, 3 days 00:00-24: 00. The target time period is "3 months, 1 day 12:00-3 months, 2 days 12: 00". The execution body may determine the time segment 1 as the target time segment since the time segment "3 months 1 days 00:00-24: 00" indicated by the time segment 1 includes the time start point of the target time segment "3 months 1 days 12: 00".
In some optional implementations of this embodiment, the executing body may determine the target timeline segment by: first, the execution body may perform a difference operation between the time start point of the target time segment and the time start point of the time segment indicated by the time segment arranged at the head of the time segment sequence, so as to obtain a difference operation result. Then, the execution subject may perform quotient calculation on the difference calculation result and the time span corresponding to the time line segment to obtain a quotient calculation result. Finally, the execution body may select, from the timeline segment sequence, a timeline segment arranged at a position indicated by the quotient result as the target timeline segment. Here, the position indicated by the quotient result may specifically be a position indicated by an integer in the quotient result. For example, if the quotient result is 2.5, the position indicated by the quotient result may be the second digit.
As an example, the target time period is 3 months, 1 day, 12:00-24: 00. The time line segment sequence includes 365 time line segments, each representing a day of the year. The execution body described above may perform a difference between 3 months, 1 day 12:00 and a time start point "1 months, 1 day 00: 00" of a time period "1 months, 1 day 00:00-1 months, 1 day 24: 00" indicated by a time segment located at the head of the time segment sequence, to obtain a difference result of 59.5 days (59.5 is 31+28+0.5, where 31 is a number of days in 1 month; 28 is a number of days in 2 months; 0.5 is a number of days corresponding to 3 months, 1 day 12:00 to 3 months, 1 day 00: 00). And then carrying out quotient calculation on the difference result 59.5 and the time span of one day to obtain a quotient calculation result 59.5. Finally, the execution body may select a timeline segment arranged at the 59 th bit (i.e., the position indicated by the quotient result) from the timeline segment sequence as the target timeline segment.
In this embodiment, the timeline segment in the timeline segment sequence may correspond to a marker in a preset marker set. The markers in the marker set may be various markers for indicating the timeline segments, including but not limited to at least one of: characters, numbers, symbols. As an example, timeline segment 1, timeline segment 2, and timeline segment 3 in the timeline segment sequence can each correspond to a token A, B, C in the token set.
In this embodiment, the time line segments in the time line segment sequence include a preset number of sub-line segments obtained by dividing the time line segments in a preset manner. The predetermined number of sub-line segments corresponds to a predetermined, predetermined number of sub-marks.
Specifically, the preset mode may be various modes. As an example, the start point of the timeline segment is a, the end point is b, and the midpoint is o. The preset manner may be a manner of dividing the time line segment from the midpoint o of the time line segment. At this time, the obtained sub-line segments may include 3 (i.e., a preset number) sub-line segments ab, ao, and ob.
In some optional implementations of this embodiment, the preset number of sub-segments of the time segment may be obtained by the execution main body or other electronic device in the following manner: firstly, a time line segment is taken as an initial sub-line segment, and the following dividing steps are executed: dividing the initial sub-line segment into two sub-line segments by taking the central position of the initial sub-line segment as a reference; determining whether the number of the sub-line segments is a preset number; in response to the predetermined number, a predetermined number of sub-line segments is obtained. Further, in response to the number of sub-line segments not being the preset number, the division step may be continued with the newly obtained sub-line segment as the initial sub-line segment.
As an example, the preset number is 7. For a certain time line segment ab, the execution subject or other electronic device may first use the time line segment ab as an initial sub-line segment, and divide the initial sub-line segment ab into a sub-line segment ao and a sub-line segment ob with reference to a central point o of the initial sub-line segment ab. And in response to obtaining three sub-line segments of the sub-line segment ab, the sub-line segment ao and the sub-line segment ob (namely in response to the fact that the number of the sub-line segments is not the preset number), continuing to use the newly obtained sub-line segment ao and the sub-line segment ob as initial sub-line segments, and dividing the initial sub-line segment ao and the initial sub-line segment ob. Specifically, the initial sub-line segment ao is divided into a sub-line segment ax and a sub-line segment xo with the central point x of the initial sub-line segment ao as a reference, and the initial sub-line segment ob is divided into a sub-line segment oy and a sub-line segment yb with the central point y of the initial sub-line segment ob as a reference. In response to obtaining seven sub-line segments, namely sub-line segment ab, sub-line segment ao, sub-line segment ob, sub-line segment ax, sub-line segment xo, sub-line segment oy and sub-line segment yb (i.e. in response to the number of sub-line segments being a preset number), the division is stopped, and seven sub-line segments "ab, ao, ob, ax, xo, oy and yb" are obtained.
In this embodiment, the sub-markers may be various markers for indicating the sub-line segments, including but not limited to at least one of the following: characters, numbers, symbols. Continuing with the example above, sub-line segment ab, sub-line segment ao, and sub-line segment ob may correspond to sub-labels 0, 01, 10, respectively.
And step 203, determining the sub-line segments of the time period indicated by the corresponding extension line segment and containing the target time period from the preset number of sub-line segments of the target time line segment as the target sub-line segment.
In this embodiment, for the preset number of sub-line segments of the target time line segment determined in step 202, the executing body may determine, from the preset number of sub-line segments of the target time line segment, a sub-line segment, as the target sub-line segment, in which the time period indicated by the corresponding extension line segment includes the target time period. The extension line section corresponding to the sub-line section can be a line section obtained by extending the sub-line section by a preset multiple. Here, the preset multiple may be any multiple, and may be, for example, 0, 1, 2, or the like. It can be understood that if the preset multiple is 0 times, the extension line segment corresponding to the sub-line segment is the sub-line segment itself.
In this embodiment, the extension of the sub-line segment may refer to the extension from the end point of the sub-line segment. As an example, the preset multiple is 2 times, and the extension line segment of the sub-line segment ao of the target time line segment ab may be a line segment ap obtained by extending the sub-line segment ao by 2 times from the end point "o". Here, it is understood that if ao indicates a time period of "3 month 1 day 00:00-3 month 1 day 12: 00", ap indicates a time period of "3 month 1 day 00:00-3 month 2 day 12: 00".
In this embodiment, if only the time period indicated by the extension line segment corresponding to one sub-line segment in the preset number of sub-line segments of the target time line segment includes the target time period, the execution main body may directly determine the sub-line segment as the target sub-line segment; if the time period indicated by the extension line segment corresponding to at least two sub-line segments in the preset number of sub-line segments of the target time line segment includes the target time period, the execution main body may select any one sub-line segment from the at least two sub-line segments as the target sub-line segment.
As an example, the target time period is "3 months, 1 day 12:00-3 months, 2 days 12: 00". The target time line segment comprises 3 sub-line segments which are respectively a sub-line segment ab, a sub-line segment ao and a sub-line segment ob. Wherein, the sub-line ab indicates a time period of "3 month 1 day 00:00-3 month 1 day 24: 00"; the sub-line segment ao indicates a time period of "3 months, 1 days 00:00-3 months, 1 days 12: 00"; the sub-line segment ob indicates a time period "3 month 1 day 12:00-3 month 1 day 24: 00". And the preset multiple corresponding to the extension sub-line segment is 1 time. The time period indicated by the extension line ax corresponding to the sub-line ab is "3 month 1 day 00:00-3 month 2 day 24: 00"; the time period indicated by the extension line segment ay corresponding to the sub-line segment ao is "3 months, 1 days 00: 00" to 3 months, 1 days, 24:00 "; the extended line segment oz corresponding to the sub-line segment ob indicates a time period of "3 month 1 day 12: 00" to 3 month 2 day 12:00 ". The extended line segments ax, ay, oz include the extended line segment ax and the extended line segment oz of the target time period, and the execution subject may select one sub-line segment from the sub-line segments ab and ob corresponding to the extended line segment ax and the extended line segment oz as the target sub-line segment.
In some optional implementations of the embodiment, in response to that a time period indicated by an extension line segment corresponding to at least two sub-line segments included in the preset number of sub-line segments of the target time line segment includes the target time period, the execution main body may select a sub-line segment with the shortest length from the at least two sub-line segments as the target sub-line segment.
Continuing with the above example, for sub-line segments ab and ob whose time periods indicated by the corresponding extension line segments include the target time period, the execution body may select the sub-line segment ob as the target sub-line segment since the length of the sub-line segment ob is smaller than the length of the sub-line segment ab.
And 204, generating a time period mark corresponding to the target time period based on the mark corresponding to the target time line segment and the sub-mark corresponding to the target sub-line segment.
In this embodiment, the execution main body may generate a time period flag corresponding to the target time period based on the flag corresponding to the target time line segment and the sub-flag corresponding to the target sub-line segment.
Specifically, the execution body may generate the time period mark corresponding to the target time period by using various methods. For example, the execution body may directly combine the mark corresponding to the target time line segment and the sub-mark corresponding to the target sub-line segment to obtain the time period mark corresponding to the target time period; or, the execution body may first convert the mark corresponding to the target time line segment and the sub-mark corresponding to the target sub-line segment to obtain the binary code, and then combine the binary code corresponding to the obtained mark and the binary code corresponding to the sub-mark to obtain the time segment mark corresponding to the target time segment.
As an example, the target timeline segment is labeled A and the target sub-line segment is labeled a. The execution body may first convert the flag a into the binary code 01000001, then convert the sub-flag a into the binary code 01100001, and finally combine the binary code 01000001 and the binary code 01100001 to obtain the time period flag 0100000101100001 corresponding to the target time period.
And step 205, storing the time period mark and the time period data to be stored into a target database in an associated manner.
In this embodiment, based on the time period flag obtained in step 204, the executing entity may store the time period flag and the time period data to be stored in the target database in an associated manner. The target database may be a predetermined database for storing time period data. Specifically, the target database may be various types of databases.
In some alternative implementations of this embodiment, the target database is a non-relational database. In practice, the non-relational database only supports one-dimensional indexes, the two-dimensional time period indexes are represented into one-dimensional time period marks, and time period data storage aiming at the non-relational database can be achieved.
In this embodiment, the execution agent may store the time period stamp and the time period data to be stored in the target database in the form of a key value pair. Specifically, the execution agent may store the time period flag as a key and the time period data to be stored as a value in association with the time period flag and the time period data to be stored in the target database.
With continued reference to fig. 3, fig. 3 is a schematic diagram of an application scenario of the method for storing data according to the present embodiment.
In the application scenario of fig. 3, the server 301 may first obtain a time period corresponding to the time period data 302 to be stored as a target time period 303 (e.g., 3 months, 1 day, 00:00-12: 00).
Then, the server 301 may determine, as the target timeline segment 3041, a timeline segment to which a time start point (e.g., 3 months, 1 days 00:00) of the target timeline segment 303 belongs from a preset timeline segment sequence 304, where the timeline segments in the timeline segment sequence 304 are used to indicate a timeline segment with a same time span (e.g., one day), the timeline segment indicated by the target timeline segment 3041 (e.g., 3 months, 1 days) includes the time start point, the timeline segments in the timeline segment sequence 304 correspond to markers (e.g., "a," "B," "C," "D," … …) in a preset marker set, the timeline segments include 3 (i.e., a preset number) of sub-line segments obtained by dividing the timeline segments in a preset manner, and the 3 sub-line segments correspond to 3 predetermined sub-markers (e.g., "0," "01," "10").
Next, the server 301 may determine, from the 3 sub-line segments of the target time line segment 3041, a sub-line segment whose time period indicated by a corresponding extension line segment includes the target time period 303 as the target sub-line segment 30411, where the extension line segment corresponding to the sub-line segment is a line segment obtained by extending the sub-line segment by 1 time (that is, by a preset multiple).
Then, the server 301 may generate a time period marker 305 corresponding to the target time period 303 based on the marker corresponding to the target timeline segment 3041 and the sub-marker corresponding to the target sub-line segment 30411.
Finally, the server 301 may store the time period marker 305 in association with the time period data to be stored 302 in the target database 306.
The method provided by the above embodiment of the present disclosure may characterize the time segment corresponding to the time segment data by the one-dimensional time segment marker determined based on the time segment sequence, and further, is helpful for saving the storage space when performing the associated storage of the time segment data and the corresponding time segment marker.
With continued reference to FIG. 4, a flow 400 of one embodiment of a method for querying data in accordance with the present disclosure is shown. The method for querying data comprises the following steps:
step 401, obtaining a query time segment and a target database for querying time segment data.
In this embodiment, an execution subject (e.g., a server shown in fig. 1) of the method for querying data may obtain the query time slot and the target database for querying the time slot data from a remote or local place through a wired connection manner or a wireless connection manner.
Here, the query time period data refers to time period data in which a corresponding time period is found from the target database to intersect with the query time period. Specifically, the query time period is q ═ tq1,tq2]Querying the time segment data refers to finding time segment data from the target database, where the found time segment data corresponds to a time segment r ═ tr1,tr2]R intersects q, i.e.: tq is a unit of time1Tr is less than or equal to2And tq2Tr is greater than or equal to1
In this embodiment, the target database is the target database described in the embodiment corresponding to fig. 2. The time period data in the target database is stored in association with the time period marker. The time segment marks are generated based on the marks of the target time segment corresponding to the time segment data and the target sub-segment sub-marks, and specific generation manners may refer to the contents in the embodiment corresponding to fig. 2, which is not described herein again.
Step 402, determining a time line segment for querying time segment data from the time line segment sequence as a query line segment based on the time starting point and the time ending point of the query time segment.
In this embodiment, based on the query time period obtained in step 401, the execution subject may determine a time line segment for querying time period data from a time line segment sequence as a query line segment.
Here, the time segment sequence is the time segment sequence described in the embodiment corresponding to fig. 2, and specifically, reference may be made to the content in the embodiment corresponding to fig. 2, which is not described herein again.
In this embodiment, the execution main body described above may first determine, from the time line segment sequence, a time line segment to which a time start point and a time end point of the query time period belong, and then determine, based on the determined time line segment, a time line segment for querying the time period data as the query line segment.
Here, the time period indicated by the time line segment to which the time start point of the inquiry time period belongs includes the time start point of the inquiry time period. The time segment indicated by the time line segment to which the time end of the query time segment belongs contains the time end of the query time segment.
Specifically, the executing entity may determine, as the query line segment, a time line segment for querying time-segment data by using various methods based on the time line segment to which the determined time starting point belongs and the time line segment to which the time ending point belongs. For example, the execution body may directly determine a timeline segment to which the determined time start point belongs and a timeline segment to which the time end point belongs as query segments; alternatively, the execution body may determine, as the query line segment, a time line segment to which the determined time start point belongs, a time line segment to which the time end point belongs, a time line segment adjacent to the time line segment to which the time start point belongs in the time line segment sequence, and a time line segment adjacent to the time end point in the time line segment sequence.
It is understood that the time segment data is stored based on the extension line segments corresponding to the child line segments when stored, and therefore, even if the time segment indicated by the time segment adjacent to the time segment to which the time start point or the time end point belongs does not intersect with the query time segment, the time segment indicated by the extension line segment may intersect with the query time segment, and therefore, while the time segment to which the determined time start point belongs and the time segment to which the time end point belongs are determined as the query line segments, determining the time segment adjacent to the time segment to which the time start point of the query time segment belongs and the time segment adjacent to the time segment to which the time end point belongs in the time segment sequence as the query line segments can improve the comprehensiveness of the query of the time segment data.
In step 403, for the obtained query line segment, the following steps are performed: determining whether an intersection exists between a time period indicated by an extension line segment corresponding to the sub-line segment and the query time period for the sub-line segment in a preset number of sub-line segments included in the query line segment; in response to the intersection being present, determining the sub-line segment as a query sub-line segment; and generating a query time segment mark corresponding to the query time segment based on the mark corresponding to the query line segment and the sub-mark corresponding to the query sub-line segment.
In this embodiment, for the query line segment obtained in step 402, the execution main body may perform the following steps (step 4031-step 4033):
step 4031, for the sub-line segments in a preset number of sub-line segments included in the query line segment, determine whether there is an intersection between the time segment indicated by the extension line segment corresponding to the sub-line segment and the query time segment.
Here, the extension line segment corresponding to the sub-line segment is similar to the extension line segment in the embodiment corresponding to fig. 2, and specific reference may be made to the content in the embodiment corresponding to fig. 2, and details are not repeated here.
In practice, the existence of an intersection of two time periods refers to a time period or a time point at which the two time periods coincide. For example, the time period indicated by the extension line segment is "3 month 1 day 12:00-3 month 2 day 12: 00", the query time period is "3 month 2 day 00:00-3 month 2 day 12: 00", and the two have a coincident time period of "3 month 2 day 00:00-3 month 2 day 12: 00", that is, the two have an intersection.
It is understood that there is an intersection of the two time periods, i.e. the two time periods intersect.
Step 4032, in response to the intersection of the time period indicated by the extension line segment corresponding to the sub-line segment and the query time period, determining the sub-line segment as a query sub-line segment.
Step 4033, based on the label corresponding to the query line segment and the sub label corresponding to the query sub line segment, a query time segment label corresponding to the query time segment is generated.
In this embodiment, the execution subject may use the method for generating a time segment marker described in the embodiment corresponding to fig. 2 to generate a query time segment marker corresponding to a query time segment based on the marker corresponding to the query line segment and the sub-marker corresponding to the query sub-line segment.
Step 404, obtaining time period data corresponding to the generated query time period marker from the target database.
In this embodiment, based on the query time period stamp obtained in step 403, the execution main body may obtain the time period data corresponding to the query time period stamp from the target database.
With continued reference to fig. 5, fig. 5 is a schematic diagram of an application scenario of the method for querying data according to the present embodiment.
In the application scenario of fig. 5, the server 501 may first obtain a query time period 502 (e.g., 3 months 1 day-3 months 2 days) for querying time period data and a target database 503, where the target database 503 may be the target database described in the embodiment corresponding to fig. 2.
The server 501 may then determine a timeline segment for querying timeline segment data from the timeline segment sequence 504 as a query segment 5041 based on the start of time (e.g., 3 months 1 days 00:00) and the end of time (e.g., 3 months 2 days 24:00) of the query time period 502.
Next, for the obtained query line segment 5041, the server 501 may perform the following steps: for each sub-line segment of the 3 (i.e., the preset number) sub-line segments included in the query line segment 5041, determining whether there is an intersection between a time segment (e.g., 3 months, 1 days 00:00-12:00) indicated by the extension line segment corresponding to the sub-line segment and the query time segment 502; in response to there being an intersection, determine the child line segment as a query child line segment 50411; based on the token corresponding to the query line segment 5041 and the subtag corresponding to the query subtank 50411, a query time segment token 505 corresponding to the query time segment 502 is generated.
Finally, the server 501 may obtain the time period data 506 corresponding to the generated query time period marker 505 from the target database 503.
The method provided by the above embodiment of the present disclosure may query the time segment data based on the one-dimensional time segment marker, and may improve the query efficiency of the time segment data compared with querying the time segment data based on the time starting point and the time ending point.
With further reference to fig. 6, as an implementation of the methods shown in the above figures, the present disclosure provides an embodiment of an apparatus for storing data, which corresponds to the method embodiment shown in fig. 2, and which is particularly applicable to various electronic devices.
As shown in fig. 6, the apparatus 600 for storing data of the present embodiment includes: a first acquisition unit 601, a first determination unit 602, a second determination unit 603, a generation unit 604, and a storage unit 605. Wherein, the first obtaining unit 601 is configured to obtain a time period corresponding to the time period data to be stored as a target time period; the first determining unit 602 is configured to determine, as a target timeline segment, a timeline segment to which a time start of a target timeline segment belongs from a preset timeline segment sequence, where the timeline segments in the timeline segment sequence are used to indicate timespans with the same time span, the timeline segment indicated by the target timeline segment includes the time start, the timeline segments in the timeline segment sequence correspond to marks in a preset mark set, the timeline segment includes a preset number of sub-segments obtained by dividing the timeline segment in a preset manner, and the preset number of sub-segments corresponds to a preset number of sub-marks; the second determining unit 603 is configured to determine, as a target sub-line segment, a sub-line segment in which a time period indicated by a corresponding extension line segment includes the target time period from among a preset number of sub-line segments of the target time line segment, where the extension line segment corresponding to the sub-line segment is a line segment obtained by extending the sub-line segment by a preset multiple; the generating unit 604 is configured to generate a time period mark corresponding to the target time period based on the mark corresponding to the target time line segment and the sub-mark corresponding to the target sub-line segment; the storage unit 605 is configured to store the time period stamp and the time period data to be stored in association in the target database.
In this embodiment, the first obtaining unit 601 of the apparatus 600 for storing data may obtain the time period data to be stored from a remote location or a local location by a wired connection manner or a wireless connection manner, and obtain a time period corresponding to the time period data to be stored as the target time period. The time period data to be stored is time period data to be stored. The time zone data is data generated in a certain time zone. The time period (i.e., the target time period) corresponding to the time period data to be stored is the time period for generating the time period data to be stored.
In this embodiment, based on the target time segment obtained by the first obtaining unit 601, the first determining unit 602 may determine, from a preset time segment sequence, a time segment to which a time start point of the target time segment belongs as the target time segment. Wherein, the time line segments in the time line segment sequence are used for indicating the time segments with the same time span. The time period indicated by the target time line segment includes the time starting point of the target time period.
In this embodiment, the timeline segment in the timeline segment sequence may correspond to a marker in a preset marker set. The markers in the marker set may be various markers for indicating the timeline segments, including but not limited to at least one of: characters, numbers, symbols.
In this embodiment, the time line segments in the time line segment sequence include a preset number of sub-line segments obtained by dividing the time line segments in a preset manner. The predetermined number of sub-line segments corresponds to a predetermined, predetermined number of sub-marks.
In this embodiment, the sub-markers may be various markers for indicating the sub-line segments, including but not limited to at least one of the following: characters, numbers, symbols.
In this embodiment, for the preset number of sub-line segments of the target time line segment determined by the first determining unit 602, the second determining unit 603 may determine, as the target sub-line segment, a sub-line segment, in which the time period indicated by the corresponding extension line segment includes the target time period, from the preset number of sub-line segments of the target time line segment. The extension line section corresponding to the sub-line section can be a line section obtained by extending the sub-line section by a preset multiple. Here, the preset multiple may be any multiple.
In this embodiment, the generating unit 604 may generate the time period flag corresponding to the target time period based on the flag corresponding to the target time line segment and the sub-flag corresponding to the target sub-line segment.
In this embodiment, based on the time zone flag obtained by the generating unit 604, the storing unit 605 may store the time zone flag and the time zone data to be stored in the target database in association with each other. The target database may be a predetermined database for storing time period data. Specifically, the target database may be various types of databases.
In some optional implementations of this embodiment, the first determining unit 602 may include: a difference module (not shown in the figure) configured to perform difference between the time starting point of the target time segment and the time starting point of the time segment indicated by the time segment arranged at the head of the time segment sequence to obtain a difference result; a quotient calculating module (not shown in the figure) configured to calculate a quotient of the difference result and the time span corresponding to the time line segment to obtain a quotient calculation result; and a selecting module (not shown in the figure) configured to select the time line segment arranged at the position indicated by the quotient result from the time line segment sequence as the target time line segment.
In some optional implementations of this embodiment, the preset number of sub-line segments of the time line segment is obtained by: taking the time line segment as an initial sub-line segment, and executing the following dividing steps: dividing the initial sub-line segment into two sub-line segments by taking the central position of the initial sub-line segment as a reference; determining whether the number of the sub-line segments is a preset number; obtaining a preset number of sub-line segments in response to the preset number; and in response to the number not being the preset number, taking the latest obtained sub-line segment as the initial sub-line segment, and continuing to execute the dividing step.
In some optional implementations of this embodiment, the second determining unit 603 may be further configured to: and in response to that the time periods indicated by the extension line segments corresponding to the at least two sub-line segments in the preset number of sub-line segments of the target time line segment contain the target time period, selecting the sub-line segment with the shortest length from the at least two sub-line segments as the target sub-line segment.
In some alternative implementations of this embodiment, the target database is a non-relational database.
It will be understood that the elements described in the apparatus 600 correspond to various steps in the method described with reference to fig. 2. Thus, the operations, features and resulting advantages described above with respect to the method are also applicable to the apparatus 600 and the units included therein, and are not described herein again.
The apparatus 600 provided by the above embodiment of the present disclosure may characterize the time segment corresponding to the time segment data by the one-dimensional time segment marker determined based on the time segment sequence, thereby being helpful to save the storage space when performing the associated storage of the time segment data and the corresponding time segment marker.
With further reference to fig. 7, as an implementation of the methods shown in the above-mentioned figures, the present disclosure provides an embodiment of an apparatus for querying data, where the embodiment of the apparatus corresponds to the embodiment of the method shown in fig. 4, and the apparatus may be specifically applied to various electronic devices.
As shown in fig. 7, the apparatus 700 for querying data of the present embodiment includes: a second acquisition unit 701, a third determination unit 702, an execution unit 703, and a third acquisition unit 704. Wherein, the second obtaining unit 701 is configured to obtain a query time period for querying time period data and a target database, wherein the target database is the target database described in any embodiment of the method described in the first aspect; the third determining unit 702 is configured to determine a time segment for querying time segment data from the time segment sequence as a query segment based on a time start point and a time end point of the query time segment; the execution unit 703 is configured to perform the following steps for the obtained query line segment: determining whether an intersection exists between a time period indicated by an extension line segment corresponding to the sub-line segment and the query time period for the sub-line segment in a preset number of sub-line segments included in the query line segment; in response to the intersection being present, determining the sub-line segment as a query sub-line segment; generating a query time segment mark corresponding to a query time segment based on the mark corresponding to the query line segment and the sub-mark corresponding to the query sub-line segment; the third obtaining unit 704 is configured to obtain time period data corresponding to the query time period stamp from the target database.
In this embodiment, the second obtaining unit 701 of the apparatus 700 for inquiring data may obtain the inquiry time slot and the target database for inquiring time slot data from a remote or local by a wired connection manner or a wireless connection manner.
Here, the query time period data refers to time period data in which a corresponding time period is found from the target database to intersect with the query time period.
In this embodiment, based on the query time period obtained by the second obtaining unit 701, the third determining unit 702 may determine a time line segment for querying time period data from the time line segment sequence as the query line segment.
In this embodiment, for the query line segment obtained by the third determining unit 702, the executing unit 703 may execute the following steps (steps 7031 to 7033):
step 7031, for a sub-line segment in a preset number of sub-line segments included in the query line segment, determining whether an intersection exists between a time segment indicated by an extension line segment corresponding to the sub-line segment and the query time segment.
Step 7032, in response to the intersection of the time period indicated by the extension line segment corresponding to the sub-line segment and the query time period, determining the sub-line segment as a query sub-line segment.
Step 7033, a query time segment flag corresponding to the query time segment is generated based on the flag corresponding to the query line segment and the sub-flag corresponding to the query sub-line segment.
In this embodiment, the execution unit 703 may generate the query time segment flag corresponding to the query time segment based on the flag corresponding to the query line segment and the sub-flag corresponding to the query sub-line segment by using the method for generating the time segment flag described in the embodiment corresponding to fig. 2.
In this embodiment, based on the query time period stamp obtained by the executing unit 703, the third obtaining unit 704 may obtain the time period data corresponding to the query time period stamp from the target database.
It will be understood that the units described in the apparatus 700 correspond to the various steps in the method described with reference to fig. 4. Thus, the operations, features and resulting advantages described above with respect to the method are also applicable to the apparatus 700 and the units included therein, and will not be described herein again.
The apparatus 700 provided by the above embodiment of the present disclosure may query the time slot data based on the one-dimensional time slot tag, and may improve the query efficiency of the time slot data compared to querying the time slot data based on the time starting point and the time ending point.
Referring now to fig. 8, a schematic diagram of an electronic device (e.g., a terminal device or server of fig. 1) 800 suitable for implementing embodiments of the present disclosure is shown. The terminal device in the embodiments of the present disclosure may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a vehicle terminal (e.g., a car navigation terminal), and the like, and a stationary terminal such as a digital TV, a desktop computer, and the like. The electronic device shown in fig. 8 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 8, an electronic device 800 may include a processing means (e.g., central processing unit, graphics processor, etc.) 801 that may perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)802 or a program loaded from a storage means 808 into a Random Access Memory (RAM) 803. In the RAM 803, various programs and data necessary for the operation of the electronic apparatus 800 are also stored. The processing apparatus 801, the ROM 802, and the RAM 803 are connected to each other by a bus 804. An input/output (I/O) interface 805 is also connected to bus 804.
Generally, the following devices may be connected to the I/O interface 805: input devices 806 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; output devices 807 including, for example, a Liquid Crystal Display (LCD), speakers, vibrators, and the like; storage 808 including, for example, magnetic tape, hard disk, etc.; and a communication device 809. The communication means 809 may allow the electronic device 800 to communicate wirelessly or by wire with other devices to exchange data. While fig. 8 illustrates an electronic device 800 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication means 809, or installed from the storage means 808, or installed from the ROM 802. The computer program, when executed by the processing apparatus 801, performs the above-described functions defined in the methods of the embodiments of the present disclosure.
It should be noted that the computer readable medium in the present disclosure may be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present disclosure, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device. The computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: acquiring a time period corresponding to time period data to be stored as a target time period; determining a time segment to which a time starting point of a target time segment belongs from a preset time segment sequence as the target time segment, wherein the time segment in the time segment sequence is used for indicating the time segment with the same time span, the time segment indicated by the target time segment comprises the time starting point, the time segment in the time segment sequence corresponds to a mark in a preset mark set, the time segment comprises a preset number of sub-segments obtained by dividing the time segment in a preset mode, and the preset number of sub-segments corresponds to a preset number of sub-marks; determining sub-line segments, which are indicated by corresponding extension line segments and comprise the target time period, from a preset number of sub-line segments of the target time line segment as target sub-line segments, wherein the extension line segments corresponding to the sub-line segments are obtained by extending the sub-line segments by preset times; generating a time period mark corresponding to the target time period based on the mark corresponding to the target time line segment and the sub-mark corresponding to the target sub-line segment; and storing the time period mark and the time period data to be stored into a target database in an associated manner.
Alternatively, the electronic device may be caused to: acquiring a query time period and a target database for querying time period data, wherein the target database is the target database described in any embodiment in the embodiment corresponding to fig. 2; determining a time line segment for querying time segment data from the time line segment sequence as a query line segment based on the time starting point and the time ending point of the query time segment; for the obtained query line segment, the following steps are performed: determining whether an intersection exists between a time period indicated by an extension line segment corresponding to the sub-line segment and the query time period for the sub-line segment in a preset number of sub-line segments included in the query line segment; in response to the intersection being present, determining the sub-line segment as a query sub-line segment; generating a query time segment mark corresponding to a query time segment based on the mark corresponding to the query line segment and the sub-mark corresponding to the query sub-line segment; and acquiring time period data corresponding to the generated query time period mark from the target database.
Computer program code for carrying out operations for aspects of the present disclosure may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present disclosure may be implemented by software or hardware. Here, the name of the unit does not constitute a limitation of the unit itself in some cases, and for example, the first acquisition unit may also be described as a "unit that acquires a target time period".
The foregoing description is only exemplary of the preferred embodiments of the disclosure and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the disclosure herein is not limited to the particular combination of features described above, but also encompasses other embodiments in which any combination of the features described above or their equivalents does not depart from the spirit of the disclosure. For example, the above features and (but not limited to) the features disclosed in this disclosure having similar functions are replaced with each other to form the technical solution.

Claims (10)

1. A method for storing data, comprising:
acquiring a time period corresponding to time period data to be stored as a target time period;
determining a time segment to which a time starting point of the target time segment belongs from a preset time segment sequence as a target time segment, wherein the time segment in the time segment sequence is used for indicating a time segment with the same time span, the time segment indicated by the target time segment comprises the time starting point, the time segment in the time segment sequence corresponds to a mark in a preset mark set, the time segment comprises a preset number of sub-segments obtained by dividing the time segment in a preset manner, and the preset number of sub-segments corresponds to a preset number of sub-marks;
determining a sub-line segment, which contains the target time period, in the time period indicated by the corresponding extension line segment from the preset number of sub-line segments of the target time line segment, wherein the extension line segment corresponding to the sub-line segment is a line segment obtained by extending the sub-line segment by a preset multiple;
generating a time period mark corresponding to the target time period based on the mark corresponding to the target time line segment and the sub-mark corresponding to the target sub-line segment;
and storing the time period mark and the time period data to be stored into a target database in an associated manner.
2. The method of claim 1, wherein the determining, from a preset sequence of timeline segments, a timeline segment to which a time start of the target time period belongs as a target timeline segment comprises:
performing difference calculation on the time starting point of the target time period and the time starting point of the time period indicated by the time line segment arranged at the head of the time line segment sequence to obtain a difference calculation result;
carrying out quotient calculation on the difference calculation result and the time span corresponding to the time line segment to obtain a quotient calculation result;
and selecting the time line segment arranged at the position indicated by the quotient finding result from the time line segment sequence as a target time line segment.
3. The method of claim 1, wherein the preset number of sub-segments of a timeline segment is obtained by:
taking the time line segment as an initial sub-line segment, and executing the following dividing steps: dividing the initial sub-line segment into two sub-line segments by taking the central position of the initial sub-line segment as a reference; determining whether the number of the sub-line segments is a preset number; obtaining a preset number of sub-line segments in response to the preset number;
and in response to the number not being the preset number, taking the latest obtained sub-line segment as an initial sub-line segment, and continuing to execute the dividing step.
4. The method of claim 1, wherein the determining, from the preset number of sub-segments of the target time line segment, the sub-segment whose time period indicated by the corresponding extension line segment includes the target time period as a target sub-segment comprises:
and in response to that the time period indicated by the extension line segments corresponding to at least two sub-line segments in the preset number of sub-line segments of the target time line segment contains the target time period, selecting the sub-line segment with the shortest length from the at least two sub-line segments as the target sub-line segment.
5. The method according to one of claims 1 to 4, wherein the target database is a non-relational database.
6. A method for querying data, comprising:
acquiring a query time period for querying time period data and a target database, wherein the target database is the target database described in one of the above claims 1 to 5;
determining a time line segment for querying time segment data from a time line segment sequence as a query line segment based on the time starting point and the time ending point of the query time segment;
for the obtained query line segment, the following steps are performed: determining whether an intersection exists between a time period indicated by an extension line segment corresponding to the sub-line segment and the query time period for the sub-line segment in a preset number of sub-line segments included in the query line segment; in response to the intersection being present, determining the sub-line segment as a query sub-line segment; generating a query time segment mark corresponding to the query time segment based on the mark corresponding to the query line segment and the sub-mark corresponding to the query sub-line segment;
and acquiring time period data corresponding to the generated query time period mark from the target database.
7. An apparatus for storing data, comprising:
a first acquisition unit configured to acquire a time period corresponding to time period data to be stored as a target time period;
the first determining unit is configured to determine a time segment to which a time starting point of the target time segment belongs from a preset time segment sequence as a target time segment, wherein the time segments in the time segment sequence are used for indicating time segments with the same time span, the time segment indicated by the target time segment comprises the time starting point, the time segments in the time segment sequence correspond to marks in a preset mark set, the time segment comprises a preset number of sub-segments obtained by dividing the time segment in a preset manner, and the preset number of sub-segments corresponds to a preset number of sub-marks;
the second determining unit is configured to determine, from a preset number of sub-line segments of the target time line segment, a sub-line segment, which includes the target time segment, in the time segment indicated by the corresponding extension line segment as a target sub-line segment, wherein the extension line segment corresponding to the sub-line segment is a line segment obtained by extending the sub-line segment by a preset multiple;
a generating unit configured to generate a time period mark corresponding to the target time period based on a mark corresponding to the target time line segment and a sub-mark corresponding to the target sub-line segment;
and the storage unit is configured to store the time period mark and the to-be-stored time period data into a target database in an associated manner.
8. An apparatus for querying data, comprising:
a second acquiring unit configured to acquire a query time zone for querying the time zone data and a target database, wherein the target database is the target database described in one of the above claims 1 to 5;
a third determination unit configured to determine a time segment for querying time segment data from a time segment sequence as a query segment based on a time start point and a time end point of the query time segment;
an execution unit configured to perform, for the obtained query line segment, the steps of: determining whether an intersection exists between a time period indicated by an extension line segment corresponding to the sub-line segment and the query time period for the sub-line segment in a preset number of sub-line segments included in the query line segment; in response to the intersection being present, determining the sub-line segment as a query sub-line segment; generating a query time segment mark corresponding to the query time segment based on the mark corresponding to the query line segment and the sub-mark corresponding to the query sub-line segment;
and the third acquisition unit is configured to acquire the time period data corresponding to the generated query time period mark from the target database.
9. An electronic device, comprising:
one or more processors;
a storage device having one or more programs stored thereon,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-6.
10. A computer-readable medium, on which a computer program is stored which, when being executed by a processor, carries out the method according to any one of claims 1-6.
CN201910924829.3A 2019-09-27 2019-09-27 Method and device for storing data and method and device for querying data Active CN110704507B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910924829.3A CN110704507B (en) 2019-09-27 2019-09-27 Method and device for storing data and method and device for querying data

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910924829.3A CN110704507B (en) 2019-09-27 2019-09-27 Method and device for storing data and method and device for querying data

Publications (2)

Publication Number Publication Date
CN110704507A CN110704507A (en) 2020-01-17
CN110704507B true CN110704507B (en) 2020-09-29

Family

ID=69196849

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910924829.3A Active CN110704507B (en) 2019-09-27 2019-09-27 Method and device for storing data and method and device for querying data

Country Status (1)

Country Link
CN (1) CN110704507B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112307017A (en) * 2020-09-16 2021-02-02 北京沃东天骏信息技术有限公司 Data storage method, query method, related equipment and storage medium
CN113779077B (en) * 2021-09-28 2024-06-18 京东城市(北京)数字科技有限公司 Time period query method, device, electronic equipment and storage medium

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP2639709B1 (en) * 2012-03-13 2019-05-22 Ricoh Company, Ltd. Method and system for storing and retrieving data
CN104699816B (en) * 2015-03-25 2017-12-12 成都华迈通信技术有限公司 A kind of data processing method and device
CN106649358A (en) * 2015-10-30 2017-05-10 北京国双科技有限公司 Data acquisition method and apparatus

Also Published As

Publication number Publication date
CN110704507A (en) 2020-01-17

Similar Documents

Publication Publication Date Title
CN109299348B (en) Data query method and device, electronic equipment and storage medium
US20130054647A1 (en) Information processing apparatus, information processing method, and program
CN110619078B (en) Method and device for pushing information
CN107257379B (en) Method and device for pushing information
CN110704507B (en) Method and device for storing data and method and device for querying data
CN111950857A (en) Index system management method and device based on service indexes and electronic equipment
CN109992719B (en) Method and apparatus for determining push priority information
CN115168362A (en) Data processing method and device, readable medium and electronic equipment
CN111273830A (en) Data display method and device, electronic equipment and computer readable medium
CN111694629A (en) Information display method and device and electronic equipment
CN110895591B (en) Method and device for positioning self-lifting point
CN107291923B (en) Information processing method and device
CN114116247A (en) Redis-based message processing method, device, system, server and medium
CN112148744A (en) Page display method and device, electronic equipment and computer readable medium
CN110765238A (en) Data encryption query method and device
CN115495519A (en) Report data processing method and device
CN111338621B (en) Method, apparatus, electronic device and computer readable medium for displaying data
CN111552715B (en) User query method and device
CN113992989A (en) Content display method, device, system, equipment and storage medium
CN111294657A (en) Information processing method and device
CN113971195A (en) Data synchronization method, device, electronic equipment and medium
CN111177588A (en) Interest point retrieval method and device
CN111294321B (en) Information processing method and device
CN112486991B (en) Database report processing method and device and electronic equipment
CN111294611B (en) Video insertion method and device, electronic equipment and computer readable storage 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
GR01 Patent grant
GR01 Patent grant