加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

数据建模 – Aerospike数据建模和查询

发布时间:2020-12-13 13:28:39 所属栏目:百科 来源:网络整理
导读:可以说我在JAVA中有以下模型 class Shape { String type; String color; String size;} 并说我有以下基于上述模型的数据. Triangle,Blue,SmallTriangle,Red,LargeCircle,SmallCircle,MediumSquare,Green,MediumStar,Large 我想回答以下问题 Given the type C
可以说我在JAVA中有以下模型

class Shape {
    String type;
    String color;
    String size;
}

并说我有以下基于上述模型的数据.

Triangle,Blue,Small
Triangle,Red,Large
Circle,Small
Circle,Medium
Square,Green,Medium
Star,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倍的存储空间.

我还希望每套都有数十亿条目.顺便说一下模型已被编辑以保护inoncent代码;)

解决方法

NoSQL中的数据建模总是关于您计划如何检索数据,吞吐量和延迟.

有几种方法可以对这些数据进行建模;最简单的是模仿每个字段变为Bin的类结构.您可以在每个bin上定义Secondary Indexes并使用Aggregation Queries来回答您的问题(上图).

但这只是一种方式;您可能需要使用不同的数据模型来满足延迟和吞吐量的因素.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读