File: item_vectorfunc.h

package info (click to toggle)
mariadb 1%3A11.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 772,520 kB
  • sloc: ansic: 2,414,714; cpp: 1,791,394; asm: 381,336; perl: 62,905; sh: 49,647; pascal: 40,897; java: 39,363; python: 20,791; yacc: 20,432; sql: 17,907; xml: 12,344; ruby: 8,544; cs: 6,542; makefile: 6,145; ada: 1,879; lex: 1,193; javascript: 996; objc: 80; tcl: 73; awk: 46; php: 22
file content (105 lines) | stat: -rw-r--r-- 3,398 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#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 <my_global.h>
#include "item.h"
#include "lex_string.h"
#include "item_func.h"

class Item_func_vec_distance: public Item_real_func
{
  Item_field *get_field_arg() const
  {
    if (args[0]->real_item()->type() == Item::FIELD_ITEM && args[1]->const_item())
      return (Item_field*)(args[0]->real_item());
    if (args[1]->real_item()->type() == Item::FIELD_ITEM && args[0]->const_item())
      return (Item_field*)(args[1])->real_item();
    return NULL;
  }
  bool check_arguments() const override
  {
    return check_argument_types_or_binary(NULL, 0, arg_count);
  }
  double (*calc_distance)(float *v1, float *v2, size_t v_len);

public:
  enum distance_kind { EUCLIDEAN, COSINE, AUTO } kind;
  Item_func_vec_distance(THD *thd, Item *a, Item *b, distance_kind kind);
  LEX_CSTRING func_name_cstring() const override
  {
    static LEX_CSTRING name[3]= {
      { STRING_WITH_LEN("VEC_DISTANCE_EUCLIDEAN") },
      { STRING_WITH_LEN("VEC_DISTANCE_COSINE") },
      { STRING_WITH_LEN("VEC_DISTANCE") }
    };
    return name[kind];
  }
  bool fix_length_and_dec(THD *thd) override;
  double val_real() override;
  Item *get_const_arg() const
  {
    if (args[0]->real_item()->type() == Item::FIELD_ITEM && args[1]->const_item())
      return args[1];
    if (args[1]->real_item()->type() == Item::FIELD_ITEM && args[0]->const_item())
      return args[0];
    return NULL;
  }
  key_map part_of_sortkey() const override;
  Item *do_get_copy(THD *thd) const override
  { return get_item_copy<Item_func_vec_distance>(thd, this); }
};


class Item_func_vec_totext: public Item_str_ascii_checksum_func
{
  bool check_arguments() const override
  {
    return check_argument_types_or_binary(NULL, 0, arg_count);
  }

public:
  bool fix_length_and_dec(THD *thd) override;
  Item_func_vec_totext(THD *thd, Item *a);
  String *val_str_ascii(String *buf) override;
  LEX_CSTRING func_name_cstring() const override
  {
    static LEX_CSTRING name= { STRING_WITH_LEN("VEC_ToText") };
    return name;
  }
  Item *do_get_copy(THD *thd) const override
  { return get_item_copy<Item_func_vec_totext>(thd, this); }
};


class Item_func_vec_fromtext: public Item_str_func
{
  String tmp_js;
public:
  bool fix_length_and_dec(THD *thd) override;
  Item_func_vec_fromtext(THD *thd, Item *a);
  String *val_str(String *buf) override;
  LEX_CSTRING func_name_cstring() const override
  {
    static LEX_CSTRING name= { STRING_WITH_LEN("VEC_FromText") };
    return name;
  }
  Item *do_get_copy(THD *thd) const override
  { return get_item_copy<Item_func_vec_fromtext>(thd, this); }
};
#endif