Skip to content

Commit

Permalink
block UPDATEs on partition key values for now
Browse files Browse the repository at this point in the history
  • Loading branch information
asg017 committed Nov 13, 2024
1 parent 21b11e1 commit 03f29d5
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
14 changes: 11 additions & 3 deletions sqlite-vec.c
Original file line number Diff line number Diff line change
Expand Up @@ -6786,19 +6786,27 @@ int vec0Update_Update(sqlite3_vtab *pVTab, int argc, sqlite3_value **argv) {
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);
if (rc != SQLITE_OK) {
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++) {
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++) {
if(p->user_column_kinds[i] != SQLITE_VEC0_USER_COLUMN_KIND_VECTOR) {
continue;
Expand Down
28 changes: 28 additions & 0 deletions tests/__snapshots__/test-partition-keys.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -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. ',
})
# ---
21 changes: 21 additions & 0 deletions tests/test-partition-keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
def __init__(self):
pass
Expand Down

0 comments on commit 03f29d5

Please sign in to comment.