| 1 | package UR::Context; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # Methods related to the import iterator (part of the loading process). | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # They are broken out here for readability purposes. The methods still live | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # in the UR::Context namespace. | ||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 266 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 266 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 266 | our $VERSION = "0.47"; # UR $VERSION; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | # A wrapper around the method of the same name in UR::DataSource::* to iterate over the | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # possible data sources involved in a query. The easy case (a query against a single data source) | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # will return the $primary_template data structure. If the query involves more than one data source, | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # then this method also returns a list containing triples (@addl_loading_info) where each member is: | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # 1) The secondary data source name | ||||||||||||||||||||||||||||||||||||||||||
| 19 | # 2) a listref of delegated properties joining the primary class to the secondary class | ||||||||||||||||||||||||||||||||||||||||||
| 20 | # 3) a rule template applicable against the secondary data source | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub _resolve_query_plan_for_ds_and_bxt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_query_plan_for_ds_and_bxt: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | my($self,$primary_data_source,$rule_template) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my $primary_query_plan = $primary_data_source->_resolve_query_plan($rule_template); | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | unless ($primary_query_plan->{'joins_across_data_sources'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | # Common, easy case | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | return $primary_query_plan; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | my @addl_loading_info; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | foreach my $secondary_data_source_id ( keys %{$primary_query_plan->{'joins_across_data_sources'}} ) { | |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my $this_ds_delegations = $primary_query_plan->{'joins_across_data_sources'}->{$secondary_data_source_id}; | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my %seen_properties; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | foreach my $delegated_property ( @$this_ds_delegations ) { | |||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $delegated_property_name = $delegated_property->property_name; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | next if ($seen_properties{$delegated_property_name}++); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my $operator = $rule_template->operator_for($delegated_property_name); | |||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | $operator ||= '='; # FIXME - shouldn't the template return this for us? | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$operator ||= "="
MC/DC0%0/1
$operator ||= "="
$operator
Truth table0%0/2
A
A= $operator
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my @secondary_params = ($delegated_property->to . ' ' . $operator); | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my $class_meta = UR::Object::Type->get($delegated_property->class_name); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my $relation_property = $class_meta->property_meta_for_name($delegated_property->via); | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $secondary_class = $relation_property->data_type; | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | # we can also add in any properties in the property's joins that also appear in the rule | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my @property_pairs = $relation_property->get_property_name_pairs_for_join(); | |||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | foreach my $pair ( @property_pairs ) { | |||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my($primary_property, $secondary_property) = @$pair; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | next if ($seen_properties{$primary_property}++); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | next unless ($rule_template->specifies_value_for($primary_property)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my $operator = $rule_template->operator_for($primary_property); | |||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | $operator ||= '='; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$operator ||= "="
MC/DC0%0/1
$operator ||= "="
$operator
Truth table0%0/2
A
A= $operator
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | push @secondary_params, "$secondary_property $operator"; | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my $secondary_rule_template = UR::BoolExpr::Template->resolve($secondary_class, @secondary_params); | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | # FIXME there should be a way to collect all the requests for the same datasource together... | ||||||||||||||||||||||||||||||||||||||||||
| 64 | # FIXME - currently in the process of switching to object-based instead of class-based data sources | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # For now, data sources are still singleton objects, so this get() will work. When we're fully on | ||||||||||||||||||||||||||||||||||||||||||
| 66 | # regular-object-based data sources, then it'll probably change to UR::DataSource->get($secondary_data_source_id); | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | my $secondary_data_source = UR::DataSource->get($secondary_data_source_id) || $secondary_data_source_id->get(); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
'UR::DataSource'->get($secondary_data_source_id) || $secondary_data_source_id->get
MC/DC0%0/2
'UR::DataSource'->get($secondary_data_source_id) || $secondary_data_source_id->get
'UR::DataSource'->get($secondary_data_source_id)
$secondary_data_source_id->get
Truth table0%0/3
A || B
A= 'UR::DataSource'->get($secondary_data_source_id)B= $secondary_data_source_id->get
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | push @addl_loading_info, | |||||||||||||||||||||||||||||||||||||||||
| 69 | $secondary_data_source, | ||||||||||||||||||||||||||||||||||||||||||
| 70 | [$delegated_property], | ||||||||||||||||||||||||||||||||||||||||||
| 71 | $secondary_rule_template; | ||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | return ($primary_query_plan, @addl_loading_info); | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | # Used by _create_secondary_loading_comparators to convert a rule against the primary data source | ||||||||||||||||||||||||||||||||||||||||||
| 80 | # to a rule that can be used against a secondary data source | ||||||||||||||||||||||||||||||||||||||||||
| 81 | # FIXME this might be made simpler be leaning on infer_property_value_from_rule()? | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub _create_secondary_rule_from_primary { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_secondary_rule_from_primary: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my($self,$primary_rule, $delegated_properties, $secondary_rule_template) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my @secondary_values; | |||||||||||||||||||||||||||||||||||||||||
| 86 | my %seen_properties; # FIXME - we've already been over this list in _resolve_query_plan_for_ds_and_bxt()... | ||||||||||||||||||||||||||||||||||||||||||
| 87 | # FIXME - is there ever a case where @$delegated_properties will be more than one item? | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | foreach my $property ( @$delegated_properties ) { | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my $value = $primary_rule->value_for($property->property_name); | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $secondary_property_name = $property->to; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $pos = $secondary_rule_template->value_position_for_property_name($secondary_property_name); | |||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $secondary_values[$pos] = $value; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $seen_properties{$property->property_name}++; | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my $class_meta = $property->class_meta; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $via_property = $class_meta->property_meta_for_name($property->via); | |||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my @pairs = $via_property->get_property_name_pairs_for_join(); | |||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | foreach my $pair ( @pairs ) { | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my($primary_property_name, $secondary_property_name) = @$pair; | |||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | next if ($seen_properties{$primary_property_name}++); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $value = $primary_rule->value_for($primary_property_name); | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | next unless $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $pos = $secondary_rule_template->value_position_for_property_name($secondary_property_name); | |||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $secondary_values[$pos] = $value; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my $secondary_rule = $secondary_rule_template->get_rule_for_values(@secondary_values); | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | return $secondary_rule; | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | # Since we'll be appending more "columns" of data to the listrefs returned by | ||||||||||||||||||||||||||||||||||||||||||
| 118 | # the primary datasource's query, we need to apply fixups to the column positions | ||||||||||||||||||||||||||||||||||||||||||
| 119 | # to all the secondary loading templates | ||||||||||||||||||||||||||||||||||||||||||
| 120 | # The column_position and object_num offsets needed for the next call of this method | ||||||||||||||||||||||||||||||||||||||||||
| 121 | # are returned | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub _fixup_secondary_loading_template_column_positions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fixup_secondary_loading_template_column_positions: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my($self,$primary_loading_templates, $secondary_loading_templates, $column_position_offset, $object_num_offset) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | if (! defined($column_position_offset) or ! defined($object_num_offset)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $column_position_offset and defined $object_num_offset
MC/DC0%0/2
defined $column_position_offset and defined $object_num_offset
defined $column_position_offset
defined $object_num_offset
Truth table0%0/3
A and B
A= defined $column_position_offsetB= defined $object_num_offset
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $column_position_offset = 0; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | foreach my $tmpl ( @{$primary_loading_templates} ) { | |||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $column_position_offset += scalar(@{$tmpl->{'column_positions'}}); | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | $object_num_offset = scalar(@{$primary_loading_templates}); | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my $this_template_column_count; | |||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | foreach my $tmpl ( @$secondary_loading_templates ) { | |||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | foreach ( @{$tmpl->{'column_positions'}} ) { | |||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | $_ += $column_position_offset; | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | foreach ( @{$tmpl->{'id_column_positions'}} ) { | |||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | $_ += $column_position_offset; | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $tmpl->{'object_num'} += $object_num_offset; | |||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $this_template_column_count += scalar(@{$tmpl->{'column_positions'}}); | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | return ($column_position_offset + $this_template_column_count, | |||||||||||||||||||||||||||||||||||||||||
| 148 | $object_num_offset + scalar(@$secondary_loading_templates) ); | ||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | # For queries that have to hit multiple data sources, this method creates two lists of | ||||||||||||||||||||||||||||||||||||||||||
| 152 | # closures. The first is a list of object fabricators, where the loading templates | ||||||||||||||||||||||||||||||||||||||||||
| 153 | # have been given fixups to the column positions (see _fixup_secondary_loading_template_column_positions()) | ||||||||||||||||||||||||||||||||||||||||||
| 154 | # The second is a list of closures for each data source (the @addl_loading_info stuff | ||||||||||||||||||||||||||||||||||||||||||
| 155 | # from _resolve_query_plan_for_ds_and_bxt) that's able to compare the row loaded from the | ||||||||||||||||||||||||||||||||||||||||||
| 156 | # primary data source and see if it joins to a row from this secondary datasource's database | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | sub _create_secondary_loading_closures { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_secondary_loading_closures: not called CC=24 SCAR=64.0
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | my($self, $primary_template, $rule, @addl_loading_info) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my $loading_templates = $primary_template->{'loading_templates'}; | |||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | # Make a mapping of property name to column positions returned by the primary query | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | my %primary_query_column_positions; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | foreach my $tmpl ( @$loading_templates ) { | |||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | my $property_name_count = scalar(@{$tmpl->{'property_names'}}); | |||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | for (my $i = 0; $i < $property_name_count; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my $property_name = $tmpl->{'property_names'}->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | my $pos = $tmpl->{'column_positions'}->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | $primary_query_column_positions{$property_name} = $pos; | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | my @secondary_object_importers; | |||||||||||||||||||||||||||||||||||||||||
| 174 | my @addl_join_comparators; | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | # used to shift the apparent column position of the secondary loading template info | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | my ($column_position_offset,$object_num_offset); | |||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | while (@addl_loading_info) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | my $secondary_data_source = shift @addl_loading_info; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | my $this_ds_delegations = shift @addl_loading_info; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | my $secondary_rule_template = shift @addl_loading_info; | |||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | my $secondary_rule = $self->_create_secondary_rule_from_primary ( | |||||||||||||||||||||||||||||||||||||||||
| 185 | $rule, | ||||||||||||||||||||||||||||||||||||||||||
| 186 | $this_ds_delegations, | ||||||||||||||||||||||||||||||||||||||||||
| 187 | $secondary_rule_template, | ||||||||||||||||||||||||||||||||||||||||||
| 188 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | $secondary_data_source = $secondary_data_source->resolve_data_sources_for_rule($secondary_rule); | |||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my $secondary_template = $self->_resolve_query_plan_for_ds_and_bxt($secondary_data_source,$secondary_rule_template); | |||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | # sets of triples where the first in the triple is the column index in the | ||||||||||||||||||||||||||||||||||||||||||
| 193 | # $secondary_db_row (in the join_comparator closure below), the second is the | ||||||||||||||||||||||||||||||||||||||||||
| 194 | # index in the $next_db_row. And the last is a flag indicating if we should | ||||||||||||||||||||||||||||||||||||||||||
| 195 | # perform a numeric comparison. This way we can preserve the order the comparisons | ||||||||||||||||||||||||||||||||||||||||||
| 196 | # should be done in | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my @join_comparison_info; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | foreach my $property ( @$this_ds_delegations ) { | |||||||||||||||||||||||||||||||||||||||||
| 199 | # first, map column names in the joined class to column names in the primary class | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | my %foreign_property_name_map; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my @this_property_joins = $property->_resolve_join_chain(); | |||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | foreach my $join ( @this_property_joins ) { | |||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | last if ($join->{foreign_class}->isa('UR::Value') and $join eq $this_property_joins[-1]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$join->{"foreign_class"}->isa("UR::Value") and $join eq $this_property_joins[-1]
MC/DC0%0/2
$join->{"foreign_class"}->isa("UR::Value") and $join eq $this_property_joins[-1]
$join->{"foreign_class"}->isa("UR::Value")
$join eq $this_property_joins[-1]
Truth table0%0/3
A and B
A= $join->{"foreign_class"}->isa("UR::Value")B= $join eq $this_property_joins[-1]
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my @source_names = @{$join->{'source_property_names'}}; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my @foreign_names = @{$join->{'foreign_property_names'}}; | |||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | @foreign_property_name_map{@foreign_names} = @source_names; | |||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | # Now, find out which numbered column in the result query maps to those names | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | my $secondary_loading_templates = $secondary_template->{'loading_templates'}; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | foreach my $tmpl ( @$secondary_loading_templates ) { | |||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | my $property_name_count = scalar(@{$tmpl->{'property_names'}}); | |||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | for (my $i = 0; $i < $property_name_count; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | my $property_name = $tmpl->{'property_names'}->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | if ($foreign_property_name_map{$property_name}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | # This is the one we're interested in... Where does it come from in the primary query? | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | my $column_position = $tmpl->{'column_positions'}->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 218 | # What are the types involved? | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | my $primary_query_column_name = $foreign_property_name_map{$property_name}; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | my $primary_property_class_meta = $primary_template->{'class_name'}->__meta__; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | my $primary_property_meta = $primary_property_class_meta->property_meta_for_name($primary_query_column_name); | |||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | unless ($primary_property_meta) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | Carp::croak("Can't resolve property metadata for property '$primary_query_column_name' of class ".$primary_template->{'class_name'}); | |||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my $secondary_class_meta = $secondary_template->{'class_name'}->__meta__; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | my $secondary_property_meta = $secondary_class_meta->property_meta_for_name($property_name); | |||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | unless ($secondary_property_meta) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | Carp::croak("Can't resolve property metadata for property '$property_name' of class ".$secondary_template->{'class_name'}); | |||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | my $comparison_type; | |||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | if ($primary_property_meta->is_numeric && $secondary_property_meta->is_numeric) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$primary_property_meta->is_numeric and $secondary_property_meta->is_numeric
MC/DC0%0/2
$primary_property_meta->is_numeric and $secondary_property_meta->is_numeric
$primary_property_meta->is_numeric
$secondary_property_meta->is_numeric
Truth table0%0/3
A and B
A= $primary_property_meta->is_numericB= $secondary_property_meta->is_numeric
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | $comparison_type = 1; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my $comparison_position; | |||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | if (exists $primary_query_column_positions{$primary_query_column_name} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | $comparison_position = $primary_query_column_positions{$primary_query_column_name}; | |||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 242 | # This isn't a real column we can get from the data source. Maybe it's | ||||||||||||||||||||||||||||||||||||||||||
| 243 | # in the constant_property_names of the primary_loading_template? | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | unless (grep { $_ eq $primary_query_column_name} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | @{$loading_templates->[0]->{'constant_property_names'}}) { | |||||||||||||||||||||||||||||||||||||||||
| 246 | die sprintf("Can't resolve datasource comparison to join %s::%s to %s:%s", | ||||||||||||||||||||||||||||||||||||||||||
| 247 | $primary_template->{'class_name'}, $primary_query_column_name, | ||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | $secondary_template->{'class_name'}, $property_name); | |||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my $comparison_value = $rule->value_for($primary_query_column_name); | |||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | unless (defined $comparison_value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | $comparison_value = $self->infer_property_value_from_rule($primary_query_column_name, $rule); | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | $comparison_position = \$comparison_value; | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | push @join_comparison_info, $column_position, | |||||||||||||||||||||||||||||||||||||||||
| 257 | $comparison_position, | ||||||||||||||||||||||||||||||||||||||||||
| 258 | $comparison_type; | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | my $secondary_db_iterator = $secondary_data_source->create_iterator_closure_for_rule($secondary_rule); | |||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my $secondary_db_row; | |||||||||||||||||||||||||||||||||||||||||
| 268 | # For this closure, pass in the row we just loaded from the primary DB query. | ||||||||||||||||||||||||||||||||||||||||||
| 269 | # This one will return the data from this secondary DB's row if the passed-in | ||||||||||||||||||||||||||||||||||||||||||
| 270 | # row successfully joins to this secondary db iterator. It returns an empty list | ||||||||||||||||||||||||||||||||||||||||||
| 271 | # if there were no matches, and returns false if there is no more data from the query | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | my $join_comparator = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | my $next_db_row = shift; # From the primary DB | |||||||||||||||||||||||||||||||||||||||||
| 274 | READ_DB_ROW: | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | while(1) { | |||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | return unless ($secondary_db_iterator); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | unless ($secondary_db_row) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ($secondary_db_row) = $secondary_db_iterator->(); | |||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | unless($secondary_db_row) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | # No more data to load | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | $secondary_db_iterator = undef; | |||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | for (my $i = 0; $i < @join_comparison_info; $i += 3) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | my $secondary_column = $join_comparison_info[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | my $primary_column = $join_comparison_info[$i+1]; | |||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | my $is_numeric = $join_comparison_info[$i+2]; | |||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | my $comparison; | |||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | if (ref $primary_column) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | # This was one of those constant value items | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | if ($is_numeric) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | $comparison = $secondary_db_row->[$secondary_column] <=> $$primary_column; | |||||||||||||||||||||||||||||||||||||||||
| 296 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | $comparison = $secondary_db_row->[$secondary_column] cmp $$primary_column; | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | if ($join_comparison_info[$i+2]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | $comparison = $secondary_db_row->[$secondary_column] <=> $next_db_row->[$primary_column]; | |||||||||||||||||||||||||||||||||||||||||
| 302 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | $comparison = $secondary_db_row->[$secondary_column] cmp $next_db_row->[$primary_column]; | |||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | if ($comparison < 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | # less than, get the next row from the secondary DB | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $secondary_db_row = undef; | |||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | redo READ_DB_ROW; | |||||||||||||||||||||||||||||||||||||||||
| 310 | } elsif ($comparison == 0) { | ||||||||||||||||||||||||||||||||||||||||||
| 311 | # This one was the same, keep looking at the others | ||||||||||||||||||||||||||||||||||||||||||
| 312 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 313 | # greater-than, there's no match for this primary DB row | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 317 | # All the joined columns compared equal, return the data | ||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | return $secondary_db_row; | |||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | Sub::Name::subname('UR::Context::__join_comparator(closure)__', $join_comparator); | |||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | push @addl_join_comparators, $join_comparator; | |||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | # And for the object importer/fabricator, here's where we need to shift the column order numbers | ||||||||||||||||||||||||||||||||||||||||||
| 326 | # over, because these closures will be called after all the db iterators' rows are concatenated | ||||||||||||||||||||||||||||||||||||||||||
| 327 | # together. We also need to make a copy of the loading_templates list so as to not mess up the | ||||||||||||||||||||||||||||||||||||||||||
| 328 | # class' notion of where the columns are | ||||||||||||||||||||||||||||||||||||||||||
| 329 | # FIXME - it seems wasteful that we need to re-created this each time. Look into some way of using | ||||||||||||||||||||||||||||||||||||||||||
| 330 | # the original copy that lives in $primary_template->{'loading_templates'}? Somewhere else? | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | my @secondary_loading_templates; | |||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | foreach my $tmpl ( @{$secondary_template->{'loading_templates'}} ) { | |||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | my %copy; | |||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | foreach my $key ( keys %$tmpl ) { | |||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | my $value_to_copy = $tmpl->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | if (ref($value_to_copy) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | $copy{$key} = [ @$value_to_copy ]; | |||||||||||||||||||||||||||||||||||||||||
| 338 | } elsif (ref($value_to_copy) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | $copy{$key} = { %$value_to_copy }; | |||||||||||||||||||||||||||||||||||||||||
| 340 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | $copy{$key} = $value_to_copy; | |||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | push @secondary_loading_templates, \%copy; | |||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 346 | ($column_position_offset,$object_num_offset) = | ||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | $self->_fixup_secondary_loading_template_column_positions($primary_template->{'loading_templates'}, | |||||||||||||||||||||||||||||||||||||||||
| 348 | \@secondary_loading_templates, | ||||||||||||||||||||||||||||||||||||||||||
| 349 | $column_position_offset,$object_num_offset); | ||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | #my($secondary_rule_template,@secondary_values) = $secondary_rule->get_template_and_values(); | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | my @secondary_values = $secondary_rule->values(); | |||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | foreach my $secondary_loading_template ( @secondary_loading_templates ) { | |||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | my $secondary_object_importer = UR::Context::ObjectFabricator->create_for_loading_template( | |||||||||||||||||||||||||||||||||||||||||
| 355 | $self, | ||||||||||||||||||||||||||||||||||||||||||
| 356 | $secondary_loading_template, | ||||||||||||||||||||||||||||||||||||||||||
| 357 | $secondary_template, | ||||||||||||||||||||||||||||||||||||||||||
| 358 | $secondary_rule, | ||||||||||||||||||||||||||||||||||||||||||
| 359 | $secondary_rule_template, | ||||||||||||||||||||||||||||||||||||||||||
| 360 | \@secondary_values, | ||||||||||||||||||||||||||||||||||||||||||
| 361 | $secondary_data_source | ||||||||||||||||||||||||||||||||||||||||||
| 362 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | next unless $secondary_object_importer; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | push @secondary_object_importers, $secondary_object_importer; | |||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | return (\@secondary_object_importers, \@addl_join_comparators); | |||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | # This returns an iterator that is used to bring objects in from an underlying | ||||||||||||||||||||||||||||||||||||||||||
| 375 | # context into this context. | ||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | sub _create_import_iterator_for_underlying_context { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_import_iterator_for_underlying_context: not called CC=20 SCAR=60.4
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | my ($self, $rule, $dsx, $this_get_serial) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | # TODO: instead of taking a data source, resolve this internally. | ||||||||||||||||||||||||||||||||||||||||||
| 380 | # The underlying context itself should be responsible for its data sources. | ||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | # Make an iterator for the primary data source. | ||||||||||||||||||||||||||||||||||||||||||
| 383 | # Primary here meaning the one for the class we're explicitly requesting. | ||||||||||||||||||||||||||||||||||||||||||
| 384 | # We may need to join to other data sources to complete the query. | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | my ($db_iterator) | |||||||||||||||||||||||||||||||||||||||||
| 386 | = $dsx->create_iterator_closure_for_rule($rule); | ||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | my ($rule_template, @values) = $rule->template_and_values(); | |||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | my ($query_plan,@addl_loading_info) = $self->_resolve_query_plan_for_ds_and_bxt($dsx,$rule_template); | |||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | my $class_name = $query_plan->{class_name}; | |||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | my $group_by = $rule_template->group_by; | |||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | my $order_by = $rule_template->order_by; | |||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | my $aggregate = $rule_template->aggregate; | |||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | if (my $sub_typing_property) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | # When the rule has a property specified which indicates a specific sub-type, catch this and re-call | ||||||||||||||||||||||||||||||||||||||||||
| 398 | # this method recursively with the specific subclass name. | ||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | my ($rule_template, @values) = $rule->template_and_values(); | |||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | my $rule_template_specifies_value_for_subtype = $query_plan->{rule_template_specifies_value_for_subtype}; | |||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | my $class_table_name = $query_plan->{class_table_name}; | |||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | warn "Implement me carefully"; | |||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | if ($rule_template_specifies_value_for_subtype) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | my $sub_classification_meta_class_name = $query_plan->{sub_classification_meta_class_name}; | |||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | my $value = $rule->value_for($sub_typing_property); | |||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | my $type_obj = $sub_classification_meta_class_name->get($value); | |||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | if ($type_obj) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | my $subclass_name = $type_obj->subclass_name($class_name); | |||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | if ($subclass_name and $subclass_name ne $class_name) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$subclass_name and $subclass_name ne $class_name
MC/DC0%0/2
$subclass_name and $subclass_name ne $class_name
$subclass_name
$subclass_name ne $class_name
Truth table0%0/3
A and B
A= $subclass_nameB= $subclass_name ne $class_name
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | #$rule = $subclass_name->define_boolexpr($rule->params_list, $sub_typing_property => $value); | ||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | $rule = UR::BoolExpr->resolve_normalized($subclass_name, $rule->params_list, $sub_typing_property => $value); | |||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | return $self->_create_import_iterator_for_underlying_context($rule,$dsx,$this_get_serial); | |||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||
| 417 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | die "No $value for $class_name?\n"; | |||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||
| 421 | elsif (not $class_table_name) { | ||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | die "No longer supported!"; | |||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | my $rule = UR::BoolExpr->resolve( | |||||||||||||||||||||||||||||||||||||||||
| 424 | $class_name, | ||||||||||||||||||||||||||||||||||||||||||
| 425 | $rule_template->get_rule_for_values(@values)->params_list, | ||||||||||||||||||||||||||||||||||||||||||
| 426 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | return $self->_create_import_iterator_for_underlying_context($rule,$dsx,$this_get_serial) | |||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||
| 429 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 430 | # continue normally | ||||||||||||||||||||||||||||||||||||||||||
| 431 | # the logic below will handle sub-classifying each returned entity | ||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | my $loading_templates = $query_plan->{loading_templates}; | |||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | my $sub_typing_property = $query_plan->{sub_typing_property}; | |||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | my $next_db_row; | |||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | my $rows = 0; # number of rows the query returned | |||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | my $recursion_desc = $query_plan->{recursion_desc}; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | my($rule_template_without_recursion_desc, $rule_template_id_without_recursion); | |||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | my($rule_without_recursion_desc, $rule_id_without_recursion); | |||||||||||||||||||||||||||||||||||||||||
| 444 | # These get set if you're doing a -recurse query, and the underlying data source doesn't support recursion | ||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | my($by_hand_recursive_rule_template,$by_hand_recursive_source_property,@by_hand_recursive_source_values,$by_hand_recursing_iterator); | |||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | if ($recursion_desc) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | $rule_template_without_recursion_desc = $query_plan->{rule_template_without_recursion_desc}; | |||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | $rule_template_id_without_recursion = $rule_template_without_recursion_desc->id; | |||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | $rule_without_recursion_desc = $rule_template_without_recursion_desc->get_rule_for_values(@values); | |||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | $rule_id_without_recursion = $rule_without_recursion_desc->id; | |||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | if ($query_plan->{'recurse_resolution_by_iteration'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | # The data source does not support a recursive query. Accomplish the same thing by | ||||||||||||||||||||||||||||||||||||||||||
| 454 | # recursing back into _create_import_iterator_for_underlying_context for each level | ||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | my $this; | |||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ($this,$by_hand_recursive_source_property) = @$recursion_desc; | |||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | my @extra; | |||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | $by_hand_recursive_rule_template = UR::BoolExpr::Template->resolve($class_name, "$this in"); | |||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | $by_hand_recursive_rule_template->recursion_desc($recursion_desc); | |||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | if (!$by_hand_recursive_rule_template or @extra) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $by_hand_recursive_rule_template or @extra
MC/DC0%0/2
not $by_hand_recursive_rule_template or @extra
not $by_hand_recursive_rule_template
@extra
Truth table0%0/3
not(A) or B
A= not $by_hand_recursive_rule_templateB= @extra
| |||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | Carp::croak("Can't resolve recursive query: Class $class_name cannot filter by one or more properties: " | |||||||||||||||||||||||||||||||||||||||||
| 463 | . join(', ', @extra)); | ||||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | my $rule_id = $rule->id; | |||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | my $rule_template_id = $rule_template->id; | |||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | my $needs_further_boolexpr_evaluation_after_loading = $query_plan->{'needs_further_boolexpr_evaluation_after_loading'}; | |||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | my %subordinate_iterator_for_class; | |||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | # TODO: move the creation of the fabricators into the query plan object initializer. | ||||||||||||||||||||||||||||||||||||||||||
| 476 | # instead of making just one import iterator, we make one per loading template | ||||||||||||||||||||||||||||||||||||||||||
| 477 | # we then have our primary iterator use these to fabricate objects for each db row | ||||||||||||||||||||||||||||||||||||||||||
| 478 | my @object_fabricators; | ||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | ▶ | if ($group_by) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 480 | # returning sets for each sub-group instead of instance objects... | ||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | my $division_point = scalar(@$group_by)-1; | |||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | my $subset_template = $rule_template->_template_for_grouped_subsets(); | |||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | my $set_class = $class_name . '::Set'; | |||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | ▶ | my @aggregate_properties = ($aggregate ? @$aggregate : ()); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | ▶ | unshift(@aggregate_properties, 'count') unless (grep { $_ eq 'count' } @aggregate_properties); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | my $fab_subref = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | my $row = $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | my @group_values = @$row[0..$division_point]; | |||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | my $ss_rule = $subset_template->get_rule_for_values(@values, @group_values); | |||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | my $set = $set_class->get($ss_rule->id); | |||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | ▶ | unless ($set) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | Carp::croak("Failed to fabricate $set_class for rule $ss_rule"); | |||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | ▶ | my $aggregates = $set->{__aggregates} ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$set->{"__aggregates"} ||= {}
MC/DC0%0/1
$set->{"__aggregates"} ||= {}
$set->{"__aggregates"}
Truth table0%0/2
A
A= $set->{"__aggregates"}
| |||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | @$aggregates{@aggregate_properties} = @$row[$division_point+1..$#$row]; | |||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | return $set; | |||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | my $object_fabricator = UR::Context::ObjectFabricator->_create( | |||||||||||||||||||||||||||||||||||||||||
| 501 | fabricator => $fab_subref, | ||||||||||||||||||||||||||||||||||||||||||
| 502 | context => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 503 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | unshift @object_fabricators, $object_fabricator; | |||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||
| 506 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 507 | # regular instances | ||||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | for my $loading_template (@$loading_templates) { | |||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | my $object_fabricator = | |||||||||||||||||||||||||||||||||||||||||
| 510 | UR::Context::ObjectFabricator->create_for_loading_template( | ||||||||||||||||||||||||||||||||||||||||||
| 511 | $self, | ||||||||||||||||||||||||||||||||||||||||||
| 512 | $loading_template, | ||||||||||||||||||||||||||||||||||||||||||
| 513 | $query_plan, | ||||||||||||||||||||||||||||||||||||||||||
| 514 | $rule, | ||||||||||||||||||||||||||||||||||||||||||
| 515 | $rule_template, | ||||||||||||||||||||||||||||||||||||||||||
| 516 | \@values, | ||||||||||||||||||||||||||||||||||||||||||
| 517 | $dsx, | ||||||||||||||||||||||||||||||||||||||||||
| 518 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | ▶ | next unless $object_fabricator; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | unshift @object_fabricators, $object_fabricator; | |||||||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||
| 524 | # For joins across data sources, we need to create importers/fabricators for those | ||||||||||||||||||||||||||||||||||||||||||
| 525 | # classes, as well as callbacks used to perform the equivalent of an SQL join in | ||||||||||||||||||||||||||||||||||||||||||
| 526 | # UR-space | ||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | my @addl_join_comparators; | |||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | ▶ | if (@addl_loading_info) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | ▶ | if ($group_by) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | Carp::croak("cross-datasource group-by is not supported yet"); | |||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | my($addl_object_fabricators, $addl_join_comparators) = | |||||||||||||||||||||||||||||||||||||||||
| 533 | $self->_create_secondary_loading_closures( $query_plan, | ||||||||||||||||||||||||||||||||||||||||||
| 534 | $rule, | ||||||||||||||||||||||||||||||||||||||||||
| 535 | @addl_loading_info | ||||||||||||||||||||||||||||||||||||||||||
| 536 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | unshift @object_fabricators, @$addl_object_fabricators; | |||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | push @addl_join_comparators, @$addl_join_comparators; | |||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | # To avoid calling the useless method 'fabricate' on a fabricator object for each object of each resultset row | ||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | my @object_fabricator_closures = map { $_->fabricator } @object_fabricators; | |||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | # Insert the key into all_objects_are_loaded to indicate that when we're done loading, we'll | ||||||||||||||||||||||||||||||||||||||||||
| 546 | # have everything | ||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | ▶ | if ($query_plan->{'rule_matches_all'} and not $group_by) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$query_plan->{"rule_matches_all"} and not $group_by
MC/DC0%0/2
$query_plan->{"rule_matches_all"} and not $group_by
$query_plan->{"rule_matches_all"}
not $group_by
Truth table0%0/3
A and not(B)
A= $query_plan->{"rule_matches_all"}B= not $group_by
| |||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | $class_name->all_objects_are_loaded(undef); | |||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | #my $is_monitor_query = $self->monitor_query(); | ||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | # Make the iterator we'll return. | ||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | my $next_object_to_return; | |||||||||||||||||||||||||||||||||||||||||
| 555 | my @object_ids_from_fabricators; | ||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | ▶ | my $underlying_context_iterator = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=46 SCAR=76.8
| |||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | ▶ | return undef unless $db_iterator; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | my $primary_object_for_next_db_row; | |||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||
| 561 | LOAD_AN_OBJECT: | ||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | ▶ | until (defined $primary_object_for_next_db_row) { # note that we return directly when the db is out of data | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | my ($next_db_row); | |||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | ▶ | ($next_db_row) = $db_iterator->() if ($db_iterator); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | ▶ | if (! $next_db_row and $by_hand_recursive_rule_template and @by_hand_recursive_source_values) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not $next_db_row and $by_hand_recursive_rule_template and @by_hand_recursive_source_values
not $next_db_row and $by_hand_recursive_rule_template
MC/DC0%0/3
not $next_db_row and $by_hand_recursive_rule_template and @by_hand_recursive_source_values
not $next_db_row
$by_hand_recursive_rule_template
@by_hand_recursive_source_values
Truth table0%0/4
not(A) and B and C
A= not $next_db_rowB= $by_hand_recursive_rule_templateC= @by_hand_recursive_source_values
| |||||||||||||||||||||||||||||||||||||||||||
| 568 | # DB is out of results for this query, we need to handle recursion here in the context | ||||||||||||||||||||||||||||||||||||||||||
| 569 | # and there are values to recurse on | ||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | ▶ | unless ($by_hand_recursing_iterator) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 571 | # Do a new get() on the data source to recursively get more data | ||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | my $recurse_rule = $by_hand_recursive_rule_template->get_rule_for_values(\@by_hand_recursive_source_values); | |||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | $by_hand_recursing_iterator = $self->_create_import_iterator_for_underlying_context($recurse_rule,$dsx,$this_get_serial); | |||||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | my $retval = $next_object_to_return; | |||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | $next_object_to_return = $by_hand_recursing_iterator->(); | |||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | ▶ | unless ($next_object_to_return) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | $by_hand_recursing_iterator = undef; | |||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | $by_hand_recursive_rule_template = undef; | |||||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | return $retval; | |||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | ▶ | unless ($next_db_row) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | $db_iterator = undef; | |||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | ▶ | if ($rows == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 588 | # if we got no data at all from the sql then we give a status | ||||||||||||||||||||||||||||||||||||||||||
| 589 | # message about it and we update all_params_loaded to indicate | ||||||||||||||||||||||||||||||||||||||||||
| 590 | # that this set of parameters yielded 0 objects | ||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | my $rule_template_is_id_only = $query_plan->{rule_template_is_id_only}; | |||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | ▶ | if ($rule_template_is_id_only) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | my $id = $rule->value_for_id; | |||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | $UR::Context::all_objects_loaded->{$class_name}->{$id} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||
| 597 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | $UR::Context::all_params_loaded->{$rule_template_id}->{$rule_id} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | ▶ | if ( $query_plan->{rule_matches_all} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 603 | # No parameters. We loaded the whole class. | ||||||||||||||||||||||||||||||||||||||||||
| 604 | # Doing a load w/o a specific ID w/o custom SQL loads the whole class. | ||||||||||||||||||||||||||||||||||||||||||
| 605 | # Set a flag so that certain optimizations can be made, such as | ||||||||||||||||||||||||||||||||||||||||||
| 606 | # short-circuiting future loads of this class. | ||||||||||||||||||||||||||||||||||||||||||
| 607 | # | ||||||||||||||||||||||||||||||||||||||||||
| 608 | # If the key still exists in the all_objects_are_loaded hash, then | ||||||||||||||||||||||||||||||||||||||||||
| 609 | # we can set it to true. This is needed in the case where the user | ||||||||||||||||||||||||||||||||||||||||||
| 610 | # gets an iterator for all the objects of some class, but unloads | ||||||||||||||||||||||||||||||||||||||||||
| 611 | # one or more of the instances (be calling unload or through the | ||||||||||||||||||||||||||||||||||||||||||
| 612 | # cache pruner) before the iterator completes. If so, _abandon_object() | ||||||||||||||||||||||||||||||||||||||||||
| 613 | # will have removed the key from the hash | ||||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | ▶ | if (exists($UR::Context::all_objects_are_loaded->{$class_name})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | $class_name->all_objects_are_loaded(1); | |||||||||||||||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | ▶ | if ($recursion_desc) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | my @results = $class_name->is_loaded($rule_without_recursion_desc); | |||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | $UR::Context::all_params_loaded->{$rule_template_id_without_recursion}{$rule_id_without_recursion} = scalar(@results); | |||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | for my $object (@results) { | |||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | $object->{__load}->{$rule_template_id_without_recursion}->{$rule_id_without_recursion}++; | |||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||
| 627 | # Apply changes to all_params_loaded that each importer has collected | ||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | foreach (@object_fabricators) { | |||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | ▶ | $_->finalize if $_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||
| 632 | # If the SQL for the subclassed items was constructed properly, then each | ||||||||||||||||||||||||||||||||||||||||||
| 633 | # of these iterators should be at the end, too. Call them one more time | ||||||||||||||||||||||||||||||||||||||||||
| 634 | # so they'll finalize their object fabricators. | ||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | foreach my $class ( keys %subordinate_iterator_for_class ) { | |||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | my $obj = $subordinate_iterator_for_class{$class}->(); | |||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | ▶ | if ($obj) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 638 | # The last time this happened, it was because a get() was done on an abstract | ||||||||||||||||||||||||||||||||||||||||||
| 639 | # base class with only 'id' as a param. When the subclassified rule was | ||||||||||||||||||||||||||||||||||||||||||
| 640 | # turned into SQL in UR::DataSource::QueryPlan() | ||||||||||||||||||||||||||||||||||||||||||
| 641 | # it removed that one 'id' filter, since it assumed any class with more than | ||||||||||||||||||||||||||||||||||||||||||
| 642 | # one ID property (usually classes have a named whatever_id property, and an alias 'id' | ||||||||||||||||||||||||||||||||||||||||||
| 643 | # property) will have a rule that covered both ID properties | ||||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | Carp::carp("Leftover objects in subordinate iterator for $class. This shouldn't happen, but it's not fatal..."); | |||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | ▶ | while ($obj = $subordinate_iterator_for_class{$class}->()) {1;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | my $retval = $next_object_to_return; | |||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | $next_object_to_return = undef; | |||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | return $retval; | |||||||||||||||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||
| 654 | # we count rows processed mainly for more concise sanity checking | ||||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | $rows++; | |||||||||||||||||||||||||||||||||||||||||
| 656 | # For multi-datasource queries, does this row successfully join with all the other datasources? | ||||||||||||||||||||||||||||||||||||||||||
| 657 | # | ||||||||||||||||||||||||||||||||||||||||||
| 658 | # Normally, the policy is for the data source query to return (possibly) more than what you | ||||||||||||||||||||||||||||||||||||||||||
| 659 | # asked for, and then we'd cache everything that may have been loaded. In this case, we're | ||||||||||||||||||||||||||||||||||||||||||
| 660 | # making the choice not to. Reason being that a join across databases is likely to involve | ||||||||||||||||||||||||||||||||||||||||||
| 661 | # a lot of objects, and we don't want to be stuffing our object cache with a lot of things | ||||||||||||||||||||||||||||||||||||||||||
| 662 | # we're not interested in. FIXME - in order for this to be true, then we could never query | ||||||||||||||||||||||||||||||||||||||||||
| 663 | # these secondary data sources against, say, a calculated property because we're never turning | ||||||||||||||||||||||||||||||||||||||||||
| 664 | # them into objects. FIXME - fix this by setting the $needs_further_boolexpr_evaluation_after_loading | ||||||||||||||||||||||||||||||||||||||||||
| 665 | # flag maybe? | ||||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | my @secondary_data; | |||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | foreach my $callback (@addl_join_comparators) { | |||||||||||||||||||||||||||||||||||||||||
| 668 | # FIXME - (no, not another one...) There's no mechanism for duplicating SQL join's | ||||||||||||||||||||||||||||||||||||||||||
| 669 | # behavior where if a row from a table joins to 2 rows in the secondary table, the | ||||||||||||||||||||||||||||||||||||||||||
| 670 | # first table's data will be in the result set twice. | ||||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | my $secondary_db_row = $callback->($next_db_row); | |||||||||||||||||||||||||||||||||||||||||
| 672 | 0 | ▶ | unless (defined $secondary_db_row) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 673 | # That data source has no more data, so there can be no more joins even if the | ||||||||||||||||||||||||||||||||||||||||||
| 674 | # primary data source has more data left to read | ||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | $db_iterator = undef; | |||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | $primary_object_for_next_db_row = undef; | |||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | last LOAD_AN_OBJECT; | |||||||||||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | ▶ | unless ($secondary_db_row) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 680 | # It returned 0 | ||||||||||||||||||||||||||||||||||||||||||
| 681 | # didn't join (but there is still more data we can read later)... throw this row out. | ||||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | $primary_object_for_next_db_row = undef; | |||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | redo LOAD_AN_OBJECT; | |||||||||||||||||||||||||||||||||||||||||
| 684 | } | ||||||||||||||||||||||||||||||||||||||||||
| 685 | # $next_db_row is a read-only value from DBI, so we need to track our additional | ||||||||||||||||||||||||||||||||||||||||||
| 686 | # data seperately and smash them together before the object importer is called | ||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | push(@secondary_data, @$secondary_db_row); | |||||||||||||||||||||||||||||||||||||||||
| 688 | } | ||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||
| 690 | # get one or more objects from this row of results | ||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | my $re_iterate = 0; | |||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | my @imported; | |||||||||||||||||||||||||||||||||||||||||
| 693 | 0 | ▶ | for (my $i = 0; $i < @object_fabricator_closures; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 694 | 0 | my $object_fabricator = $object_fabricator_closures[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||
| 696 | # The usual case is that the query is just against one data source, and so the importer | ||||||||||||||||||||||||||||||||||||||||||
| 697 | # callback is just given the row returned from the DB query. For multiple data sources, | ||||||||||||||||||||||||||||||||||||||||||
| 698 | # we need to smash together the primary and all the secondary lists | ||||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | my $imported_object; | |||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||
| 701 | #my $object_creation_time; | ||||||||||||||||||||||||||||||||||||||||||
| 702 | #if ($is_monitor_query) { | ||||||||||||||||||||||||||||||||||||||||||
| 703 | # $object_creation_time = Time::HiRes::time(); | ||||||||||||||||||||||||||||||||||||||||||
| 704 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||
| 706 | 0 | ▶ | if (@secondary_data) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | $imported_object = $object_fabricator->([@$next_db_row, @secondary_data]); | |||||||||||||||||||||||||||||||||||||||||
| 708 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 709 | 0 | $imported_object = $object_fabricator->($next_db_row); | |||||||||||||||||||||||||||||||||||||||||
| 710 | } | ||||||||||||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||||||||||
| 712 | #if ($is_monitor_query) { | ||||||||||||||||||||||||||||||||||||||||||
| 713 | # $self->_log_query_for_rule($class_name, $rule, sprintf("QUERY: object fabricator took %.4f s",Time::HiRes::time() - $object_creation_time)); | ||||||||||||||||||||||||||||||||||||||||||
| 714 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | ▶ | if ($imported_object and not ref($imported_object)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$imported_object and not ref $imported_object
MC/DC0%0/2
$imported_object and not ref $imported_object
$imported_object
not ref $imported_object
Truth table0%0/3
A and not(B)
A= $imported_objectB= not ref $imported_object
| |||||||||||||||||||||||||||||||||||||||||||
| 717 | # object requires sub-classsification in a way which involves different db data. | ||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | $re_iterate = 1; | |||||||||||||||||||||||||||||||||||||||||
| 719 | } | ||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | push @imported, $imported_object; | |||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||
| 722 | # If the object ID for fabricator slot $i changes, then we can apply the | ||||||||||||||||||||||||||||||||||||||||||
| 723 | # all_params_loaded changes from iterators 0 .. $i-1 because we know we've | ||||||||||||||||||||||||||||||||||||||||||
| 724 | # loaded all the hangoff data related to the previous object | ||||||||||||||||||||||||||||||||||||||||||
| 725 | # remember that the last fabricator in the list is for the primary object | ||||||||||||||||||||||||||||||||||||||||||
| 726 | 0 | ▶ | if (defined $imported_object and ref($imported_object)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $imported_object and ref $imported_object
MC/DC0%0/2
defined $imported_object and ref $imported_object
defined $imported_object
ref $imported_object
Truth table0%0/3
A and B
A= defined $imported_objectB= ref $imported_object
| |||||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | ▶ | if (!defined $object_ids_from_fabricators[$i]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | $object_ids_from_fabricators[$i] = $imported_object->id; | |||||||||||||||||||||||||||||||||||||||||
| 729 | } elsif ($object_ids_from_fabricators[$i] ne $imported_object->id) { | ||||||||||||||||||||||||||||||||||||||||||
| 730 | 0 | ▶ | for (my $j = 0; $j < $i; $j++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | $object_fabricators[$j]->apply_all_params_loaded; | |||||||||||||||||||||||||||||||||||||||||
| 732 | } | ||||||||||||||||||||||||||||||||||||||||||
| 733 | 0 | $object_ids_from_fabricators[$i] = $imported_object->id; | |||||||||||||||||||||||||||||||||||||||||
| 734 | } | ||||||||||||||||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||||||||||||||||
| 736 | } | ||||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||
| 738 | 0 | $primary_object_for_next_db_row = $imported[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||||||||||||
| 740 | # The object importer will return undef for an object if no object | ||||||||||||||||||||||||||||||||||||||||||
| 741 | # got created for that $next_db_row, and will return a string if the object | ||||||||||||||||||||||||||||||||||||||||||
| 742 | # needs to be subclassed before being returned. Don't put serial numbers on | ||||||||||||||||||||||||||||||||||||||||||
| 743 | # these | ||||||||||||||||||||||||||||||||||||||||||
| 744 | 0 | map { $_->{'__get_serial'} = $this_get_serial } | |||||||||||||||||||||||||||||||||||||||||
| 745 | 0 | ▶ | grep { defined && ref } | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $_ && ref $_
MC/DC0%0/2
defined $_ && ref $_
defined $_
ref $_
Truth table0%0/3
A && B
A= defined $_B= ref $_
| |||||||||||||||||||||||||||||||||||||||||||
| 746 | @imported; | ||||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||
| 748 | 0 | ▶ | if ($re_iterate and defined($primary_object_for_next_db_row) and ! ref($primary_object_for_next_db_row)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$re_iterate and defined $primary_object_for_next_db_row and not ref $primary_object_for_next_db_row
$re_iterate and defined $primary_object_for_next_db_row
MC/DC0%0/3
$re_iterate and defined $primary_object_for_next_db_row and not ref $primary_object_for_next_db_row
$re_iterate
defined $primary_object_for_next_db_row
not ref $primary_object_for_next_db_row
Truth table0%0/4
A and B and not(C)
A= $re_iterateB= defined $primary_object_for_next_db_rowC= not ref $primary_object_for_next_db_row
| |||||||||||||||||||||||||||||||||||||||||||
| 749 | # It is possible that one or more objects go into subclasses which require more | ||||||||||||||||||||||||||||||||||||||||||
| 750 | # data than is on the results row. For each subclass (or set of subclasses), | ||||||||||||||||||||||||||||||||||||||||||
| 751 | # we make a more specific, subordinate iterator to delegate-to. | ||||||||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | my $subclass_name = $primary_object_for_next_db_row; | |||||||||||||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||||||||||||
| 755 | 0 | my $subclass_meta = UR::Object::Type->get(class_name => $subclass_name); | |||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | my $table_subclass = $subclass_meta->most_specific_subclass_with_table(); | |||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | my $sub_iterator = $subordinate_iterator_for_class{$table_subclass}; | |||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | ▶ | unless ($sub_iterator) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 759 | #print "parallel iteration for loading $subclass_name under $class_name!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 760 | 0 | my $sub_classified_rule_template = $rule_template->sub_classify($subclass_name); | |||||||||||||||||||||||||||||||||||||||||
| 761 | 0 | my $sub_classified_rule = $sub_classified_rule_template->get_normalized_rule_for_values(@values); | |||||||||||||||||||||||||||||||||||||||||
| 762 | $sub_iterator | ||||||||||||||||||||||||||||||||||||||||||
| 763 | 0 | = $subordinate_iterator_for_class{$table_subclass} | |||||||||||||||||||||||||||||||||||||||||
| 764 | = $self->_create_import_iterator_for_underlying_context($sub_classified_rule,$dsx,$this_get_serial); | ||||||||||||||||||||||||||||||||||||||||||
| 765 | } | ||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | ($primary_object_for_next_db_row) = $sub_iterator->(); | |||||||||||||||||||||||||||||||||||||||||
| 767 | 0 | ▶ | if (! defined $primary_object_for_next_db_row) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 768 | # the newly subclassed object | ||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | redo LOAD_AN_OBJECT; | |||||||||||||||||||||||||||||||||||||||||
| 770 | } | ||||||||||||||||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||||||||||||||||
| 772 | } # end of handling a possible subordinate iterator delegate | ||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | ▶ | unless (defined $primary_object_for_next_db_row) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 775 | #if (!$primary_object_for_next_db_row or $rule->evaluate($primary_object_for_next_db_row)) { | ||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | redo LOAD_AN_OBJECT; | |||||||||||||||||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | ▶ | if ( !$group_by and (ref($primary_object_for_next_db_row) ne $class_name) and (not $primary_object_for_next_db_row->isa($class_name)) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not $group_by and ref $primary_object_for_next_db_row ne $class_name and not $primary_object_for_next_db_row->isa($class_name)
not $group_by and ref $primary_object_for_next_db_row ne $class_name
MC/DC0%0/3
not $group_by and ref $primary_object_for_next_db_row ne $class_name and not $primary_object_for_next_db_row->isa($class_name)
not $group_by
ref $primary_object_for_next_db_row ne $class_name
not $primary_object_for_next_db_row->isa($class_name)
Truth table0%0/4
not(A) and B and not(C)
A= not $group_byB= ref $primary_object_for_next_db_row ne $class_nameC= not $primary_object_for_next_db_row->isa($class_name)
| |||||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | $primary_object_for_next_db_row = undef; | |||||||||||||||||||||||||||||||||||||||||
| 781 | 0 | redo LOAD_AN_OBJECT; | |||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | ▶ | if ($by_hand_recursive_source_property) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 785 | 0 | my @values = grep { defined } $primary_object_for_next_db_row->$by_hand_recursive_source_property; | |||||||||||||||||||||||||||||||||||||||||
| 786 | 0 | push @by_hand_recursive_source_values, @values; | |||||||||||||||||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | ▶ | if (! defined($next_object_to_return) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $next_object_to_return or builtin::refaddr($next_object_to_return) == builtin::refaddr($primary_object_for_next_db_row)
MC/DC0%0/2
not defined $next_object_to_return or builtin::refaddr($next_object_to_return) == builtin::refaddr($primary_object_for_next_db_row)
not defined $next_object_to_return
builtin::refaddr($next_object_to_return) == builtin::refaddr($primary_object_for_next_db_row)
Truth table0%0/3
not(A) or B
A= not defined $next_object_to_returnB= builtin::refaddr($next_object_to_return) == builtin::refaddr($primary_object_for_next_db_row)
| |||||||||||||||||||||||||||||||||||||||||||
| 790 | or (Scalar::Util::refaddr($next_object_to_return) == Scalar::Util::refaddr($primary_object_for_next_db_row)) | ||||||||||||||||||||||||||||||||||||||||||
| 791 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 792 | # The first time through the iterator, we need to buffer the object until | ||||||||||||||||||||||||||||||||||||||||||
| 793 | # $primary_object_for_next_db_row is something different. | ||||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | $next_object_to_return = $primary_object_for_next_db_row; | |||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | $primary_object_for_next_db_row = undef; | |||||||||||||||||||||||||||||||||||||||||
| 796 | 0 | redo LOAD_AN_OBJECT; | |||||||||||||||||||||||||||||||||||||||||
| 797 | } | ||||||||||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||
| 800 | } # end of loop until we have a defined object to return | ||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||
| 802 | #foreach my $object_fabricator ( @object_fabricators ) { | ||||||||||||||||||||||||||||||||||||||||||
| 803 | # # Don't apply all_params_loaded for primary fab until it's all done | ||||||||||||||||||||||||||||||||||||||||||
| 804 | # next if ($object_fabricator eq $object_fabricators[-1]); | ||||||||||||||||||||||||||||||||||||||||||
| 805 | # $object_fabricator->apply_all_params_loaded; | ||||||||||||||||||||||||||||||||||||||||||
| 806 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||
| 808 | 0 | my $retval = $next_object_to_return; | |||||||||||||||||||||||||||||||||||||||||
| 809 | 0 | $next_object_to_return = $primary_object_for_next_db_row; | |||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | return $retval; | |||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | Sub::Name::subname('UR::Context::__underlying_context_iterator(closure)__', $underlying_context_iterator); | |||||||||||||||||||||||||||||||||||||||||
| 814 | 0 | return $underlying_context_iterator; | |||||||||||||||||||||||||||||||||||||||||
| 815 | } | ||||||||||||||||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||
| 819 | 266 | 1; | |||||||||||||||||||||||||||||||||||||||||