« blib/lib/App/RecordStream/Operation/delta.pm
↑ Summary
blib/lib/App/RecordStream/Operation/help.pm »
| 1 | package App::RecordStream::Operation::stream2table; | ||||||||||||
| 2 | |||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 2 | ▶ | use base qw(App::RecordStream::Operation); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | sub init { | ||||||||||||
| 9 | 2 | ▶ | my $this = shift; | ||||||||||
|
Subroutine
init: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||
| 10 | 2 | my $args = shift; | |||||||||||
| 11 | |||||||||||||
| 12 | 2 | my $field; | |||||||||||
| 13 | 2 | my $spec = { | |||||||||||
| 14 | "field|f=s" => \$field, | ||||||||||||
| 15 | }; | ||||||||||||
| 16 | |||||||||||||
| 17 | 2 | $this->parse_options($args, $spec); | |||||||||||
| 18 | |||||||||||||
| 19 | 1 | ▶ | die "You must specify a --field option\n" unless defined($field); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 20 | |||||||||||||
| 21 | 1 | $this->{'FIELD'} = $field; | |||||||||||
| 22 | 1 | $this->{'REMOVE_FIELD'} = (not ($field =~ m![/@]!)); | |||||||||||
| 23 | } | ||||||||||||
| 24 | |||||||||||||
| 25 | sub accept_record { | ||||||||||||
| 26 | 4 | ▶ | my $this = shift; | ||||||||||
|
Subroutine
accept_record: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||
| 27 | 4 | my $record = shift; | |||||||||||
| 28 | |||||||||||||
| 29 | 4 | my $key = ${$record->guess_key_from_spec($this->{'FIELD'})}; | |||||||||||
| 30 | |||||||||||||
| 31 | 4 | ▶ | if ( $this->{'REMOVE_FIELD'} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 32 | 4 | $record->remove($this->{'FIELD'}); | |||||||||||
| 33 | } | ||||||||||||
| 34 | |||||||||||||
| 35 | 4 | ▶ | $this->{'HASH'}->{$key} ||= []; | ||||||||||
|
Condition100%2/2
$this->{"HASH"}{$key} ||= []
MC/DC100%1/1
$this->{"HASH"}{$key} ||= []
$this->{"HASH"}{$key}
Truth table100%2/2
A
A= $this->{"HASH"}{$key}
| |||||||||||||
| 36 | 4 | push @{$this->{'HASH'}->{$key}}, $record; | |||||||||||
| 37 | |||||||||||||
| 38 | 4 | return 1; | |||||||||||
| 39 | } | ||||||||||||
| 40 | |||||||||||||
| 41 | sub stream_done { | ||||||||||||
| 42 | 1 | ▶ | my $this = shift; | ||||||||||
|
Subroutine
stream_done: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||
| 43 | |||||||||||||
| 44 | 1 | ▶ | while(scalar keys %{$this->{'HASH'}} > 0) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 45 | 3 | my $record = App::RecordStream::Record->new(); | |||||||||||
| 46 | 3 | my $found = 0; | |||||||||||
| 47 | 3 | foreach my $key (keys %{$this->{'HASH'}}) { | |||||||||||
| 48 | 6 | my $old_record = shift @{$this->{'HASH'}->{$key}}; | |||||||||||
| 49 | 6 | ▶ | if ( $old_record ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 50 | 4 | $record->set($key, $old_record); | |||||||||||
| 51 | 4 | $found = 1; | |||||||||||
| 52 | } | ||||||||||||
| 53 | else { | ||||||||||||
| 54 | 2 | delete $this->{'HASH'}->{$key}; | |||||||||||
| 55 | } | ||||||||||||
| 56 | } | ||||||||||||
| 57 | 3 | ▶ | $this->push_record($record) if ( $found ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 58 | } | ||||||||||||
| 59 | } | ||||||||||||
| 60 | |||||||||||||
| 61 | sub add_help_types { | ||||||||||||
| 62 | 2 | ▶ | my $this = shift; | ||||||||||
|
Subroutine
add_help_types: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 63 | 2 | $this->use_help_type('keyspecs'); | |||||||||||
| 64 | } | ||||||||||||
| 65 | |||||||||||||
| 66 | sub usage { | ||||||||||||
| 67 | 1 | ▶ | my $this = shift; | ||||||||||
|
Subroutine
usage: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 68 | |||||||||||||
| 69 | 1 | my $options = [ | |||||||||||
| 70 | ['field <FIELD>', 'Field to use as the column key, may be a keyspec'], | ||||||||||||
| 71 | ]; | ||||||||||||
| 72 | |||||||||||||
| 73 | 1 | my $args_string = $this->options_string($options); | |||||||||||
| 74 | |||||||||||||
| 75 | 1 | my $usage = <<USAGE; | |||||||||||
| 76 | Usage: recs-stream2table <args> [<files>] | ||||||||||||
| 77 | __FORMAT_TEXT__ | ||||||||||||
| 78 | Transforms a list of records, combinging records based on a column, FIELD. | ||||||||||||
| 79 | In order, the values of the column will be added to the output records. | ||||||||||||
| 80 | |||||||||||||
| 81 | Note: This script spools the stream into memory | ||||||||||||
| 82 | __FORMAT_TEXT__ | ||||||||||||
| 83 | |||||||||||||
| 84 | This stream: | ||||||||||||
| 85 | { "column": "foo", "data": "foo1" } | ||||||||||||
| 86 | { "column": "foo", "data": "foo2" } | ||||||||||||
| 87 | { "column": "boo", "data": "boo1" } | ||||||||||||
| 88 | { "column": "boo", "data": "boo2" } | ||||||||||||
| 89 | |||||||||||||
| 90 | with recs-stream2table --field column becomes: | ||||||||||||
| 91 | {"boo":{"data":"boo1"},"foo":{"data":"foo1"}} | ||||||||||||
| 92 | {"boo":{"data":"boo2"},"foo":{"data":"foo2"}} | ||||||||||||
| 93 | |||||||||||||
| 94 | __FORMAT_TEXT__ | ||||||||||||
| 95 | Hint: use recs-flatten if you want those values to be in the top level of | ||||||||||||
| 96 | the record | ||||||||||||
| 97 | |||||||||||||
| 98 | The full input record will be associated with the value of the FIELD. The | ||||||||||||
| 99 | field itself will be removed from the nested record if the passed field is | ||||||||||||
| 100 | not a key spec. | ||||||||||||
| 101 | __FORMAT_TEXT__ | ||||||||||||
| 102 | |||||||||||||
| 103 | Arguments: | ||||||||||||
| 104 | $args_string | ||||||||||||
| 105 | |||||||||||||
| 106 | Examples: | ||||||||||||
| 107 | # Transform a record stream with each stat on one line to a stream with one | ||||||||||||
| 108 | # value for each stat present on one line | ||||||||||||
| 109 | ... | recs-stream2table --field stat | ||||||||||||
| 110 | USAGE | ||||||||||||
| 111 | } | ||||||||||||
| 112 | |||||||||||||
| 113 | 2 | 1; | |||||||||||