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
b80b63bd
Commit
b80b63bd
authored
Nov 25, 2023
by
Sergei Golubchik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-32885 VEC_DISTANCE() function
parent
8478a06c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
117 additions
and
2 deletions
+117
-2
libmysqld/CMakeLists.txt
libmysqld/CMakeLists.txt
+1
-1
sql/CMakeLists.txt
sql/CMakeLists.txt
+1
-1
sql/item.h
sql/item.h
+1
-0
sql/item_create.cc
sql/item_create.cc
+24
-0
sql/item_vectorfunc.cc
sql/item_vectorfunc.cc
+42
-0
sql/item_vectorfunc.h
sql/item_vectorfunc.h
+48
-0
No files found.
libmysqld/CMakeLists.txt
View file @
b80b63bd
...
...
@@ -101,7 +101,7 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
../sql/sql_show.cc ../sql/sql_state.c
../sql/sql_statistics.cc ../sql/sql_string.cc
../sql/sql_table.cc ../sql/sql_test.cc
../sql/ddl_log.cc
../sql/ddl_log.cc
../sql/item_vectorfunc.cc
../sql/sql_trigger.cc ../sql/sql_udf.cc ../sql/sql_union.cc
../sql/sql_update.cc ../sql/sql_view.cc ../sql/sql_profile.cc
../sql/gcalc_tools.cc ../sql/gcalc_slicescan.cc
...
...
sql/CMakeLists.txt
View file @
b80b63bd
...
...
@@ -103,7 +103,7 @@ SET (SQL_SOURCE
filesort_utils.cc
filesort.cc gstream.cc
signal_handler.cc
handler.cc
handler.cc
item_vectorfunc.cc
hostname.cc init.cc item.cc item_buff.cc item_cmpfunc.cc
item_create.cc item_func.cc item_geofunc.cc item_row.cc
item_strfunc.cc item_subselect.cc item_sum.cc item_timefunc.cc
...
...
sql/item.h
View file @
b80b63bd
...
...
@@ -6619,6 +6619,7 @@ class Item_int_with_ref :public Item_int
#include "item_subselect.h"
#include "item_xmlfunc.h"
#include "item_jsonfunc.h"
#include "item_vectorfunc.h"
#include "item_create.h"
#include "item_vers.h"
#endif
...
...
sql/item_create.cc
View file @
b80b63bd
...
...
@@ -6235,6 +6235,29 @@ Create_func_year_week::create_native(THD *thd, const LEX_CSTRING *name,
return
func
;
}
class
Create_func_vec_distance
:
public
Create_func_arg2
{
public:
Item
*
create_2_arg
(
THD
*
thd
,
Item
*
arg1
,
Item
*
arg2
)
override
;
static
Create_func_vec_distance
s_singleton
;
protected:
Create_func_vec_distance
()
=
default
;
virtual
~
Create_func_vec_distance
()
=
default
;
};
Create_func_vec_distance
Create_func_vec_distance
::
s_singleton
;
Item
*
Create_func_vec_distance
::
create_2_arg
(
THD
*
thd
,
Item
*
arg1
,
Item
*
arg2
)
{
return
new
(
thd
->
mem_root
)
Item_func_vec_distance
(
thd
,
arg1
,
arg2
);
}
#define BUILDER(F) & F::s_singleton
/*
...
...
@@ -6461,6 +6484,7 @@ const Native_func_registry func_array[] =
{
{
STRING_WITH_LEN
(
"UPDATEXML"
)
},
BUILDER
(
Create_func_xml_update
)},
{
{
STRING_WITH_LEN
(
"UPPER"
)
},
BUILDER
(
Create_func_ucase
)},
{
{
STRING_WITH_LEN
(
"UUID_SHORT"
)
},
BUILDER
(
Create_func_uuid_short
)},
{
{
STRING_WITH_LEN
(
"VEC_DISTANCE"
)
},
BUILDER
(
Create_func_vec_distance
)},
{
{
STRING_WITH_LEN
(
"VERSION"
)
},
BUILDER
(
Create_func_version
)},
{
{
STRING_WITH_LEN
(
"WEEK"
)
},
BUILDER
(
Create_func_week
)},
{
{
STRING_WITH_LEN
(
"WEEKDAY"
)
},
BUILDER
(
Create_func_weekday
)},
...
...
sql/item_vectorfunc.cc
0 → 100644
View file @
b80b63bd
/* Copyright (c) 2023, MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
/**
@file
@brief
This file defines all vector functions
*/
#include <my_global.h>
#include "item.h"
double
Item_func_vec_distance
::
val_real
()
{
String
*
r1
=
args
[
0
]
->
val_str
();
String
*
r2
=
args
[
1
]
->
val_str
();
null_value
=
!
r1
||
!
r2
||
r1
->
length
()
!=
r2
->
length
()
||
r1
->
length
()
%
sizeof
(
float
);
if
(
null_value
)
return
0
;
float
*
v1
=
(
float
*
)
r1
->
ptr
();
float
*
v2
=
(
float
*
)
r2
->
ptr
();
double
d
=
0
;
for
(
uint
i
=
0
;
i
<
r1
->
length
()
/
sizeof
(
float
);
i
++
)
d
+=
(
v1
[
i
]
-
v2
[
i
])
*
(
v1
[
i
]
-
v2
[
i
]);
return
sqrt
(
d
);
}
sql/item_vectorfunc.h
0 → 100644
View file @
b80b63bd
#ifndef ITEM_VECTORFUNC_INCLUDED
#define ITEM_VECTORFUNC_INCLUDED
/* Copyright (C) 2023, MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
/* This file defines all vector functions */
#include "lex_string.h"
#include "item_func.h"
class
Item_func_vec_distance
:
public
Item_real_func
{
protected:
bool
check_arguments
()
const
override
{
return
check_argument_types_or_binary
(
NULL
,
0
,
arg_count
);
}
public:
Item_func_vec_distance
(
THD
*
thd
,
Item
*
a
,
Item
*
b
)
:
Item_real_func
(
thd
,
a
,
b
)
{}
bool
fix_length_and_dec
(
THD
*
thd
)
override
{
set_maybe_null
();
return
Item_real_func
::
fix_length_and_dec
(
thd
);
}
double
val_real
()
override
;
LEX_CSTRING
func_name_cstring
()
const
override
{
static
LEX_CSTRING
name
=
{
STRING_WITH_LEN
(
"vec_distance"
)
};
return
name
;
}
Item
*
do_get_copy
(
THD
*
thd
)
const
override
{
return
get_item_copy
<
Item_func_vec_distance
>
(
thd
,
this
);
}
};
#endif
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