简体   繁体   English

UNIX时间戳是行键的一部分时,如何扫描hbase表?

[英]how to scan hbase table when unix timestamp is part of the rowkey?

we have hbase table with row key as AccountId and unixtimestamp. 我们有hbase表,其行键为AccountId和unixtimestamp。

eg: ACNTID1359694800000 例如: ACNTID1359694800000

Account Id: ACNTID
unixtimestamp: 1359694800000

1359694800000 is the value for 2/1/2013 13596948000001359694800000的值

I am looking for a query for Account Ids on a give date? 我在寻找给定日期的帐户ID的查询? can i use startrow, stop row logic. 我可以使用startrow,停止行逻辑。 Any other ways? 还有其他方法吗?

You are on the right track. 您走在正确的轨道上。 The startrow is inclusive and the end row is exclusive. 起始行是包含在内的,最后一行是专有的。 So just add 1 to the unix timestamp on the end row and you are set. 因此,只需在末行的Unix时间戳上添加1,就可以设置好了。

scan 'mytable', {STARTROW => 'ACNTID1359694800000', ENDROW => 'ACNTID1359694800001'}

Your rowkey structure doesn't support getting account id's for any given unix timestamp, since the timestamp in your case is in the righter most part of the rowkey or atleast not using STARTROW & STOPROW alone. 您的rowkey结构不支持获取任何给定的unix时间戳的帐户ID,因为在您的情况下,时间戳位于rowkey的最右侧,或者至少不单独使用STARTROW和STOPROW。 To get the desired result, your query should scan all rowkeys of the table and do the filtering for the given timestamp . 为了获得所需的结果,您的查询应扫描表的所有行键,并针对给定的timestamp进行过滤。 HBase comes with a Filter called RowFilter , used along with Scan , to restrict the rows returned by HBase. HBase带有一个名为RowFilter的过滤器,与Scan一起使用,以限制HBase返回的行。 Since you store the rowkey as text, you can use SubStringComparator or RegexStringComparator along with the RowFilter . 由于将行键存储为文本,因此可以将SubStringComparatorRegexStringComparatorRowFilter一起使用。 The command line equivalent of this is, 等效于命令行的是,

scan 'table_name', { FILTER =>"RowFilter(=,'substring:1359694800000')"}

The above command will return all rows that has 1359694800000 in their rowkey. 上面的命令将返回其行键中包含1359694800000所有行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM