Improve indentation in Gitlab::Database::Median

This commit is contained in:
Timothy Andrew 2016-09-21 02:18:57 +05:30
parent a57c77f6c2
commit 6df2d57394

View file

@ -30,12 +30,15 @@ module Gitlab
query = arel_table. query = arel_table.
from(arel_table.project(Arel.sql('*')).order(arel_table[column_sym]).as(arel_table.table_name)). from(arel_table.project(Arel.sql('*')).order(arel_table[column_sym]).as(arel_table.table_name)).
project(average([arel_table[column_sym]], 'median')). project(average([arel_table[column_sym]], 'median')).
where(Arel::Nodes::Between.new( where(
Arel.sql("(select @row_id := @row_id + 1)"), Arel::Nodes::Between.new(
Arel::Nodes::And.new( Arel.sql("(select @row_id := @row_id + 1)"),
[Arel.sql('@ct/2.0'), Arel::Nodes::And.new(
Arel.sql('@ct/2.0 + 1')] [Arel.sql('@ct/2.0'),
))). Arel.sql('@ct/2.0 + 1')]
)
)
).
# Disallow negative values # Disallow negative values
where(arel_table[column_sym].gteq(0)) where(arel_table[column_sym].gteq(0))
@ -75,11 +78,15 @@ module Gitlab
# by 'where cte.row_id between cte.ct / 2.0 AND cte.ct / 2.0 + 1'). Find the average of the # by 'where cte.row_id between cte.ct / 2.0 AND cte.ct / 2.0 + 1'). Find the average of the
# selected rows, and this is the median value. # selected rows, and this is the median value.
cte_table.project(average([extract_epoch(cte_table[column_sym])], "median")). cte_table.project(average([extract_epoch(cte_table[column_sym])], "median")).
where(Arel::Nodes::Between.new( where(
cte_table[:row_id], Arel::Nodes::Between.new(
Arel::Nodes::And.new( cte_table[:row_id],
[(cte_table[:ct] / Arel.sql('2.0')), Arel::Nodes::And.new(
(cte_table[:ct] / Arel.sql('2.0') + 1)]))). [(cte_table[:ct] / Arel.sql('2.0')),
(cte_table[:ct] / Arel.sql('2.0') + 1)]
)
)
).
with(query_so_far, cte) with(query_so_far, cte)
end end