deepfos 1.1.60__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- deepfos/__init__.py +6 -0
- deepfos/_version.py +21 -0
- deepfos/algo/__init__.py +0 -0
- deepfos/algo/graph.py +171 -0
- deepfos/algo/segtree.py +31 -0
- deepfos/api/V1_1/__init__.py +0 -0
- deepfos/api/V1_1/business_model.py +119 -0
- deepfos/api/V1_1/dimension.py +599 -0
- deepfos/api/V1_1/models/__init__.py +0 -0
- deepfos/api/V1_1/models/business_model.py +1033 -0
- deepfos/api/V1_1/models/dimension.py +2768 -0
- deepfos/api/V1_2/__init__.py +0 -0
- deepfos/api/V1_2/dimension.py +285 -0
- deepfos/api/V1_2/models/__init__.py +0 -0
- deepfos/api/V1_2/models/dimension.py +2923 -0
- deepfos/api/__init__.py +0 -0
- deepfos/api/account.py +167 -0
- deepfos/api/accounting_engines.py +147 -0
- deepfos/api/app.py +626 -0
- deepfos/api/approval_process.py +198 -0
- deepfos/api/base.py +983 -0
- deepfos/api/business_model.py +160 -0
- deepfos/api/consolidation.py +129 -0
- deepfos/api/consolidation_process.py +106 -0
- deepfos/api/datatable.py +341 -0
- deepfos/api/deep_pipeline.py +61 -0
- deepfos/api/deepconnector.py +36 -0
- deepfos/api/deepfos_task.py +92 -0
- deepfos/api/deepmodel.py +188 -0
- deepfos/api/dimension.py +486 -0
- deepfos/api/financial_model.py +319 -0
- deepfos/api/journal_model.py +119 -0
- deepfos/api/journal_template.py +132 -0
- deepfos/api/memory_financial_model.py +98 -0
- deepfos/api/models/__init__.py +3 -0
- deepfos/api/models/account.py +483 -0
- deepfos/api/models/accounting_engines.py +756 -0
- deepfos/api/models/app.py +1338 -0
- deepfos/api/models/approval_process.py +1043 -0
- deepfos/api/models/base.py +234 -0
- deepfos/api/models/business_model.py +805 -0
- deepfos/api/models/consolidation.py +711 -0
- deepfos/api/models/consolidation_process.py +248 -0
- deepfos/api/models/datatable_mysql.py +427 -0
- deepfos/api/models/deep_pipeline.py +55 -0
- deepfos/api/models/deepconnector.py +28 -0
- deepfos/api/models/deepfos_task.py +386 -0
- deepfos/api/models/deepmodel.py +308 -0
- deepfos/api/models/dimension.py +1576 -0
- deepfos/api/models/financial_model.py +1796 -0
- deepfos/api/models/journal_model.py +341 -0
- deepfos/api/models/journal_template.py +854 -0
- deepfos/api/models/memory_financial_model.py +478 -0
- deepfos/api/models/platform.py +178 -0
- deepfos/api/models/python.py +221 -0
- deepfos/api/models/reconciliation_engine.py +411 -0
- deepfos/api/models/reconciliation_report.py +161 -0
- deepfos/api/models/role_strategy.py +884 -0
- deepfos/api/models/smartlist.py +237 -0
- deepfos/api/models/space.py +1137 -0
- deepfos/api/models/system.py +1065 -0
- deepfos/api/models/variable.py +463 -0
- deepfos/api/models/workflow.py +946 -0
- deepfos/api/platform.py +199 -0
- deepfos/api/python.py +90 -0
- deepfos/api/reconciliation_engine.py +181 -0
- deepfos/api/reconciliation_report.py +64 -0
- deepfos/api/role_strategy.py +234 -0
- deepfos/api/smartlist.py +69 -0
- deepfos/api/space.py +582 -0
- deepfos/api/system.py +372 -0
- deepfos/api/variable.py +154 -0
- deepfos/api/workflow.py +264 -0
- deepfos/boost/__init__.py +6 -0
- deepfos/boost/py_jstream.py +89 -0
- deepfos/boost/py_pandas.py +20 -0
- deepfos/cache.py +121 -0
- deepfos/config.py +6 -0
- deepfos/core/__init__.py +27 -0
- deepfos/core/cube/__init__.py +10 -0
- deepfos/core/cube/_base.py +462 -0
- deepfos/core/cube/constants.py +21 -0
- deepfos/core/cube/cube.py +408 -0
- deepfos/core/cube/formula.py +707 -0
- deepfos/core/cube/syscube.py +532 -0
- deepfos/core/cube/typing.py +7 -0
- deepfos/core/cube/utils.py +238 -0
- deepfos/core/dimension/__init__.py +11 -0
- deepfos/core/dimension/_base.py +506 -0
- deepfos/core/dimension/dimcreator.py +184 -0
- deepfos/core/dimension/dimension.py +472 -0
- deepfos/core/dimension/dimexpr.py +271 -0
- deepfos/core/dimension/dimmember.py +155 -0
- deepfos/core/dimension/eledimension.py +22 -0
- deepfos/core/dimension/filters.py +99 -0
- deepfos/core/dimension/sysdimension.py +168 -0
- deepfos/core/logictable/__init__.py +5 -0
- deepfos/core/logictable/_cache.py +141 -0
- deepfos/core/logictable/_operator.py +663 -0
- deepfos/core/logictable/nodemixin.py +673 -0
- deepfos/core/logictable/sqlcondition.py +609 -0
- deepfos/core/logictable/tablemodel.py +497 -0
- deepfos/db/__init__.py +36 -0
- deepfos/db/cipher.py +660 -0
- deepfos/db/clickhouse.py +191 -0
- deepfos/db/connector.py +195 -0
- deepfos/db/daclickhouse.py +171 -0
- deepfos/db/dameng.py +101 -0
- deepfos/db/damysql.py +189 -0
- deepfos/db/dbkits.py +358 -0
- deepfos/db/deepengine.py +99 -0
- deepfos/db/deepmodel.py +82 -0
- deepfos/db/deepmodel_kingbase.py +83 -0
- deepfos/db/edb.py +214 -0
- deepfos/db/gauss.py +83 -0
- deepfos/db/kingbase.py +83 -0
- deepfos/db/mysql.py +184 -0
- deepfos/db/oracle.py +131 -0
- deepfos/db/postgresql.py +192 -0
- deepfos/db/sqlserver.py +99 -0
- deepfos/db/utils.py +135 -0
- deepfos/element/__init__.py +89 -0
- deepfos/element/accounting.py +348 -0
- deepfos/element/apvlprocess.py +215 -0
- deepfos/element/base.py +398 -0
- deepfos/element/bizmodel.py +1269 -0
- deepfos/element/datatable.py +2467 -0
- deepfos/element/deep_pipeline.py +186 -0
- deepfos/element/deepconnector.py +59 -0
- deepfos/element/deepmodel.py +1806 -0
- deepfos/element/dimension.py +1254 -0
- deepfos/element/fact_table.py +427 -0
- deepfos/element/finmodel.py +1485 -0
- deepfos/element/journal.py +840 -0
- deepfos/element/journal_template.py +943 -0
- deepfos/element/pyscript.py +412 -0
- deepfos/element/reconciliation.py +553 -0
- deepfos/element/rolestrategy.py +243 -0
- deepfos/element/smartlist.py +457 -0
- deepfos/element/variable.py +756 -0
- deepfos/element/workflow.py +560 -0
- deepfos/exceptions/__init__.py +239 -0
- deepfos/exceptions/hook.py +86 -0
- deepfos/lazy.py +104 -0
- deepfos/lazy_import.py +84 -0
- deepfos/lib/__init__.py +0 -0
- deepfos/lib/_javaobj.py +366 -0
- deepfos/lib/asynchronous.py +879 -0
- deepfos/lib/concurrency.py +107 -0
- deepfos/lib/constant.py +39 -0
- deepfos/lib/decorator.py +310 -0
- deepfos/lib/deepchart.py +778 -0
- deepfos/lib/deepux.py +477 -0
- deepfos/lib/discovery.py +273 -0
- deepfos/lib/edb_lexer.py +789 -0
- deepfos/lib/eureka.py +156 -0
- deepfos/lib/filterparser.py +751 -0
- deepfos/lib/httpcli.py +106 -0
- deepfos/lib/jsonstreamer.py +80 -0
- deepfos/lib/msg.py +394 -0
- deepfos/lib/nacos.py +225 -0
- deepfos/lib/patch.py +92 -0
- deepfos/lib/redis.py +241 -0
- deepfos/lib/serutils.py +181 -0
- deepfos/lib/stopwatch.py +99 -0
- deepfos/lib/subtask.py +572 -0
- deepfos/lib/sysutils.py +703 -0
- deepfos/lib/utils.py +1003 -0
- deepfos/local.py +160 -0
- deepfos/options.py +670 -0
- deepfos/translation.py +237 -0
- deepfos-1.1.60.dist-info/METADATA +33 -0
- deepfos-1.1.60.dist-info/RECORD +175 -0
- deepfos-1.1.60.dist-info/WHEEL +5 -0
- deepfos-1.1.60.dist-info/top_level.txt +1 -0
deepfos/db/deepmodel.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""DeepModel数据表客户端"""
|
|
2
|
+
from deepfos.lib.decorator import cached_property
|
|
3
|
+
from typing import Union, List, Iterable, TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
import pandas as pd
|
|
6
|
+
|
|
7
|
+
from deepfos.api.datatable import DeepModelAPI
|
|
8
|
+
from deepfos.cache import Manager, SpaceSeperatedTTLCache
|
|
9
|
+
from deepfos.lib.utils import cachedclass
|
|
10
|
+
from deepfos.lib.decorator import singleton
|
|
11
|
+
from .dbkits import BaseSqlParser, SyncMeta, T_DataInfo
|
|
12
|
+
from .connector import DeepModelAPIConnector
|
|
13
|
+
from .postgresql import _AsyncPostgreSQLClient
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
'DeepModelClient',
|
|
18
|
+
'AsyncDeepModelClient',
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@singleton
|
|
23
|
+
class SqlParser(BaseSqlParser):
|
|
24
|
+
api_cls = DeepModelAPI
|
|
25
|
+
|
|
26
|
+
@cached_property
|
|
27
|
+
def datatable_cls(self):
|
|
28
|
+
from deepfos.element.datatable import AsyncDataTableDeepModel
|
|
29
|
+
return AsyncDataTableDeepModel
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# -----------------------------------------------------------------------------
|
|
33
|
+
# core
|
|
34
|
+
class _AsyncDeepModelClient(_AsyncPostgreSQLClient):
|
|
35
|
+
def __init__(self, version: Union[float, str] = None): # noqa
|
|
36
|
+
self.parser = SqlParser()
|
|
37
|
+
self.connector = DeepModelAPIConnector(version)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class _DeepModelClient(_AsyncDeepModelClient, metaclass=SyncMeta):
|
|
41
|
+
synchronize = (
|
|
42
|
+
'exec_sqls',
|
|
43
|
+
'query_dfs',
|
|
44
|
+
'insert_df',
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
if TYPE_CHECKING: # pragma: no cover
|
|
48
|
+
def exec_sqls(
|
|
49
|
+
self,
|
|
50
|
+
sqls: Union[str, Iterable[str]],
|
|
51
|
+
table_info: T_DataInfo = None
|
|
52
|
+
):
|
|
53
|
+
...
|
|
54
|
+
|
|
55
|
+
def query_dfs(
|
|
56
|
+
self,
|
|
57
|
+
sqls: Union[str, Iterable[str]],
|
|
58
|
+
table_info: T_DataInfo = None
|
|
59
|
+
) -> Union[pd.DataFrame, List[pd.DataFrame]]:
|
|
60
|
+
...
|
|
61
|
+
|
|
62
|
+
def insert_df(
|
|
63
|
+
self,
|
|
64
|
+
dataframe: pd.DataFrame,
|
|
65
|
+
element_name: str = None,
|
|
66
|
+
table_name: str = None,
|
|
67
|
+
updatecol: Iterable[str] = None,
|
|
68
|
+
table_info: T_DataInfo = None,
|
|
69
|
+
chunksize: int = None,
|
|
70
|
+
conflict_target: Iterable[str] = None,
|
|
71
|
+
):
|
|
72
|
+
...
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@cachedclass(Manager.create_cache(SpaceSeperatedTTLCache, maxsize=5, ttl=3600))
|
|
76
|
+
class AsyncDeepModelClient(_AsyncDeepModelClient):
|
|
77
|
+
pass
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@cachedclass(Manager.create_cache(SpaceSeperatedTTLCache, maxsize=5, ttl=3600))
|
|
81
|
+
class DeepModelClient(_DeepModelClient):
|
|
82
|
+
pass
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""DeepModel KingBase数据表客户端"""
|
|
2
|
+
from deepfos.lib.decorator import cached_property
|
|
3
|
+
from typing import Union, List, Iterable, TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
import pandas as pd
|
|
6
|
+
|
|
7
|
+
from deepfos.api.datatable import DeepModelKingBaseAPI
|
|
8
|
+
from deepfos.cache import Manager, SpaceSeperatedTTLCache
|
|
9
|
+
from deepfos.lib.utils import cachedclass
|
|
10
|
+
from deepfos.lib.decorator import singleton
|
|
11
|
+
from .dbkits import BaseSqlParser, SyncMeta, T_DataInfo
|
|
12
|
+
from .connector import DeepModelKingBaseAPIConnector
|
|
13
|
+
from .kingbase import _AsyncKingBaseClient
|
|
14
|
+
from .postgresql import PostgreSQLConvertor
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
'DeepModelKingBaseClient',
|
|
19
|
+
'AsyncDeepModelKingBaseClient',
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@singleton
|
|
24
|
+
class SqlParser(BaseSqlParser):
|
|
25
|
+
api_cls = DeepModelKingBaseAPI
|
|
26
|
+
|
|
27
|
+
@cached_property
|
|
28
|
+
def datatable_cls(self):
|
|
29
|
+
from deepfos.element.datatable import AsyncDataTableDeepModelKingBase
|
|
30
|
+
return AsyncDataTableDeepModelKingBase
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# -----------------------------------------------------------------------------
|
|
34
|
+
# core
|
|
35
|
+
class _AsyncDeepModelKingBaseClient(_AsyncKingBaseClient):
|
|
36
|
+
def __init__(self, version: Union[float, str] = None): # noqa
|
|
37
|
+
self.parser = SqlParser()
|
|
38
|
+
self.connector = DeepModelKingBaseAPIConnector(version)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class _DeepModelKingBaseClient(_AsyncDeepModelKingBaseClient, metaclass=SyncMeta):
|
|
42
|
+
synchronize = (
|
|
43
|
+
'exec_sqls',
|
|
44
|
+
'query_dfs',
|
|
45
|
+
'insert_df',
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
if TYPE_CHECKING: # pragma: no cover
|
|
49
|
+
def exec_sqls(
|
|
50
|
+
self,
|
|
51
|
+
sqls: Union[str, Iterable[str]],
|
|
52
|
+
table_info: T_DataInfo = None
|
|
53
|
+
):
|
|
54
|
+
...
|
|
55
|
+
|
|
56
|
+
def query_dfs(
|
|
57
|
+
self,
|
|
58
|
+
sqls: Union[str, Iterable[str]],
|
|
59
|
+
table_info: T_DataInfo = None
|
|
60
|
+
) -> Union[pd.DataFrame, List[pd.DataFrame]]:
|
|
61
|
+
...
|
|
62
|
+
|
|
63
|
+
def insert_df(
|
|
64
|
+
self,
|
|
65
|
+
dataframe: pd.DataFrame,
|
|
66
|
+
element_name: str = None,
|
|
67
|
+
table_name: str = None,
|
|
68
|
+
updatecol: Iterable[str] = None,
|
|
69
|
+
table_info: T_DataInfo = None,
|
|
70
|
+
chunksize: int = None,
|
|
71
|
+
conflict_target: Iterable[str] = None,
|
|
72
|
+
):
|
|
73
|
+
...
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@cachedclass(Manager.create_cache(SpaceSeperatedTTLCache, maxsize=5, ttl=3600))
|
|
77
|
+
class AsyncDeepModelKingBaseClient(_AsyncDeepModelKingBaseClient):
|
|
78
|
+
pass
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@cachedclass(Manager.create_cache(SpaceSeperatedTTLCache, maxsize=5, ttl=3600))
|
|
82
|
+
class DeepModelKingBaseClient(_DeepModelKingBaseClient):
|
|
83
|
+
pass
|
deepfos/db/edb.py
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from typing import Dict
|
|
3
|
+
|
|
4
|
+
from edgedb import AsyncIOClient, errors, enums, describe, abstract
|
|
5
|
+
from edgedb.abstract import (
|
|
6
|
+
DescribeContext, QueryContext, QueryWithArgs,
|
|
7
|
+
_query_opts # noqa
|
|
8
|
+
)
|
|
9
|
+
from edgedb.asyncio_client import (
|
|
10
|
+
AsyncIOConnection, AsyncIOIteration, # noqa
|
|
11
|
+
AsyncIORetry
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
from deepfos import OPTION
|
|
15
|
+
|
|
16
|
+
__all__ = ['create_async_client']
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def collect_output_frame(ele_desc: describe.AnyType):
|
|
20
|
+
if isinstance(ele_desc, describe.ObjectType):
|
|
21
|
+
return {
|
|
22
|
+
(field, element.is_implicit == 0): collect_output_frame(element.type)
|
|
23
|
+
for field, element in ele_desc.elements.items()
|
|
24
|
+
}
|
|
25
|
+
if isinstance(ele_desc, describe.ArrayType):
|
|
26
|
+
return collect_output_frame(ele_desc.element_type)
|
|
27
|
+
if isinstance(ele_desc, describe.NamedTupleType):
|
|
28
|
+
return {
|
|
29
|
+
field: collect_output_frame(ele_type)
|
|
30
|
+
for field, ele_type in ele_desc.element_types.items()
|
|
31
|
+
}
|
|
32
|
+
if isinstance(ele_desc, describe.TupleType):
|
|
33
|
+
return [collect_output_frame(ele_type) for ele_type in ele_desc.element_types]
|
|
34
|
+
return ele_desc.name
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def normalize_kw(query: str, kw: Dict):
|
|
38
|
+
from deepfos.lib.edb_lexer import EdgeQLLexer
|
|
39
|
+
lexer = EdgeQLLexer()
|
|
40
|
+
lexer.setinputstr(query)
|
|
41
|
+
expected_args = list(
|
|
42
|
+
map(
|
|
43
|
+
lambda t: t.text[1::],
|
|
44
|
+
filter(lambda x: x.type == 'ARGUMENT', lexer.lex())
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
result = {}
|
|
48
|
+
for arg_name in expected_args:
|
|
49
|
+
if arg_name in kw:
|
|
50
|
+
result[arg_name] = kw[arg_name]
|
|
51
|
+
else:
|
|
52
|
+
result.setdefault(arg_name)
|
|
53
|
+
return result
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class _AsyncEdgeDBConnection(AsyncIOConnection):
|
|
57
|
+
async def raw_query(self, query_context, capabilities=enums.Capability.NONE):
|
|
58
|
+
if self.is_closed():
|
|
59
|
+
await self.connect()
|
|
60
|
+
|
|
61
|
+
reconnect = False
|
|
62
|
+
i = 0
|
|
63
|
+
query = query_context.query.query
|
|
64
|
+
kwargs = query_context.query.kwargs
|
|
65
|
+
query_context = query_context._replace(
|
|
66
|
+
query=query_context.query._replace(
|
|
67
|
+
kwargs=normalize_kw(query, kwargs)
|
|
68
|
+
)
|
|
69
|
+
)
|
|
70
|
+
args = dict(
|
|
71
|
+
query=query_context.query.query,
|
|
72
|
+
args=query_context.query.args,
|
|
73
|
+
kwargs=query_context.query.kwargs,
|
|
74
|
+
reg=query_context.cache.codecs_registry,
|
|
75
|
+
qc=query_context.cache.query_cache,
|
|
76
|
+
output_format=query_context.query_options.output_format,
|
|
77
|
+
expect_one=query_context.query_options.expect_one,
|
|
78
|
+
required_one=query_context.query_options.required_one,
|
|
79
|
+
allow_capabilities=capabilities,
|
|
80
|
+
)
|
|
81
|
+
if query_context.state is not None:
|
|
82
|
+
args["state"] = query_context.state.as_dict()
|
|
83
|
+
while True:
|
|
84
|
+
i += 1
|
|
85
|
+
try:
|
|
86
|
+
if reconnect:
|
|
87
|
+
await self.connect(single_attempt=True)
|
|
88
|
+
result = await self._protocol.query(**args)
|
|
89
|
+
codecs = query_context.cache.query_cache.get(
|
|
90
|
+
args['query'],
|
|
91
|
+
args['output_format'],
|
|
92
|
+
# implicit_limit
|
|
93
|
+
0,
|
|
94
|
+
# inline_typenames
|
|
95
|
+
False,
|
|
96
|
+
# inline_typeids
|
|
97
|
+
False,
|
|
98
|
+
args['expect_one'],
|
|
99
|
+
)
|
|
100
|
+
if codecs is not None:
|
|
101
|
+
out_dc = codecs[2]
|
|
102
|
+
frame_desc = collect_output_frame(out_dc.make_type(
|
|
103
|
+
DescribeContext(
|
|
104
|
+
query='',
|
|
105
|
+
state=query_context.state,
|
|
106
|
+
inject_type_names=False
|
|
107
|
+
)
|
|
108
|
+
))
|
|
109
|
+
else:
|
|
110
|
+
frame_desc = None
|
|
111
|
+
return frame_desc, result
|
|
112
|
+
except errors.EdgeDBError as e:
|
|
113
|
+
if query_context.retry_options is None:
|
|
114
|
+
raise
|
|
115
|
+
if not e.has_tag(errors.SHOULD_RETRY):
|
|
116
|
+
raise e
|
|
117
|
+
if capabilities is None:
|
|
118
|
+
cache_item = query_context.cache.query_cache.get(
|
|
119
|
+
query_context.query.query,
|
|
120
|
+
query_context.query_options.output_format,
|
|
121
|
+
implicit_limit=0,
|
|
122
|
+
inline_typenames=False,
|
|
123
|
+
inline_typeids=False,
|
|
124
|
+
expect_one=query_context.query_options.expect_one,
|
|
125
|
+
)
|
|
126
|
+
if cache_item is not None:
|
|
127
|
+
_, _, _, capabilities = cache_item
|
|
128
|
+
# A query is read-only if it has no capabilities i.e.
|
|
129
|
+
# capabilities == 0. Read-only queries are safe to retry.
|
|
130
|
+
# Explicit transaction conflicts as well.
|
|
131
|
+
if (
|
|
132
|
+
capabilities != 0
|
|
133
|
+
and not isinstance(e, errors.TransactionConflictError)
|
|
134
|
+
):
|
|
135
|
+
raise e
|
|
136
|
+
rule = query_context.retry_options.get_rule_for_exception(e)
|
|
137
|
+
if i >= rule.attempts:
|
|
138
|
+
raise e
|
|
139
|
+
await self.sleep(rule.backoff(i))
|
|
140
|
+
reconnect = self.is_closed()
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class _AsyncIOIteration(AsyncIOIteration):
|
|
144
|
+
async def _execute(self, query_context: abstract.QueryContext):
|
|
145
|
+
with self._exclusive():
|
|
146
|
+
await self._ensure_transaction()
|
|
147
|
+
return await self._connection.raw_query(
|
|
148
|
+
query_context, enums.Capability.MODIFICATIONS
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
async def execute(self, commands: str, *args, **kwargs):
|
|
152
|
+
return await self._execute(QueryContext(
|
|
153
|
+
query=QueryWithArgs(commands, args, kwargs),
|
|
154
|
+
cache=self._get_query_cache(),
|
|
155
|
+
query_options=_query_opts,
|
|
156
|
+
retry_options=self._get_retry_options(),
|
|
157
|
+
state=self._get_state(),
|
|
158
|
+
))
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
class _AsyncIORetry(AsyncIORetry):
|
|
162
|
+
async def __anext__(self):
|
|
163
|
+
# Note: when changing this code consider also
|
|
164
|
+
# updating Retry.__next__.
|
|
165
|
+
if self._done:
|
|
166
|
+
raise StopAsyncIteration
|
|
167
|
+
if self._next_backoff:
|
|
168
|
+
await asyncio.sleep(self._next_backoff)
|
|
169
|
+
self._done = True
|
|
170
|
+
iteration = _AsyncIOIteration(self, self._owner, self._iteration)
|
|
171
|
+
self._iteration += 1
|
|
172
|
+
return iteration
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
class _AsyncIOClient(AsyncIOClient):
|
|
176
|
+
def transaction(self) -> _AsyncIORetry:
|
|
177
|
+
return _AsyncIORetry(self)
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
# All deprecated space in v3dev & v3test & alpha
|
|
181
|
+
deprecated_space = [
|
|
182
|
+
'ulqtqb',
|
|
183
|
+
'zauoyn',
|
|
184
|
+
'ocixjo',
|
|
185
|
+
'kqgboa',
|
|
186
|
+
'xnthjj',
|
|
187
|
+
'itarfd',
|
|
188
|
+
'thugts',
|
|
189
|
+
'atadqj',
|
|
190
|
+
'cfzqdn',
|
|
191
|
+
'bwpxhl',
|
|
192
|
+
'znjcye',
|
|
193
|
+
'chhwqs',
|
|
194
|
+
'zguhhs',
|
|
195
|
+
'svaakp',
|
|
196
|
+
]
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def create_async_client(default_module=None, dbname=None):
|
|
200
|
+
if dbname is None:
|
|
201
|
+
space = OPTION.api.header['space']
|
|
202
|
+
dbname = None if space in deprecated_space else f"deepmodel_space{space}"
|
|
203
|
+
cli = _AsyncIOClient(
|
|
204
|
+
connection_class=_AsyncEdgeDBConnection,
|
|
205
|
+
max_concurrency=None,
|
|
206
|
+
dsn=OPTION.edgedb.dsn,
|
|
207
|
+
database=dbname,
|
|
208
|
+
tls_security='insecure',
|
|
209
|
+
wait_until_available=30,
|
|
210
|
+
timeout=OPTION.edgedb.timeout,
|
|
211
|
+
)
|
|
212
|
+
if default_module:
|
|
213
|
+
cli = cli.with_default_module(default_module)
|
|
214
|
+
return cli
|
deepfos/db/gauss.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""Gauss客户端"""
|
|
2
|
+
from deepfos.lib.decorator import cached_property
|
|
3
|
+
from typing import Union, List, Iterable, TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
import pandas as pd
|
|
6
|
+
|
|
7
|
+
from deepfos.api.datatable import GaussAPI
|
|
8
|
+
from deepfos.cache import Manager, SpaceSeperatedTTLCache
|
|
9
|
+
from deepfos.lib.utils import cachedclass
|
|
10
|
+
from deepfos.lib.decorator import singleton
|
|
11
|
+
from .dbkits import BaseSqlParser, SyncMeta, T_DataInfo
|
|
12
|
+
from .connector import GaussAPIConnector
|
|
13
|
+
from .mysql import _AbsAsyncMySQLClient # noqa
|
|
14
|
+
from .postgresql import _AsyncPostgreSQLClient
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
'GaussClient',
|
|
19
|
+
'AsyncGaussClient',
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@singleton
|
|
24
|
+
class SqlParser(BaseSqlParser):
|
|
25
|
+
api_cls = GaussAPI
|
|
26
|
+
|
|
27
|
+
@cached_property
|
|
28
|
+
def datatable_cls(self):
|
|
29
|
+
from deepfos.element.datatable import AsyncDataTableGauss
|
|
30
|
+
return AsyncDataTableGauss
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# -----------------------------------------------------------------------------
|
|
34
|
+
# core
|
|
35
|
+
class _AsyncGaussClient(_AsyncPostgreSQLClient):
|
|
36
|
+
def __init__(self, version: Union[float, str] = None): # noqa
|
|
37
|
+
self.parser = SqlParser()
|
|
38
|
+
self.connector = GaussAPIConnector(version)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class _GaussClient(_AsyncGaussClient, metaclass=SyncMeta):
|
|
42
|
+
synchronize = (
|
|
43
|
+
'exec_sqls',
|
|
44
|
+
'query_dfs',
|
|
45
|
+
'insert_df',
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
if TYPE_CHECKING: # pragma: no cover
|
|
49
|
+
def exec_sqls(
|
|
50
|
+
self,
|
|
51
|
+
sqls: Union[str, Iterable[str]],
|
|
52
|
+
table_info: T_DataInfo = None
|
|
53
|
+
):
|
|
54
|
+
...
|
|
55
|
+
|
|
56
|
+
def query_dfs(
|
|
57
|
+
self,
|
|
58
|
+
sqls: Union[str, Iterable[str]],
|
|
59
|
+
table_info: T_DataInfo = None
|
|
60
|
+
) -> Union[pd.DataFrame, List[pd.DataFrame]]:
|
|
61
|
+
...
|
|
62
|
+
|
|
63
|
+
def insert_df(
|
|
64
|
+
self,
|
|
65
|
+
dataframe: pd.DataFrame,
|
|
66
|
+
element_name: str = None,
|
|
67
|
+
table_name: str = None,
|
|
68
|
+
updatecol: Iterable[str] = None,
|
|
69
|
+
table_info: T_DataInfo = None,
|
|
70
|
+
chunksize: int = None,
|
|
71
|
+
conflict_target: Iterable[str] = None,
|
|
72
|
+
):
|
|
73
|
+
...
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@cachedclass(Manager.create_cache(SpaceSeperatedTTLCache, maxsize=5, ttl=3600))
|
|
77
|
+
class AsyncGaussClient(_AsyncGaussClient):
|
|
78
|
+
pass
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@cachedclass(Manager.create_cache(SpaceSeperatedTTLCache, maxsize=5, ttl=3600))
|
|
82
|
+
class GaussClient(_GaussClient):
|
|
83
|
+
pass
|
deepfos/db/kingbase.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""KingBase客户端"""
|
|
2
|
+
from deepfos.lib.decorator import cached_property
|
|
3
|
+
from typing import Union, List, Iterable, TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
import pandas as pd
|
|
6
|
+
|
|
7
|
+
from deepfos.api.datatable import KingBaseAPI
|
|
8
|
+
from deepfos.cache import Manager, SpaceSeperatedTTLCache
|
|
9
|
+
from deepfos.lib.utils import cachedclass
|
|
10
|
+
from deepfos.lib.decorator import singleton
|
|
11
|
+
from .dbkits import BaseSqlParser, SyncMeta, T_DataInfo
|
|
12
|
+
from .connector import KingBaseAPIConnector
|
|
13
|
+
from .mysql import _AbsAsyncMySQLClient # noqa
|
|
14
|
+
from .postgresql import _AsyncPostgreSQLClient, PostgreSQLConvertor
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
'KingBaseClient',
|
|
18
|
+
'AsyncKingBaseClient',
|
|
19
|
+
'_AsyncKingBaseClient',
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@singleton
|
|
24
|
+
class SqlParser(BaseSqlParser):
|
|
25
|
+
api_cls = KingBaseAPI
|
|
26
|
+
|
|
27
|
+
@cached_property
|
|
28
|
+
def datatable_cls(self):
|
|
29
|
+
from deepfos.element.datatable import AsyncDataTableKingBase
|
|
30
|
+
return AsyncDataTableKingBase
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# -----------------------------------------------------------------------------
|
|
34
|
+
# core
|
|
35
|
+
class _AsyncKingBaseClient(_AsyncPostgreSQLClient):
|
|
36
|
+
def __init__(self, version: Union[float, str] = None): # noqa
|
|
37
|
+
self.parser = SqlParser()
|
|
38
|
+
self.connector = KingBaseAPIConnector(version)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class _KingBaseClient(_AsyncKingBaseClient, metaclass=SyncMeta):
|
|
42
|
+
synchronize = (
|
|
43
|
+
'exec_sqls',
|
|
44
|
+
'query_dfs',
|
|
45
|
+
'insert_df',
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
if TYPE_CHECKING: # pragma: no cover
|
|
49
|
+
def exec_sqls(
|
|
50
|
+
self,
|
|
51
|
+
sqls: Union[str, Iterable[str]],
|
|
52
|
+
table_info: T_DataInfo = None
|
|
53
|
+
):
|
|
54
|
+
...
|
|
55
|
+
|
|
56
|
+
def query_dfs(
|
|
57
|
+
self,
|
|
58
|
+
sqls: Union[str, Iterable[str]],
|
|
59
|
+
table_info: T_DataInfo = None
|
|
60
|
+
) -> Union[pd.DataFrame, List[pd.DataFrame]]:
|
|
61
|
+
...
|
|
62
|
+
|
|
63
|
+
def insert_df(
|
|
64
|
+
self,
|
|
65
|
+
dataframe: pd.DataFrame,
|
|
66
|
+
element_name: str = None,
|
|
67
|
+
table_name: str = None,
|
|
68
|
+
updatecol: Iterable[str] = None,
|
|
69
|
+
table_info: T_DataInfo = None,
|
|
70
|
+
chunksize: int = None,
|
|
71
|
+
conflict_target: Iterable[str] = None,
|
|
72
|
+
):
|
|
73
|
+
...
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@cachedclass(Manager.create_cache(SpaceSeperatedTTLCache, maxsize=5, ttl=3600))
|
|
77
|
+
class AsyncKingBaseClient(_AsyncKingBaseClient):
|
|
78
|
+
pass
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@cachedclass(Manager.create_cache(SpaceSeperatedTTLCache, maxsize=5, ttl=3600))
|
|
82
|
+
class KingBaseClient(_KingBaseClient):
|
|
83
|
+
pass
|