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