Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ensembl-hive
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
7
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-hive
Commits
e4fbcf73
Commit
e4fbcf73
authored
11 years ago
by
Leo Gordon
Browse files
Options
Downloads
Patches
Plain Diff
count_all_by... now also supports multicolumn filtering using _AND_ (with examples in t/ )
parent
a67276fa
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/Bio/EnsEMBL/Hive/DBSQL/BaseAdaptor.pm
+20
-10
20 additions, 10 deletions
modules/Bio/EnsEMBL/Hive/DBSQL/BaseAdaptor.pm
t/fetch_and_count_by_multiple_columns.pl
+26
-0
26 additions, 0 deletions
t/fetch_and_count_by_multiple_columns.pl
with
46 additions
and
10 deletions
modules/Bio/EnsEMBL/Hive/DBSQL/BaseAdaptor.pm
+
20
−
10
View file @
e4fbcf73
...
...
@@ -407,13 +407,13 @@ sub AUTOLOAD {
my
(
$self
)
=
@_
;
my
$column_set
=
$self
->
column_set
();
my
$filter_components
=
$filter_string
&&
[
split
(
'
_and_
'
,
$filter_string
)
];
my
$filter_components
=
$filter_string
&&
[
split
(
/_AND_/i
,
$filter_string
)
];
foreach
my
$column_name
(
@$filter_components
)
{
unless
(
$column_set
->
{
$column_name
})
{
die
"
unknown column '
$column_name
'
";
}
}
my
$key_components
=
$key_string
&&
[
split
(
'
_and_
'
,
$key_string
)
];
my
$key_components
=
$key_string
&&
[
split
(
/_AND_/i
,
$key_string
)
];
foreach
my
$column_name
(
@$key_components
)
{
unless
(
$column_set
->
{
$column_name
})
{
die
"
unknown column '
$column_name
'
";
...
...
@@ -434,19 +434,29 @@ sub AUTOLOAD {
);
};
goto
&$AUTOLOAD
;
# restart the new method
}
elsif
(
$AUTOLOAD
=~
/::count_all_by_(\w+)$/
)
{
my
$filter_
name
=
$
1
;
my
$filter_
string
=
$
1
;
my
(
$self
)
=
@_
;
my
$column_set
=
$self
->
column_set
();
if
(
$column_set
->
{
$filter_name
})
{
# print "Setting up '$AUTOLOAD' method\n";
*$AUTOLOAD
=
sub
{
my
(
$self
,
$filter_value
)
=
@_
;
return
$self
->
count_all
("
$filter_name
='
$filter_value
'
");
};
goto
&$AUTOLOAD
;
# restart the new method
}
else
{
die
"
unknown column '
$filter_name
'
";
my
$filter_components
=
$filter_string
&&
[
split
(
/_AND_/i
,
$filter_string
)
];
foreach
my
$column_name
(
@$filter_components
)
{
unless
(
$column_set
->
{
$column_name
})
{
die
"
unknown column '
$column_name
'
";
}
}
# print "Setting up '$AUTOLOAD' method\n";
*$AUTOLOAD
=
sub
{
my
$self
=
shift
@_
;
return
$self
->
count_all
(
join
('
AND
',
map
{
"
$filter_components
->[
$_
]='
$_
[
$_
]'
"
}
0
..
scalar
(
@$filter_components
)
-
1
),
);
};
goto
&$AUTOLOAD
;
# restart the new method
}
elsif
(
$AUTOLOAD
=~
/::remove_all_by_(\w+)$/
)
{
my
$filter_name
=
$
1
;
...
...
@@ -461,7 +471,7 @@ sub AUTOLOAD {
die
"
unknown column '
$filter_name
'
";
}
}
elsif
(
$AUTOLOAD
=~
/::update_(\w+)$/
)
{
my
@columns_to_update
=
split
(
'
_and_
'
,
$
1
);
my
@columns_to_update
=
split
(
/_AND_/i
,
$
1
);
# print "Setting up '$AUTOLOAD' method\n";
*$AUTOLOAD
=
sub
{
my
(
$self
,
$object
)
=
@_
;
return
$self
->
update
(
$object
,
@columns_to_update
);
};
goto
&$AUTOLOAD
;
# restart the new method
...
...
This diff is collapsed.
Click to expand it.
t/fetch_and_count_by_multiple_columns.pl
0 → 100755
+
26
−
0
View file @
e4fbcf73
#!/usr/bin/env perl
use
strict
;
use
warnings
;
use
Data::
Dumper
;
use
Getopt::
Long
;
use
Bio::EnsEMBL::Hive::DBSQL::
DBAdaptor
;
my
$url
;
GetOptions
(
'
url=s
'
=>
\
$url
);
die
"
Please specify the -url
\n
"
unless
(
$url
);
$ENV
{'
EHIVE_ROOT_DIR
'}
=
$ENV
{'
ENSEMBL_CVS_ROOT_DIR
'}
.
'
/ensembl-hive
';
# I'm just being lazy. For the correct way to set this variable check eHive scripts
my
$hive_dba
=
Bio::EnsEMBL::Hive::DBSQL::
DBAdaptor
->
new
(
-
url
=>
$url
);
print
"
Filtering on 1 column:
\n
";
print
join
("
\n
",
map
{
"
\t
"
.
$_
->
toString
}
@
{
$hive_dba
->
get_DataflowRuleAdaptor
->
fetch_all_by_from_analysis_id
(
1
)
}
)
.
"
\n
";
print
"
Filtering on 2 columns:
\n
";
print
join
("
\n
",
map
{
"
\t
"
.
$_
->
toString
}
@
{
$hive_dba
->
get_DataflowRuleAdaptor
->
fetch_all_by_from_analysis_id_AND_branch_code
(
1
,
2
)
}
)
.
"
\n
";
print
"
Count(filter by 1 'from_analysis_id' column)
"
.
$hive_dba
->
get_DataflowRuleAdaptor
->
count_all_by_from_analysis_id
(
1
)
.
"
\n
";
print
"
Count(filter by 1 'branch_code' column)
"
.
$hive_dba
->
get_DataflowRuleAdaptor
->
count_all_by_branch_code
(
1
)
.
"
\n
";
print
"
Count(filter by 2 columns)
"
.
$hive_dba
->
get_DataflowRuleAdaptor
->
count_all_by_from_analysis_id_AND_branch_code
(
1
,
2
)
.
"
\n
";
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