ygo 1.0.1__py3-none-any.whl → 1.0.3__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.
Potentially problematic release.
This version of ygo might be problematic. Click here for more details.
- ycat/__init__.py +14 -2
- ycat/client.py +32 -47
- ycat/parse.py +1 -1
- {ygo-1.0.1.dist-info → ygo-1.0.3.dist-info}/METADATA +1 -2
- {ygo-1.0.1.dist-info → ygo-1.0.3.dist-info}/RECORD +8 -8
- {ygo-1.0.1.dist-info → ygo-1.0.3.dist-info}/WHEEL +1 -1
- {ygo-1.0.1.dist-info → ygo-1.0.3.dist-info}/licenses/LICENSE +0 -0
- {ygo-1.0.1.dist-info → ygo-1.0.3.dist-info}/top_level.txt +0 -0
ycat/__init__.py
CHANGED
|
@@ -7,16 +7,28 @@ Created on 2025/5/14 18:29
|
|
|
7
7
|
---------------------------------------------
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
|
-
from .client import
|
|
10
|
+
from .client import (
|
|
11
|
+
HOME,
|
|
12
|
+
CATDB,
|
|
13
|
+
get_settings,
|
|
14
|
+
sql,
|
|
15
|
+
put,
|
|
16
|
+
create_engine_ck,
|
|
17
|
+
create_engine_mysql,
|
|
18
|
+
read_mysql,
|
|
19
|
+
read_ck,
|
|
20
|
+
tb_path,
|
|
21
|
+
)
|
|
11
22
|
|
|
12
23
|
__all__ = [
|
|
13
24
|
"HOME",
|
|
14
25
|
"CATDB",
|
|
15
|
-
"
|
|
26
|
+
"get_settings",
|
|
16
27
|
"sql",
|
|
17
28
|
"put",
|
|
18
29
|
"create_engine_ck",
|
|
19
30
|
"create_engine_mysql",
|
|
20
31
|
"read_mysql",
|
|
21
32
|
"read_ck",
|
|
33
|
+
"tb_path",
|
|
22
34
|
]
|
ycat/client.py
CHANGED
|
@@ -8,21 +8,21 @@ Created on 2024/7/1 09:44
|
|
|
8
8
|
"""
|
|
9
9
|
import os
|
|
10
10
|
import re
|
|
11
|
+
from functools import partial
|
|
11
12
|
from typing import Optional
|
|
12
|
-
from .yck import connect, query_polars
|
|
13
13
|
|
|
14
|
-
import duckdb
|
|
15
14
|
import polars as pl
|
|
16
|
-
import ylog
|
|
17
15
|
from dynaconf import Dynaconf
|
|
18
16
|
from sqlalchemy import create_engine
|
|
19
|
-
from functools import partial
|
|
20
17
|
|
|
18
|
+
import ylog
|
|
21
19
|
from .parse import extract_table_names_from_sql
|
|
20
|
+
from .yck import connect, query_polars
|
|
22
21
|
|
|
23
22
|
# 配置文件在 “~/.catdb/setting.toml”
|
|
24
23
|
USERHOME = os.path.expanduser('~') # 用户家目录
|
|
25
|
-
|
|
24
|
+
NAME = "catdb"
|
|
25
|
+
CONFIG_PATH = os.path.join(USERHOME, f".{NAME}", "settings.toml")
|
|
26
26
|
if not os.path.exists(CONFIG_PATH):
|
|
27
27
|
try:
|
|
28
28
|
os.makedirs(os.path.dirname(CONFIG_PATH))
|
|
@@ -30,9 +30,9 @@ if not os.path.exists(CONFIG_PATH):
|
|
|
30
30
|
...
|
|
31
31
|
except Exception as e:
|
|
32
32
|
ylog.error(f"配置文件生成失败: {e}")
|
|
33
|
-
catdb_path = os.path.join(USERHOME,
|
|
33
|
+
catdb_path = os.path.join(USERHOME, NAME)
|
|
34
34
|
template_content = f"""[paths]
|
|
35
|
-
|
|
35
|
+
{NAME}="{catdb_path}" # 本地数据库,默认家目录
|
|
36
36
|
|
|
37
37
|
## 数据库配置:
|
|
38
38
|
[database]
|
|
@@ -54,17 +54,19 @@ catdb="{catdb_path}" # 本地数据库,默认家目录
|
|
|
54
54
|
|
|
55
55
|
def get_settings():
|
|
56
56
|
try:
|
|
57
|
-
return Dynaconf(settings_files=[CONFIG_PATH])
|
|
57
|
+
return Dynaconf(settings_files=[CONFIG_PATH]).as_dict()
|
|
58
58
|
except:
|
|
59
|
-
return
|
|
59
|
+
return {}
|
|
60
60
|
|
|
61
61
|
|
|
62
62
|
HOME = USERHOME
|
|
63
|
-
CATDB = os.path.join(HOME,
|
|
63
|
+
CATDB = os.path.join(HOME, NAME)
|
|
64
64
|
# 读取配置文件覆盖
|
|
65
65
|
SETTINGS = get_settings()
|
|
66
66
|
if SETTINGS is not None:
|
|
67
|
-
CATDB = SETTINGS
|
|
67
|
+
CATDB = SETTINGS["PATHS"][NAME]
|
|
68
|
+
if not CATDB.endswith(NAME):
|
|
69
|
+
CATDB = os.path.join(CATDB, NAME)
|
|
68
70
|
|
|
69
71
|
|
|
70
72
|
# ======================== 本地数据库 catdb ========================
|
|
@@ -82,19 +84,12 @@ def tb_path(tb_name: str) -> str:
|
|
|
82
84
|
"""
|
|
83
85
|
return os.path.join(CATDB, tb_name)
|
|
84
86
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
写入的数据
|
|
92
|
-
tb_name: str
|
|
93
|
-
表名,支持路径写法, a/b/c
|
|
94
|
-
partitions: Optional[List[str]]
|
|
95
|
-
根据哪些字段进行分区,默认不分区
|
|
96
|
-
"""
|
|
97
|
-
tbpath = tb_path(tb_name)
|
|
87
|
+
|
|
88
|
+
def put(df: pl.DataFrame, tb_name: str, partitions: Optional[list[str]] = None, abs_path: bool = False):
|
|
89
|
+
if not abs_path:
|
|
90
|
+
tbpath = tb_path(tb_name)
|
|
91
|
+
else:
|
|
92
|
+
tbpath = tb_name
|
|
98
93
|
if not os.path.exists(tbpath):
|
|
99
94
|
try:
|
|
100
95
|
os.makedirs(tbpath)
|
|
@@ -106,41 +101,30 @@ def put(df: pl.DataFrame, tb_name: str, partitions: Optional[list[str]] = None):
|
|
|
106
101
|
df.write_parquet(tbpath, partition_by=partitions)
|
|
107
102
|
|
|
108
103
|
|
|
109
|
-
def sql(query: str):
|
|
110
|
-
"""
|
|
111
|
-
从duckdb中读取数据, query语法与mysql一致,特殊语法请查duckdb官网: https://duckdb.org/docs/sql/query_syntax/select
|
|
112
|
-
Parameters
|
|
113
|
-
----------
|
|
114
|
-
query: str
|
|
115
|
-
查询语句
|
|
116
|
-
Returns
|
|
117
|
-
-------
|
|
118
|
-
result: duckdb.DuckDBPyRelation
|
|
119
|
-
查询结果
|
|
120
|
-
"""
|
|
104
|
+
def sql(query: str, abs_path: bool = False):
|
|
121
105
|
tbs = extract_table_names_from_sql(query)
|
|
122
106
|
convertor = dict()
|
|
123
107
|
for tb in tbs:
|
|
124
|
-
|
|
125
|
-
|
|
108
|
+
if not abs_path:
|
|
109
|
+
db_path = tb_path(tb)
|
|
110
|
+
else:
|
|
111
|
+
db_path = tb
|
|
112
|
+
format_tb = f"read_parquet('{db_path}/**/*.parquet')"
|
|
126
113
|
convertor[tb] = format_tb
|
|
127
114
|
pattern = re.compile("|".join(re.escape(k) for k in convertor.keys()))
|
|
128
115
|
new_query = pattern.sub(lambda m: convertor[m.group(0)], query)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
conn.execute("PRAGMA threads=1;")
|
|
132
|
-
res = conn.execute(new_query).fetch_arrow_table()
|
|
133
|
-
res = pl.from_arrow(res)
|
|
134
|
-
conn.close()
|
|
135
|
-
return res
|
|
116
|
+
return pl.sql(new_query).collect()
|
|
117
|
+
|
|
136
118
|
|
|
137
119
|
def create_engine_ck(urls: list[str], user: str, password: str):
|
|
138
120
|
return partial(connect, urls, user, password)
|
|
139
121
|
|
|
140
|
-
|
|
122
|
+
|
|
123
|
+
def read_ck(sql, eng) -> pl.DataFrame:
|
|
141
124
|
with eng() as conn:
|
|
142
125
|
return query_polars(sql, conn)
|
|
143
126
|
|
|
127
|
+
|
|
144
128
|
def create_engine_mysql(url, user, password, database):
|
|
145
129
|
"""
|
|
146
130
|
:param url: <host>:<port>
|
|
@@ -152,6 +136,7 @@ def create_engine_mysql(url, user, password, database):
|
|
|
152
136
|
engine = create_engine(f"mysql+pymysql://{user}:{password}@{url}/{database}")
|
|
153
137
|
return engine
|
|
154
138
|
|
|
139
|
+
|
|
155
140
|
def read_mysql(sql, eng) -> pl.DataFrame:
|
|
156
141
|
with eng.connect() as conn:
|
|
157
|
-
return pl.read_database(sql, conn)
|
|
142
|
+
return pl.read_database(sql, conn)
|
ycat/parse.py
CHANGED
|
@@ -33,7 +33,7 @@ def extract_table_names_from_sql(sql_query):
|
|
|
33
33
|
# 遍历解析后的语句块
|
|
34
34
|
for statement in parsed:
|
|
35
35
|
# 转换为字符串
|
|
36
|
-
statement_str = str(statement).lower()
|
|
36
|
+
statement_str = str(statement)# .lower()
|
|
37
37
|
|
|
38
38
|
# 将字符串中的特殊语法置空
|
|
39
39
|
statement_str = re.sub(r'(substring|extract)\s*\(((.|\s)*?)\)', '', statement_str)
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ygo
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Project-URL: homepage, https://github.com/link-yundi/ygo
|
|
5
5
|
Project-URL: repository, https://github.com/link-yundi/ygo
|
|
6
6
|
Requires-Python: >=3.8
|
|
7
7
|
Description-Content-Type: text/markdown
|
|
8
8
|
License-File: LICENSE
|
|
9
9
|
Requires-Dist: clickhouse-driver>=0.2.9
|
|
10
|
-
Requires-Dist: duckdb>=1.2.2
|
|
11
10
|
Requires-Dist: dynaconf>=3.2.11
|
|
12
11
|
Requires-Dist: joblib>=1.4.2
|
|
13
12
|
Requires-Dist: loguru>=0.7.3
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
ycat/__init__.py,sha256=
|
|
2
|
-
ycat/client.py,sha256=
|
|
1
|
+
ycat/__init__.py,sha256=zBMOFStzKSt_5jw4af6YFtPD5Svr8fJlZkP_AdUjCoA,554
|
|
2
|
+
ycat/client.py,sha256=tsrJUeoy_cFiHjX7hnh0dtnO_3njhtMLrQcAfi0TYgQ,3796
|
|
3
3
|
ycat/dtype.py,sha256=mRGLDe_Ho6-tDsoj5wwrAzozEoIYCAHGKdpRqgBfUcI,12577
|
|
4
|
-
ycat/parse.py,sha256=
|
|
4
|
+
ycat/parse.py,sha256=9Kgr33nHYC96TGpZs98PAu0cbK-FrR0pfuf8lfD647I,2289
|
|
5
5
|
ycat/yck.py,sha256=FlGMBuKEngB4TwFXMp4P3dLg9IfFmUg3eDqXzQ0kQoI,2738
|
|
6
6
|
ygo/__init__.py,sha256=FMN06Tfa8_oV26eklBZCtGTyHZ6MghHxHj4PS_FSXCA,222
|
|
7
7
|
ygo/exceptions.py,sha256=4Kd92kpwpsXHJJkSv4OqcN--PEEvIGGvDDgOOsk68gg,385
|
|
8
8
|
ygo/ygo.py,sha256=vCMUur_41yY0QB4gj8K5wBZHql_cbmANhI8QwPRCTmo,11613
|
|
9
|
-
ygo-1.0.
|
|
9
|
+
ygo-1.0.3.dist-info/licenses/LICENSE,sha256=6AKUWQ1xe-jwPSFv_H6FMQLNNWb7AYqzuEUTwlP2S8M,1067
|
|
10
10
|
ylog/__init__.py,sha256=2sIp4PHNoQMCi0QtIarTI4raACd7SdRHNY7fY5hKYwc,397
|
|
11
11
|
ylog/core.py,sha256=uO_r5wDrBN5edV_TDHUNzcqRs6DMDDrrjfyqYZhak4w,7716
|
|
12
|
-
ygo-1.0.
|
|
13
|
-
ygo-1.0.
|
|
14
|
-
ygo-1.0.
|
|
15
|
-
ygo-1.0.
|
|
12
|
+
ygo-1.0.3.dist-info/METADATA,sha256=ksiTv_WXxiia5RlkTkbHRU8v4vZudgatBIaVe7PZOfo,1980
|
|
13
|
+
ygo-1.0.3.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
|
|
14
|
+
ygo-1.0.3.dist-info/top_level.txt,sha256=jEbfiz5fX4iSzDg8_Npdv5SIC_Kphmb1m3vuyD9ZC1E,14
|
|
15
|
+
ygo-1.0.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|