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
16738fe3
Commit
16738fe3
authored
10 years ago
by
Leo Gordon
Browse files
Options
Downloads
Patches
Plain Diff
added autoloaded counting in groups; removed some undefined value warnings
parent
458c761b
No related branches found
No related tags found
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
+60
-19
60 additions, 19 deletions
modules/Bio/EnsEMBL/Hive/DBSQL/BaseAdaptor.pm
t/fetch_and_count_by_multiple_columns.pl
+5
-0
5 additions, 0 deletions
t/fetch_and_count_by_multiple_columns.pl
with
65 additions
and
19 deletions
modules/Bio/EnsEMBL/Hive/DBSQL/BaseAdaptor.pm
+
60
−
19
View file @
16738fe3
...
...
@@ -249,25 +249,47 @@ sub _table_info_loader {
sub
count_all
{
my
(
$self
,
$constraint
)
=
@_
;
my
(
$self
,
$constraint
,
$key_list
)
=
@_
;
my
$table_name
=
$self
->
table_name
();
my
$sql
=
"
SELECT COUNT(*) FROM
$table_name
";
my
$sql
=
"
SELECT
"
.
(
$key_list
?
join
('
,
',
@$key_list
,
'')
:
'')
.
"
COUNT(*) FROM
$table_name
";
if
(
$constraint
)
{
# in case $constraint contains any kind of JOIN (regular, LEFT, RIGHT, etc) do not put WHERE in front:
$sql
.=
((
$constraint
=~
/\bJOIN\b/i
)
?
'
'
:
'
WHERE
')
.
$constraint
;
}
if
(
$key_list
)
{
$sql
.=
"
GROUP BY
"
.
join
('
,
',
@$key_list
);
}
# warn "SQL: $sql\n";
my
$sth
=
$self
->
prepare
(
$sql
);
$sth
->
execute
;
my
(
$count
)
=
$sth
->
fetchrow_array
();
$sth
->
finish
;
$sth
->
execute
;
my
$result_struct
;
# will be autovivified to the correct data structure
while
(
my
$hashref
=
$sth
->
fetchrow_hashref
)
{
my
$pptr
=
\
$result_struct
;
if
(
$key_list
)
{
foreach
my
$syll
(
@$key_list
)
{
$pptr
=
\
$$pptr
->
{
$hashref
->
{
$syll
}};
# using pointer-to-pointer to enforce same-level vivification
}
}
$$pptr
=
$hashref
->
{'
COUNT(*)
'};
}
return
$count
;
unless
(
defined
(
$result_struct
))
{
if
(
$key_list
and
scalar
(
@$key_list
))
{
$result_struct
=
{};
}
else
{
$result_struct
=
0
;
}
}
return
$result_struct
;
}
...
...
@@ -539,17 +561,23 @@ sub AUTOLOAD {
my
$column_set
=
$self
->
column_set
();
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
'
";
if
(
$filter_components
)
{
foreach
my
$column_name
(
@$filter_components
)
{
unless
(
$column_set
->
{
$column_name
})
{
die
"
unknown column '
$column_name
'
";
}
}
}
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
'
";
if
(
$key_components
)
{
foreach
my
$column_name
(
@$key_components
)
{
unless
(
$column_set
->
{
$column_name
})
{
die
"
unknown column '
$column_name
'
";
}
}
}
if
(
$value_column
&&
!
$column_set
->
{
$value_column
})
{
die
"
unknown column '
$value_column
'
";
}
...
...
@@ -558,7 +586,7 @@ sub AUTOLOAD {
*$AUTOLOAD
=
sub
{
my
$self
=
shift
@_
;
return
$self
->
fetch_all
(
join
('
AND
',
map
{
"
$filter_components
->[
$_
]='
$_
[
$_
]'
"
}
0
..
scalar
(
@$filter_components
)
-
1
),
$filter_components
&&
join
('
AND
',
map
{
"
$filter_components
->[
$_
]='
$_
[
$_
]'
"
}
0
..
scalar
(
@$filter_components
)
-
1
),
!
$all
,
$key_components
,
$value_column
...
...
@@ -566,16 +594,28 @@ sub AUTOLOAD {
};
goto
&$AUTOLOAD
;
# restart the new method
}
elsif
(
$AUTOLOAD
=~
/::count_all_by_(\w+)$/
)
{
my
$filter_string
=
$
1
;
}
elsif
(
$AUTOLOAD
=~
/::count_all(?:_by_(\w+))?(?:_HASHED_FROM_(\w+?))?$/
)
{
my
$filter_string
=
$
1
;
my
$key_string
=
$
2
;
my
(
$self
)
=
@_
;
my
$column_set
=
$self
->
column_set
();
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
'
";
if
(
$filter_components
)
{
foreach
my
$column_name
(
@$filter_components
)
{
unless
(
$column_set
->
{
$column_name
})
{
die
"
unknown column '
$column_name
'
";
}
}
}
my
$key_components
=
$key_string
&&
[
split
(
/_AND_/i
,
$key_string
)
];
if
(
$key_components
)
{
foreach
my
$column_name
(
@$key_components
)
{
unless
(
$column_set
->
{
$column_name
})
{
die
"
unknown column '
$column_name
'
";
}
}
}
...
...
@@ -583,7 +623,8 @@ sub AUTOLOAD {
*$AUTOLOAD
=
sub
{
my
$self
=
shift
@_
;
return
$self
->
count_all
(
join
('
AND
',
map
{
"
$filter_components
->[
$_
]='
$_
[
$_
]'
"
}
0
..
scalar
(
@$filter_components
)
-
1
),
$filter_components
&&
join
('
AND
',
map
{
"
$filter_components
->[
$_
]='
$_
[
$_
]'
"
}
0
..
scalar
(
@$filter_components
)
-
1
),
$key_components
,
);
};
goto
&$AUTOLOAD
;
# restart the new method
...
...
This diff is collapsed.
Click to expand it.
t/fetch_and_count_by_multiple_columns.pl
+
5
−
0
View file @
16738fe3
...
...
@@ -24,3 +24,8 @@ print "Count(filter by 1 'from_analysis_id' column) ".$hive_dba->get_DataflowRul
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
";
print
"
Count workers:
"
.
$hive_dba
->
get_WorkerAdaptor
->
count_all
()
.
"
\n
";
print
"
Count workers by meadow_user:
"
.
$hive_dba
->
get_WorkerAdaptor
->
count_all_by_meadow_user
('
lg4
')
.
"
\n
";
print
"
Count workers HASHED FROM meadow_user:
"
.
Dumper
(
$hive_dba
->
get_WorkerAdaptor
->
count_all_HASHED_FROM_meadow_user
())
.
"
\n
";
print
"
Count workers HASHED FROM meadow_type, meadow_user:
"
.
Dumper
(
$hive_dba
->
get_WorkerAdaptor
->
count_all_HASHED_FROM_meadow_type_AND_meadow_user
())
.
"
\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