问题描述
在 OrientDB 中,我使用此用例.但是,我没有选择将我的顶点作为嵌入列表附加到相应的小时,而是选择创建从小时到时间依赖的顶点的一条边.
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.
出于争论的缘故,可以说每个小时最多有60个时间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
从用例中可以看到,我可以使用UNION
一次性获得多个指定的时间分支.
I can see from the use case that I can use UNION
to get several specified time branches in one go.
SELECT expand( records ) FROM (
SELECT union( month[3].day[20].hour[10].out(), month[3].day[20].hour[11].out() ) AS records
FROM Year WHERE year = 2015
)
如果您只有很少的分支机构,则此方法很好,但如果要获取给定时间范围内的所有记录,则效果不佳.假设您想获取所有记录之间的记录;
This works fine if you only have a small number of branches but it doesn't work very well if you want to get all the records for a given time span. Say you wanted to get all the records between;
month[3].day[20].hour[11] -> month[3].day[29].hour[23]
我可以遍历时间跨度并创建一个巨大的联合查询,但是在某些时候,我认为查询会太长,而且我猜想它不会很有效.我还可以完全绕开时间分支,并根据时间戳直接查询向量.
I could iterate through the timespan and create a huge union query but at some point I guess the query would be too long and my guess is that it wouldn't be very efficient. I could also completely bypass the time branches and query the Vectors directly based on the timestamp.
SELECT FROM Sector WHERE timestamp BETWEEN 1406588622 AND 1406588624
问题是您失去了时间分支所获得的所有效率.
The problem being that you loose all efficiencies gained by the time branches.
推荐答案
通过试验和阅读有关orientdb中数据类型的知识,我发现:
By experimenting and reading a bit about data types in orientdb, I found that :
方括号允许:
- 按一个索引过滤,例如out()[0]
- 通过多个索引过滤,例如out()[0,2,4]
- 按范围过滤,例如out()[0-9]
选项1(更新):
如果您不想创建所有索引并且范围很小,则唯一的选择是使用工会在多个时间加入. 此处是文档中使用联合的查询示例.
Using a union to join on multiple time is the only option if you don't want to create all indexes and if your range is small. Here is a query exemple using union in the documentation.
选项2:
如果始终为您的时间创建所有索引,并且在宽范围内进行过滤,则应按范围进行过滤.与选项1相比,这种方法的性能更高,这是因为必须创建要在其上进行过滤的所有索引. 有关字段部分的正式文档.
If you always have all the indexes created for your time and if you filter on wide ranges, you should filter by ranges. This is more performant then option 1 for the cost of having to create all indexes on which you want to filter on. Official documentation about field part.
这是查询的样子:
select
*
from
(
select
expand(hour[0-23].out())
from
(select
expand(month[3].day[20-29])
from
Year
where
year = 2015)
)
where timestamp > 1406588622
我强烈建议阅读此.
这篇关于OrientDB时间跨度搜索查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!