Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
Signed-off-by: Praneeth Bedapudi <praneeth@bpraneeth.com>
  • Loading branch information
bedapudi6788 committed Dec 11, 2023
1 parent 414e045 commit 860ffdc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 76 deletions.
36 changes: 4 additions & 32 deletions Query.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ schema = {
"age": "number",
"password": "string",
"verified": "boolean",
"nicknames": "flatlist",
"address_details": "flatdict",
"profile_picture": "blob",
"tag_line": "string",
"tag_line_embedding": "other",
"birthday": "datetime",
"metadata": "json",
"mark_list": "flatlist"
"address": "json",
"profile_picture": "blob",
"description": "compressed_string",
"tag_line_embedding": "other"
}


Expand All @@ -37,31 +34,6 @@ schema = {
| {"$or": [{"age": {"$gte": 20, "$lte": 30}}, {"name": "john"}]} | ((age >= 20) and (age <= 30)) or (name == "john") |


<!-- - Example of queries on text (regex is supported)
| Query | Explanation |
|--------------------------------------------------|------------------------------------------------------------------------------------------------------------|
| {"name": {"$regex": "doe", "$options": "i"}} | name contains "doe" (case insensitive) | -->



#### Example of queries on flatlist and flatdict


| Query | Explanation |
|--------------------------------------------------|------------------------------------------------------------------------------------------------------------|
| {"nicknames": "John"} | "John" in nicknames |
| {"nicknames": ["John", "Doe"]} | nicknames == ["John", "Doe"]|
| {"nicknames": {"$in": ["John", "Doe"]}} | "John" in nicknames or "Doe" in nicknames |
| {"nicknames": {"$all": ["John", "Doe"]}} | "John" in nicknames and "Doe" in nicknames |
| {"nicknames": {"$size": 2}} | len(nicknames) == 2 |
| {"nicknames.0": "John"} | nicknames[0] == "John" |
| {"nicknames": {"$ne": "John"}} | "John" not in nicknames |


| {"address_details": {"city": "Springfield"}} | address_details.city == "Springfield" |
| {"address_details": {"city": {"$in": ["Springfield", "Chicago"]}}} | address_details.city == "Springfield" or address_details.city == "Chicago" |


#### Example of queries on blob or other

| Query | Explanation |
Expand Down
64 changes: 21 additions & 43 deletions liteindex/defined_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,56 +34,46 @@ def serialize_record(original_key_to_key_hash, schema, record, compressor):
hashed_key = original_key_to_key_hash[k]

if _type == "boolean":
_record[hashed_key] = int(v) if v is not None else None
_record[hashed_key] = None if v is None else int(v)

elif _type == "string":
_record[hashed_key] = v if v is not None else None
_record[hashed_key] = v

elif _type == "number":
_record[hashed_key] = v if v is not None else None
_record[hashed_key] = v

elif _type == "datetime":
_record[hashed_key] = v.timestamp() if v is not None else None
_record[hashed_key] = None if v is None else v.timestamp()

elif _type == "compressed_string":
_record[hashed_key] = (
sqlite3.Binary(compressor.compress(v.encode()))
if compressor is not False
else v.encode()
if v is not None
else None
None if v is None else compressor.compress(v.encode()) if compressor is not False else v.encode()
)

# blob
elif _type == "blob":
_record[f"__size_{hashed_key}"] = len(v) if v is not None else None
_record[f"__size_{hashed_key}"] = None if v is None else len(v)

_record[f"__hash_{hashed_key}"] = hash_bytes(v) if v is not None else None
_record[f"__hash_{hashed_key}"] = None if v is None else hash_bytes(v)

_record[hashed_key] = (
sqlite3.Binary(compressor.compress(v) if compressor is not False else v)
if v is not None
else None
None if v is None else compressor.compress(v) if compressor is not False else v
)

elif _type == "other":
v = (
pickle.dumps(v, protocol=pickle.HIGHEST_PROTOCOL)
if v is not None
else None
None if v is None else pickle.dumps(v, protocol=pickle.HIGHEST_PROTOCOL)
)

_record[f"__size_{hashed_key}"] = len(v) if v is not None else None
_record[f"__hash_{hashed_key}"] = hash_bytes(v) if v is not None else None
_record[f"__size_{hashed_key}"] = None if v is None else len(v)
_record[f"__hash_{hashed_key}"] = None if v is None else hash_bytes(v)

_record[hashed_key] = (
sqlite3.Binary(compressor.compress(v) if compressor is not False else v)
if v is not None
else None
None if v is None else compressor.compress(v) if compressor is not False else v
)

elif _type == "json":
_record[hashed_key] = json.dumps(v) if v is not None else None
_record[hashed_key] = None if v is None else json.dumps(v)

return _record

Expand All @@ -97,47 +87,35 @@ def deserialize_record(
key_type = hashed_key_schema[k]

if key_type == "boolean":
_record[original_key] = bool(v) if v is not None else None
_record[original_key] = None if v is None else bool(v)

elif key_type == "string":
_record[original_key] = v if v is not None else None
_record[original_key] = v

elif key_type == "number":
_record[original_key] = v if v is not None else None
_record[original_key] = v

elif key_type == "datetime":
_record[original_key] = (
datetime.datetime.fromtimestamp(v) if v is not None else None
None if v is None else datetime.datetime.fromtimestamp(v)
)

elif key_type == "compressed_string":
_record[original_key] = (
decompressor.decompress(v).decode()
if decompressor is not False
else v.decode()
if v is not None
else None
None if v is None else decompressor.decompress(v).decode() if decompressor is not False else v.decode()
)

elif key_type == "blob":
_record[original_key] = (
decompressor.decompress(v)
if decompressor is not False
else v
if v is not None
else None
None if v is None else decompressor.decompress(v) if decompressor is not False else v
)

elif key_type == "other":
_record[original_key] = (
pickle.loads(decompressor.decompress(v))
if decompressor is not False
else pickle.loads(v)
if v is not None
else None
None if v is None else pickle.loads(decompressor.decompress(v)) if decompressor is not False else pickle.loads(v)
)

elif key_type == "json":
_record[original_key] = json.loads(v) if v is not None else None
_record[original_key] = None if v is None else json.loads(v)

return _record
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
EMAIL = "praneeth@bpraneeth.com"
AUTHOR = "BEDAPUDI PRANEETH"
REQUIRES_PYTHON = ">=3.6.0"
VERSION = "0.0.2.dev23"
VERSION = "0.0.2.dev24"

# What packages are required for this module to be executed?
REQUIRED = [
Expand Down

0 comments on commit 860ffdc

Please sign in to comment.