简体   繁体   中英

OrientDB Time Search Query

In OrientDB I have setup a time series using this use case . However, instead of appending my Vertex as an embedded list to the respective hour I have opted to just create an edge from the hour to the time dependent Vertex.

For arguments sake lets say that each hour has up to 60 time Vertex each identified by a timestamp. This means I can perform the following query to obtain a specific desired Vertex:

SELECT FROM ( SELECT expand( month[5].day[12].hour[0].out() ) FROM Year WHERE year = 2015) WHERE timestamp = 1434146922

The first part of this question is whether there are any advantages/disadvantages to storing the timestamp as a property of the Vertex (as above query) versus storing it as the edge (or an edge property). In which case I think the query would be:

SELECT expand( month[5].day[12].hour[0].out('1434146922') ) FROM Year WHERE year = 2015

Although this looks more elegant I have 2 concerns; the overhead of creating new edge types. The flexibility if you don't actually know the exact timestamp.

The second part of the question relates to the fact that once I have isolated the individual Vertex based on time, this is only the head of a hierarchal tree of Vertex.

I could of course get the @rid from the above query and then construct a new query but I was wondering how I could adapt the above to do it all in one. For example assume there is a boolean property called active in all the hierarchal Vertexes. How can I get all the Vertex that are true ?

Answer for the first part of your question :

Like stated in the use case documentation :

If you need more granularity than the Hour you can go ahead until the Time unit you need:

Hour -> minute (map) -> Minute -> second (map) -> Second

You get more flexibility by adding more precision to the tree instead of storing a timestamp of the time in the hour.

Adding more precision to the tree has the only advantage of being able to group by smaller time unit in a really efficient way. If you don't need to group by a smaller unit then an hour, then you don't have to add more precision.

The timestamp should be stored in the vertex property because the filtering will be easy and efficient. Check out this blog bost to know the best way to filter on a vertex property when traversing : Improved SQL filtering

Answer for the second part of your question :

Get the specific vertex and then do your query on the hiearachical tree of vertex :

<your-hierachical-tree-query> from (select out('edge')[property = "value"] from
(select expand(month[1].day[1].hour[1].min[1]) from Year where year = 2015))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM