1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.coprocessor;
20
21 import static org.junit.Assert.assertEquals;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.hadoop.conf.Configuration;
26 import org.apache.hadoop.hbase.*;
27 import org.apache.hadoop.hbase.client.HTable;
28 import org.apache.hadoop.hbase.client.Put;
29 import org.apache.hadoop.hbase.client.Scan;
30 import org.apache.hadoop.hbase.client.Durability;
31 import org.apache.hadoop.hbase.client.coprocessor.AggregationClient;
32 import org.apache.hadoop.hbase.client.coprocessor.LongColumnInterpreter;
33 import org.apache.hadoop.hbase.filter.Filter;
34 import org.apache.hadoop.hbase.filter.PrefixFilter;
35 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.EmptyMsg;
36 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.LongMsg;
37 import org.apache.hadoop.hbase.testclassification.MediumTests;
38 import org.apache.hadoop.hbase.util.Bytes;
39 import org.junit.AfterClass;
40 import org.junit.BeforeClass;
41 import org.junit.Test;
42 import org.junit.experimental.categories.Category;
43
44
45
46
47
48 @Category(MediumTests.class)
49 public class TestAggregateProtocol {
50 protected static Log myLog = LogFactory.getLog(TestAggregateProtocol.class);
51
52
53
54
55 private static final TableName TEST_TABLE =
56 TableName.valueOf("TestTable");
57 private static final byte[] TEST_FAMILY = Bytes.toBytes("TestFamily");
58 private static final byte[] TEST_QUALIFIER = Bytes.toBytes("TestQualifier");
59 private static final byte[] TEST_MULTI_CQ = Bytes.toBytes("TestMultiCQ");
60
61 private static byte[] ROW = Bytes.toBytes("testRow");
62 private static final int ROWSIZE = 20;
63 private static final int rowSeperator1 = 5;
64 private static final int rowSeperator2 = 12;
65 private static byte[][] ROWS = makeN(ROW, ROWSIZE);
66
67 private static HBaseTestingUtility util = new HBaseTestingUtility();
68 private static Configuration conf = util.getConfiguration();
69
70
71
72
73
74
75 @BeforeClass
76 public static void setupBeforeClass() throws Exception {
77
78 conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
79 "org.apache.hadoop.hbase.coprocessor.AggregateImplementation");
80
81 util.startMiniCluster(2);
82 HTable table = util.createTable(TEST_TABLE, TEST_FAMILY);
83 util.createMultiRegions(util.getConfiguration(), table, TEST_FAMILY,
84 new byte[][] { HConstants.EMPTY_BYTE_ARRAY, ROWS[rowSeperator1],
85 ROWS[rowSeperator2] });
86
87
88
89
90 for (int i = 0; i < ROWSIZE; i++) {
91 Put put = new Put(ROWS[i]);
92 put.setDurability(Durability.SKIP_WAL);
93 Long l = new Long(i);
94 put.add(TEST_FAMILY, TEST_QUALIFIER, Bytes.toBytes(l));
95 table.put(put);
96 Put p2 = new Put(ROWS[i]);
97 put.setDurability(Durability.SKIP_WAL);
98 p2.add(TEST_FAMILY, Bytes.add(TEST_MULTI_CQ, Bytes.toBytes(l)), Bytes
99 .toBytes(l * 10));
100 table.put(p2);
101 }
102 table.close();
103 }
104
105
106
107
108
109 @AfterClass
110 public static void tearDownAfterClass() throws Exception {
111 util.shutdownMiniCluster();
112 }
113
114
115
116
117
118
119
120 private static byte[][] makeN(byte[] base, int n) {
121 byte[][] ret = new byte[n][];
122 for (int i = 0; i < n; i++) {
123 ret[i] = Bytes.add(base, Bytes.toBytes(i));
124 }
125 return ret;
126 }
127
128
129
130
131
132
133
134 @Test (timeout=300000)
135 public void testMedianWithValidRange() throws Throwable {
136 AggregationClient aClient = new AggregationClient(conf);
137 Scan scan = new Scan();
138 scan.addColumn(TEST_FAMILY,TEST_QUALIFIER);
139 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
140 new LongColumnInterpreter();
141 long median = aClient.median(TEST_TABLE, ci,
142 scan);
143 assertEquals(8L, median);
144 }
145
146
147
148
149
150
151
152
153
154
155 @Test (timeout=300000)
156 public void testRowCountWithValidRange() throws Throwable {
157 AggregationClient aClient = new AggregationClient(conf);
158 Scan scan = new Scan();
159 scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
160 scan.setStartRow(ROWS[2]);
161 scan.setStopRow(ROWS[14]);
162 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
163 new LongColumnInterpreter();
164 long rowCount = aClient.rowCount(TEST_TABLE, ci, scan);
165 assertEquals(12, rowCount);
166 }
167
168
169
170
171
172
173 @Test (timeout=300000)
174 public void testRowCountAllTable() throws Throwable {
175 AggregationClient aClient = new AggregationClient(conf);
176 Scan scan = new Scan();
177 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
178 new LongColumnInterpreter();
179 long rowCount = aClient.rowCount(TEST_TABLE, ci,
180 scan);
181 assertEquals(ROWSIZE, rowCount);
182 }
183
184
185
186
187
188
189 @Test (timeout=300000)
190 public void testRowCountWithInvalidRange1() {
191 AggregationClient aClient = new AggregationClient(conf);
192 Scan scan = new Scan();
193 scan.setStartRow(ROWS[5]);
194 scan.setStopRow(ROWS[2]);
195
196 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
197 new LongColumnInterpreter();
198 long rowCount = -1;
199 try {
200 rowCount = aClient.rowCount(TEST_TABLE, ci, scan);
201 } catch (Throwable e) {
202 myLog.error("Exception thrown in the invalidRange method"
203 + e.getStackTrace());
204 }
205 assertEquals(-1, rowCount);
206 }
207
208
209
210
211
212
213 @Test (timeout=300000)
214 public void testRowCountWithInvalidRange2() {
215 AggregationClient aClient = new AggregationClient(conf);
216 Scan scan = new Scan();
217 scan.setStartRow(ROWS[5]);
218 scan.setStopRow(ROWS[5]);
219
220 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
221 new LongColumnInterpreter();
222 long rowCount = -1;
223 try {
224 rowCount = aClient.rowCount(TEST_TABLE, ci, scan);
225 } catch (Throwable e) {
226 rowCount = 0;
227 }
228 assertEquals(0, rowCount);
229 }
230
231 @Test (timeout=300000)
232 public void testRowCountWithNullCQ() throws Throwable {
233 AggregationClient aClient = new AggregationClient(conf);
234 Scan scan = new Scan();
235 scan.addFamily(TEST_FAMILY);
236 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
237 new LongColumnInterpreter();
238 long rowCount = aClient.rowCount(TEST_TABLE, ci,
239 scan);
240 assertEquals(20, rowCount);
241 }
242
243 @Test (timeout=300000)
244 public void testRowCountWithPrefixFilter() throws Throwable {
245 AggregationClient aClient = new AggregationClient(conf);
246 Scan scan = new Scan();
247 scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
248 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
249 new LongColumnInterpreter();
250 Filter f = new PrefixFilter(Bytes.toBytes("foo:bar"));
251 scan.setFilter(f);
252 long rowCount = aClient.rowCount(TEST_TABLE, ci,
253 scan);
254 assertEquals(0, rowCount);
255 }
256
257
258
259
260
261
262
263
264
265 @Test (timeout=300000)
266 public void testMaxWithValidRange() throws Throwable {
267 AggregationClient aClient = new AggregationClient(conf);
268 Scan scan = new Scan();
269 scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
270 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
271 new LongColumnInterpreter();
272 long maximum = aClient.max(TEST_TABLE, ci, scan);
273 assertEquals(19, maximum);
274 }
275
276
277
278
279 @Test (timeout=300000)
280 public void testMaxWithValidRange2() throws Throwable {
281 AggregationClient aClient = new AggregationClient(conf);
282 Scan scan = new Scan();
283 scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
284 scan.setStartRow(ROWS[5]);
285 scan.setStopRow(ROWS[15]);
286 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
287 new LongColumnInterpreter();
288 long max = aClient.max(TEST_TABLE, ci, scan);
289 assertEquals(14, max);
290 }
291
292 @Test (timeout=300000)
293 public void testMaxWithValidRangeWithNoCQ() throws Throwable {
294 AggregationClient aClient = new AggregationClient(conf);
295 Scan scan = new Scan();
296 scan.addFamily(TEST_FAMILY);
297 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
298 new LongColumnInterpreter();
299 long maximum = aClient.max(TEST_TABLE, ci, scan);
300 assertEquals(190, maximum);
301 }
302
303 @Test (timeout=300000)
304 public void testMaxWithValidRange2WithNoCQ() throws Throwable {
305 AggregationClient aClient = new AggregationClient(conf);
306 Scan scan = new Scan();
307 scan.addFamily(TEST_FAMILY);
308 scan.setStartRow(ROWS[6]);
309 scan.setStopRow(ROWS[7]);
310 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
311 new LongColumnInterpreter();
312 long max = aClient.max(TEST_TABLE, ci, scan);
313 assertEquals(60, max);
314 }
315
316 @Test (timeout=300000)
317 public void testMaxWithValidRangeWithNullCF() {
318 AggregationClient aClient = new AggregationClient(conf);
319 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
320 new LongColumnInterpreter();
321 Scan scan = new Scan();
322 Long max = null;
323 try {
324 max = aClient.max(TEST_TABLE, ci, scan);
325 } catch (Throwable e) {
326 max = null;
327 }
328 assertEquals(null, max);
329
330 }
331
332 @Test (timeout=300000)
333 public void testMaxWithInvalidRange() {
334 AggregationClient aClient = new AggregationClient(conf);
335 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
336 new LongColumnInterpreter();
337 Scan scan = new Scan();
338 scan.setStartRow(ROWS[4]);
339 scan.setStopRow(ROWS[2]);
340 scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
341 long max = Long.MIN_VALUE;
342 try {
343 max = aClient.max(TEST_TABLE, ci, scan);
344 } catch (Throwable e) {
345 max = 0;
346 }
347 assertEquals(0, max);
348 }
349
350 @Test (timeout=300000)
351 public void testMaxWithInvalidRange2() throws Throwable {
352 long max = Long.MIN_VALUE;
353 Scan scan = new Scan();
354 scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
355 scan.setStartRow(ROWS[4]);
356 scan.setStopRow(ROWS[4]);
357 try {
358 AggregationClient aClient = new AggregationClient(conf);
359 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
360 new LongColumnInterpreter();
361 max = aClient.max(TEST_TABLE, ci, scan);
362 } catch (Exception e) {
363 max = 0;
364 }
365 assertEquals(0, max);
366 }
367
368 @Test (timeout=300000)
369 public void testMaxWithFilter() throws Throwable {
370 Long max = 0l;
371 AggregationClient aClient = new AggregationClient(conf);
372 Scan scan = new Scan();
373 scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
374 Filter f = new PrefixFilter(Bytes.toBytes("foo:bar"));
375 scan.setFilter(f);
376 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
377 new LongColumnInterpreter();
378 max = aClient.max(TEST_TABLE, ci, scan);
379 assertEquals(null, max);
380 }
381
382
383
384
385
386
387
388
389 @Test (timeout=300000)
390 public void testMinWithValidRange() throws Throwable {
391 AggregationClient aClient = new AggregationClient(conf);
392 Scan scan = new Scan();
393 scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
394 scan.setStartRow(HConstants.EMPTY_START_ROW);
395 scan.setStopRow(HConstants.EMPTY_END_ROW);
396 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
397 new LongColumnInterpreter();
398 Long min = aClient.min(TEST_TABLE, ci,
399 scan);
400 assertEquals(0l, min.longValue());
401 }
402
403
404
405
406 @Test (timeout=300000)
407 public void testMinWithValidRange2() throws Throwable {
408 AggregationClient aClient = new AggregationClient(conf);
409 Scan scan = new Scan();
410 scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
411 scan.setStartRow(ROWS[5]);
412 scan.setStopRow(ROWS[15]);
413 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
414 new LongColumnInterpreter();
415 long min = aClient.min(TEST_TABLE, ci, scan);
416 assertEquals(5, min);
417 }
418
419 @Test (timeout=300000)
420 public void testMinWithValidRangeWithNoCQ() throws Throwable {
421 AggregationClient aClient = new AggregationClient(conf);
422 Scan scan = new Scan();
423 scan.addFamily(TEST_FAMILY);
424 scan.setStartRow(HConstants.EMPTY_START_ROW);
425 scan.setStopRow(HConstants.EMPTY_END_ROW);
426 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
427 new LongColumnInterpreter();
428 long min = aClient.min(TEST_TABLE, ci,
429 scan);
430 assertEquals(0, min);
431 }
432
433 @Test (timeout=300000)
434 public void testMinWithValidRange2WithNoCQ() throws Throwable {
435 AggregationClient aClient = new AggregationClient(conf);
436 Scan scan = new Scan();
437 scan.addFamily(TEST_FAMILY);
438 scan.setStartRow(ROWS[6]);
439 scan.setStopRow(ROWS[7]);
440 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
441 new LongColumnInterpreter();
442 long min = aClient.min(TEST_TABLE, ci, scan);
443 assertEquals(6, min);
444 }
445
446 @Test (timeout=300000)
447 public void testMinWithValidRangeWithNullCF() {
448 AggregationClient aClient = new AggregationClient(conf);
449 Scan scan = new Scan();
450 scan.setStartRow(ROWS[5]);
451 scan.setStopRow(ROWS[15]);
452 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
453 new LongColumnInterpreter();
454 Long min = null;
455 try {
456 min = aClient.min(TEST_TABLE, ci, scan);
457 } catch (Throwable e) {
458 }
459 assertEquals(null, min);
460
461 }
462
463 @Test (timeout=300000)
464 public void testMinWithInvalidRange() {
465 AggregationClient aClient = new AggregationClient(conf);
466 Long min = null;
467 Scan scan = new Scan();
468 scan.addFamily(TEST_FAMILY);
469 scan.setStartRow(ROWS[4]);
470 scan.setStopRow(ROWS[2]);
471 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
472 new LongColumnInterpreter();
473 try {
474 min = aClient.min(TEST_TABLE, ci, scan);
475 } catch (Throwable e) {
476 }
477 assertEquals(null, min);
478 }
479
480 @Test (timeout=300000)
481 public void testMinWithInvalidRange2() {
482 AggregationClient aClient = new AggregationClient(conf);
483 Scan scan = new Scan();
484 scan.addFamily(TEST_FAMILY);
485 scan.setStartRow(ROWS[6]);
486 scan.setStopRow(ROWS[6]);
487 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
488 new LongColumnInterpreter();
489 Long min = null;
490 try {
491 min = aClient.min(TEST_TABLE, ci, scan);
492 } catch (Throwable e) {
493 }
494 assertEquals(null, min);
495 }
496
497 @Test (timeout=300000)
498 public void testMinWithFilter() throws Throwable {
499 AggregationClient aClient = new AggregationClient(conf);
500 Scan scan = new Scan();
501 scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
502 Filter f = new PrefixFilter(Bytes.toBytes("foo:bar"));
503 scan.setFilter(f);
504 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
505 new LongColumnInterpreter();
506 Long min = null;
507 min = aClient.min(TEST_TABLE, ci, scan);
508 assertEquals(null, min);
509 }
510
511
512
513
514
515
516
517 @Test (timeout=300000)
518 public void testSumWithValidRange() throws Throwable {
519 AggregationClient aClient = new AggregationClient(conf);
520 Scan scan = new Scan();
521 scan.addColumn(TEST_FAMILY,TEST_QUALIFIER);
522 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
523 new LongColumnInterpreter();
524 long sum = aClient.sum(TEST_TABLE, ci,
525 scan);
526 assertEquals(190, sum);
527 }
528
529
530
531
532 @Test (timeout=300000)
533 public void testSumWithValidRange2() throws Throwable {
534 AggregationClient aClient = new AggregationClient(conf);
535 Scan scan = new Scan();
536 scan.addColumn(TEST_FAMILY,TEST_QUALIFIER);
537 scan.setStartRow(ROWS[5]);
538 scan.setStopRow(ROWS[15]);
539 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
540 new LongColumnInterpreter();
541 long sum = aClient.sum(TEST_TABLE, ci, scan);
542 assertEquals(95, sum);
543 }
544
545 @Test (timeout=300000)
546 public void testSumWithValidRangeWithNoCQ() throws Throwable {
547 AggregationClient aClient = new AggregationClient(conf);
548 Scan scan = new Scan();
549 scan.addFamily(TEST_FAMILY);
550 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
551 new LongColumnInterpreter();
552 long sum = aClient.sum(TEST_TABLE, ci,
553 scan);
554 assertEquals(190 + 1900, sum);
555 }
556
557 @Test (timeout=300000)
558 public void testSumWithValidRange2WithNoCQ() throws Throwable {
559 AggregationClient aClient = new AggregationClient(conf);
560 Scan scan = new Scan();
561 scan.addFamily(TEST_FAMILY);
562 scan.setStartRow(ROWS[6]);
563 scan.setStopRow(ROWS[7]);
564 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
565 new LongColumnInterpreter();
566 long sum = aClient.sum(TEST_TABLE, ci, scan);
567 assertEquals(6 + 60, sum);
568 }
569
570 @Test (timeout=300000)
571 public void testSumWithValidRangeWithNullCF() {
572 AggregationClient aClient = new AggregationClient(conf);
573 Scan scan = new Scan();
574 scan.setStartRow(ROWS[6]);
575 scan.setStopRow(ROWS[7]);
576 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
577 new LongColumnInterpreter();
578 Long sum = null;
579 try {
580 sum = aClient.sum(TEST_TABLE, ci, scan);
581 } catch (Throwable e) {
582 }
583 assertEquals(null, sum);
584
585 }
586
587 @Test (timeout=300000)
588 public void testSumWithInvalidRange() {
589 AggregationClient aClient = new AggregationClient(conf);
590 Scan scan = new Scan();
591 scan.addFamily(TEST_FAMILY);
592 scan.setStartRow(ROWS[6]);
593 scan.setStopRow(ROWS[2]);
594 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
595 new LongColumnInterpreter();
596 Long sum = null;
597 try {
598 sum = aClient.sum(TEST_TABLE, ci, scan);
599 } catch (Throwable e) {
600 }
601 assertEquals(null, sum);
602 }
603
604 @Test (timeout=300000)
605 public void testSumWithFilter() throws Throwable {
606 AggregationClient aClient = new AggregationClient(conf);
607 Filter f = new PrefixFilter(Bytes.toBytes("foo:bar"));
608 Scan scan = new Scan();
609 scan.addFamily(TEST_FAMILY);
610 scan.setFilter(f);
611 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
612 new LongColumnInterpreter();
613 Long sum = null;
614 sum = aClient.sum(TEST_TABLE, ci, scan);
615 assertEquals(null, sum);
616 }
617
618
619
620
621
622
623
624 @Test (timeout=300000)
625 public void testAvgWithValidRange() throws Throwable {
626 AggregationClient aClient = new AggregationClient(conf);
627 Scan scan = new Scan();
628 scan.addColumn(TEST_FAMILY,TEST_QUALIFIER);
629 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
630 new LongColumnInterpreter();
631 double avg = aClient.avg(TEST_TABLE, ci,
632 scan);
633 assertEquals(9.5, avg, 0);
634 }
635
636
637
638
639 @Test (timeout=300000)
640 public void testAvgWithValidRange2() throws Throwable {
641 AggregationClient aClient = new AggregationClient(conf);
642 Scan scan = new Scan();
643 scan.addColumn(TEST_FAMILY,TEST_QUALIFIER);
644 scan.setStartRow(ROWS[5]);
645 scan.setStopRow(ROWS[15]);
646 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
647 new LongColumnInterpreter();
648 double avg = aClient.avg(TEST_TABLE, ci, scan);
649 assertEquals(9.5, avg, 0);
650 }
651
652 @Test (timeout=300000)
653 public void testAvgWithValidRangeWithNoCQ() throws Throwable {
654 AggregationClient aClient = new AggregationClient(conf);
655 Scan scan = new Scan();
656 scan.addFamily(TEST_FAMILY);
657 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
658 new LongColumnInterpreter();
659 double avg = aClient.avg(TEST_TABLE, ci,
660 scan);
661 assertEquals(104.5, avg, 0);
662 }
663
664 @Test (timeout=300000)
665 public void testAvgWithValidRange2WithNoCQ() throws Throwable {
666 AggregationClient aClient = new AggregationClient(conf);
667 Scan scan = new Scan();
668 scan.addFamily(TEST_FAMILY);
669 scan.setStartRow(ROWS[6]);
670 scan.setStopRow(ROWS[7]);
671 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
672 new LongColumnInterpreter();
673 double avg = aClient.avg(TEST_TABLE, ci, scan);
674 assertEquals(6 + 60, avg, 0);
675 }
676
677 @Test (timeout=300000)
678 public void testAvgWithValidRangeWithNullCF() {
679 AggregationClient aClient = new AggregationClient(conf);
680 Scan scan = new Scan();
681 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
682 new LongColumnInterpreter();
683 Double avg = null;
684 try {
685 avg = aClient.avg(TEST_TABLE, ci, scan);
686 } catch (Throwable e) {
687 }
688 assertEquals(null, avg);
689
690 }
691
692 @Test (timeout=300000)
693 public void testAvgWithInvalidRange() {
694 AggregationClient aClient = new AggregationClient(conf);
695 Scan scan = new Scan();
696 scan.addColumn(TEST_FAMILY,TEST_QUALIFIER);
697 scan.setStartRow(ROWS[5]);
698 scan.setStopRow(ROWS[1]);
699 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
700 new LongColumnInterpreter();
701 Double avg = null;
702 try {
703 avg = aClient.avg(TEST_TABLE, ci, scan);
704 } catch (Throwable e) {
705 }
706 assertEquals(null, avg);
707 }
708
709 @Test (timeout=300000)
710 public void testAvgWithFilter() throws Throwable {
711 AggregationClient aClient = new AggregationClient(conf);
712 Scan scan = new Scan();
713 scan.addColumn(TEST_FAMILY,TEST_QUALIFIER);
714 Filter f = new PrefixFilter(Bytes.toBytes("foo:bar"));
715 scan.setFilter(f);
716 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
717 new LongColumnInterpreter();
718 Double avg = null;
719 avg = aClient.avg(TEST_TABLE, ci, scan);
720 assertEquals(Double.NaN, avg, 0);
721 }
722
723
724
725
726
727
728
729 @Test (timeout=300000)
730 public void testStdWithValidRange() throws Throwable {
731 AggregationClient aClient = new AggregationClient(conf);
732 Scan scan = new Scan();
733 scan.addColumn(TEST_FAMILY,TEST_QUALIFIER);
734 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
735 new LongColumnInterpreter();
736 double std = aClient.std(TEST_TABLE, ci,
737 scan);
738 assertEquals(5.766, std, 0.05d);
739 }
740
741
742
743
744 @Test (timeout=300000)
745 public void testStdWithValidRange2() throws Throwable {
746 AggregationClient aClient = new AggregationClient(conf);
747 Scan scan = new Scan();
748 scan.addColumn(TEST_FAMILY,TEST_QUALIFIER);
749 scan.setStartRow(ROWS[5]);
750 scan.setStopRow(ROWS[15]);
751 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
752 new LongColumnInterpreter();
753 double std = aClient.std(TEST_TABLE, ci, scan);
754 assertEquals(2.87, std, 0.05d);
755 }
756
757 @Test (timeout=300000)
758 public void testStdWithValidRangeWithNoCQ() throws Throwable {
759 AggregationClient aClient = new AggregationClient(conf);
760 Scan scan = new Scan();
761 scan.addFamily(TEST_FAMILY);
762 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
763 new LongColumnInterpreter();
764 double std = aClient.std(TEST_TABLE, ci,
765 scan);
766 assertEquals(63.42, std, 0.05d);
767 }
768
769 @Test (timeout=300000)
770 public void testStdWithValidRange2WithNoCQ() throws Throwable {
771 AggregationClient aClient = new AggregationClient(conf);
772 Scan scan = new Scan();
773 scan.addFamily(TEST_FAMILY);
774 scan.setStartRow(ROWS[6]);
775 scan.setStopRow(ROWS[7]);
776 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
777 new LongColumnInterpreter();
778 double std = aClient.std(TEST_TABLE, ci, scan);
779 assertEquals(0, std, 0);
780 }
781
782 @Test (timeout=300000)
783 public void testStdWithValidRangeWithNullCF() {
784 AggregationClient aClient = new AggregationClient(conf);
785 Scan scan = new Scan();
786 scan.setStartRow(ROWS[6]);
787 scan.setStopRow(ROWS[17]);
788 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
789 new LongColumnInterpreter();
790 Double std = null;
791 try {
792 std = aClient.std(TEST_TABLE, ci, scan);
793 } catch (Throwable e) {
794 }
795 assertEquals(null, std);
796
797 }
798
799 @Test (timeout=300000)
800 public void testStdWithInvalidRange() {
801 AggregationClient aClient = new AggregationClient(conf);
802 Scan scan = new Scan();
803 scan.addFamily(TEST_FAMILY);
804 scan.setStartRow(ROWS[6]);
805 scan.setStopRow(ROWS[1]);
806 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
807 new LongColumnInterpreter();
808 Double std = null;
809 try {
810 std = aClient.std(TEST_TABLE, ci, scan);
811 } catch (Throwable e) {
812 }
813 assertEquals(null, std);
814 }
815
816 @Test (timeout=300000)
817 public void testStdWithFilter() throws Throwable {
818 AggregationClient aClient = new AggregationClient(conf);
819 Filter f = new PrefixFilter(Bytes.toBytes("foo:bar"));
820 Scan scan = new Scan();
821 scan.addFamily(TEST_FAMILY);
822 scan.setFilter(f);
823 final ColumnInterpreter<Long, Long, EmptyMsg, LongMsg, LongMsg> ci =
824 new LongColumnInterpreter();
825 Double std = null;
826 std = aClient.std(TEST_TABLE, ci, scan);
827 assertEquals(Double.NaN, std, 0);
828 }
829 }