gpt4 book ai didi

java - HBase 扫描时间范围在 Scala 中不起作用

转载 作者:可可西里 更新时间:2023-11-01 14:52:28 25 4
gpt4 key购买 nike

我编写 scala 代码来根据时间范围检索数据。这是我的代码:

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 的所有数据。

我希望它与 Hbase Shell 中的以下查询相同:

scan 'tm_movie', { TIMERANGE => [1470387596203,1470387596204] }

有什么想法吗?

最佳答案

我通过 Fix its Iterator 找到了解决方案,这是我的代码:

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)
}

}
}

关于java - HBase 扫描时间范围在 Scala 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38887556/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com