Java如何实现一行存多个值,HBase为Scala / Java API中的同一行键存储具有2个或更多值的特定列的数据...

I have a file with following contents:

UserID Email

1001 abc@yahoo.com

1001 def@gmail.com

1002 gft@gmail.com

1002 rtf@yahoo.com

I want to store the data like this:

ROW COLUMN+CELL

1001 column=cf:Email, timestamp=1487917201278, value=abc@yahoo.com

1001 column=cf:Email, timestamp=1487917201279, value=def@gmail.com

1002 column=cf:Email, timestamp=1487917201286, value=gft@gmail.com

1002 column=cf:Email, timestamp=1487917201287, value=rtf@yahoo.com

I am using Put for example: put 'table', '1001', 'cf:Email', 'def@gmail.com' but it is giving me

ROW COLUMN+CELL

1001 column=cf:Email, timestamp=1487917201279, value=def@gmail.com

1002 column=cf:Email, timestamp=1487917201286, value=rtf@yahoo.com

It is overriding the previous value. But HBase supposed to store multiple values for a particular column based on timestamp.

Is there anyway that I can store both email addresses for particular UserID?

解决方案

You may want to take a closer look at the HBase documentation on versions. Note especially where it says

By default, i.e. if you specify no explicit version, when doing a get, the cell whose version has the largest value is returned

But I wouldn't pursue using multiple versions to store multiple values this way. You have to explicitly specify the maximum number of versions and it will apply to every column in that family. I would be more inclined to use distinct column names (such as Email1, Email2, ...)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值