[Bio] / Sprout / ERDB.pm Repository:
ViewVC logotype

Diff of /Sprout/ERDB.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.55, Sat Jun 24 23:49:10 2006 UTC revision 1.67, Fri Jul 14 01:36:29 2006 UTC
# Line 91  Line 91 
91    
92  32-bit signed integer  32-bit signed integer
93    
94    =item counter
95    
96    32-bit unsigned integer
97    
98  =item date  =item date
99    
100  64-bit unsigned integer, representing a PERL date/time value  64-bit unsigned integer, representing a PERL date/time value
# Line 318  Line 322 
322  # "maxLen" is the maximum permissible length of the incoming string data used to populate a field  # "maxLen" is the maximum permissible length of the incoming string data used to populate a field
323  # of the specified type. "dataGen" is PERL string that will be evaluated if no test data generation  # of the specified type. "dataGen" is PERL string that will be evaluated if no test data generation
324  # string is specified in the field definition. "avgLen" is the average byte length for estimating  # string is specified in the field definition. "avgLen" is the average byte length for estimating
325  # record sizes.  # record sizes. "sort" is the key modifier for the sort command.
326  my %TypeTable = ( char =>    { sqlType => 'CHAR(1)',            maxLen => 1,            avgLen =>   1, dataGen => "StringGen('A')" },  my %TypeTable = ( char =>    { sqlType => 'CHAR(1)',            maxLen => 1,            avgLen =>   1, sort => "",  dataGen => "StringGen('A')" },
327                    int =>     { sqlType => 'INTEGER',            maxLen => 20,           avgLen =>   4, dataGen => "IntGen(0, 99999999)" },                    int =>     { sqlType => 'INTEGER',            maxLen => 20,           avgLen =>   4, sort => "n", dataGen => "IntGen(0, 99999999)" },
328                    string =>  { sqlType => 'VARCHAR(255)',       maxLen => 255,          avgLen => 100, dataGen => "StringGen(IntGen(10,250))" },                    counter => { sqlType => 'INTEGER UNSIGNED',   maxLen => 20,           avgLen =>   4, sort => "n", dataGen => "IntGen(0, 99999999)" },
329                    text =>    { sqlType => 'TEXT',               maxLen => 1000000000,   avgLen => 500, dataGen => "StringGen(IntGen(80,1000))" },                    string =>  { sqlType => 'VARCHAR(255)',       maxLen => 255,          avgLen => 100, sort => "",  dataGen => "StringGen(IntGen(10,250))" },
330                    date =>    { sqlType => 'BIGINT',             maxLen => 80,           avgLen =>   8, dataGen => "DateGen(-7, 7, IntGen(0,1400))" },                    text =>    { sqlType => 'TEXT',               maxLen => 1000000000,   avgLen => 500, sort => "",  dataGen => "StringGen(IntGen(80,1000))" },
331                    float =>   { sqlType => 'DOUBLE PRECISION',   maxLen => 40,           avgLen =>   8, dataGen => "FloatGen(0.0, 100.0)" },                    date =>    { sqlType => 'BIGINT',             maxLen => 80,           avgLen =>   8, sort => "n", dataGen => "DateGen(-7, 7, IntGen(0,1400))" },
332                    boolean => { sqlType => 'SMALLINT',           maxLen => 1,            avgLen =>   1, dataGen => "IntGen(0, 1)" },                    float =>   { sqlType => 'DOUBLE PRECISION',   maxLen => 40,           avgLen =>   8, sort => "g", dataGen => "FloatGen(0.0, 100.0)" },
333                      boolean => { sqlType => 'SMALLINT',           maxLen => 1,            avgLen =>   1, sort => "n", dataGen => "IntGen(0, 1)" },
334                   'hash-string' =>                   'hash-string' =>
335                               { sqlType => 'VARCHAR(22)',        maxLen => 22,           avgLen =>  22, dataGen => "SringGen(22)" },                               { sqlType => 'VARCHAR(22)',        maxLen => 22,           avgLen =>  22, sort => "",  dataGen => "SringGen(22)" },
336                   'id-string' =>                   'id-string' =>
337                               { sqlType => 'VARCHAR(25)',        maxLen => 25,           avgLen =>  25, dataGen => "SringGen(22)" },                               { sqlType => 'VARCHAR(25)',        maxLen => 25,           avgLen =>  25, sort => "",  dataGen => "SringGen(22)" },
338                   'key-string' =>                   'key-string' =>
339                               { sqlType => 'VARCHAR(40)',        maxLen => 40,           avgLen =>  10, dataGen => "StringGen(IntGen(10,40))" },                               { sqlType => 'VARCHAR(40)',        maxLen => 40,           avgLen =>  10, sort => "",  dataGen => "StringGen(IntGen(10,40))" },
340                   'name-string' =>                   'name-string' =>
341                               { sqlType => 'VARCHAR(80)',        maxLen => 80,           avgLen =>  40, dataGen => "StringGen(IntGen(10,80))" },                               { sqlType => 'VARCHAR(80)',        maxLen => 80,           avgLen =>  40, sort => "",  dataGen => "StringGen(IntGen(10,80))" },
342                   'medium-string' =>                   'medium-string' =>
343                               { sqlType => 'VARCHAR(160)',       maxLen => 160,          avgLen =>  40, dataGen => "StringGen(IntGen(10,160))" },                               { sqlType => 'VARCHAR(160)',       maxLen => 160,          avgLen =>  40, sort => "",  dataGen => "StringGen(IntGen(10,160))" },
344                  );                  );
345    
346  # Table translating arities into natural language.  # Table translating arities into natural language.
# Line 1431  Line 1436 
1436  sub GetCount {  sub GetCount {
1437      # Get the parameters.      # Get the parameters.
1438      my ($self, $objectNames, $filter, $params) = @_;      my ($self, $objectNames, $filter, $params) = @_;
1439        # Insure the params argument is an array reference if the caller left it off.
1440        if (! defined($params)) {
1441            $params = [];
1442        }
1443      # Declare the return variable.      # Declare the return variable.
1444      my $retVal;      my $retVal;
1445      # Find out if we're counting an entity or a relationship.      # Find out if we're counting an entity or a relationship.
# Line 1623  Line 1632 
1632  The next statement inserts a C<HasProperty> relationship between feature C<fig|158879.1.peg.1> and  The next statement inserts a C<HasProperty> relationship between feature C<fig|158879.1.peg.1> and
1633  property C<4> with an evidence URL of C<http://seedu.uchicago.edu/query.cgi?article_id=142>.  property C<4> with an evidence URL of C<http://seedu.uchicago.edu/query.cgi?article_id=142>.
1634    
1635  C<< $erdb->InsertObject('HasProperty', { 'from-link' => 'fig|158879.1.peg.1', 'to-link' => 4, evidence = 'http://seedu.uchicago.edu/query.cgi?article_id=142'}); >>  C<< $erdb->InsertObject('HasProperty', { 'from-link' => 'fig|158879.1.peg.1', 'to-link' => 4, evidence => 'http://seedu.uchicago.edu/query.cgi?article_id=142'}); >>
1636    
1637  =over 4  =over 4
1638    
# Line 1833  Line 1842 
1842          }          }
1843      }      }
1844      # Analyze the table to improve performance.      # Analyze the table to improve performance.
1845        Trace("Analyzing and compacting $relationName.") if T(3);
1846      $dbh->vacuum_it($relationName);      $dbh->vacuum_it($relationName);
1847        Trace("$relationName load completed.") if T(3);
1848      # Return the statistics.      # Return the statistics.
1849      return $retVal;      return $retVal;
1850  }  }
# Line 3233  Line 3244 
3244    
3245  =head3 SortNeeded  =head3 SortNeeded
3246    
3247  C<< my $flag = $erdb->SortNeeded($relationName); >>  C<< my $parms = $erdb->SortNeeded($relationName); >>
3248    
3249    Return the pipe command for the sort that should be applied to the specified
3250    relation when creating the load file.
3251    
3252    For example, if the load file should be sorted ascending by the first
3253    field, this method would return
3254    
3255  Return TRUE if the specified relation should be sorted during loading to remove duplicate keys,      sort -k1 -t"\t"
3256  else FALSE.  
3257    If the first field is numeric, the method would return
3258    
3259        sort -k1n -t"\t"
3260    
3261    Unfortunately, due to a bug in the C<sort> command, we cannot eliminate duplicate
3262    keys using a sort.
3263    
3264  =over 4  =over 4
3265    
# Line 3244  Line 3267 
3267    
3268  Name of the relation to be examined.  Name of the relation to be examined.
3269    
3270  =item RETURN  =item
3271    
3272  Returns TRUE if the relation needs a sort, else FALSE.  Returns the sort command to use for sorting the relation, suitable for piping.
3273    
3274  =back  =back
3275    
# Line 3255  Line 3278 
3278  sub SortNeeded {  sub SortNeeded {
3279      # Get the parameters.      # Get the parameters.
3280      my ($self, $relationName) = @_;      my ($self, $relationName) = @_;
3281      # Declare the return variable.      # Declare a descriptor to hold the names of the key fields.
3282      my $retVal = 0;      my @keyNames = ();
3283      # Find out if the relation is a primary entity relation.      # Get the relation structure.
3284        my $relationData = $self->_FindRelation($relationName);
3285        # Find out if the relation is a primary entity relation,
3286        # a relationship relation, or a secondary entity relation.
3287      my $entityTable = $self->{_metaData}->{Entities};      my $entityTable = $self->{_metaData}->{Entities};
3288        my $relationshipTable = $self->{_metaData}->{Relationships};
3289      if (exists $entityTable->{$relationName}) {      if (exists $entityTable->{$relationName}) {
3290          my $keyType = $entityTable->{$relationName}->{keyType};          # Here we have a primary entity relation.
3291          Trace("Relation $relationName found in entity table with key type $keyType.") if T(3);          push @keyNames, "id";
3292          # If the key is not a hash string, we must do the sort.      } elsif (exists $relationshipTable->{$relationName}) {
3293          if ($keyType ne 'hash-string') {          # Here we have a relationship. We sort using the FROM index.
3294              $retVal = 1;          my $relationshipData = $relationshipTable->{$relationName};
3295            my $index = $relationData->{Indexes}->{"idx${relationName}From"};
3296            push @keyNames, @{$index->{IndexFields}};
3297        } else {
3298            # Here we have a secondary entity relation, so we have a sort on the ID field.
3299            push @keyNames, "id";
3300        }
3301        # Now we parse the key names into sort parameters. First, we prime the return
3302        # string.
3303        my $retVal = "sort -t\"\t\" ";
3304        # Get the relation's field list.
3305        my @fields = @{$relationData->{Fields}};
3306        # Loop through the keys.
3307        for my $keyData (@keyNames) {
3308            # Get the key and the ordering.
3309            my ($keyName, $ordering);
3310            if ($keyData =~ /^([^ ]+) DESC/) {
3311                ($keyName, $ordering) = ($1, "descending");
3312            } else {
3313                ($keyName, $ordering) = ($keyData, "ascending");
3314            }
3315            # Find the key's position and type.
3316            my $fieldSpec;
3317            for (my $i = 0; $i <= $#fields && ! $fieldSpec; $i++) {
3318                my $thisField = $fields[$i];
3319                if ($thisField->{name} eq $keyName) {
3320                    # Get the sort modifier for this field type. The modifier
3321                    # decides whether we're using a character, numeric, or
3322                    # floating-point sort.
3323                    my $modifier = $TypeTable{$thisField->{type}}->{sort};
3324                    # If the index is descending for this field, denote we want
3325                    # to reverse the sort order on this field.
3326                    if ($ordering eq 'descending') {
3327                        $modifier .= "r";
3328                    }
3329                    # Store the position and modifier into the field spec, which
3330                    # will stop the inner loop. Note that the field number is
3331                    # 1-based in the sort command, so we have to increment the
3332                    # index.
3333                    $fieldSpec = ($i + 1) . $modifier;
3334                }
3335          }          }
3336            # Add this field to the sort command.
3337            $retVal .= " -k$fieldSpec";
3338      }      }
3339      # Return the result.      # Return the result.
3340      return $retVal;      return $retVal;

Legend:
Removed from v.1.55  
changed lines
  Added in v.1.67

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3