存储数据并通过元数据搜索?
假设我有一组数据,其中每一行都是一对坐标:(X, Y)。 与每个点相关联的是任意元数据,例如 {color: Yellow}
或 {age: 2 年}
。
我希望能够以可以查询元数据的方式存储数据和元数据(例如:[rows where {age: 2 年,颜色:黄色}]
)并在返回接收所有匹配的坐标行。
没有预定义的元数据列或值,所有坐标行也不一定具有相同的元数据列。 存储这些数据以实现最快访问的最佳方式是什么? 是否可以使用 Tokyo Cabinet(没有 Tokyo Tyrant)或 SQLite 之类的东西,或者是否有更好的选择?
Let's say I have a set of data where each row is a pair of coordinates: (X, Y). Associated with each point I have arbitrary metadata, such as {color: yellow}
or {age: 2 years}
.
I'd like to be able to store the data and metadata in such a way that I can query the metadata (eg: [rows where {age: 2 years, color: yellow}]
) and in return receive all of the matching coordinate rows.
There are no predefined metadata columns or values, nor will all coordinate rows necessarily have the same metadata columns. What would be the best way to store this data for the fastest access? Would it be possible using something such as Tokyo Cabinet (without Tokyo Tyrant) or SQLite, or is there a better option?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用@Dav的模式,获取“[年龄=2且颜色=蓝色的所有坐标行]”的方法是(假设(ID,Key,Value)在元数据表中是唯一的,即后者没有完全重复的行):
Using @Dav's schema, a way to get " [all coordinate rows where age=2 and color=blue] " is (assuming (ID, Key, Value) is Unique in metadatatable, i.e., the latter has no entirely duplicate rows):
由于列既不是预定义的,也不是所有行中一致的,因此您必须要么
使用bigtable类型实现,例如google appengine(带listproperty的exapndo模型)或cassandra/hbase等(请参阅http ://en.wikipedia.org/wiki/BigTable)
对于使用 sqlite 的简单实现,您可以创建一个格式化为的字符串字段
Since the columns are neither predefined nor consistent across all rows you have to either go
with bigtable type implementations such as google appengine (exapndo models w/listproperty) or cassandra/hbase etc. (see http://en.wikipedia.org/wiki/BigTable)
For simple implementations using sqlite you could create a string field formatted as
任何关系数据库都应该能够处理类似的事情(您基本上只是在几个表之间进行联接,一个用于数据,一个用于元数据)。 SQLite 应该可以正常工作。
您的第一个表将包含数据本身以及每个条目的唯一 ID。 然后,您的第二个表将具有 3 个工作列:元数据键、元数据值和关联的条目 ID。
示例数据表:
示例元数据表:
然后,如果您想搜索年龄至少为 3 的所有数据点,您可以使用如下查询:
Any relational database should be able to handle something like that (you'd basically just being doing a join between a couple of tables, one for the data and one for the metadata). SQLite should work fine.
Your first table would have the data itself with a unique IDs for each entry. Then your second table would have something like 3 working columns: metadata key, metadata value, and associated entry id.
Example data table:
Example metadata table:
Then if you wanted to search for all data points with an age of at least 3, you'd use a query like this: