Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
b5c104d0
Commit
b5c104d0
authored
Sep 07, 2017
by
Varun Gupta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changes made according to the review given, mostly fixing coding style errors
parent
24e219b1
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
196 deletions
+28
-196
mysql-test/r/win_percentile_cont.result
mysql-test/r/win_percentile_cont.result
+0
-111
mysql-test/t/win_percentile_cont.test
mysql-test/t/win_percentile_cont.test
+0
-55
sql/item.h
sql/item.h
+0
-3
sql/item_windowfunc.h
sql/item_windowfunc.h
+10
-8
sql/sql_window.cc
sql/sql_window.cc
+18
-19
No files found.
mysql-test/r/win_percentile_cont.result
deleted
100644 → 0
View file @
24e219b1
CREATE TABLE student (name CHAR(10), test double, score DECIMAL(19,4));
INSERT INTO student VALUES
('Chun', 0, 3), ('Chun', 0, 7),
('Kaolin', 0.5, 3), ('Kaolin', 0.6, 7),
('Kaolin', 0.5, 4),
('Tatiana', 0.8, 4), ('Tata', 0.8, 4);
select name, percentile_disc(0.5) within group(order by score) over () from student;
name percentile_disc(0.5) within group(order by score) over ()
Chun 4.0000000000
Chun 4.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
Tatiana 4.0000000000
Tata 4.0000000000
select name, percentile_cont(0.5) within group(order by score) over () from student;
name percentile_cont(0.5) within group(order by score) over ()
Chun 4.0000000000
Chun 4.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
Tatiana 4.0000000000
Tata 4.0000000000
select name, percentile_cont(null) within group(order by score) over (partition by name) from student;
name percentile_cont(null) within group(order by score) over (partition by name)
Chun NULL
Chun NULL
Kaolin NULL
Kaolin NULL
Kaolin NULL
Tatiana NULL
Tata NULL
select name, percentile_disc(null) within group(order by score) over (partition by name) from student;
name percentile_disc(null) within group(order by score) over (partition by name)
Chun NULL
Chun NULL
Kaolin NULL
Kaolin NULL
Kaolin NULL
Tatiana NULL
Tata NULL
select name, percentile_cont(0.5) within group(order by score) over (partition by name) as c from student;
name c
Chun 5.0000000000
Chun 5.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
Tatiana 4.0000000000
Tata 4.0000000000
select name, percentile_disc(0.5) within group(order by score) over (partition by name) as c from student;
name c
Chun 3.0000000000
Chun 3.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
Tatiana 4.0000000000
Tata 4.0000000000
select * from ( select name , percentile_cont(0.5) within group ( order by score) over (partition by name ) from student ) as t;
name percentile_cont(0.5) within group ( order by score) over (partition by name )
Chun 5.0000000000
Chun 5.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
Tatiana 4.0000000000
Tata 4.0000000000
select * from ( select name , percentile_disc(0.5) within group ( order by score) over (partition by name ) from student ) as t;
name percentile_disc(0.5) within group ( order by score) over (partition by name )
Chun 3.0000000000
Chun 3.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
Tatiana 4.0000000000
Tata 4.0000000000
select name from student a where (select percentile_disc(0.5) within group (order by score) over (partition by name) from student b limit 1) >= 0.5;
name
Chun
Chun
Kaolin
Kaolin
Kaolin
Tatiana
Tata
select score, percentile_cont(0.5) within group(order by name) over (partition by score) from student;
ERROR HY000: Numeric datatype is required for Percentile_CONT function
select score, percentile_disc(0.5) within group(order by name) over (partition by score) from student;
score percentile_disc(0.5) within group(order by name) over (partition by score)
3.0000 Chun
7.0000 Chun
3.0000 Chun
7.0000 Chun
4.0000 Tata
4.0000 Tata
4.0000 Tata
select percentile_disc(0.5) within group(order by score,test) over (partition by name) from student;
ERROR HY000: Incorrect number of elements in the order list for 'percentile_disc'
select percentile_cont(0.5) within group(order by score,test) over (partition by name) from student;
ERROR HY000: Incorrect number of elements in the order list for 'percentile_cont'
select percentile_disc(1.5) within group(order by score) over (partition by name) from student;
ERROR HY000: Argument to the percentile functions does not belong to the range [0,1]
select percentile_cont(1.5) within group(order by score) over (partition by name) from student;
ERROR HY000: Argument to the percentile functions does not belong to the range [0,1]
select name,percentile_cont(test) within group(order by score) over (partition by name) from student;
ERROR HY000: Argument to the percentile functions is not a constant
select name, percentile_disc(test) within group(order by score) over (partition by name) from student;
ERROR HY000: Argument to the percentile functions is not a constant
drop table student;
mysql-test/t/win_percentile_cont.test
deleted
100644 → 0
View file @
24e219b1
CREATE
TABLE
student
(
name
CHAR
(
10
),
test
double
,
score
DECIMAL
(
19
,
4
));
INSERT
INTO
student
VALUES
(
'Chun'
,
0
,
3
),
(
'Chun'
,
0
,
7
),
(
'Kaolin'
,
0.5
,
3
),
(
'Kaolin'
,
0.6
,
7
),
(
'Kaolin'
,
0.5
,
4
),
(
'Tatiana'
,
0.8
,
4
),
(
'Tata'
,
0.8
,
4
);
#no partition clause
select
name
,
percentile_disc
(
0.5
)
within
group
(
order
by
score
)
over
()
from
student
;
select
name
,
percentile_cont
(
0.5
)
within
group
(
order
by
score
)
over
()
from
student
;
# argument set to null
select
name
,
percentile_cont
(
null
)
within
group
(
order
by
score
)
over
(
partition
by
name
)
from
student
;
select
name
,
percentile_disc
(
null
)
within
group
(
order
by
score
)
over
(
partition
by
name
)
from
student
;
# complete query with partition column
select
name
,
percentile_cont
(
0.5
)
within
group
(
order
by
score
)
over
(
partition
by
name
)
as
c
from
student
;
select
name
,
percentile_disc
(
0.5
)
within
group
(
order
by
score
)
over
(
partition
by
name
)
as
c
from
student
;
#subqueries having percentile functions
select
*
from
(
select
name
,
percentile_cont
(
0.5
)
within
group
(
order
by
score
)
over
(
partition
by
name
)
from
student
)
as
t
;
select
*
from
(
select
name
,
percentile_disc
(
0.5
)
within
group
(
order
by
score
)
over
(
partition
by
name
)
from
student
)
as
t
;
select
name
from
student
a
where
(
select
percentile_disc
(
0.5
)
within
group
(
order
by
score
)
over
(
partition
by
name
)
from
student
b
limit
1
)
>=
0.5
;
# WITH STORED PROCEDURES
#DISALLOWED FIELDS IN ORDER BY CLAUSE
--
error
ER_WRONG_TYPE_FOR_PERCENTILE_CONT
select
score
,
percentile_cont
(
0.5
)
within
group
(
order
by
name
)
over
(
partition
by
score
)
from
student
;
select
score
,
percentile_disc
(
0.5
)
within
group
(
order
by
name
)
over
(
partition
by
score
)
from
student
;
# error with 2 order by elements
--
error
ER_NOT_SINGLE_ELEMENT_ORDER_LIST
select
percentile_disc
(
0.5
)
within
group
(
order
by
score
,
test
)
over
(
partition
by
name
)
from
student
;
--
error
ER_NOT_SINGLE_ELEMENT_ORDER_LIST
select
percentile_cont
(
0.5
)
within
group
(
order
by
score
,
test
)
over
(
partition
by
name
)
from
student
;
#parameter value should be in the range of 0 to 1( NEED TO THINK A WAY FOR THIS)
--
error
ER_ARGUMENT_OUT_OF_RANGE
select
percentile_disc
(
1.5
)
within
group
(
order
by
score
)
over
(
partition
by
name
)
from
student
;
--
error
ER_ARGUMENT_OUT_OF_RANGE
select
percentile_cont
(
1.5
)
within
group
(
order
by
score
)
over
(
partition
by
name
)
from
student
;
--
error
ER_ARGUMENT_NOT_CONSTANT
select
name
,
percentile_cont
(
test
)
within
group
(
order
by
score
)
over
(
partition
by
name
)
from
student
;
--
error
ER_ARGUMENT_NOT_CONSTANT
select
name
,
percentile_disc
(
test
)
within
group
(
order
by
score
)
over
(
partition
by
name
)
from
student
;
#CHECK TYPE OF THE ARGUMENT, SHOULD BE ONLY NUMERICAL
#select name, percentile_cont(name) within group(order by score) over (partition by name) from student;
drop
table
student
;
sql/item.h
View file @
b5c104d0
...
...
@@ -5341,7 +5341,6 @@ class Cached_item_real :public Cached_item_item
Cached_item_real
(
Item
*
item_par
)
:
Cached_item_item
(
item_par
),
value
(
0.0
)
{}
bool
cmp
(
void
);
int
cmp_read_only
();
double
get_value
(){
return
value
;}
};
class
Cached_item_int
:
public
Cached_item_item
...
...
@@ -5351,7 +5350,6 @@ class Cached_item_int :public Cached_item_item
Cached_item_int
(
Item
*
item_par
)
:
Cached_item_item
(
item_par
),
value
(
0
)
{}
bool
cmp
(
void
);
int
cmp_read_only
();
longlong
get_value
(){
return
value
;}
};
...
...
@@ -5362,7 +5360,6 @@ class Cached_item_decimal :public Cached_item_item
Cached_item_decimal
(
Item
*
item_par
);
bool
cmp
(
void
);
int
cmp_read_only
();
my_decimal
*
get_value
(){
return
&
value
;};
};
class
Cached_item_field
:
public
Cached_item
...
...
sql/item_windowfunc.h
View file @
b5c104d0
...
...
@@ -757,14 +757,14 @@ class Item_sum_percentile_disc : public Item_sum_cume_dist,
bool
add
()
{
Item
*
arg
=
get_arg
(
0
);
Item
*
arg
=
get_arg
(
0
);
if
(
arg
->
is_null
())
return
false
;
if
(
first_call
)
{
prev_value
=
arg
->
val_real
();
if
(
prev_value
>
1
||
prev_value
<
0
)
if
(
prev_value
>
1
||
prev_value
<
0
)
{
my_error
(
ER_ARGUMENT_OUT_OF_RANGE
,
MYF
(
0
));
return
true
;
...
...
@@ -821,7 +821,7 @@ class Item_sum_percentile_disc : public Item_sum_cume_dist,
void
fix_length_and_dec
()
{
decimals
=
10
;
// TODO-cvicentiu find out how many decimals the standard
decimals
=
5
;
// TODO-cvicentiu find out how many decimals the standard
// requires.
}
...
...
@@ -829,6 +829,7 @@ class Item_sum_percentile_disc : public Item_sum_cume_dist,
{
return
get_item_copy
<
Item_sum_percentile_disc
>
(
thd
,
mem_root
,
this
);
}
void
setup_window_func
(
THD
*
thd
,
Window_spec
*
window_spec
);
void
setup_hybrid
(
THD
*
thd
,
Item
*
item
);
bool
fix_fields
(
THD
*
thd
,
Item
**
ref
);
private:
Item_cache
*
value
;
...
...
@@ -876,7 +877,7 @@ class Item_sum_percentile_cont : public Item_sum_cume_dist,
bool
add
()
{
Item
*
arg
=
get_arg
(
0
);
Item
*
arg
=
get_arg
(
0
);
if
(
arg
->
is_null
())
return
false
;
...
...
@@ -884,7 +885,7 @@ class Item_sum_percentile_cont : public Item_sum_cume_dist,
{
first_call
=
false
;
prev_value
=
arg
->
val_real
();
if
(
prev_value
>
1
||
prev_value
<
0
)
if
(
prev_value
>
1
||
prev_value
<
0
)
{
my_error
(
ER_ARGUMENT_OUT_OF_RANGE
,
MYF
(
0
));
return
true
;
...
...
@@ -950,7 +951,7 @@ class Item_sum_percentile_cont : public Item_sum_cume_dist,
void
fix_length_and_dec
()
{
decimals
=
10
;
// TODO-cvicentiu find out how many decimals the standard
decimals
=
5
;
// TODO-cvicentiu find out how many decimals the standard
// requires.
}
...
...
@@ -958,6 +959,7 @@ class Item_sum_percentile_cont : public Item_sum_cume_dist,
{
return
get_item_copy
<
Item_sum_percentile_cont
>
(
thd
,
mem_root
,
this
);
}
void
setup_window_func
(
THD
*
thd
,
Window_spec
*
window_spec
);
void
setup_hybrid
(
THD
*
thd
,
Item
*
item
);
bool
fix_fields
(
THD
*
thd
,
Item
**
ref
);
private:
Item_cache
*
floor_value
;
...
...
sql/sql_window.cc
View file @
b5c104d0
...
...
@@ -1743,7 +1743,17 @@ class Frame_unbounded_following_set_count : public Frame_unbounded_following
/* Walk to the end of the partition, find how many rows there are. */
while
(
!
cursor
.
next
())
num_rows_in_partition
++
;
set_win_funcs_row_count
(
num_rows_in_partition
);
}
ha_rows
get_curr_rownum
()
const
{
return
cursor
.
get_rownum
();
}
protected:
void
set_win_funcs_row_count
(
ha_rows
num_rows_in_partition
)
{
List_iterator_fast
<
Item_sum
>
it
(
sum_functions
);
Item_sum
*
item
;
while
((
item
=
it
++
))
...
...
@@ -1753,20 +1763,16 @@ class Frame_unbounded_following_set_count : public Frame_unbounded_following
item_with_row_count
->
set_row_count
(
num_rows_in_partition
);
}
}
ha_rows
get_curr_rownum
()
const
{
return
cursor
.
get_rownum
();
}
};
class
Frame_unbounded_following_set_count_special
:
public
Frame_unbounded_following_set_count
class
Frame_unbounded_following_set_count_no_nulls
:
public
Frame_unbounded_following_set_count
{
public:
Frame_unbounded_following_set_count_
special
(
THD
*
thd
,
Frame_unbounded_following_set_count_
no_nulls
(
THD
*
thd
,
SQL_I_List
<
ORDER
>
*
partition_list
,
SQL_I_List
<
ORDER
>
*
order_list
,
Item
*
arg
)
:
SQL_I_List
<
ORDER
>
*
order_list
)
:
Frame_unbounded_following_set_count
(
thd
,
partition_list
,
order_list
)
{
order_item
=
order_list
->
first
->
item
[
0
];
...
...
@@ -1782,16 +1788,9 @@ class Frame_unbounded_following_set_count_special: public Frame_unbounded_follow
{
if
(
!
order_item
->
is_null
())
num_rows_in_partition
++
;
}
while
(
!
cursor
.
next
());
}
while
(
!
cursor
.
next
());
List_iterator_fast
<
Item_sum
>
it
(
sum_functions
);
Item_sum
*
item
;
while
((
item
=
it
++
))
{
Item_sum_window_with_row_count
*
item_with_row_count
=
static_cast
<
Item_sum_window_with_row_count
*>
(
item
);
item_with_row_count
->
set_row_count
(
num_rows_in_partition
);
}
set_win_funcs_row_count
(
num_rows_in_partition
);
}
ha_rows
get_curr_rownum
()
const
...
...
@@ -2614,9 +2613,9 @@ void get_window_functions_required_cursors(
{
if
(
item_win_func
->
only_single_element_order_list
())
{
fc
=
new
Frame_unbounded_following_set_count_
special
(
thd
,
fc
=
new
Frame_unbounded_following_set_count_
no_nulls
(
thd
,
item_win_func
->
window_spec
->
partition_list
,
item_win_func
->
window_spec
->
order_list
,
item_win_func
->
window_func
()
->
get_arg
(
0
)
);
item_win_func
->
window_spec
->
order_list
);
}
else
{
...
...
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