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

[CUBVEC-8] Survey on adding Vector Type #5636

Draft
wants to merge 25 commits into
base: cubvec/cubvec
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9f50e06
stage 1: add VIMKIM to lex & parser
vimkim Nov 15, 2024
4072171
stage 2: add DB_TYPE_VIMKIM
vimkim Nov 15, 2024
2a17b53
stage 3: add tp_vimkim for primitive type
vimkim Nov 15, 2024
711a720
stage 4: add to object_prinre and query_executor to print VIMKIM
vimkim Nov 15, 2024
39a9f87
feat(cast): add tp_value_cast conversion logic
vimkim Nov 18, 2024
24fbb97
add mr_setval_vimkim
vimkim Nov 18, 2024
9b2f77e
add dbval to ptval conversion logic
vimkim Nov 18, 2024
5918d91
feat(object primitive): add mr_writeval_vimkim
vimkim Nov 18, 2024
863c340
add readval_vimkim for csql_result
vimkim Nov 18, 2024
1966b0c
feat(csql_result_format): vimkim to csql result conversion switch case
vimkim Nov 18, 2024
e7c84e5
feat(type_checking): infer common type to PT_TYPE_VIMKIM for select w…
vimkim Nov 19, 2024
58c3a1b
feat(dbtype_def): add dbvector
vimkim Nov 20, 2024
a70dab2
feat(dbtype_function.i): db_get_vimkim, db_make_vimkim now return con…
vimkim Nov 20, 2024
71e26c9
feat(object_primitive): replace tp_Vimkim mr function series
vimkim Nov 20, 2024
e7da41e
fix(parse_dbi, tree): add vector_buf to pt_data_value
vimkim Nov 20, 2024
24a7050
feat(csql_result_format): csql output format vimkim
vimkim Nov 20, 2024
104a2ec
feat(object_domain): coerce string to vimkim with float parsing
vimkim Nov 20, 2024
b8b29ee
refactor(object_domain): remove unnecessary int -> vector conversion …
vimkim Nov 21, 2024
b982af3
feat(parser/*): add vector element & dimension to PT_NODE
vimkim Nov 25, 2024
8ddaffd
misc(csql_grammar): DBG_TRACE_LEVEL 2
vimkim Nov 25, 2024
b795b56
fix(dbtype_function.*): warnings due to vimkim type db function signa…
vimkim Nov 25, 2024
3bc0100
misc(csql_grammar): disable parser debugger
vimkim Nov 25, 2024
3badaff
fix(parse_tree_cl): disable DEBUG_PT_APPLY_WALK
vimkim Nov 25, 2024
5e6e12e
fix(*): vimkim -> print vector
vimkim Nov 29, 2024
5c89b02
Merge remote-tracking branch 'cub/develop' into cubvec-survey-vimkim-…
vimkim Dec 5, 2024
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
1 change: 1 addition & 0 deletions src/compat/db_macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ db_value_domain_init (DB_VALUE * value, const DB_TYPE type, const int precision,
break;

case DB_TYPE_NULL:
case DB_TYPE_VIMKIM:
case DB_TYPE_INTEGER:
case DB_TYPE_BIGINT:
case DB_TYPE_FLOAT:
Expand Down
11 changes: 10 additions & 1 deletion src/compat/dbtype_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -722,14 +722,15 @@ extern "C"
DB_TYPE_DATETIMETZ = 38,
DB_TYPE_DATETIMELTZ = 39,
DB_TYPE_JSON = 40,
DB_TYPE_VIMKIM = 41,

/* aliases */
DB_TYPE_LIST = DB_TYPE_SEQUENCE,
DB_TYPE_SMALLINT = DB_TYPE_SHORT, /* SQL SMALLINT */
DB_TYPE_VARCHAR = DB_TYPE_STRING, /* SQL CHAR(n) VARYING values */
DB_TYPE_UTIME = DB_TYPE_TIMESTAMP, /* SQL TIMESTAMP */

DB_TYPE_LAST = DB_TYPE_JSON
DB_TYPE_LAST = DB_TYPE_VIMKIM,
} DB_TYPE;

/* Domain information stored in DB_VALUE structures. */
Expand Down Expand Up @@ -1051,6 +1052,13 @@ extern "C"
JSON_DOC *document;
};

typedef struct db_vector DB_VECTOR;
struct db_vector
{
const float *buf;
int length;
};

/* A union of all of the possible basic type values. This is used in the definition of the DB_VALUE which is the fundamental
* structure used in passing data in and out of the db_ function layer.
*/
Expand Down Expand Up @@ -1082,6 +1090,7 @@ extern "C"
DB_RESULTSET rset;
DB_ENUM_ELEMENT enumeration;
DB_JSON json;
DB_VECTOR vector;
};

/* This is the primary structure used for passing values in and out of the db_ function layer. Values are always tagged with
Expand Down
3 changes: 3 additions & 0 deletions src/compat/dbtype_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ extern "C"
extern bool db_is_json_value_type (DB_TYPE type);
extern bool db_is_json_doc_type (DB_TYPE type);

extern const float *db_get_vimkim (const DB_VALUE * value);
extern int db_get_vimkim_size (const DB_VALUE * value);
extern int db_get_int (const DB_VALUE * value);
extern DB_C_SHORT db_get_short (const DB_VALUE * value);
extern DB_BIGINT db_get_bigint (const DB_VALUE * value);
Expand Down Expand Up @@ -341,6 +343,7 @@ extern "C"
extern JSON_DOC *db_get_json_document (const DB_VALUE * value);

extern int db_make_null (DB_VALUE * value);
extern int db_make_vimkim (DB_VALUE * value, const float * buf, const int size);
extern int db_make_int (DB_VALUE * value, const int num);
extern int db_make_float (DB_VALUE * value, const DB_C_FLOAT num);
extern int db_make_double (DB_VALUE * value, const DB_C_DOUBLE num);
Expand Down
60 changes: 60 additions & 0 deletions src/compat/dbtype_function.i
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#if !defined (_NO_INLINE_DBTYPE_FUNCTION_)
#include "porting_inline.hpp"

STATIC_INLINE const float *db_get_vimkim (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
STATIC_INLINE int db_get_vimkim_size (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
STATIC_INLINE int db_get_int (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
STATIC_INLINE DB_C_SHORT db_get_short (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
STATIC_INLINE DB_BIGINT db_get_bigint (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
Expand Down Expand Up @@ -69,6 +71,7 @@ STATIC_INLINE int db_make_db_char (DB_VALUE * value, INTL_CODESET codeset, const
const int size) __attribute__ ((ALWAYS_INLINE));

STATIC_INLINE int db_make_null (DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
STATIC_INLINE int db_make_vimkim (DB_VALUE * value, const float * buf, const int size) __attribute__ ((ALWAYS_INLINE));
STATIC_INLINE int db_make_int (DB_VALUE * value, const int num) __attribute__ ((ALWAYS_INLINE));
STATIC_INLINE int db_make_float (DB_VALUE * value, const DB_C_FLOAT num) __attribute__ ((ALWAYS_INLINE));
STATIC_INLINE int db_make_double (DB_VALUE * value, const DB_C_DOUBLE num) __attribute__ ((ALWAYS_INLINE));
Expand Down Expand Up @@ -145,6 +148,40 @@ STATIC_INLINE DB_TYPE db_value_domain_type (const DB_VALUE * value) __attribute_
#include <assert.h>
#include "memory_cwrapper.h"

/*
* db_get_vimkim() -
* return :
* value(in):
*/
const float *
db_get_vimkim (const DB_VALUE * value)
{
#if defined (API_ACTIVE_CHECKS)
CHECK_1ARG_ZERO (value);
#endif

assert (value->domain.general_info.type == DB_TYPE_VIMKIM);

return value->data.vector.buf;
}

/*
* db_get_vimkim() -
* return :
* value(in):
*/
int
db_get_vimkim_size (const DB_VALUE * value)
{
#if defined (API_ACTIVE_CHECKS)
CHECK_1ARG_ZERO (value);
#endif

assert (value->domain.general_info.type == DB_TYPE_VIMKIM);

return value->data.vector.length;
}

/*
* db_get_int() -
* return :
Expand Down Expand Up @@ -1044,6 +1081,29 @@ db_make_null (DB_VALUE * value)
return NO_ERROR;
}

/*
* db_make_vimkim() -
* return :
* value(out) :
* num(in):
*/
int
db_make_vimkim (DB_VALUE * value, const float *buf, const int size)
{
#if defined (API_ACTIVE_CHECKS)
CHECK_1ARG_ERROR (value);
#endif

value->domain.general_info.type = DB_TYPE_VIMKIM;
value->data.vector.buf = buf;
value->data.vector.length = size;

value->domain.general_info.is_null = 0;
value->need_clear = false;

return NO_ERROR;
}

/*
* db_make_int() -
* return :
Expand Down
24 changes: 24 additions & 0 deletions src/executables/csql_result_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,30 @@ csql_db_value_as_string (DB_VALUE * value, int *length, const CSQL_ARGUMENT * cs
len = strlen (result);
}
break;
case DB_TYPE_VIMKIM:
{
const float * vimkim = db_get_vimkim (value);
const int vimkim_size = db_get_vimkim_size (value);


std::ostringstream oss;
oss << "[";

// Add elements to the string stream
for (int i = 0; i < vimkim_size; ++i) {
if (i > 0) {
oss << ", ";
}
oss << vimkim[i];
}
oss << "]";
result = strdup(oss.str().c_str());
}
if (result)
{
len = strlen (result);
}
break;
case DB_TYPE_INTEGER:
result =
bigint_to_string (db_get_int (value), default_int_profile.fieldwidth, default_int_profile.leadingzeros,
Expand Down
58 changes: 58 additions & 0 deletions src/object/object_domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -7090,6 +7090,46 @@ tp_value_coerce_strict (const DB_VALUE * src, DB_VALUE * dest, const TP_DOMAIN *
return err;
}


// Function to parse the string into a dynamically allocated float array
float* parseFloatArray(const std::string& input, int& outSize) {
// Check if the input starts with '[' and ends with ']'
if (input.empty() || input.front() != '[' || input.back() != ']') {
outSize = 0;
return nullptr;
}

// Remove the square brackets
std::string content = input.substr(1, input.size() - 2);

// Use a stringstream to parse floats
std::stringstream ss(content);
std::vector<float> temp;

// Extract floats separated by commas
std::string item;
while (std::getline(ss, item, ',')) {
try {
// Trim whitespace and convert to float
temp.push_back(std::stof(item));
} catch (...) {
// Handle conversion errors (invalid input)
outSize = 0;
return nullptr;
}
}

// Allocate a dynamic array and copy values from the vector
outSize = temp.size();
float* result(new float[outSize]);
for (int i = 0; i < outSize; ++i) {
result[i] = temp[i];
}

return result;
}


/*
* tp_value_coerce_internal - Coerce a value into one of another domain.
* return: error code
Expand Down Expand Up @@ -7529,6 +7569,24 @@ tp_value_cast_internal (const DB_VALUE * src, DB_VALUE * dest, const TP_DOMAIN *
}
break;

case DB_TYPE_VIMKIM:
switch (original_type)
{
case DB_TYPE_CHAR:
{
const char *str = db_get_string(src);

int size;
auto farray = parseFloatArray(std::string(str), size);

db_make_vimkim(target, farray, (int)size);
break;
}
default:
status = DOMAIN_INCOMPATIBLE;
break;
}
break;
case DB_TYPE_INTEGER:
switch (original_type)
{
Expand Down
Loading
Loading