public long getLastTimestamp() { return this.result.getStopTimestamp(); } }
@Override public List<GroupbyKeyValue> read() throws IOException { return this.result.getKeyValues(); }
public long getFirstTimestamp() { return this.result.getStartTimestamp(); }
@Test public void testAggregateResultTimestamp() { AggregateResult result1 = new AggregateResult(); result1.setStartTimestamp(2L); result1.setStopTimestamp(4L); AggregateResult result2 = new AggregateResult(); result2.setStartTimestamp(1L); result2.setStopTimestamp(3L); AggregateResultCallback callback = new AggregateResultCallbackImpl(new ArrayList<AggregateFunctionType>()); callback.update(null, null, result1); callback.update(null, null, result2); AggregateResult result3 = callback.result(); Assert.assertEquals(1L, result3.getStartTimestamp()); Assert.assertEquals(4L, result3.getStopTimestamp()); }
@Override public void aggregate(RpcController controller, AggregateProtos.AggregateRequest request, RpcCallback<AggregateProtos.AggregateResult> done) { AggregateResult result = null; try { result = this.aggregate(ProtoBufConverter.fromPBEntityDefinition(request.getEntityDefinition()), ProtoBufConverter.fromPBScan(request.getScan()), ProtoBufConverter.fromPBStringList(request.getGroupbyFieldsList()), ProtoBufConverter.fromPBByteArrayList(request.getAggregateFuncTypesList()), ProtoBufConverter.fromPBStringList(request.getAggregatedFieldsList()) ); } catch (IOException e) { ResponseConverter.setControllerException(controller, e); } try { done.run(ProtoBufConverter.toPBAggregateResult(result)); } catch (IOException e) { throw new RuntimeException("Failed to convert result to PB-based message", e); } }
public void update(byte[] region, byte[] row, AggregateResult result) { AggregateResult _result = result; regionCounter ++; kvCounter += _result.getKeyValues().size(); if(this.startTimestamp == 0 || this.startTimestamp > _result.getStartTimestamp()){ this.startTimestamp = _result.getStartTimestamp(); } if(this.stopTimestamp == 0 || this.stopTimestamp < _result.getStopTimestamp()){ this.stopTimestamp = _result.getStopTimestamp(); } for(GroupbyKeyValue keyValue:_result.getKeyValues()){ update(keyValue); } }
@Test public void testGroupTimeSeriesAggMaxClient() { try { List<GroupbyKeyValue> result = client.aggregate(table, ed, scan, Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.max), Arrays.asList("field2"), true, startTime, System.currentTimeMillis(), 10).getKeyValues(); if (LOG.isDebugEnabled()) LOG.debug("MAX"); logGroupbyKeyValue(result); Assert.assertNotNull(result); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } }
public static AggregateResult fromPBResult(AggregateProtos.AggregateResult pbResult) throws IOException { ByteArrayDataInput byteArrayDataInput = ByteStreams.newDataInput(pbResult.getByteArray().toByteArray()); ; AggregateResult result = new AggregateResult(); result.readFields(byteArrayDataInput); return result; }
@Override protected void onOpen(HTableInterface tbl, Scan scan) throws IOException { this.result = this.aggregateClient.aggregate( tbl, this.ed, scan, this.aggregateCondition.getGroupbyFields(), this.aggregateCondition.getAggregateFunctionTypes(), this.aggregateCondition.getAggregateFields(), this.aggregateCondition.isTimeSeries(), this.startTime, this.endTime, this.aggregateCondition.getIntervalMS()); }
@Override public void aggregate(RpcController controller, AggregateProtos.AggregateRequest request, RpcCallback<AggregateProtos.AggregateResult> done) { AggregateResult result = null; try { result = this.aggregate(ProtoBufConverter.fromPBEntityDefinition(request.getEntityDefinition()), ProtoBufConverter.fromPBScan(request.getScan()), ProtoBufConverter.fromPBStringList(request.getGroupbyFieldsList()), ProtoBufConverter.fromPBByteArrayList(request.getAggregateFuncTypesList()), ProtoBufConverter.fromPBStringList(request.getAggregatedFieldsList()) ); } catch (IOException e) { ResponseConverter.setControllerException(controller, e); } try { done.run(ProtoBufConverter.toPBAggregateResult(result)); } catch (IOException e) { throw new RuntimeException("Failed to convert result to PB-based message",e); } }
public void update(byte[] region, byte[] row, AggregateResult result) { AggregateResult _result = result; regionCounter++; kvCounter += _result.getKeyValues().size(); if (this.startTimestamp == 0 || this.startTimestamp > _result.getStartTimestamp()) { this.startTimestamp = _result.getStartTimestamp(); } if (this.stopTimestamp == 0 || this.stopTimestamp < _result.getStopTimestamp()) { this.stopTimestamp = _result.getStopTimestamp(); } for (GroupbyKeyValue keyValue : _result.getKeyValues()) { update(keyValue); } } }
@Test public void testGroupTimeSeriesAggMinClient() { try { List<GroupbyKeyValue> result = client.aggregate(table, ed, scan, Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.min), Arrays.asList("field2"), true, startTime, System.currentTimeMillis(), 10).getKeyValues(); if (LOG.isDebugEnabled()) LOG.debug("MIN"); logGroupbyKeyValue(result); Assert.assertNotNull(result); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } }
public static AggregateResult fromPBResult(AggregateProtos.AggregateResult pbResult) throws IOException { ByteArrayDataInput byteArrayDataInput = ByteStreams.newDataInput(pbResult.getByteArray().toByteArray());; AggregateResult result = new AggregateResult(); result.readFields(byteArrayDataInput); return result; }
public long getLastTimestamp() { return this.result.getStopTimestamp(); } }
@Override public List<GroupbyKeyValue> read() throws IOException { return this.result.getKeyValues(); }
public long getFirstTimestamp() { return this.result.getStartTimestamp(); }
@Override protected void onOpen(HTableInterface tbl, Scan scan) throws IOException { this.result = this.aggregateClient.aggregate( tbl, this.ed, scan, this.aggregateCondition.getGroupbyFields(), this.aggregateCondition.getAggregateFunctionTypes(), this.aggregateCondition.getAggregateFields(), this.aggregateCondition.isTimeSeries(), this.startTime, this.endTime, this.aggregateCondition.getIntervalMS()); }
@Test public void testGroupTimeSeriesAggCountClient() { try { List<GroupbyKeyValue> result = client.aggregate(table, ed, scan, Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("count"), true, startTime, System.currentTimeMillis(), 10).getKeyValues(); if (LOG.isDebugEnabled()) LOG.debug("COUNT"); logGroupbyKeyValue(result); Assert.assertNotNull(result); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } }
@Test public void testGroupTimeSeriesAggSumClient() { try { List<GroupbyKeyValue> result = client.aggregate(table, ed, scan, Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("field2"), true, startTime, System.currentTimeMillis(), 10).getKeyValues(); if (LOG.isDebugEnabled()) LOG.debug("SUM"); logGroupbyKeyValue(result); Assert.assertNotNull(result); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } }
@Test public void testGroupTimeSeriesAggAvgClient() { try { List<GroupbyKeyValue> result = client.aggregate(table, ed, scan, Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.min), Arrays.asList("field2"), true, startTime, System.currentTimeMillis(), 10).getKeyValues(); if (LOG.isDebugEnabled()) LOG.debug("MIN"); logGroupbyKeyValue(result); Assert.assertNotNull(result); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } }