Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ensembl
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ensembl-gh-mirror
ensembl
Commits
6c3413e2
Commit
6c3413e2
authored
13 years ago
by
Andreas Kusalananda Kähäri
Browse files
Options
Downloads
Patches
Plain Diff
Make this upload stable IDs into release 65 databases correctly.
parent
53837993
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/Bio/EnsEMBL/IdMapping/BaseObject.pm
+80
-28
80 additions, 28 deletions
modules/Bio/EnsEMBL/IdMapping/BaseObject.pm
with
80 additions
and
28 deletions
modules/Bio/EnsEMBL/IdMapping/BaseObject.pm
+
80
−
28
View file @
6c3413e2
...
...
@@ -302,63 +302,115 @@ sub dump_table_to_file {
=cut
sub upload_file_into_table {
my $self = shift;
my $dbtype = shift;
my $table = shift;
my $filename = shift;
my $self
= shift;
my $dbtype
= shift;
my $table
= shift;
my $filename
= shift;
my $no_check_empty = shift;
# argument check
unless (
(
$dbtype eq 'source') or ($dbtype eq 'target'
)
) {
unless (
(
$dbtype eq 'source'
) or (
$dbtype eq 'target'
)
) {
throw("Missing or unknown db type: $dbtype.");
}
throw("Need a table name.") unless ($table);
throw("Need a filename.") unless ($filename);
throw("Need a filename.")
unless ($filename);
# sanity check for dry run
if ($self->conf->param('dry_run')) {
$self->logger->warning("dry_run - skipping db upload for $filename.\n");
if ( $self->conf->param('dry_run') ) {
$self->logger->warning(
"dry_run - skipping db upload for $filename.\n");
return;
}
my $file = join('/', $self->conf->param('basedir'), 'tables', $filename);
my $file =
join( '/', $self->conf->param('basedir'), 'tables', $filename );
my $r = 0;
if (-s $file) {
$self->logger->debug("$file -> $table\n", 1);
if ( -s $file ) {
$self->logger->debug( "$file -> $table\n", 1 );
my $dba = $self->cache->get_DBAdaptor($dbtype);
my $dbh = $dba->dbc->db_handle;
my $idtable = 0;
if ( $table =~ /^([^_]+)_stable_id/ ) {
# This is a stable_id table we're working with.
$idtable = 1;
$table = $1;
}
# check table is empty
my ($sql, $sth);
my (
$sql, $sth
);
unless ($no_check_empty) {
$sql = qq(SELECT count(*) FROM $table);
if ($idtable) {
$sql =
qq(SELECT count(*) FROM $table WHERE stable_id IS NOT NULL);
}
else {
$sql = qq(SELECT count(*) FROM $table);
}
$sth = $dbh->prepare($sql);
$sth->execute;
my ($c) = $sth->fetchrow_array;
$sth->finish;
if ($c) {
$self->logger->warning("Table $table not empty: found $c entries.\n", 1);
$self->logger->info("Data not uploaded!\n", 1);
if ( $c > 0 ) {
if ($idtable) {
$self->logger->warning(
"Table $table contains $c stable IDs.\n",
1 );
}
else {
$self->logger->warning(
"Table $table not empty: found $c entries.\n",
1 );
}
$self->logger->info( "Data not uploaded!\n", 1 );
return $r;
}
}
}
## end unless ($no_check_empty)
# now upload the data
$sql = qq(LOAD DATA LOCAL INFILE '$file' INTO TABLE $table);
$sth = $dbh->prepare($sql);
$r = $sth->execute;
$sth->finish;
if ($idtable) {
# Create a temporary table, upload the data into it, and then
# update the main table.
$dbh->do(
qq( CREATE TABLE stable_id_$$ ( object_id INTEGER UNSIGNED,
stable_id VARCHAR(255),
version SMALLINT UNSIGNED,
created_date DATETIME,
modified_date DATETIME,
PRIMARY KEY(object_id) ) )
);
$dbh->do(
qq(LOAD DATA LOCAL INFILE '$file' INTO TABLE stable_id_$$));
$dbh->do(
qq(
UPDATE TABLE $table, stable_id_$$
SET $table.stable_id=stable_id_$$.stable_id,
$table.version=stable_id_$$.version,
$table.created_date=stable_id_$$.created_date,
$table.modified_date=stable_id_$$.modified_date
WHERE $table.${table}_id = stable_id_$$.object_id )
);
$dbh->do(qq(DROP TABLE stable_id_$$));
} ## end if ($idtable)
else {
$dbh->do(qq(LOAD DATA LOCAL INFILE '$file' INTO TABLE $table));
}
$dbh->do(qq(OPTIMIZE TABLE $table));
} else {
$self->logger->warning("No data found in file $filename.\n", 1);
} ## end if ( -s $file )
else {
$self->logger->warning( "No data found in file $filename.\n", 1 );
}
return $r;
}
}
## end sub upload_file_into_table
=head2 logger
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment