summaryrefslogtreecommitdiff
path: root/sql/item_jsonfunc.cc
diff options
context:
space:
mode:
authorAlexey Botchkov <holyfoot@askmonty.org>2019-10-14 14:24:22 +0400
committerAlexey Botchkov <holyfoot@askmonty.org>2019-10-14 14:24:22 +0400
commitba8e5e689c8a1756573c9cbf6a59e9ec32d86457 (patch)
tree28767f4bb6609bea651a179da5214129438f0be7 /sql/item_jsonfunc.cc
parentb1c2c4ee1b246144033c95d849d59ed0a1192829 (diff)
downloadmariadb-git-ba8e5e689c8a1756573c9cbf6a59e9ec32d86457.tar.gz
MDEV-16620 JSON_ARRAYAGG and JSON_OBJECTAGG.
Ison_objectagg implemented.
Diffstat (limited to 'sql/item_jsonfunc.cc')
-rw-r--r--sql/item_jsonfunc.cc116
1 files changed, 116 insertions, 0 deletions
diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc
index 72c0dfcdf6d..aa3993e57df 100644
--- a/sql/item_jsonfunc.cc
+++ b/sql/item_jsonfunc.cc
@@ -3643,3 +3643,119 @@ String* Item_func_json_arrayagg::val_str(String *str)
return str;
}
+
+
+Item_func_json_objectagg::
+Item_func_json_objectagg(THD *thd, Item_func_json_objectagg *item)
+ :Item_sum(thd, item)
+{
+ result.set_charset(collation.collation);
+ result.append("{");
+}
+
+
+bool
+Item_func_json_objectagg::fix_fields(THD *thd, Item **ref)
+{
+ uint i; /* for loop variable */
+ DBUG_ASSERT(fixed == 0);
+
+ if (init_sum_func_check(thd))
+ return TRUE;
+
+ maybe_null= 1;
+
+ /*
+ Fix fields for select list and ORDER clause
+ */
+
+ for (i=0 ; i < arg_count ; i++)
+ {
+ if (args[i]->fix_fields_if_needed_for_scalar(thd, &args[i]))
+ return TRUE;
+ m_with_subquery|= args[i]->with_subquery();
+ with_param|= args[i]->with_param;
+ with_window_func|= args[i]->with_window_func;
+ }
+
+ /* skip charset aggregation for order columns */
+ if (agg_arg_charsets_for_string_result(collation, args, arg_count))
+ return 1;
+
+ result.set_charset(collation.collation);
+ result_field= 0;
+ null_value= 1;
+ max_length= (uint32)(thd->variables.group_concat_max_len
+ / collation.collation->mbminlen
+ * collation.collation->mbmaxlen);
+
+ if (check_sum_func(thd, ref))
+ return TRUE;
+
+ fixed= 1;
+ return FALSE;
+}
+
+
+void Item_func_json_objectagg::cleanup()
+{
+ DBUG_ENTER("Item_func_json_objectagg::cleanup");
+ Item_sum::cleanup();
+
+ result.length(1);
+ DBUG_VOID_RETURN;
+}
+
+
+Item *Item_func_json_objectagg::copy_or_same(THD* thd)
+{
+ return new (thd->mem_root) Item_func_json_objectagg(thd, this);
+}
+
+
+void Item_func_json_objectagg::clear()
+{
+ result.length(1);
+ null_value= 1;
+}
+
+
+bool Item_func_json_objectagg::add()
+{
+ StringBuffer<MAX_FIELD_WIDTH> buf;
+ String *key;
+
+ key= args[0]->val_str(&buf);
+ if (args[0]->is_null())
+ return 0;
+
+ null_value= 0;
+ if (result.length() > 1)
+ result.append(", ");
+
+ result.append("\"");
+ result.append(*key);
+ result.append("\":");
+
+ buf.length(0);
+ append_json_value(&result, args[1], &buf);
+
+ return 0;
+}
+
+
+String* Item_func_json_objectagg::val_str(String* str)
+{
+ DBUG_ASSERT(fixed == 1);
+ if (null_value)
+ return 0;
+
+ result.append("}");
+ return &result;
+}
+
+
+void Item_func_json_objectagg::print(String *str, enum_query_type query_type)
+{
+}
+