用scala

时间:2016-10-17 20:42:14

标签: scala accumulo

我在accumulo命名记录中有一个表,每个row_id都有几个系列和限定符,在accumulo shell中看起来像这样。

michaelp@accumulo records> scan
2016-10-17 16:27:55,359 [Shell.audit] INFO : michaelp@accumulo records> scan
E001 department:sales []    0
E001 hire_date:20160101 []    0
E001 name:bob []    0
E001 name:jerry []    0
E002 department:marketing []    0
E002 hire_date:20160202 []    0
E002 name:sarah []    0
E003 department:engineering []    0
E003 hire_date:20160303 []    0
E003 name:joe []    0

我希望能够使用scala连接器扫描这几行。在需要导入之后,我的代码如下所示:

var opts = new ClientOnRequiredTable()
var bsOpts = new BatchScannerOpts()
opts.parseArgs("test", Array("-t", "records","-u", "michaelp", "-p", "****", "-z", "zookeeper:2181", "-i", "accumulo"), bsOpts)
var connector = opts.getConnector()
var batchReader = connector.createBatchScanner("records", opts.auths, bsOpts.scanThreads)
batchReader.setTimeout(bsOpts.scanTimeout, TimeUnit.MILLISECONDS)
var x = new Range()  
var y = new LinkedList[Range]
y.add(x)
batchReader.setRanges(y)

我传入一个空范围来获取表格中的每一行。问题是当我尝试迭代结果时。它坚持第一行。

scala> while (batchReader.iterator.hasNext()) {println(batchReader.iterator.next.getKey().toString())}
E001 department:sales [] 1476720996135 false
E001 department:sales [] 1476720996135 false
E001 department:sales [] 1476720996135 false
E001 department:sales [] 1476720996135 false
E001 department:sales [] 1476720996135 false
E001 department:sales [] 1476720996135 false
E001 department:sales [] 1476720996135 false
E001 department:sales [] 1476720996135 false
E001 department:sales [] 1476720996135 false
E001 department:sales [] 1476720996135 false
E001 department:sales [] 1476720996135 false
E001 department:sales [] 1476720996135 false
E001 department:sales [] 1476720996135 false
E001 department:sales [] 1476720996135 false
E001 department:sales [] 1476720996135 false
E001 department:sales [] 1476720996135 false
...

那么为什么迭代器不会移动?

1 个答案:

答案 0 :(得分:4)

因为当你调用<br>时,每次都会创建新的迭代器。而是做类似下面的事情

batchReader.iterator