Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add numberlong type support to mongo #2224

Merged
merged 2 commits into from
Aug 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading