From f7a3992875f506f3d04f5829128c7485e80c351e Mon Sep 17 00:00:00 2001 From: cyqxyy <> Date: Wed, 2 Aug 2023 12:59:21 +0800 Subject: [PATCH 1/2] add numberlong type support to mongo --- sql/engines/mongo.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sql/engines/mongo.py b/sql/engines/mongo.py index 13d5f90af0..ae8b100a35 100644 --- a/sql/engines/mongo.py +++ b/sql/engines/mongo.py @@ -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 @@ -197,6 +198,7 @@ def __next_const(self): "newDate", "ISODate", "newISODate", + "NumberLong", ): # ======类似的类型比较多还需单独处理,如int()等 data_type = outstr for c in self.__remain_str(): @@ -230,6 +232,14 @@ 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) From 38227cde67a41c704443597ff2ba05d9027df497 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=B6=E9=9F=B5=E6=B8=85=E9=A6=99=E6=82=A0=E6=82=A0?= <15079792983@163.com> Date: Wed, 2 Aug 2023 13:31:05 +0800 Subject: [PATCH 2/2] fix lint --- sql/engines/mongo.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sql/engines/mongo.py b/sql/engines/mongo.py index ae8b100a35..7a7c2aa844 100644 --- a/sql/engines/mongo.py +++ b/sql/engines/mongo.py @@ -232,9 +232,7 @@ 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" - ): + elif data_type.replace(" ", "") in ("NumberLong"): nuStr = re.findall(r"NumberLong\(.*?\)", outstr) # 单独处理NumberLong if len(nuStr) > 0: id_str = re.findall(r"\(.*?\)", nuStr[0])