存储数据并通过元数据搜索?

发布于 2024-07-30 03:39:58 字数 342 浏览 2 评论 0原文

假设我有一组数据,其中每一行都是一对坐标:(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

离不开的别离 2024-08-06 03:39:58

使用@Dav的模式,获取“[年龄=2且颜色=蓝色的所有坐标行]”的方法是(假设(ID,Key,Value)在元数据表中是唯一的,即后者没有完全重复的行):

SELECT datatable.Data 
  FROM datatable
  JOIN metatadatable AS m USING(ID)
  WHERE (m.Key="age" AND m.Value=2)
     OR (m.Key="color" AND m.Value="blue")
  GROUP BY datatable.ID, datatable.Data
  HAVING COUNT()=2

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):

SELECT datatable.Data 
  FROM datatable
  JOIN metatadatable AS m USING(ID)
  WHERE (m.Key="age" AND m.Value=2)
     OR (m.Key="color" AND m.Value="blue")
  GROUP BY datatable.ID, datatable.Data
  HAVING COUNT()=2
醉酒的小男人 2024-08-06 03:39:58

由于列既不是预定义的,也不是所有行中一致的,因此您必须要么
使用bigtable类型实现,例如google appengine(带listproperty的exapndo模型)或cassandra/hbase等(请参阅http ://en.wikipedia.org/wiki/BigTable

对于使用 sqlite 的简单实现,您可以创建一个格式化为的字符串字段

f1  | f2  | metadata as string
x1  | y1  | cola:val-a1 colb:val-b1 colc:val-c1
x2  | y2  | cola:val-a2 colx:val-x2

and use SELECT * from table WHERE metadata like "%cola:val-a2%"

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

f1  | f2  | metadata as string
x1  | y1  | cola:val-a1 colb:val-b1 colc:val-c1
x2  | y2  | cola:val-a2 colx:val-x2

and use SELECT * from table WHERE metadata like "%cola:val-a2%"
纵山崖 2024-08-06 03:39:58

任何关系数据库都应该能够处理类似的事情(您基本上只是在几个表之间进行联接,一个用于数据,一个用于元数据)。 SQLite 应该可以正常工作。

您的第一个表将包含数据本身以及每个条目的唯一 ID。 然后,您的第二个表将具有 3 个工作列:元数据键、元数据值和关联的条目 ID。

示例数据表:

ID  Data
--------
1   (1,1)
2   (7,4)
3   (2,3)

示例元数据表:

ID     Key         Value
--------------------------
1      "color"     yellow
1      "age"       3
2      "color"     "blue"
2      "age"       2
3      "color"     "blue"
3      "age"       4
3      "loc"       "usa"

然后,如果您想搜索年龄至少为 3 的所有数据点,您可以使用如下查询:

SELECT * from datatable WHERE datatable.ID = metadatatable.ID AND metadatatable.Key="age" AND metadatatable.Value >= 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:

ID  Data
--------
1   (1,1)
2   (7,4)
3   (2,3)

Example metadata table:

ID     Key         Value
--------------------------
1      "color"     yellow
1      "age"       3
2      "color"     "blue"
2      "age"       2
3      "color"     "blue"
3      "age"       4
3      "loc"       "usa"

Then if you wanted to search for all data points with an age of at least 3, you'd use a query like this:

SELECT * from datatable WHERE datatable.ID = metadatatable.ID AND metadatatable.Key="age" AND metadatatable.Value >= 3
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文