Skip to content

Commit

Permalink
add numberlong type support to mongo (#2224)
Browse files Browse the repository at this point in the history
* add numberlong type support to mongo

* fix lint

---------

Co-authored-by: cyqxyy <>
  • Loading branch information
cyqxyy committed Aug 2, 2023
1 parent cedc1f3 commit 6c0d15a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sql/engines/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pymongo.errors import OperationFailure
from dateutil.parser import parse
from bson.objectid import ObjectId
from bson.int64 import Int64

from . import EngineBase
from .models import ResultSet, ReviewSet, ReviewResult
Expand Down Expand Up @@ -197,6 +198,7 @@ def __next_const(self):
"newDate",
"ISODate",
"newISODate",
"NumberLong",
): # ======类似的类型比较多还需单独处理,如int()等
data_type = outstr
for c in self.__remain_str():
Expand Down Expand Up @@ -230,6 +232,12 @@ def __next_const(self):
date_content = date_regex.findall(outstr)
if len(date_content) > 0:
return parse(date_content[0], yearfirst=True)
elif data_type.replace(" ", "") in ("NumberLong"):
nuStr = re.findall(r"NumberLong\(.*?\)", outstr) # 单独处理NumberLong
if len(nuStr) > 0:
id_str = re.findall(r"\(.*?\)", nuStr[0])
nlong = id_str[0].replace(" ", "")[2:-2]
return Int64(nlong)
elif outstr:
return outstr
raise Exception('Invalid symbol "%s"' % outstr)
Expand Down

0 comments on commit 6c0d15a

Please sign in to comment.