| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::RecordStream::Operation::topn; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = "4.0.23"; |
|
4
|
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
832
|
use strict; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
59
|
|
|
6
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
49
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
8
|
use base qw(App::RecordStream::Operation); |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
695
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub init { |
|
11
|
3
|
|
|
3
|
0
|
5
|
my $this = shift; |
|
12
|
3
|
|
|
|
|
5
|
my $args = shift; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
3
|
|
|
|
|
5
|
my $top = 10; |
|
16
|
3
|
|
|
|
|
5
|
my $value_delimiter = "9t%7Oz%]"; |
|
17
|
3
|
|
|
|
|
15
|
my $key_groups = App::RecordStream::KeyGroups->new(); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $spec = { |
|
20
|
3
|
|
|
3
|
|
2159
|
"key|k=s" => sub { $key_groups->add_groups($_[1]); }, |
|
21
|
3
|
|
|
|
|
16
|
"topn|n=i" => \$top, |
|
22
|
|
|
|
|
|
|
"delimiter=s" => \$value_delimiter, |
|
23
|
|
|
|
|
|
|
}; |
|
24
|
|
|
|
|
|
|
|
|
25
|
3
|
|
|
|
|
12
|
$this->parse_options($args, $spec); |
|
26
|
|
|
|
|
|
|
|
|
27
|
3
|
50
|
|
|
|
8
|
die "Must at least specify --topn " unless $top; |
|
28
|
|
|
|
|
|
|
|
|
29
|
3
|
|
|
|
|
7
|
$this->{'KEY_GROUPS'} = $key_groups; |
|
30
|
3
|
|
|
|
|
6
|
$this->{'NUM'} = $top; |
|
31
|
|
|
|
|
|
|
$this->{'DELIM'} = $value_delimiter, |
|
32
|
|
|
|
|
|
|
|
|
33
|
3
|
|
|
|
|
30
|
$this->{'PRIOR_KEY_VALUES'} = ""; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub init_keys { |
|
37
|
3
|
|
|
3
|
0
|
6
|
my $this = shift; |
|
38
|
3
|
|
|
|
|
4
|
my $record = shift; |
|
39
|
|
|
|
|
|
|
|
|
40
|
3
|
|
|
|
|
10
|
$this->{'KEYS'} = $this->{'KEY_GROUPS'}->get_keyspecs($record); |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub accept_record { |
|
44
|
15
|
|
|
15
|
0
|
22
|
my $this = shift; |
|
45
|
15
|
|
|
|
|
24
|
my $record = shift; |
|
46
|
|
|
|
|
|
|
|
|
47
|
15
|
100
|
|
|
|
35
|
if ( ! $this->{'KEYS'} ) { |
|
48
|
3
|
|
|
|
|
7
|
$this->init_keys($record); |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
15
|
|
|
|
|
24
|
my $current_key_values = ""; |
|
52
|
15
|
|
|
|
|
20
|
foreach my $k ( @{$this->{'KEYS'}} ) { |
|
|
15
|
|
|
|
|
31
|
|
|
53
|
15
|
|
|
|
|
23
|
$current_key_values .= ${$record->guess_key_from_spec( $k )} . $this->{'DELIM'}; |
|
|
15
|
|
|
|
|
35
|
|
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
15
|
|
|
|
|
37
|
$this->{'NUM_SEEN'}->{$current_key_values}++; |
|
57
|
15
|
100
|
|
|
|
39
|
if( $this->{'NUM_SEEN'}->{$current_key_values} <= $this->{'NUM'} ) { |
|
58
|
13
|
|
|
|
|
44
|
$this->push_record($record); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
15
|
|
|
|
|
64
|
return 1; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub add_help_types { |
|
65
|
3
|
|
|
3
|
0
|
6
|
my $this = shift; |
|
66
|
3
|
|
|
|
|
13
|
$this->use_help_type('keyspecs'); |
|
67
|
3
|
|
|
|
|
9
|
$this->use_help_type('keygroups'); |
|
68
|
3
|
|
|
|
|
10
|
$this->use_help_type('keys'); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub usage |
|
72
|
|
|
|
|
|
|
{ |
|
73
|
0
|
|
|
0
|
0
|
|
my $this = shift; |
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my $options = [ |
|
76
|
|
|
|
|
|
|
['key ', 'Comma separated list of fields. May be specified multiple times. May be a keyspec or keygroup, see \'--help-keys\' for more'], |
|
77
|
|
|
|
|
|
|
['topn | -n ', 'Number of records to output. Default is 10.'], |
|
78
|
|
|
|
|
|
|
['delimiter ', 'String used internally to delimit values when performing a topn on a keyspec that inlcudeds multiple keys. This value defaults to "9t%7Oz%]" which may - under unusual and bizarre corner cases - cause false positive key matches if your values contain this value. You can set this to any string.'], |
|
79
|
|
|
|
|
|
|
]; |
|
80
|
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $args_string = $this->options_string($options); |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return <
|
|
84
|
|
|
|
|
|
|
Usage: recs-topn [] |
|
85
|
|
|
|
|
|
|
__FORMAT_TEXT__ |
|
86
|
|
|
|
|
|
|
Outputs the top n records from input stream or from . You may |
|
87
|
|
|
|
|
|
|
segment the input stream based on a list of keys such that unique values |
|
88
|
|
|
|
|
|
|
of keys are treated as distinct input streams. This enables |
|
89
|
|
|
|
|
|
|
top n listings per value groupings. The key values need not be contiguous |
|
90
|
|
|
|
|
|
|
in the input record stream. |
|
91
|
|
|
|
|
|
|
__FORMAT_TEXT__ |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$args_string |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Examples: |
|
96
|
|
|
|
|
|
|
Output just the top 5 records |
|
97
|
|
|
|
|
|
|
cat records | recs-topn -n=5 |
|
98
|
|
|
|
|
|
|
(this is equivalent to executing "cat records | recs-grep '\$line < 5'") |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Output just 10 records for each area |
|
101
|
|
|
|
|
|
|
cat records | recs-sort --key area | recs-topn -n=10 --key area |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Output the top 10 longest running queries per area and priority level |
|
104
|
|
|
|
|
|
|
cat records | recs-sort --key area,priority,runtime=-n | recs-topn -n=10 --key area,priority |
|
105
|
|
|
|
|
|
|
USAGE |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |