scala中使用HBASE的scan方法查询数据

主要是确定startrow以及stoprow来查找特定区间内的数据
   def scanFunc(uuid: String, table: Table): ListBuffer[String] = {
        var result = new ListBuffer[String]
        
        val scan = new Scan()
        
        val filter = new SingleColumnValueExcludeFilter(Bytes.toBytes("cf"), Bytes.toBytes("fsts"), CompareFilter.CompareOp.EQUAL, Bytes.toBytes("3"))
        
        scan.addFamily(Bytes.toBytes("cf"))

        scan.setStartRow(Bytes.toBytes(uuid + "0000000000000000"))
        scan.setStopRow(Bytes.toBytes(uuid + "ffffffffffffffff"))
        
        scan.setFilter(filter)
        
        var  scanner1: ResultScanner = null
        
        try{
          scanner1 = table.getScanner(scan)
          val it: util.Iterator[Result] = scanner1.iterator()
          while (it.hasNext) {
            val next: Result = it.next()
            val v = Bytes.toString(next.getValue(Bytes.toBytes("cf"), Bytes.toBytes("fid")))
            result.append(v)
          }
    
        }catch {
          case e: IOException => println(e)
        }
        finally {
          if(scanner1 != null) {
            scanner1.close()
          }
        }
        return result
      }



版权声明:本文为EnterPine原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。