Skip to content

Commit

Permalink
fixup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asg017 committed Nov 13, 2024
1 parent 84d6a14 commit c7bcf58
Showing 1 changed file with 21 additions and 25 deletions.
46 changes: 21 additions & 25 deletions tests/test-loadable.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def connect(ext, path=":memory:", extra_entrypoint=None):
db = connect(EXT_PATH)


def explain_query_plan(sql):
def explain_query_plan(sql, db=db):
return db.execute("explain query plan " + sql).fetchone()["detail"]


Expand Down Expand Up @@ -1420,6 +1420,7 @@ def test_vec0_point():
assert execute_all(db, "select * from t2 where id = 'xxx'") == []


# @pytest.mark.skip(reason="TODO failing locally for some reason")
def test_vec0_text_pk():
db = connect(EXT_PATH)
db.execute(
Expand Down Expand Up @@ -1497,6 +1498,13 @@ def test_vec0_text_pk():
]

if SUPPORTS_VTAB_IN:
assert re.match(
("SCAN (TABLE )?t VIRTUAL TABLE INDEX 0:3{___}___\[___"),
explain_query_plan(
"select t_id, distance from t where aaa match '' and k = 3 and t_id in ('t_2', 't_3')",
db=db,
),
)
assert execute_all(
db,
"select t_id, distance from t where aaa match ? and k = 3 and t_id in ('t_2', 't_3')",
Expand Down Expand Up @@ -1939,20 +1947,6 @@ def test_vec0_create_errors():
db.execute("create virtual table t1 using vec0(a float[1])")
db.set_authorizer(None)

db.set_authorizer(authorizer_deny_on(sqlite3.SQLITE_INSERT, "t1_chunks"))
with _raises(
"Could not create create an initial chunk",
):
db.execute("create virtual table t1 using vec0(a float[1])")
db.set_authorizer(None)

db.set_authorizer(authorizer_deny_on(sqlite3.SQLITE_INSERT, "t1_vector_chunks00"))
with _raises(
"Could not create create an initial chunk",
):
db.execute("create virtual table t1 using vec0(a float[1])")
db.set_authorizer(None)

# EVIDENCE-OF: V21406_05476 vec0 init raises error on 'latest chunk' init error
db.execute("BEGIN")
db.set_authorizer(authorizer_deny_on(sqlite3.SQLITE_READ, "t1_chunks", ""))
Expand Down Expand Up @@ -2231,32 +2225,34 @@ def test_smoke():
},
]
chunk = db.execute("select * from vec_xyz_chunks").fetchone()
assert chunk["chunk_id"] == 1
assert chunk["validity"] == bytearray(int(1024 / 8))
assert chunk["rowids"] == bytearray(int(1024 * 8))
vchunk = db.execute("select * from vec_xyz_vector_chunks00").fetchone()
assert vchunk["rowid"] == 1
assert vchunk["vectors"] == bytearray(int(1024 * 4 * 2))
# as of TODO, no initial row is inside the chunks table
assert chunk is None
# assert chunk["chunk_id"] == 1
# assert chunk["validity"] == bytearray(int(1024 / 8))
# assert chunk["rowids"] == bytearray(int(1024 * 8))
# vchunk = db.execute("select * from vec_xyz_vector_chunks00").fetchone()
# assert vchunk["rowid"] == 1
# assert vchunk["vectors"] == bytearray(int(1024 * 4 * 2))

assert re.match(
"SCAN (TABLE )?vec_xyz VIRTUAL TABLE INDEX 0:knn:",
"SCAN (TABLE )?vec_xyz VIRTUAL TABLE INDEX 0:3{___}___",
explain_query_plan(
"select * from vec_xyz where a match X'' and k = 10 order by distance"
),
)
if SUPPORTS_VTAB_LIMIT:
assert re.match(
"SCAN (TABLE )?vec_xyz VIRTUAL TABLE INDEX 0:knn:",
"SCAN (TABLE )?vec_xyz VIRTUAL TABLE INDEX 0:3{___}___",
explain_query_plan(
"select * from vec_xyz where a match X'' order by distance limit 10"
),
)
assert re.match(
"SCAN (TABLE )?vec_xyz VIRTUAL TABLE INDEX 0:fullscan",
"SCAN (TABLE )?vec_xyz VIRTUAL TABLE INDEX 0:1",
explain_query_plan("select * from vec_xyz"),
)
assert re.match(
"SCAN (TABLE )?vec_xyz VIRTUAL TABLE INDEX 3:point",
"SCAN (TABLE )?vec_xyz VIRTUAL TABLE INDEX 3:2",
explain_query_plan("select * from vec_xyz where rowid = 4"),
)

Expand Down

0 comments on commit c7bcf58

Please sign in to comment.