rm double/int32, just float/int64

This commit is contained in:
Alex Garcia 2024-11-13 22:23:47 -08:00
parent 06e28da3a5
commit 9fffdc4d1b
3 changed files with 100 additions and 191 deletions

View file

@ -2090,10 +2090,8 @@ int vec0_parse_auxiliary_column_definition(const char *source, int source_length
typedef enum { typedef enum {
VEC0_METADATA_COLUMN_KIND_BOOLEAN, VEC0_METADATA_COLUMN_KIND_BOOLEAN,
VEC0_METADATA_COLUMN_KIND_INT32, VEC0_METADATA_COLUMN_KIND_INTEGER,
VEC0_METADATA_COLUMN_KIND_INT64,
VEC0_METADATA_COLUMN_KIND_FLOAT, VEC0_METADATA_COLUMN_KIND_FLOAT,
VEC0_METADATA_COLUMN_KIND_DOUBLE,
VEC0_METADATA_COLUMN_KIND_TEXT, VEC0_METADATA_COLUMN_KIND_TEXT,
// TODO: blob, date, datetime // TODO: blob, date, datetime
} vec0_metadata_column_kind; } vec0_metadata_column_kind;
@ -2141,14 +2139,10 @@ int vec0_parse_metadata_column_definition(const char *source, int source_length,
int n = token.end - token.start; int n = token.end - token.start;
if (sqlite3_strnicmp(t, "boolean", n) == 0 || sqlite3_strnicmp(t, "bool", n) == 0) { if (sqlite3_strnicmp(t, "boolean", n) == 0 || sqlite3_strnicmp(t, "bool", n) == 0) {
column_type = VEC0_METADATA_COLUMN_KIND_BOOLEAN; column_type = VEC0_METADATA_COLUMN_KIND_BOOLEAN;
}else if (sqlite3_strnicmp(t, "int32", n) == 0 || sqlite3_strnicmp(t, "integer32", n) == 0) {
column_type = VEC0_METADATA_COLUMN_KIND_INT32;
}else if (sqlite3_strnicmp(t, "int64", n) == 0 || sqlite3_strnicmp(t, "integer64", n) == 0 || sqlite3_strnicmp(t, "integer", n) == 0 || sqlite3_strnicmp(t, "int", n) == 0) { }else if (sqlite3_strnicmp(t, "int64", n) == 0 || sqlite3_strnicmp(t, "integer64", n) == 0 || sqlite3_strnicmp(t, "integer", n) == 0 || sqlite3_strnicmp(t, "int", n) == 0) {
column_type = VEC0_METADATA_COLUMN_KIND_INT64; column_type = VEC0_METADATA_COLUMN_KIND_INTEGER;
}else if (sqlite3_strnicmp(t, "float", n) == 0 || sqlite3_strnicmp(t, "float32", n) == 0 || sqlite3_strnicmp(t, "f32", n) == 0) { }else if (sqlite3_strnicmp(t, "float", n) == 0 || sqlite3_strnicmp(t, "double", n) == 0 || sqlite3_strnicmp(t, "float64", n) == 0 || sqlite3_strnicmp(t, "f64", n) == 0) {
column_type = VEC0_METADATA_COLUMN_KIND_FLOAT; column_type = VEC0_METADATA_COLUMN_KIND_FLOAT;
} else if (sqlite3_strnicmp(t, "double", n) == 0 || sqlite3_strnicmp(t, "float64", n) == 0 || sqlite3_strnicmp(t, "f64", n) == 0) {
column_type = VEC0_METADATA_COLUMN_KIND_DOUBLE;
} else if (sqlite3_strnicmp(t, "text", n) == 0) { } else if (sqlite3_strnicmp(t, "text", n) == 0) {
column_type = VEC0_METADATA_COLUMN_KIND_TEXT; column_type = VEC0_METADATA_COLUMN_KIND_TEXT;
} else { } else {
@ -4070,16 +4064,7 @@ int vec0_result_metadata_value_for_rowid(vec0_vtab *p, i64 rowid, int metadata_i
sqlite3_result_int(context, value); sqlite3_result_int(context, value);
break; break;
} }
case VEC0_METADATA_COLUMN_KIND_INT32: { case VEC0_METADATA_COLUMN_KIND_INTEGER: {
int value;
rc = sqlite3_blob_read(blobValue, &value, sizeof(value), chunk_offset * sizeof(i32));
if(rc != SQLITE_OK) {
goto done;
}
sqlite3_result_int(context, value);
break;
}
case VEC0_METADATA_COLUMN_KIND_INT64: {
i64 value; i64 value;
rc = sqlite3_blob_read(blobValue, &value, sizeof(value), chunk_offset * sizeof(i64)); rc = sqlite3_blob_read(blobValue, &value, sizeof(value), chunk_offset * sizeof(i64));
if(rc != SQLITE_OK) { if(rc != SQLITE_OK) {
@ -4089,15 +4074,6 @@ int vec0_result_metadata_value_for_rowid(vec0_vtab *p, i64 rowid, int metadata_i
break; break;
} }
case VEC0_METADATA_COLUMN_KIND_FLOAT: { case VEC0_METADATA_COLUMN_KIND_FLOAT: {
float value;
rc = sqlite3_blob_read(blobValue, &value, sizeof(value), chunk_offset * sizeof(f32));
if(rc != SQLITE_OK) {
goto done;
}
sqlite3_result_double(context, (double) value);
break;
}
case VEC0_METADATA_COLUMN_KIND_DOUBLE: {
double value; double value;
rc = sqlite3_blob_read(blobValue, &value, sizeof(value), chunk_offset * sizeof(double)); rc = sqlite3_blob_read(blobValue, &value, sizeof(value), chunk_offset * sizeof(double));
if(rc != SQLITE_OK) { if(rc != SQLITE_OK) {
@ -4335,13 +4311,9 @@ int vec0_metadata_chunk_size(vec0_metadata_column_kind kind, int chunk_size) {
switch(kind) { switch(kind) {
case VEC0_METADATA_COLUMN_KIND_BOOLEAN: case VEC0_METADATA_COLUMN_KIND_BOOLEAN:
return chunk_size / 8; return chunk_size / 8;
case VEC0_METADATA_COLUMN_KIND_INT32: case VEC0_METADATA_COLUMN_KIND_INTEGER:
return chunk_size * sizeof(int32_t);
case VEC0_METADATA_COLUMN_KIND_INT64:
return chunk_size * sizeof(i64); return chunk_size * sizeof(i64);
case VEC0_METADATA_COLUMN_KIND_FLOAT: case VEC0_METADATA_COLUMN_KIND_FLOAT:
return chunk_size * sizeof(f32);
case VEC0_METADATA_COLUMN_KIND_DOUBLE:
return chunk_size * sizeof(double); return chunk_size * sizeof(double);
case VEC0_METADATA_COLUMN_KIND_TEXT: case VEC0_METADATA_COLUMN_KIND_TEXT:
return chunk_size * VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH; return chunk_size * VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH;
@ -5824,19 +5796,11 @@ int vec0_set_metadata_filter_bitmap(
szMatch = blobSize == size / CHAR_BIT; szMatch = blobSize == size / CHAR_BIT;
break; break;
} }
case VEC0_METADATA_COLUMN_KIND_INT32: { case VEC0_METADATA_COLUMN_KIND_INTEGER: {
szMatch = blobSize == size * sizeof(i32);
break;
}
case VEC0_METADATA_COLUMN_KIND_INT64: {
szMatch = blobSize == size * sizeof(i64); szMatch = blobSize == size * sizeof(i64);
break; break;
} }
case VEC0_METADATA_COLUMN_KIND_FLOAT: { case VEC0_METADATA_COLUMN_KIND_FLOAT: {
szMatch = blobSize == size * sizeof(f32);
break;
}
case VEC0_METADATA_COLUMN_KIND_DOUBLE: {
szMatch = blobSize == size * sizeof(double); szMatch = blobSize == size * sizeof(double);
break; break;
} }
@ -5860,38 +5824,7 @@ int vec0_set_metadata_filter_bitmap(
} }
break; break;
} }
case VEC0_METADATA_COLUMN_KIND_INT32: { case VEC0_METADATA_COLUMN_KIND_INTEGER: {
i32 * array = (i32*) buffer;
i32 target = sqlite3_value_int(value);
switch(op) {
case VEC0_METADATA_OPERATOR_EQ: {
for(int i = 0; i < size; i++) { bitmap_set(b, i, array[i] == target); }
break;
}
case VEC0_METADATA_OPERATOR_GT: {
for(int i = 0; i < size; i++) { bitmap_set(b, i, array[i] > target); }
break;
}
case VEC0_METADATA_OPERATOR_LE: {
for(int i = 0; i < size; i++) { bitmap_set(b, i, array[i] <= target); }
break;
}
case VEC0_METADATA_OPERATOR_LT: {
for(int i = 0; i < size; i++) { bitmap_set(b, i, array[i] < target); }
break;
}
case VEC0_METADATA_OPERATOR_GE: {
for(int i = 0; i < size; i++) { bitmap_set(b, i, array[i] >= target); }
break;
}
case VEC0_METADATA_OPERATOR_NE: {
for(int i = 0; i < size; i++) { bitmap_set(b, i, array[i] != target); }
break;
}
}
break;
}
case VEC0_METADATA_COLUMN_KIND_INT64: {
i64 * array = (i64*) buffer; i64 * array = (i64*) buffer;
i64 target = sqlite3_value_int64(value); i64 target = sqlite3_value_int64(value);
switch(op) { switch(op) {
@ -5923,37 +5856,6 @@ int vec0_set_metadata_filter_bitmap(
break; break;
} }
case VEC0_METADATA_COLUMN_KIND_FLOAT: { case VEC0_METADATA_COLUMN_KIND_FLOAT: {
f32 * array = (f32*) buffer;
f32 target = (f32) sqlite3_value_double(value);
switch(op) {
case VEC0_METADATA_OPERATOR_EQ: {
for(int i = 0; i < size; i++) { bitmap_set(b, i, array[i] == target); }
break;
}
case VEC0_METADATA_OPERATOR_GT: {
for(int i = 0; i < size; i++) { bitmap_set(b, i, array[i] > target); }
break;
}
case VEC0_METADATA_OPERATOR_LE: {
for(int i = 0; i < size; i++) { bitmap_set(b, i, array[i] <= target); }
break;
}
case VEC0_METADATA_OPERATOR_LT: {
for(int i = 0; i < size; i++) { bitmap_set(b, i, array[i] < target); }
break;
}
case VEC0_METADATA_OPERATOR_GE: {
for(int i = 0; i < size; i++) { bitmap_set(b, i, array[i] >= target); }
break;
}
case VEC0_METADATA_OPERATOR_NE: {
for(int i = 0; i < size; i++) { bitmap_set(b, i, array[i] != target); }
break;
}
}
break;
}
case VEC0_METADATA_COLUMN_KIND_DOUBLE: {
double * array = (double*) buffer; double * array = (double*) buffer;
double target = sqlite3_value_double(value); double target = sqlite3_value_double(value);
switch(op) { switch(op) {
@ -7418,27 +7320,23 @@ int vec0_insert_metadata_values(vec0_vtab *p, int argc, sqlite3_value ** argv, i
case VEC0_METADATA_COLUMN_KIND_BOOLEAN: { case VEC0_METADATA_COLUMN_KIND_BOOLEAN: {
if(sqlite3_value_type(v) != SQLITE_INTEGER || ((sqlite3_value_int(v) != 0) && (sqlite3_value_int(v) != 1))) { if(sqlite3_value_type(v) != SQLITE_INTEGER || ((sqlite3_value_int(v) != 0) && (sqlite3_value_int(v) != 1))) {
rc = SQLITE_ERROR; rc = SQLITE_ERROR;
vtab_set_error(&p->base, "Expected 0 or 1 for BOOLEAN metadata column %s.%s.%s", p->schemaName, p->tableName, p->shadowMetadataChunksNames[metadata_idx]); vtab_set_error(&p->base, "Expected 0 or 1 for BOOLEAN metadata column %.*s", p->metadata_columns[metadata_idx].name_length, p->metadata_columns[metadata_idx].name);
goto done; goto done;
} }
break; break;
} }
case VEC0_METADATA_COLUMN_KIND_INT32: { case VEC0_METADATA_COLUMN_KIND_INTEGER: {
// TODO verify v is SQLITE_INTEGER, fits in int32 if(sqlite3_value_type(v) != SQLITE_INTEGER) {
break; rc = SQLITE_ERROR;
vtab_set_error(&p->base, "Expected integer for INTEGER metadata column %.*s, received %s", p->metadata_columns[metadata_idx].name_length, p->metadata_columns[metadata_idx].name, type_name(sqlite3_value_type(v)));
goto done;
} }
case VEC0_METADATA_COLUMN_KIND_INT64: {
// TODO verify v is SQLITE_INTEGER, fits in int64
break; break;
} }
case VEC0_METADATA_COLUMN_KIND_FLOAT: { case VEC0_METADATA_COLUMN_KIND_FLOAT: {
// TODO verify v is SQLITE_FLOAT // TODO verify v is SQLITE_FLOAT
break; break;
} }
case VEC0_METADATA_COLUMN_KIND_DOUBLE: {
// TODO verify v is SQLITE_FLOAT
break;
}
case VEC0_METADATA_COLUMN_KIND_TEXT: { case VEC0_METADATA_COLUMN_KIND_TEXT: {
// TODO verify v is SQLITE_TEXT // TODO verify v is SQLITE_TEXT
break; break;
@ -7470,22 +7368,12 @@ int vec0_insert_metadata_values(vec0_vtab *p, int argc, sqlite3_value ** argv, i
rc = sqlite3_blob_write(blobValue, &block, sizeof(u8), chunk_offset / CHAR_BIT); rc = sqlite3_blob_write(blobValue, &block, sizeof(u8), chunk_offset / CHAR_BIT);
break; break;
} }
case VEC0_METADATA_COLUMN_KIND_INT32: { case VEC0_METADATA_COLUMN_KIND_INTEGER: {
int value = sqlite3_value_int(v);
rc = sqlite3_blob_write(blobValue, &value, sizeof(value), chunk_offset * sizeof(i32));
break;
}
case VEC0_METADATA_COLUMN_KIND_INT64: {
i64 value = sqlite3_value_int64(v); i64 value = sqlite3_value_int64(v);
rc = sqlite3_blob_write(blobValue, &value, sizeof(value), chunk_offset * sizeof(i64)); rc = sqlite3_blob_write(blobValue, &value, sizeof(value), chunk_offset * sizeof(i64));
break; break;
} }
case VEC0_METADATA_COLUMN_KIND_FLOAT: { case VEC0_METADATA_COLUMN_KIND_FLOAT: {
float value = (float) sqlite3_value_double(v);
rc = sqlite3_blob_write(blobValue, &value, sizeof(value), chunk_offset * sizeof(float));
break;
}
case VEC0_METADATA_COLUMN_KIND_DOUBLE: {
double value = sqlite3_value_double(v); double value = sqlite3_value_double(v);
rc = sqlite3_blob_write(blobValue, &value, sizeof(value), chunk_offset * sizeof(double)); rc = sqlite3_blob_write(blobValue, &value, sizeof(value), chunk_offset * sizeof(double));
break; break;

View file

@ -295,11 +295,6 @@
'rows': list([ 'rows': list([
]), ]),
}), }),
'v_metadata_chunks04': OrderedDict({
'sql': 'select * from v_metadata_chunks04',
'rows': list([
]),
}),
'v_rowids': OrderedDict({ 'v_rowids': OrderedDict({
'sql': 'select * from v_rowids', 'sql': 'select * from v_rowids',
'rows': list([ 'rows': list([
@ -314,21 +309,21 @@
# --- # ---
# name: test_normal.2 # name: test_normal.2
OrderedDict({ OrderedDict({
'sql': 'insert into v(vector, n1, n2, f, d, t) values (?, ?, ?, ?, ?, ?)', 'sql': 'insert into v(vector, b, n, f, t) values (?, ?, ?, ?, ?)',
'rows': list([ 'rows': list([
]), ]),
}) })
# --- # ---
# name: test_normal.3 # name: test_normal.3
OrderedDict({ OrderedDict({
'sql': 'insert into v(vector, n1, n2, f, d, t) values (?, ?, ?, ?, ?, ?)', 'sql': 'insert into v(vector, b, n, f, t) values (?, ?, ?, ?, ?)',
'rows': list([ 'rows': list([
]), ]),
}) })
# --- # ---
# name: test_normal.4 # name: test_normal.4
OrderedDict({ OrderedDict({
'sql': 'insert into v(vector, n1, n2, f, d, t) values (?, ?, ?, ?, ?, ?)', 'sql': 'insert into v(vector, b, n, f, t) values (?, ?, ?, ?, ?)',
'rows': list([ 'rows': list([
]), ]),
}) })
@ -340,28 +335,25 @@
OrderedDict({ OrderedDict({
'rowid': 1, 'rowid': 1,
'vector': b'\x11\x11\x11\x11', 'vector': b'\x11\x11\x11\x11',
'n1': 1, 'b': 1,
'n2': 1, 'n': 1,
'f': 1.100000023841858, 'f': 1.1,
'd': 1.1,
't': 'one', 't': 'one',
}), }),
OrderedDict({ OrderedDict({
'rowid': 2, 'rowid': 2,
'vector': b'""""', 'vector': b'""""',
'n1': 2, 'b': 1,
'n2': 2, 'n': 2,
'f': 2.200000047683716, 'f': 2.2,
'd': 2.2,
't': 'two', 't': 'two',
}), }),
OrderedDict({ OrderedDict({
'rowid': 3, 'rowid': 3,
'vector': b'3333', 'vector': b'3333',
'n1': 3, 'b': 1,
'n2': 3, 'n': 3,
'f': 3.299999952316284, 'f': 3.3,
'd': 3.3,
't': 'three', 't': 'three',
}), }),
]), ]),
@ -385,7 +377,7 @@
'rows': list([ 'rows': list([
OrderedDict({ OrderedDict({
'rowid': 1, 'rowid': 1,
'data': b'\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'data': b'\x07',
}), }),
]), ]),
}), }),
@ -403,21 +395,12 @@
'rows': list([ 'rows': list([
OrderedDict({ OrderedDict({
'rowid': 1, 'rowid': 1,
'data': b'\xcd\xcc\x8c?\xcd\xcc\x0c@33S@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'data': b'\x9a\x99\x99\x99\x99\x99\xf1?\x9a\x99\x99\x99\x99\x99\x01@ffffff\n@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
}), }),
]), ]),
}), }),
'v_metadata_chunks03': OrderedDict({ 'v_metadata_chunks03': OrderedDict({
'sql': 'select * from v_metadata_chunks03', 'sql': 'select * from v_metadata_chunks03',
'rows': list([
OrderedDict({
'rowid': 1,
'data': b'\x9a\x99\x99\x99\x99\x99\xf1?\x9a\x99\x99\x99\x99\x99\x01@ffffff\n@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
}),
]),
}),
'v_metadata_chunks04': OrderedDict({
'sql': 'select * from v_metadata_chunks04',
'rows': list([ 'rows': list([
OrderedDict({ OrderedDict({
'rowid': 1, 'rowid': 1,
@ -475,7 +458,7 @@
'name': 'v', 'name': 'v',
'tbl_name': 'v', 'tbl_name': 'v',
'rootpage': 0, 'rootpage': 0,
'sql': 'CREATE VIRTUAL TABLE v using vec0(vector float[1], n1 int, n2 int64, f float, d double, t text, chunk_size=8)', 'sql': 'CREATE VIRTUAL TABLE v using vec0(vector float[1], b boolean, n int, f float, t text, chunk_size=8)',
}), }),
OrderedDict({ OrderedDict({
'type': 'table', 'type': 'table',
@ -512,13 +495,6 @@
'rootpage': 13, 'rootpage': 13,
'sql': 'CREATE TABLE "v_metadata_chunks03"(rowid PRIMARY KEY, data BLOB NOT NULL)', 'sql': 'CREATE TABLE "v_metadata_chunks03"(rowid PRIMARY KEY, data BLOB NOT NULL)',
}), }),
OrderedDict({
'type': 'table',
'name': 'v_metadata_chunks04',
'tbl_name': 'v_metadata_chunks04',
'rootpage': 15,
'sql': 'CREATE TABLE "v_metadata_chunks04"(rowid PRIMARY KEY, data BLOB NOT NULL)',
}),
OrderedDict({ OrderedDict({
'type': 'table', 'type': 'table',
'name': 'v_rowids', 'name': 'v_rowids',
@ -719,19 +695,19 @@
'rows': list([ 'rows': list([
OrderedDict({ OrderedDict({
'rowid': 1, 'rowid': 1,
'data': b'\x99\x00\x00\x00~\x01\x00\x005\x00\x00\x00\xd2\x00\x00\x00]\x00\x00\x00\xa7\x00\x00\x00\xe2\x01\x00\x00-\x01\x00\x00', 'data': b'\x99\x00\x00\x00\x00\x00\x00\x00~\x01\x00\x00\x00\x00\x00\x005\x00\x00\x00\x00\x00\x00\x00\xd2\x00\x00\x00\x00\x00\x00\x00]\x00\x00\x00\x00\x00\x00\x00\xa7\x00\x00\x00\x00\x00\x00\x00\xe2\x01\x00\x00\x00\x00\x00\x00-\x01\x00\x00\x00\x00\x00\x00',
}), }),
OrderedDict({ OrderedDict({
'rowid': 2, 'rowid': 2,
'data': b'\x86\x00\x00\x00B\x00\x00\x00X\x00\x00\x00;\x00\x00\x00\xa7\x01\x00\x00\x13\x01\x00\x00\xbf\x00\x00\x00:\x01\x00\x00', 'data': b'\x86\x00\x00\x00\x00\x00\x00\x00B\x00\x00\x00\x00\x00\x00\x00X\x00\x00\x00\x00\x00\x00\x00;\x00\x00\x00\x00\x00\x00\x00\xa7\x01\x00\x00\x00\x00\x00\x00\x13\x01\x00\x00\x00\x00\x00\x00\xbf\x00\x00\x00\x00\x00\x00\x00:\x01\x00\x00\x00\x00\x00\x00',
}), }),
OrderedDict({ OrderedDict({
'rowid': 3, 'rowid': 3,
'data': b'J\x00\x00\x00\xc9\x00\x00\x00\x8f\x01\x00\x00\xba\x00\x00\x00V\x01\x00\x00\xc3\x01\x00\x00\n\x02\x00\x00\x0f\x01\x00\x00', 'data': b'J\x00\x00\x00\x00\x00\x00\x00\xc9\x00\x00\x00\x00\x00\x00\x00\x8f\x01\x00\x00\x00\x00\x00\x00\xba\x00\x00\x00\x00\x00\x00\x00V\x01\x00\x00\x00\x00\x00\x00\xc3\x01\x00\x00\x00\x00\x00\x00\n\x02\x00\x00\x00\x00\x00\x00\x0f\x01\x00\x00\x00\x00\x00\x00',
}), }),
OrderedDict({ OrderedDict({
'rowid': 4, 'rowid': 4,
'data': b'6\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'data': b'6\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
}), }),
]), ]),
}), }),
@ -740,19 +716,19 @@
'rows': list([ 'rows': list([
OrderedDict({ OrderedDict({
'rowid': 1, 'rowid': 1,
'data': b'33\x93@ff&@\x00\x00\xa0@ff\x86@\x9a\x99Y@ff\x96@\x9a\x999@\x00\x00\xa0@', 'data': b'ffffff\x12@\xcd\xcc\xcc\xcc\xcc\xcc\x04@\x00\x00\x00\x00\x00\x00\x14@\xcd\xcc\xcc\xcc\xcc\xcc\x10@333333\x0b@\xcd\xcc\xcc\xcc\xcc\xcc\x12@333333\x07@\x00\x00\x00\x00\x00\x00\x14@',
}), }),
OrderedDict({ OrderedDict({
'rowid': 2, 'rowid': 2,
'data': b'33\x83@\xcd\xccL@\xcd\xcc\x9c@333@\x00\x00\x90@fff@\xcd\xcc\x8c@\x9a\x99\x89@', 'data': b'ffffff\x10@\x9a\x99\x99\x99\x99\x99\t@\x9a\x99\x99\x99\x99\x99\x13@ffffff\x06@\x00\x00\x00\x00\x00\x00\x12@\xcd\xcc\xcc\xcc\xcc\xcc\x0c@\x9a\x99\x99\x99\x99\x99\x11@333333\x11@',
}), }),
OrderedDict({ OrderedDict({
'rowid': 3, 'rowid': 3,
'data': b'\x00\x00@@\x00\x00\xa0@\xcd\xcc,@\x9a\x99\x99@\x00\x00\x80@\xcd\xcc\x8c@33\x93@\x9a\x99\x89@', 'data': b'\x00\x00\x00\x00\x00\x00\x08@\x00\x00\x00\x00\x00\x00\x14@\x9a\x99\x99\x99\x99\x99\x05@333333\x13@\x00\x00\x00\x00\x00\x00\x10@\x9a\x99\x99\x99\x99\x99\x11@ffffff\x12@333333\x11@',
}), }),
OrderedDict({ OrderedDict({
'rowid': 4, 'rowid': 4,
'data': b'\x9a\x99y@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'data': b'333333\x0f@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
}), }),
]), ]),
}), }),
@ -987,7 +963,7 @@
'title': 'Dune', 'title': 'Dune',
'genre': 'scifi', 'genre': 'scifi',
'num_reviews': 451, 'num_reviews': 451,
'mean_rating': 4.400000095367432, 'mean_rating': 4.4,
'is_favorited': 1, 'is_favorited': 1,
'distance': 6.5, 'distance': 6.5,
}), }),
@ -1112,22 +1088,22 @@
'rows': list([ 'rows': list([
OrderedDict({ OrderedDict({
'movie_id': 19, 'movie_id': 19,
'mean_rating': 2.700000047683716, 'mean_rating': 2.7,
'distance': 81.0, 'distance': 81.0,
}), }),
OrderedDict({ OrderedDict({
'movie_id': 12, 'movie_id': 12,
'mean_rating': 2.799999952316284, 'mean_rating': 2.8,
'distance': 88.0, 'distance': 88.0,
}), }),
OrderedDict({ OrderedDict({
'movie_id': 7, 'movie_id': 7,
'mean_rating': 2.9000000953674316, 'mean_rating': 2.9,
'distance': 93.0, 'distance': 93.0,
}), }),
OrderedDict({ OrderedDict({
'movie_id': 2, 'movie_id': 2,
'mean_rating': 2.5999999046325684, 'mean_rating': 2.6,
'distance': 98.0, 'distance': 98.0,
}), }),
]), ]),
@ -1139,17 +1115,17 @@
'rows': list([ 'rows': list([
OrderedDict({ OrderedDict({
'movie_id': 24, 'movie_id': 24,
'mean_rating': 4.300000190734863, 'mean_rating': 4.3,
'distance': 76.0, 'distance': 76.0,
}), }),
OrderedDict({ OrderedDict({
'movie_id': 23, 'movie_id': 23,
'mean_rating': 4.599999904632568, 'mean_rating': 4.6,
'distance': 77.0, 'distance': 77.0,
}), }),
OrderedDict({ OrderedDict({
'movie_id': 22, 'movie_id': 22,
'mean_rating': 4.400000095367432, 'mean_rating': 4.4,
'distance': 78.0, 'distance': 78.0,
}), }),
OrderedDict({ OrderedDict({
@ -1159,7 +1135,7 @@
}), }),
OrderedDict({ OrderedDict({
'movie_id': 20, 'movie_id': 20,
'mean_rating': 4.800000190734863, 'mean_rating': 4.8,
'distance': 80.0, 'distance': 80.0,
}), }),
]), ]),
@ -1172,3 +1148,36 @@
]), ]),
}) })
# --- # ---
# name: test_types[illegal-boolean]
dict({
'error': 'OperationalError',
'message': 'Expected 0 or 1 for BOOLEAN metadata column b',
})
# ---
# name: test_types[illegal-float]
OrderedDict({
'sql': 'insert into v(vector, b, n, f, t) values (?, ?, ?, ?, ?)',
'rows': list([
]),
})
# ---
# name: test_types[illegal-int]
dict({
'error': 'OperationalError',
'message': 'Expected integer for INTEGER metadata column n, received TEXT',
})
# ---
# name: test_types[illegal-text]
OrderedDict({
'sql': 'insert into v(vector, b, n, f, t) values (?, ?, ?, ?, ?)',
'rows': list([
]),
})
# ---
# name: test_types[legal]
OrderedDict({
'sql': 'insert into v(vector, b, n, f, t) values (?, ?, ?, ?, ?)',
'rows': list([
]),
})
# ---

View file

@ -17,7 +17,7 @@ def test_constructor_limit(db, snapshot):
def test_normal(db, snapshot): def test_normal(db, snapshot):
db.execute( db.execute(
"create virtual table v using vec0(vector float[1], n1 int, n2 int64, f float, d double, t text, chunk_size=8)" "create virtual table v using vec0(vector float[1], b boolean, n int, f float, t text, chunk_size=8)"
) )
assert exec( assert exec(
db, "select * from sqlite_master where type = 'table' order by name" db, "select * from sqlite_master where type = 'table' order by name"
@ -25,12 +25,10 @@ def test_normal(db, snapshot):
assert vec0_shadow_table_contents(db, "v") == snapshot() assert vec0_shadow_table_contents(db, "v") == snapshot()
INSERT = "insert into v(vector, n1, n2, f, d, t) values (?, ?, ?, ?, ?, ?)" INSERT = "insert into v(vector, b, n, f, t) values (?, ?, ?, ?, ?)"
assert exec(db, INSERT, [b"\x11\x11\x11\x11", 1, 1, 1.1, 1.1, "one"]) == snapshot() assert exec(db, INSERT, [b"\x11\x11\x11\x11", 1, 1, 1.1, "one"]) == snapshot()
assert exec(db, INSERT, [b"\x22\x22\x22\x22", 2, 2, 2.2, 2.2, "two"]) == snapshot() assert exec(db, INSERT, [b"\x22\x22\x22\x22", 1, 2, 2.2, "two"]) == snapshot()
assert ( assert exec(db, INSERT, [b"\x33\x33\x33\x33", 1, 3, 3.3, "three"]) == snapshot()
exec(db, INSERT, [b"\x33\x33\x33\x33", 3, 3, 3.3, 3.3, "three"]) == snapshot()
)
assert exec(db, "select * from v") == snapshot() assert exec(db, "select * from v") == snapshot()
assert vec0_shadow_table_contents(db, "v") == snapshot() assert vec0_shadow_table_contents(db, "v") == snapshot()
@ -47,7 +45,21 @@ def test_normal(db, snapshot):
def test_types(db, snapshot): def test_types(db, snapshot):
pass db.execute(
"create virtual table v using vec0(vector float[1], b boolean, n int, f float, t text, chunk_size=8)"
)
INSERT = "insert into v(vector, b, n, f, t) values (?, ?, ?, ?, ?)"
assert exec(db, INSERT, [b"\x11\x11\x11\x11", 1, 1, 1.1, "test"]) == snapshot(
name="legal"
)
# fmt: off
assert exec(db, INSERT, [b"\x11\x11\x11\x11", 'illegal', 1, 1.1, 'test']) == snapshot(name="illegal-boolean")
assert exec(db, INSERT, [b"\x11\x11\x11\x11", 1, 'illegal', 1.1, 'test']) == snapshot(name="illegal-int")
assert exec(db, INSERT, [b"\x11\x11\x11\x11", 1, 1, 'illegal', 'test']) == snapshot(name="illegal-float")
assert exec(db, INSERT, [b"\x11\x11\x11\x11", 1, 1, 1.1, 420]) == snapshot(name="illegal-text")
# fmt: on
def test_updates(db, snapshot): def test_updates(db, snapshot):