doris icon indicating copy to clipboard operation
doris copied to clipboard

[opt](fucntion) improve json_extract function handle const column

Open zhangstar333 opened this issue 7 months ago • 25 comments

Proposed changes

VARCHAR json_extract(VARCHAR json_str, VARCHAR path[, VARCHAR path] ...)

  for (int i = 0; i < arguments.size(); i++) {
       column_ptrs.push_back(
               block.get_by_position(arguments[i]).column->convert_to_full_column_if_const());
       data_columns.push_back(assert_cast<const ColumnString*>(column_ptrs.back().get()));
   }

before not handle const column, as the input arguments are variadic,
and most user case is like: json_extract(column, '$.fparam.nested_2')
so could special deal with two arguments could reuse json document.

mysql [test]>select count(json_extract(a, '$.fparam.nested_2')) from json_table_2;
+---------------------------------------------+
| count(json_extract(a, '$.fparam.nested_2')) |
+---------------------------------------------+
|                                    10000001 |
+---------------------------------------------+
1 row in set (1.06 sec)

mysql [test]>select count(json_extract(a, '$.fparam.nested_2')) from json_table_2;
+---------------------------------------------+
| count(json_extract(a, '$.fparam.nested_2')) |
+---------------------------------------------+
|                                    10000001 |
+---------------------------------------------+
1 row in set (1.02 sec)

mysql [test]>
mysql [test]>
mysql [test]>select count(json_extract(a, '$.fparam.nested_2')) from json_table_2;
+---------------------------------------------+
| count(json_extract(a, '$.fparam.nested_2')) |
+---------------------------------------------+
|                                    10000001 |
+---------------------------------------------+
1 row in set (44.22 sec)

mysql [test]>select count(json_extract(a, '$.fparam.nested_2')) from json_table_2;
+---------------------------------------------+
| count(json_extract(a, '$.fparam.nested_2')) |
+---------------------------------------------+
|                                    10000001 |
+---------------------------------------------+
1 row in set (42.80 sec)

zhangstar333 avatar Jun 27 '24 08:06 zhangstar333