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