File Coverage

blib/lib/App/RecordStream/Aggregator/DistinctCount.pm
Criterion Covered Total %
statement 33 36 91.6
branch n/a
condition n/a
subroutine 11 14 78.5
pod 0 8 0.0
total 44 58 75.8


line stmt bran cond sub pod time code
1             package App::RecordStream::Aggregator::DistinctCount;
2              
3             our $VERSION = "4.0.24";
4              
5 6     6   2786 use strict;
  6         12  
  6         154  
6 6     6   27 use warnings;
  6         11  
  6         137  
7              
8 6     6   254 use App::RecordStream::Aggregator;
  6         11  
  6         106  
9 6     6   297 use App::RecordStream::DomainLanguage::Registry;
  6         15  
  6         127  
10 6     6   35 use App::RecordStream::DomainLanguage::Valuation::KeySpec;
  6         13  
  6         133  
11              
12 6     6   29 use base qw(App::RecordStream::Aggregator::Aggregation);
  6         10  
  6         2163  
13              
14             sub new
15             {
16 1     1 0 124 my $class = shift;
17 1         4 my $field = shift;
18              
19 1         14 return new_from_valuation($class, App::RecordStream::DomainLanguage::Valuation::KeySpec->new($field));
20             }
21              
22             sub new_from_valuation
23             {
24 10     10 0 29 my $class = shift;
25 10         27 my ($valuation) = @_;
26              
27 10         33 my $this =
28             {
29             'valuation' => $valuation,
30             };
31 10         28 bless $this, $class;
32              
33 10         79 return $this;
34             }
35              
36             sub squish
37             {
38 40     40 0 85 my ($this, $cookie) = @_;
39              
40 40         127 return scalar(keys(%$cookie));
41             }
42              
43             sub short_usage
44             {
45 0     0 0 0 return "count unique values from provided field";
46             }
47              
48             sub long_usage
49             {
50 0     0 0 0 return <
51             Usage: dct,
52             Finds the number of unique values for a field and returns it. Will load all
53             values into memory.
54             EOF
55             }
56              
57             sub argct
58             {
59 0     0 0 0 return 1;
60             }
61              
62             sub initial
63             {
64 40     40 0 96 return {};
65             }
66              
67             sub combine
68             {
69 312     312 0 608 my ($this, $cookie, $record) = @_;
70              
71 312         743 my $value = $this->{'valuation'}->evaluate_record($record);
72              
73 312         675 $cookie->{$value} = 1;
74              
75 312         1016 return $cookie;
76             }
77              
78             App::RecordStream::Aggregator->register_implementation('dcount', __PACKAGE__);
79             App::RecordStream::Aggregator->register_implementation('dct', __PACKAGE__);
80             App::RecordStream::Aggregator->register_implementation('distinctcount', __PACKAGE__);
81             App::RecordStream::Aggregator->register_implementation('distinctct', __PACKAGE__);
82              
83             App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'dcount', 'VALUATION');
84             App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'dct', 'VALUATION');
85             App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'distinctcount', 'VALUATION');
86             App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'distinctct', 'VALUATION');
87              
88             1;