[MDEV-19994] Add class Function_collection Created: 2019-07-09  Updated: 2019-10-14  Resolved: 2019-07-09

Status: Closed
Project: MariaDB Server
Component/s: GIS
Fix Version/s: 10.5.0

Type: Task Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MDEV-274 The data type for IPv6/IPv4 addresses... Closed
blocks MDEV-4912 Data type plugin API version 1 Closed

 Description   

Data type plugins should be able to provide their own sets of built-in functions.

Let's add a new class Function_collection, as follows:

class Function_collection
{
public:
  virtual ~Function_collection() {}
  virtual bool init()= 0;
  virtual void cleanup()= 0;
  virtual Create_func *find_native_function_builder(THD *thd,
                                                    const LEX_CSTRING &name)
                                                    const= 0;
};

and, as a prove of the conceipt, move all GIS functions into a new class Function_collection_geometry.

  • The method init() will do the collection initialization, e.g. create a hash to lookup Create_func builders by function names.
  • The method cleanup will free all memory allocated by init(), e.g. free the lookup hash.
  • The method find_native_function_builder will lookup a function by name and return its Create_func builder (or NULL if the function is not found).

This task will also do the following:

  • Move all GIS function Create_func_xxx classes from item_create_cc to item_geofunc.cc
  • Move definitions of Create_func_arg0, Create_func_arg1, Create_func_arg2, Create_func_arg3 from item_create.cc to item_create.h, so function collection plugins can reuse these classes.
  • Remove this code from the bison grammar:

    -        | geometry_function
    -          {
    -#ifdef HAVE_SPATIAL
    -            $$= $1;
    -            /* $1 may be NULL, GEOM_NEW not tested for out of memory */
    -            if (unlikely($$ == NULL))
    -              MYSQL_YYABORT;
    -#else
    -            my_yyabort_error((ER_FEATURE_DISABLED, MYF(0), sym_group_geom.name,
    -                              sym_group_geom.needed_define));
    -#endif
    -          }
    -        ;
    -
    -geometry_function:
    -          CONTAINS_SYM '(' expr ',' expr ')'
    -          {
    -            $$= GEOM_NEW(thd,
    -                         Item_func_spatial_precise_rel(thd, $3, $5,
    -                                                 Item_func::SP_CONTAINS_FUNC));
    -          }
    -        | WITHIN '(' expr ',' expr ')'
    -          {
    -            $$= GEOM_NEW(thd, Item_func_spatial_precise_rel(thd, $3, $5,
    -                                                    Item_func::SP_WITHIN_FUNC));
    -          }
    
    

    and add something like this into the function_call_generic rule:

            | CONTAINS_SYM '(' opt_expr_list ')'
              {
                if (!($$= Lex->make_item_func_call_native_or_parse_error(thd,
                                                                         $1, $3)))
                  MYSQL_YYABORT;
              }
            | WITHIN '(' opt_expr_list ')'
              {
                if (!($$= Lex->make_item_func_call_native_or_parse_error(thd,
                                                                         $1, $3)))
                  MYSQL_YYABORT;
              }
    

  • Add a global instance of Function_collection_geometry

Later, in a separate MDEV, we'll add a new plugin type, MYSQL_FUNCTION_COLLECTION_PLUGIN.



 Comments   
Comment by Sergei Golubchik [ 2019-07-09 ]

I don't think it belongs to data type plugins. It should be a new UDF-replacement "function" plugin type.

of course, it can be in the same .so as a data type plugin and loaded with the same INSTALL SONAME command.

Comment by Alexander Barkov [ 2019-07-09 ]

I agree.

1. Data type shared libraries will be able to have at the same time:

  • the data type definition (in Type_handler_xxx and Field_xxx), and
  • an optional "function" plugin
    For example, the GIS implementation will most likely have Type_handler_geometry/Field_geom and all GIS functions in the same .so.

2. But it will be also possible to have "function" plugins alone (i.e. a plugin with a set of functions, without any new data types).

The new class Function_collection will be reused in both cases.

Generated at Thu Feb 08 08:55:56 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.