sub assemble_collapsing_parser {
my $args = shift;
+ # it may get unset further down
+ my $no_rowid_container = $args->{hri_style};
+
my ($top_node_key, $top_node_key_assembler);
if (scalar @{$args->{collapse_map}{-identifying_columns}}) {
-custom_node_key => $top_node_key,
};
+ $no_rowid_container = 0;
}
else {
die('Unexpected collapse map contents');
my ($data_assemblers, $stats) = __visit_infmap_collapse ($args);
- my @idcol_args = $args->{hri_style} ? ('', '') : (
+ my @idcol_args = $no_rowid_container ? ('', '') : (
', %cur_row_ids', # only declare the variable if we'll use it
sprintf( <<'EOS', join ', ', sort { $a <=> $b } keys %{ $stats->{idcols_seen} } ),
# !!! note - different var than the one above
# change the quoted placeholders to unquoted alias-references
$parser_src =~ s/ \' \xFF__VALPOS__(\d+)__\xFF \' /"\$cur_row_data->[$1]"/gex;
- $parser_src =~ s/ \' \xFF__IDVALPOS__(\d+)__\xFF \' /$args->{hri_style} ? "\$cur_row_data->[$1]" : "\$cur_row_ids{$1}" /gex;
+ $parser_src =~ s/
+ \' \xFF__IDVALPOS__(\d+)__\xFF \'
+ /
+ $no_rowid_container ? "\$cur_row_data->[$1]" : "\$cur_row_ids{$1}"
+ /gex;
$parser_src = " { use strict; use warnings FATAL => 'all';\n$parser_src\n }";
}
hri_style => 1,
}),
' my $rows_pos = 0;
- my ($result_pos, @collapse_idx, $cur_row_data);
+ my ($result_pos, @collapse_idx, $cur_row_data, %cur_row_ids);
while ($cur_row_data = (
( $rows_pos >= 0 and $_[0][$rows_pos++] ) or do { $rows_pos = -1; undef } )
( $_[1] and $_[1]->() )
) {
+ $cur_row_ids{$_} = defined $$cur_row_data[$_] ? $$cur_row_data[$_] : "\0NULL\xFF$rows_pos\xFF$_\0"
+ for (0, 2, 3, 4, 8);
+
# cache expensive set of ops in a non-existent rowid slot
- $cur_row_data->[10] = (
+ $cur_row_ids{10} = (
( ( defined $cur_row_data->[0] ) && (join "\xFF", q{}, $cur_row_data->[0], q{} ))
or
( ( defined $cur_row_data->[2] ) && (join "\xFF", q{}, $cur_row_data->[2], q{} ))
);
# a present cref in $_[1] implies lazy prefetch, implies a supplied stash in $_[2]
- $_[1] and $result_pos and ! $collapse_idx[0]{$cur_row_data->[10]} and (unshift @{$_[2]}, $cur_row_data) and last;
+ $_[1] and $result_pos and ! $collapse_idx[0]{$cur_row_ids{10}} and (unshift @{$_[2]}, $cur_row_data) and last;
- $collapse_idx[0]{$cur_row_data->[10]} ||= $_[0][$result_pos++] = { year => $$cur_row_data[1] };
+ $collapse_idx[0]{$cur_row_ids{10}} ||= $_[0][$result_pos++] = { year => $$cur_row_data[1] };
- (! defined $cur_row_data->[0] ) ? $collapse_idx[0]{$cur_row_data->[10]}{single_track} = undef : do {
+ (! defined $cur_row_data->[0] ) ? $collapse_idx[0]{$cur_row_ids{10}}{single_track} = undef : do {
- $collapse_idx[0]{$cur_row_data->[10]}{single_track} ||= ($collapse_idx[1]{$cur_row_data->[0]} = { trackid => $$cur_row_data[0] });
+ $collapse_idx[0]{$cur_row_ids{10}}{single_track} ||= ($collapse_idx[1]{$cur_row_ids{0}} = { trackid => $$cur_row_data[0] });
- $collapse_idx[1]{$cur_row_data->[0]}{cd} ||= $collapse_idx[2]{$cur_row_data->[0]};
+ $collapse_idx[1]{$cur_row_ids{0}}{cd} ||= $collapse_idx[2]{$cur_row_ids{0}};
- $collapse_idx[2]{$cur_row_data->[0]}{artist} ||= ($collapse_idx[3]{$cur_row_data->[0]} = { artistid => $$cur_row_data[6] });
+ $collapse_idx[2]{$cur_row_ids{0}}{artist} ||= ($collapse_idx[3]{$cur_row_ids{0}} = { artistid => $$cur_row_data[6] });
- (! defined $cur_row_data->[4] ) ? $collapse_idx[3]{$cur_row_data->[0]}{cds} = [] : do {
+ (! defined $cur_row_data->[4] ) ? $collapse_idx[3]{$cur_row_ids{0}}{cds} = [] : do {
- (! $collapse_idx[4]{$cur_row_data->[0]}{$cur_row_data->[4]} )
+ (! $collapse_idx[4]{$cur_row_ids{0}}{$cur_row_ids{4}} )
and
- push @{$collapse_idx[3]{$cur_row_data->[0]}{cds}}, (
- $collapse_idx[4]{$cur_row_data->[0]}{$cur_row_data->[4]} = { cdid => $$cur_row_data[4], genreid => $$cur_row_data[7], year => $$cur_row_data[5] }
+ push @{$collapse_idx[3]{$cur_row_ids{0}}{cds}}, (
+ $collapse_idx[4]{$cur_row_ids{0}}{$cur_row_ids{4}} = { cdid => $$cur_row_data[4], genreid => $$cur_row_data[7], year => $$cur_row_data[5] }
);
- (! defined $cur_row_data->[8] ) ? $collapse_idx[4]{$cur_row_data->[0]}{$cur_row_data->[4]}{tracks} = [] : do {
+ (! defined $cur_row_data->[8] ) ? $collapse_idx[4]{$cur_row_ids{0}}{$cur_row_ids{4}}{tracks} = [] : do {
- (! $collapse_idx[5]{$cur_row_data->[0]}{$cur_row_data->[4]}{$cur_row_data->[8]} )
+ (! $collapse_idx[5]{$cur_row_ids{0}}{$cur_row_ids{4}}{$cur_row_ids{8}} )
and
- push @{$collapse_idx[4]{$cur_row_data->[0]}{$cur_row_data->[4]}{tracks}}, (
- $collapse_idx[5]{$cur_row_data->[0]}{$cur_row_data->[4]}{$cur_row_data->[8]} = { title => $$cur_row_data[8] }
+ push @{$collapse_idx[4]{$cur_row_ids{0}}{$cur_row_ids{4}}{tracks}}, (
+ $collapse_idx[5]{$cur_row_ids{0}}{$cur_row_ids{4}}{$cur_row_ids{8}} = { title => $$cur_row_data[8] }
);
};
};
};
- (! defined $cur_row_data->[2] ) ? $collapse_idx[0]{$cur_row_data->[10]}{tracks} = [] : do {
- (! $collapse_idx[6]{$cur_row_data->[2]}{$cur_row_data->[3]} )
+ (! defined $cur_row_data->[2] ) ? $collapse_idx[0]{$cur_row_ids{10}}{tracks} = [] : do {
+ (! $collapse_idx[6]{$cur_row_ids{2}}{$cur_row_ids{3}} )
and
- push @{$collapse_idx[0]{$cur_row_data->[10]}{tracks}}, (
- $collapse_idx[6]{$cur_row_data->[2]}{$cur_row_data->[3]} = { cd => $$cur_row_data[2], title => $$cur_row_data[3] }
+ push @{$collapse_idx[0]{$cur_row_ids{10}}{tracks}}, (
+ $collapse_idx[6]{$cur_row_ids{2}}{$cur_row_ids{3}} = { cd => $$cur_row_data[2], title => $$cur_row_data[3] }
);
};
}