HBase扫描时间范围在Scala中不起作用 [英] HBase Scan TimeRange Does not Work in Scala
本文介绍了HBase扫描时间范围在Scala中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写scala代码来根据时间范围检索数据。这里是我的代码:
I write scala code to retrieve data based on its time range. Here're my code :
object Hbase_Scan_TimeRange {
def main(args: Array[String]): Unit = {
//===Basic Hbase (Non Deprecated)===Start
Logger.getLogger(this.getClass)
Logger.getLogger("org").setLevel(Level.ERROR)
BasicConfigurator.configure()
val conf = HBaseConfiguration.create()
val connection = ConnectionFactory.createConnection(conf)
val admin = connection.getAdmin()
//===Basic Hbase (Non Deprecated)===End
val scan = new Scan()
val _min = 1470387596203L
val _max = 1470387596204L
scan.setTimeRange(1470387596203L,1470387596204L)
val table = connection.getTable(TableName.valueOf("tm_movie"))
val scanner = table.getScanner(scan)
var result = scanner.next()
println()
while (result != null ) {
//===start
println(result)
}
}
}
然而,不起作用。它仍然显示来自 tm_movie
的所有数据。
However, it does not work.It still showing all data from tm_movie
.
我预计它会和Hbase Shell中的查询一样:
I am expecting it will same as below query in Hbase Shell :
scan 'tm_movie', { TIMERANGE => [1470387596203,1470387596204] }
任何想法?
推荐答案
我找到了Fix it Iterator的解决方案,这里是我的代码:
I found solution by Fix its Iterator, Here're my code :
object Hbase_Scan_TimeRange {
def main(args: Array[String]): Unit = {
//===Basic Hbase (Non Deprecated)===Start
Logger.getLogger(this.getClass)
Logger.getLogger("org").setLevel(Level.ERROR)
BasicConfigurator.configure()
val conf = HBaseConfiguration.create()
val connection = ConnectionFactory.createConnection(conf)
val admin = connection.getAdmin()
//===Basic Hbase (Non Deprecated)===End
val scans = new Scan()
scans.setMaxVersions(1)
val _min = 1470387596203L
val _max = 1470387596204L
scans.setTimeRange(1470387596203L, 1470387596204L)
val table = connection.getTable(TableName.valueOf("tm_movie"))
val scanner = table.getScanner(scans)
val result = scanner.iterator()
while(result.hasNext)
{
val data = result.next()
val movieId = Bytes.toString(data.getValue(Bytes.toBytes("data"),Bytes.toBytes("movieId")))
val movieName = Bytes.toString(data.getValue(Bytes.toBytes("data"),Bytes.toBytes("movieName")))
val movieGenre = Bytes.toString(data.getValue(Bytes.toBytes("data"),Bytes.toBytes("movieGenre")))
println()
println("movieGenre::"+movieGenre)
println("movieName::"+movieName)
println("movieId::"+movieId)
}
}
}
这篇关于HBase扫描时间范围在Scala中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文