Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
6df2d573
Commit
6df2d573
authored
Sep 21, 2016
by
Timothy Andrew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve indentation in `Gitlab::Database::Median`
parent
a57c77f6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
11 deletions
+18
-11
lib/gitlab/database/median.rb
lib/gitlab/database/median.rb
+18
-11
No files found.
lib/gitlab/database/median.rb
View file @
6df2d573
...
@@ -30,12 +30,15 @@ module Gitlab
...
@@ -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
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment