mirror of
https://github.com/asg017/sqlite-vec.git
synced 2026-04-25 08:46:49 +02:00
block UPDATEs on partition key values for now
This commit is contained in:
parent
21b11e1e83
commit
03f29d581d
3 changed files with 60 additions and 3 deletions
14
sqlite-vec.c
14
sqlite-vec.c
|
|
@ -6786,19 +6786,27 @@ int vec0Update_Update(sqlite3_vtab *pVTab, int argc, sqlite3_value **argv) {
|
||||||
rowid = sqlite3_value_int64(argv[0]);
|
rowid = sqlite3_value_int64(argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. get chunk_id and chunk_offset from _rowids
|
// 1) get chunk_id and chunk_offset from _rowids
|
||||||
rc = vec0_get_chunk_position(p, rowid, NULL, &chunk_id, &chunk_offset);
|
rc = vec0_get_chunk_position(p, rowid, NULL, &chunk_id, &chunk_offset);
|
||||||
if (rc != SQLITE_OK) {
|
if (rc != SQLITE_OK) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2) iterate over all new vectors, update the vectors
|
// 2) update any partition key values
|
||||||
for (int i = 0; i < vec0_num_defined_user_columns(p); i++) {
|
for (int i = 0; i < vec0_num_defined_user_columns(p); i++) {
|
||||||
if(p->user_column_kinds[i] != SQLITE_VEC0_USER_COLUMN_KIND_PARTITION) {
|
if(p->user_column_kinds[i] != SQLITE_VEC0_USER_COLUMN_KIND_PARTITION) {
|
||||||
// TODO handle partition key values in UPDATEs
|
continue;
|
||||||
}
|
}
|
||||||
|
int partition_key_idx = p->user_column_idxs[i];
|
||||||
|
sqlite3_value * value = argv[2+VEC0_COLUMN_USERN_START + i];
|
||||||
|
if(sqlite3_value_nochange(value)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
vtab_set_error(pVTab, "UPDATE on partition key columns are not supported yet. ");
|
||||||
|
return SQLITE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3) iterate over all new vectors, update the vectors
|
||||||
for (int i = 0; i < vec0_num_defined_user_columns(p); i++) {
|
for (int i = 0; i < vec0_num_defined_user_columns(p); i++) {
|
||||||
if(p->user_column_kinds[i] != SQLITE_VEC0_USER_COLUMN_KIND_VECTOR) {
|
if(p->user_column_kinds[i] != SQLITE_VEC0_USER_COLUMN_KIND_VECTOR) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -215,3 +215,31 @@
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
|
# name: test_updates[1. Initial dataset]
|
||||||
|
OrderedDict({
|
||||||
|
'sql': 'select * from v',
|
||||||
|
'rows': list([
|
||||||
|
OrderedDict({
|
||||||
|
'rowid': 1,
|
||||||
|
'p': 'a',
|
||||||
|
'a': b'\x11\x11\x11\x11',
|
||||||
|
}),
|
||||||
|
OrderedDict({
|
||||||
|
'rowid': 2,
|
||||||
|
'p': 'a',
|
||||||
|
'a': b'""""',
|
||||||
|
}),
|
||||||
|
OrderedDict({
|
||||||
|
'rowid': 3,
|
||||||
|
'p': 'a',
|
||||||
|
'a': b'3333',
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_updates[2. update #1]
|
||||||
|
dict({
|
||||||
|
'error': 'OperationalError',
|
||||||
|
'message': 'UPDATE on partition key columns are not supported yet. ',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,27 @@ def test_types(db, snapshot):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_updates(db, snapshot):
|
||||||
|
db.execute(
|
||||||
|
"create virtual table v using vec0(p text partition key, a float[1], chunk_size=8)"
|
||||||
|
)
|
||||||
|
|
||||||
|
db.execute(
|
||||||
|
"insert into v(rowid, p, a) values (?, ?, ?)", [1, "a", b"\x11\x11\x11\x11"]
|
||||||
|
)
|
||||||
|
db.execute(
|
||||||
|
"insert into v(rowid, p, a) values (?, ?, ?)", [2, "a", b"\x22\x22\x22\x22"]
|
||||||
|
)
|
||||||
|
db.execute(
|
||||||
|
"insert into v(rowid, p, a) values (?, ?, ?)", [3, "a", b"\x33\x33\x33\x33"]
|
||||||
|
)
|
||||||
|
|
||||||
|
assert exec(db, "select * from v") == snapshot(name="1. Initial dataset")
|
||||||
|
assert exec(db, "update v set p = ? where rowid = ?", ["new", 1]) == snapshot(
|
||||||
|
name="2. update #1"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Row:
|
class Row:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue