Skip to content

Commit

Permalink
Merge pull request #1417 from p-l-/enh-documentdb-top-net
Browse files Browse the repository at this point in the history
DB/DocumentDB: support top net values
  • Loading branch information
p-l- committed Aug 8, 2022
2 parents 26d545b + bbf729e commit 0d4aa2b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
5 changes: 3 additions & 2 deletions ivre/db/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@


class DocumentDBNmap(MongoDBNmap):
pass
is_documentdb = True


class DocumentDBView(MongoDBView):
is_documentdb = True
# DocumentDB has no support for text indexes
indexes = MongoDBActive.indexes
schema_migrations_indexes = MongoDBActive.schema_migrations_indexes


class DocumentDBPassive(MongoDBPassive):
pass
is_documentdb = True


class DocumentDBAgent(MongoDBAgent):
Expand Down
33 changes: 25 additions & 8 deletions ivre/db/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def log_pipeline(pipeline):

class MongoDB(DB):

is_documentdb = False # set to True for AWS DocumentDB sub-classes
indexes: List[List[Tuple[List[IndexKey], Dict[str, Any]]]] = []
schema_migrations_indexes: List[
Dict[int, Dict[str, List[Tuple[List[IndexKey], Dict[str, Any]]]]]
Expand Down Expand Up @@ -3322,10 +3323,18 @@ def outputproc(x):
field = "addr"
# This should not overflow thanks to .searchipv4() filter
addr = {"$add": ["$addr_1", 0x7FFF000100000000]}
specialproj = {
"_id": 0,
"addr": {"$floor": {"$divide": [addr, 2 ** (32 - mask)]}},
}
specialproj = {"_id": 0}
if self.is_documentdb:
# AWS DocumentDB lacks $floor aggregation operator,
# just like MongoDB < 3.2
specialproj["addr"] = {
"$subtract": [
{"$divide": [addr, 2 ** (32 - mask)]},
{"$mod": [{"$divide": [addr, 2 ** (32 - mask)]}, 1]},
]
}
else:
specialproj["addr"] = {"$floor": {"$divide": [addr, 2 ** (32 - mask)]}}
flt = self.flt_and(flt, self.searchipv4())

def outputproc(x):
Expand Down Expand Up @@ -5025,10 +5034,18 @@ def outputproc(x):
field = "addr"
# This should not overflow thanks to .searchipv4() filter
addr = {"$add": ["$addr_1", 0x7FFF000100000000]}
specialproj = {
"_id": 0,
"addr": {"$floor": {"$divide": [addr, 2 ** (32 - mask)]}},
}
specialproj = {"_id": 0}
if self.is_documentdb:
# AWS DocumentDB lacks $floor aggregation operator,
# just like MongoDB < 3.2
specialproj["addr"] = {
"$subtract": [
{"$divide": [addr, 2 ** (32 - mask)]},
{"$mod": [{"$divide": [addr, 2 ** (32 - mask)]}, 1]},
]
}
else:
specialproj["addr"] = {"$floor": {"$divide": [addr, 2 ** (32 - mask)]}}
flt = self.flt_and(flt, self.searchipv4())

def outputproc(x):
Expand Down

0 comments on commit 0d4aa2b

Please sign in to comment.