假设我在JAVA中有以下模型
class Shape {
String type;
String color;
String size;
}假设我有以下基于上述模型的数据。
Triangle, Blue, Small
Triangle, Red, Large
Circle, Blue, Small
Circle, Blue, Medium
Square, Green, Medium
Star, Blue, Large我想回答以下问题
Given the type Circle how many unique colors?
Answer: 1
Given the type Circle how many unique sizes?
Answer: 2
Given the color Blue how many unique shapes?
Answer: 2
Given the color Blue how many unique sizes?
Answer: 3
Given the size Small how many unique shapes?
Answer: 2
Given the size Small how many unique colors?
Answer: 1我想知道我是否应该用以下的方式.
set: shapes -> key: type -> bin(s): list of colors, list of sizes
set: colors -> key: color -> bin(s): list of shapes, list of sizes
set: sizes -> key: size -> bin(s): list of shapes, list of colors还是有更好的方法来做这件事?如果我这样做,我需要3倍的存储空间。
我还希望每组都有数十亿个条目。顺便说一下,模型已被修改,以保护固有的代码;)
发布于 2015-10-06 22:46:56
NoSQL中的数据建模总是关于您计划如何检索数据、在什么吞吐量和在什么延迟时。
有几种方法可以对这些数据进行建模;最简单的方法是模拟每个字段都变成Bin的类结构。您可以在每个回收站上定义辅助索引,并使用聚合查询回答您的问题(上面)。
但这只是一种方法;您可能需要使用不同的数据模型来满足延迟和吞吐量的因素。
https://stackoverflow.com/questions/32957002
复制相似问题