Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(shannon): to support vector data type #336

Merged
merged 1 commit into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions client/mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,11 @@ static COMMANDS commands[] = {
{"TO_DAYS", 0, nullptr, false, ""},
{"TOUCHES", 0, nullptr, false, ""},
{"TRIM", 0, nullptr, false, ""},
{"TO_VECTOR", 0, nullptr, false, ""},
{"STRING_TO_VECTOR", 0, nullptr, false, ""},
{"FROM_VECTOR", 0, nullptr, false, ""},
{"VECTOR_TO_STRING", 0, nullptr, false, ""},
{"VECTOR_DIM", 0, nullptr, false, ""},
{"UCASE", 0, nullptr, false, ""},
{"UNCOMPRESS", 0, nullptr, false, ""},
{"UNCOMPRESSED_LENGTH", 0, nullptr, false, ""},
Expand Down Expand Up @@ -3925,6 +3930,7 @@ static bool is_binary_field(MYSQL_FIELD *field) {
field->type == MYSQL_TYPE_VAR_STRING ||
field->type == MYSQL_TYPE_STRING ||
field->type == MYSQL_TYPE_VARCHAR ||
field->type == MYSQL_TYPE_VECTOR ||
field->type == MYSQL_TYPE_GEOMETRY));
}

Expand Down
1 change: 1 addition & 0 deletions client/mysqldump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4156,6 +4156,7 @@ static void dump_table(char *table, char *db) {
field->type == MYSQL_TYPE_VAR_STRING ||
field->type == MYSQL_TYPE_VARCHAR ||
field->type == MYSQL_TYPE_BLOB ||
field->type == MYSQL_TYPE_VECTOR ||
field->type == MYSQL_TYPE_LONG_BLOB ||
field->type == MYSQL_TYPE_MEDIUM_BLOB ||
field->type == MYSQL_TYPE_TINY_BLOB ||
Expand Down
27 changes: 27 additions & 0 deletions client/mysqltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8302,6 +8302,30 @@ static void append_field(DYNAMIC_STRING *ds, uint col_idx, MYSQL_FIELD *field,
}
#endif

const size_t temp_val_max_width = (1 << 14);
char temp_val[temp_val_max_width];
DYNAMIC_STRING ds_temp = {.str = nullptr, .length = 0, .max_length = 0};
if (field->type == MYSQL_TYPE_VECTOR && !is_null) {
/* Do a binary to hex conversion for vector type */
size_t orig_len = len;
len = 2 + orig_len * 2;
char *destination = temp_val;
if (len > temp_val_max_width) {
init_dynamic_string(&ds_temp, "", len + 1);
destination = ds_temp.str;
}
const char *ptr = val;
const char *end = ptr + orig_len;
val = destination;
int written = sprintf(destination, "0x");
destination += written;
for (; ptr < end; ptr++, destination += written) {
written = sprintf(
destination, "%02X",
*(static_cast<const uchar *>(static_cast<const void *>(ptr))));
}
}

if (!display_result_vertically) {
if (col_idx) dynstr_append_mem(ds, "\t", 1);
replace_dynstr_append_mem(ds, val, len);
Expand All @@ -8311,6 +8335,9 @@ static void append_field(DYNAMIC_STRING *ds, uint col_idx, MYSQL_FIELD *field,
replace_dynstr_append_mem(ds, val, len);
dynstr_append_mem(ds, "\n", 1);
}
if (ds_temp.str != nullptr) {
dynstr_free(&ds_temp);
}
}

/*
Expand Down
2 changes: 1 addition & 1 deletion cmake/mysql_version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#

SET(SHARED_LIB_MAJOR_VERSION "24")
SET(SHARED_LIB_MINOR_VERSION "0")
SET(SHARED_LIB_MINOR_VERSION "1")
SET(PROTOCOL_VERSION "10")

# Generate "something" to trigger cmake rerun when MYSQL_VERSION changes
Expand Down
1 change: 1 addition & 0 deletions include/field_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ enum enum_field_types {
MYSQL_TYPE_DATETIME2, /**< Internal to MySQL. Not used in protocol */
MYSQL_TYPE_TIME2, /**< Internal to MySQL. Not used in protocol */
MYSQL_TYPE_TYPED_ARRAY, /**< Used for replication only */
MYSQL_TYPE_VECTOR = 242,
MYSQL_TYPE_INVALID = 243,
MYSQL_TYPE_BOOL = 244, /**< Currently just a placeholder */
MYSQL_TYPE_JSON = 245,
Expand Down
1 change: 1 addition & 0 deletions include/mysql.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
MYSQL_TYPE_DATETIME2,
MYSQL_TYPE_TIME2,
MYSQL_TYPE_TYPED_ARRAY,
MYSQL_TYPE_VECTOR = 242,
MYSQL_TYPE_INVALID = 243,
MYSQL_TYPE_BOOL = 244,
MYSQL_TYPE_JSON = 245,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@
#define MYSQL_SP_ARG_TYPE_VAR_STRING (1ULL << 31)
#define MYSQL_SP_ARG_TYPE_STRING (1ULL << 32)
#define MYSQL_SP_ARG_TYPE_GEOMETRY (1ULL << 33)
#define MYSQL_SP_ARG_TYPE_VECTOR (1ULL << 34)

#endif
3 changes: 3 additions & 0 deletions libmysql/libmysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2915,6 +2915,7 @@ static void fetch_string_with_conversion(MYSQL_BIND *param, char *value,
case MYSQL_TYPE_MEDIUM_BLOB:
case MYSQL_TYPE_LONG_BLOB:
case MYSQL_TYPE_BLOB:
case MYSQL_TYPE_VECTOR:
case MYSQL_TYPE_DECIMAL:
case MYSQL_TYPE_NEWDECIMAL:
default: {
Expand Down Expand Up @@ -3526,6 +3527,7 @@ static bool is_binary_compatible(enum enum_field_types type1,
range4[] = {
MYSQL_TYPE_ENUM, MYSQL_TYPE_SET, MYSQL_TYPE_TINY_BLOB,
MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_BLOB,
MYSQL_TYPE_VECTOR,
MYSQL_TYPE_VAR_STRING, MYSQL_TYPE_STRING, MYSQL_TYPE_GEOMETRY,
MYSQL_TYPE_DECIMAL, MYSQL_TYPE_NULL};
static const enum enum_field_types *range_list[] = {range1, range2, range3,
Expand Down Expand Up @@ -3628,6 +3630,7 @@ static bool setup_one_fetch_function(MYSQL_BIND *param, MYSQL_FIELD *field) {
case MYSQL_TYPE_MEDIUM_BLOB:
case MYSQL_TYPE_LONG_BLOB:
case MYSQL_TYPE_BLOB:
case MYSQL_TYPE_VECTOR:
case MYSQL_TYPE_BIT:
assert(param->buffer_length != 0);
param->fetch_result = fetch_result_bin;
Expand Down
2 changes: 2 additions & 0 deletions libs/mysql/binlog/event/binary_log_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ unsigned int max_display_length_for_field(enum_field_types sql_type,
*/
return uint_max(metadata * 8);

case MYSQL_TYPE_VECTOR:
case MYSQL_TYPE_LONG_BLOB:
case MYSQL_TYPE_GEOMETRY:
case MYSQL_TYPE_JSON:
Expand Down Expand Up @@ -347,6 +348,7 @@ uint32_t calc_field_size(unsigned char col, const unsigned char *master_data,
case MYSQL_TYPE_MEDIUM_BLOB:
case MYSQL_TYPE_LONG_BLOB:
case MYSQL_TYPE_BLOB:
case MYSQL_TYPE_VECTOR:
case MYSQL_TYPE_GEOMETRY:
case MYSQL_TYPE_JSON: {
/*
Expand Down
21 changes: 21 additions & 0 deletions libs/mysql/binlog/event/rows_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,24 @@ static void parse_geometry_type(std::vector<unsigned int> &vec,
}
}

/**
Parses VECTOR_DIMENSIONALITY field.
@param[out] vec stores vector columns's dimensionality extracted from
field.
@param[in] reader_obj the Event_reader object containing the serialized
field.
@param[in] length length of the field
*/
static void parse_vector_dimensionality(std::vector<unsigned int> &vec,
Event_reader &reader_obj,
unsigned int length) {
const char *field = reader_obj.ptr();
while (reader_obj.ptr() < field + length) {
vec.push_back(reader_obj.net_field_length_ll());
if (reader_obj.has_error()) return;
}
}

/**
Parses SIMPLE_PRIMARY_KEY field.

Expand Down Expand Up @@ -373,6 +391,9 @@ Table_map_event::Optional_metadata_fields::Optional_metadata_fields(
case COLUMN_VISIBILITY:
parse_column_visibility(&m_column_visibility, reader_obj, len);
break;
case VECTOR_DIMENSIONALITY:
parse_vector_dimensionality(m_vector_dimensionality, reader_obj, len);
break;
default:
BAPI_ASSERT(0);
}
Expand Down
6 changes: 4 additions & 2 deletions libs/mysql/binlog/event/rows_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,9 @@ class Table_map_event : public Binary_log_event {
columns, optimized to minimize
space when many columns have the
same charset. */
COLUMN_VISIBILITY /* Flag to indicate column visibility
attribute. */
COLUMN_VISIBILITY, /* Flag to indicate column visibility
attribute. */
VECTOR_DIMENSIONALITY /* Vector column dimensionality */
};

/**
Expand Down Expand Up @@ -605,6 +606,7 @@ class Table_map_event : public Binary_log_event {
std::vector<str_vector> m_enum_str_value;
std::vector<str_vector> m_set_str_value;
std::vector<unsigned int> m_geometry_type;
std::vector<unsigned int> m_vector_dimensionality;
/*
The uint_pair means <column index, prefix length>. Prefix length is 0 if
whole column value is used.
Expand Down
Loading