Skip to content

Commit

Permalink
KVIndex math
Browse files Browse the repository at this point in the history
Signed-off-by: Praneeth Bedapudi <[email protected]>
  • Loading branch information
bedapudi6788 committed Mar 18, 2024
1 parent aabf85f commit 5fc5d8f
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions liteindex/kv_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,26 @@ def search(
return results

def math(self, key, value, op):
ops = {"+": "+", "-": "-", "*": "*", "/": "/", "//": "//", "%": "%", "**": "**"}
pass
ops = {
"+=": "+",
"-=": "-",
"*=": "*",
"/=": "/",
"%=": "%"
}

if op not in ops:
raise ValueError(f"Unsupported operation: {op}")

sql_query = f"UPDATE kv_index SET num_value = num_value {ops[op]} ? WHERE key_hash = ? RETURNING num_value"

with self.__connection as conn:
row = conn.execute(sql_query, (value, self.__encode_and_hash(key)[0])).fetchone()

if row is None:
raise KeyError

return row[0]

def __run_eviction(self, conn):
if self.eviction.policy == EvictionCfg.EvictNone:
Expand Down

0 comments on commit 5fc5d8f

Please sign in to comment.