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
74198384
Commit
74198384
authored
Jun 04, 2020
by
Alexey Botchkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-21914 JSON_ARRAYAGG doesn't reject ORDER BY clause, but doesn't work either.
ORDER BY fixed for JSON_ARRAYAGG.
parent
07daf735
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
81 additions
and
18 deletions
+81
-18
mysql-test/main/func_json.result
mysql-test/main/func_json.result
+3
-0
mysql-test/main/func_json.test
mysql-test/main/func_json.test
+2
-0
sql/item_jsonfunc.cc
sql/item_jsonfunc.cc
+62
-3
sql/item_jsonfunc.h
sql/item_jsonfunc.h
+5
-3
sql/item_sum.cc
sql/item_sum.cc
+4
-12
sql/item_sum.h
sql/item_sum.h
+5
-0
No files found.
mysql-test/main/func_json.result
View file @
74198384
...
...
@@ -1240,6 +1240,9 @@ select * from v;
JSON_DATA
[{"type": "permPeriod", "id": "asd"}]
drop view v;
select json_arrayagg(a order by a asc) from (select 1 a union select 2 a) t;
json_arrayagg(a order by a asc)
[1,2]
#
# End of 10.5 tests
#
mysql-test/main/func_json.test
View file @
74198384
...
...
@@ -759,6 +759,8 @@ create view v as (select json_arrayagg(json_object("type", "permPeriod", "id", "
select
*
from
v
;
drop
view
v
;
select
json_arrayagg
(
a
order
by
a
asc
)
from
(
select
1
a
union
select
2
a
)
t
;
--
echo
#
--
echo
# End of 10.5 tests
--
echo
#
...
...
sql/item_jsonfunc.cc
View file @
74198384
...
...
@@ -1452,6 +1452,52 @@ static int append_json_value(String *str, Item *item, String *tmp_val)
}
static
int
append_json_value_from_field
(
String
*
str
,
Item
*
i
,
Field
*
f
,
const
uchar
*
key
,
size_t
offset
,
String
*
tmp_val
)
{
if
(
i
->
type_handler
()
->
is_bool_type
())
{
longlong
v_int
=
f
->
val_int
(
key
+
offset
);
const
char
*
t_f
;
int
t_f_len
;
if
(
f
->
is_null
(
offset
))
goto
append_null
;
if
(
v_int
)
{
t_f
=
"true"
;
t_f_len
=
4
;
}
else
{
t_f
=
"false"
;
t_f_len
=
5
;
}
return
str
->
append
(
t_f
,
t_f_len
);
}
{
String
*
sv
=
f
->
val_str
(
tmp_val
,
key
+
offset
);
if
(
f
->
is_null
(
offset
))
goto
append_null
;
if
(
i
->
is_json_type
())
return
str
->
append
(
sv
->
ptr
(),
sv
->
length
());
if
(
i
->
result_type
()
==
STRING_RESULT
)
{
return
str
->
append
(
"
\"
"
,
1
)
||
st_append_escaped
(
str
,
sv
)
||
str
->
append
(
"
\"
"
,
1
);
}
return
st_append_escaped
(
str
,
sv
);
}
append_null:
return
str
->
append
(
"null"
,
4
);
}
static
int
append_json_keyname
(
String
*
str
,
Item
*
item
,
String
*
tmp_val
)
{
String
*
sv
=
item
->
val_str
(
tmp_val
);
...
...
@@ -3621,12 +3667,25 @@ int Arg_comparator::compare_e_json_str_basic(Item *j, Item *s)
}
String
*
Item_func_json_arrayagg
::
convert_to_json
(
Item
*
item
)
String
*
Item_func_json_arrayagg
::
get_str_from_item
(
Item
*
i
,
String
*
tmp
)
{
m_tmp_json
.
length
(
0
);
if
(
append_json_value
(
&
m_tmp_json
,
i
,
tmp
))
return
NULL
;
return
&
m_tmp_json
;
}
String
*
Item_func_json_arrayagg
::
get_str_from_field
(
Item
*
i
,
Field
*
f
,
String
*
tmp
,
const
uchar
*
key
,
size_t
offset
)
{
String
tmp
;
m_tmp_json
.
length
(
0
);
append_json_value
(
&
m_tmp_json
,
item
,
&
tmp
);
if
(
append_json_value_from_field
(
&
m_tmp_json
,
i
,
f
,
key
,
offset
,
tmp
))
return
NULL
;
return
&
m_tmp_json
;
}
...
...
sql/item_jsonfunc.h
View file @
74198384
...
...
@@ -542,10 +542,13 @@ class Item_func_json_arrayagg : public Item_func_group_concat
Overrides Item_func_group_concat::skip_nulls()
NULL-s should be added to the result as JSON null value.
*/
virtual
bool
skip_nulls
()
const
{
return
false
;
}
bool
skip_nulls
()
const
{
return
false
;
}
String
*
get_str_from_item
(
Item
*
i
,
String
*
tmp
);
String
*
get_str_from_field
(
Item
*
i
,
Field
*
f
,
String
*
tmp
,
const
uchar
*
key
,
size_t
offset
);
public:
String
m_tmp_json
;
/* Used in
convert_to_json
. */
String
m_tmp_json
;
/* Used in
get_str_from_*.
. */
Item_func_json_arrayagg
(
THD
*
thd
,
Name_resolution_context
*
context_arg
,
bool
is_distinct
,
List
<
Item
>
*
is_select
,
const
SQL_I_List
<
ORDER
>
&
is_order
,
String
*
is_separator
,
...
...
@@ -560,7 +563,6 @@ class Item_func_json_arrayagg : public Item_func_group_concat
const
char
*
func_name
()
const
{
return
"json_arrayagg("
;
}
enum
Sumfunctype
sum_func
()
const
{
return
JSON_ARRAYAGG_FUNC
;}
String
*
convert_to_json
(
Item
*
item
);
String
*
val_str
(
String
*
str
);
Item
*
get_copy
(
THD
*
thd
)
...
...
sql/item_sum.cc
View file @
74198384
...
...
@@ -3660,7 +3660,7 @@ int dump_leaf_key(void* key_arg, element_count count __attribute__((unused)),
because it contains both order and arg list fields.
*/
if
((
*
arg
)
->
const_item
())
res
=
(
*
arg
)
->
val_str
(
&
tmp
);
res
=
item
->
get_str_from_item
(
*
arg
,
&
tmp
);
else
{
Field
*
field
=
(
*
arg
)
->
get_tmp_table_field
();
...
...
@@ -3669,19 +3669,10 @@ int dump_leaf_key(void* key_arg, element_count count __attribute__((unused)),
uint
offset
=
(
field
->
offset
(
field
->
table
->
record
[
0
])
-
table
->
s
->
null_bytes
);
DBUG_ASSERT
(
offset
<
table
->
s
->
reclength
);
res
=
field
->
val_str
(
&
tmp
,
key
+
offset
);
res
=
item
->
get_str_from_field
(
*
arg
,
field
,
&
tmp
,
key
,
offset
);
}
else
res
=
(
*
arg
)
->
val_str
(
&
tmp
);
}
if
(
item
->
sum_func
()
==
Item_sum
::
JSON_ARRAYAGG_FUNC
)
{
/*
JSON_ARRAYAGG needs to convert the type into valid JSON before
appending it to the result
*/
Item_func_json_arrayagg
*
arrayagg
=
(
Item_func_json_arrayagg
*
)
item_arg
;
res
=
arrayagg
->
convert_to_json
(
*
arg
);
res
=
item
->
get_str_from_item
(
*
arg
,
&
tmp
);
}
if
(
res
)
...
...
@@ -3981,6 +3972,7 @@ bool Item_func_group_concat::repack_tree(THD *thd)
return
0
;
}
/*
Repacking the tree is expensive. But it keeps the tree small, and
inserting into an unnecessary large tree is also waste of time.
...
...
sql/item_sum.h
View file @
74198384
...
...
@@ -1924,6 +1924,11 @@ class Item_func_group_concat : public Item_sum
Redefined in JSON_ARRAYAGG.
*/
virtual
bool
skip_nulls
()
const
{
return
true
;
}
virtual
String
*
get_str_from_item
(
Item
*
i
,
String
*
tmp
)
{
return
i
->
val_str
(
tmp
);
}
virtual
String
*
get_str_from_field
(
Item
*
i
,
Field
*
f
,
String
*
tmp
,
const
uchar
*
key
,
size_t
offset
)
{
return
f
->
val_str
(
tmp
,
key
+
offset
);
}
public:
// Methods used by ColumnStore
bool
get_distinct
()
const
{
return
distinct
;
}
...
...
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