sqlh 0.2.6__tar.gz → 0.2.7__tar.gz
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.
- {sqlh-0.2.6 → sqlh-0.2.7}/PKG-INFO +1 -1
- {sqlh-0.2.6 → sqlh-0.2.7}/pyproject.toml +1 -1
- {sqlh-0.2.6 → sqlh-0.2.7}/sqlh/__init__.py +3 -1
- {sqlh-0.2.6 → sqlh-0.2.7}/sqlh/cli.py +14 -0
- {sqlh-0.2.6 → sqlh-0.2.7}/sqlh/tests/test_utils.py +10 -4
- {sqlh-0.2.6 → sqlh-0.2.7}/sqlh/utils.py +13 -0
- {sqlh-0.2.6 → sqlh-0.2.7}/README.md +0 -0
- {sqlh-0.2.6 → sqlh-0.2.7}/sqlh/.DS_Store +0 -0
- {sqlh-0.2.6 → sqlh-0.2.7}/sqlh/core/graph.py +0 -0
- {sqlh-0.2.6 → sqlh-0.2.7}/sqlh/core/helper.py +0 -0
- {sqlh-0.2.6 → sqlh-0.2.7}/sqlh/core/keywords.py +0 -0
- {sqlh-0.2.6 → sqlh-0.2.7}/sqlh/static/dagre_template.html +0 -0
- {sqlh-0.2.6 → sqlh-0.2.7}/sqlh/static/mermaid_template.html +0 -0
- {sqlh-0.2.6 → sqlh-0.2.7}/sqlh/tests/test_cli.py +0 -0
- {sqlh-0.2.6 → sqlh-0.2.7}/sqlh/tests/test_graph.py +0 -0
- {sqlh-0.2.6 → sqlh-0.2.7}/sqlh/tests/test_import.py +0 -0
- {sqlh-0.2.6 → sqlh-0.2.7}/sqlh/tests/test_sqlhelper.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: sqlh
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.7
|
|
4
4
|
Summary: A lightweight SQL lineage analysis library for tracking table dependencies in data pipelines
|
|
5
5
|
Keywords: sql,lineage,data-pipeline,dag,dependency,database,etl,data-engineering
|
|
6
6
|
Maintainer: Perry DU
|
|
@@ -11,9 +11,10 @@ from .utils import (
|
|
|
11
11
|
search_related_tables,
|
|
12
12
|
search_related_upstream_tables,
|
|
13
13
|
visualize_dag,
|
|
14
|
+
table_count
|
|
14
15
|
)
|
|
15
16
|
|
|
16
|
-
__version__ = "0.2.
|
|
17
|
+
__version__ = "0.2.7"
|
|
17
18
|
|
|
18
19
|
__all__ = [
|
|
19
20
|
"split_sql",
|
|
@@ -29,4 +30,5 @@ __all__ = [
|
|
|
29
30
|
"search_related_tables",
|
|
30
31
|
"search_command_json",
|
|
31
32
|
"visualize_dag",
|
|
33
|
+
"table_count"
|
|
32
34
|
]
|
|
@@ -19,6 +19,7 @@ from .utils import (
|
|
|
19
19
|
search_related_tables,
|
|
20
20
|
search_related_upstream_tables,
|
|
21
21
|
visualize_dag,
|
|
22
|
+
table_count
|
|
22
23
|
)
|
|
23
24
|
|
|
24
25
|
|
|
@@ -91,6 +92,15 @@ def arg_parse():
|
|
|
91
92
|
web_parser.add_argument("--html-path", help="html file path for visualization", default=".")
|
|
92
93
|
web_parser.add_argument("-h", "--help", action="help", default=argparse.SUPPRESS, help="show this help message")
|
|
93
94
|
|
|
95
|
+
# table-count 子命令
|
|
96
|
+
table_count_parser = subparsers.add_parser(
|
|
97
|
+
"table-count",
|
|
98
|
+
parents=[parent_parser],
|
|
99
|
+
help="count the number of tables",
|
|
100
|
+
add_help=False,
|
|
101
|
+
)
|
|
102
|
+
table_count_parser.add_argument("-t", "--table", help="table name to search")
|
|
103
|
+
table_count_parser.add_argument("-h", "--help", action="help", default=argparse.SUPPRESS, help="show this help message")
|
|
94
104
|
return parser.parse_args()
|
|
95
105
|
|
|
96
106
|
|
|
@@ -151,3 +161,7 @@ def main():
|
|
|
151
161
|
print(f"open web page: {html_file_path}")
|
|
152
162
|
visualize_dag(get_all_dag(sql_stmt_str), template_type="dagre", filename=html_file_path)
|
|
153
163
|
return
|
|
164
|
+
|
|
165
|
+
elif args.command == "table-count":
|
|
166
|
+
for table, count in table_count(sql_stmt_str, args.table):
|
|
167
|
+
print(f"{table}: {count}")
|
|
@@ -26,7 +26,7 @@ def test_get_all_root_tables():
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
def test_search_related_upstream_tables():
|
|
29
|
-
a = utils.search_related_upstream_tables(sql_stmt_str, "
|
|
29
|
+
a = utils.search_related_upstream_tables(sql_stmt_str, "ods_hive.ods_order")
|
|
30
30
|
if isinstance(a, Tuple):
|
|
31
31
|
print(utils.list_command_text(a[0]))
|
|
32
32
|
else:
|
|
@@ -34,7 +34,7 @@ def test_search_related_upstream_tables():
|
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
def test_search_related_downstream_tables():
|
|
37
|
-
a = utils.search_related_downstream_tables(sql_stmt_str, "
|
|
37
|
+
a = utils.search_related_downstream_tables(sql_stmt_str, "ods_hive.ods_order")
|
|
38
38
|
if isinstance(a, Tuple):
|
|
39
39
|
print(utils.list_command_text(a[0]))
|
|
40
40
|
else:
|
|
@@ -42,7 +42,7 @@ def test_search_related_downstream_tables():
|
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
def test_search_related_tables():
|
|
45
|
-
a = utils.search_related_tables(sql_stmt_str, "
|
|
45
|
+
a = utils.search_related_tables(sql_stmt_str, "ods_hive.ods_order")
|
|
46
46
|
if isinstance(a, Tuple):
|
|
47
47
|
print(utils.list_command_text(a[0]))
|
|
48
48
|
else:
|
|
@@ -78,9 +78,15 @@ def test_search_command_json():
|
|
|
78
78
|
|
|
79
79
|
|
|
80
80
|
def test_search_related_root_tables():
|
|
81
|
-
output = utils.search_related_root_tables(sql_stmt_str, "ods_hive.
|
|
81
|
+
output = utils.search_related_root_tables(sql_stmt_str, "ods_hive.ods_order")
|
|
82
82
|
# print(utils.list_command_text(output[0]))
|
|
83
83
|
if isinstance(output, Tuple):
|
|
84
84
|
print(utils.list_command_text(output[0]))
|
|
85
85
|
else:
|
|
86
86
|
print(output)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def test_table_count():
|
|
90
|
+
print(utils.table_count(sql_stmt_str))
|
|
91
|
+
for table, count in utils.table_count(sql_stmt_str, 'ods_hive.ods_order'):
|
|
92
|
+
print(f"{table}: {count}")
|
|
@@ -21,6 +21,7 @@ Example:
|
|
|
21
21
|
|
|
22
22
|
import json
|
|
23
23
|
import re
|
|
24
|
+
from collections import Counter
|
|
24
25
|
from pathlib import Path
|
|
25
26
|
from typing import List, Literal, Tuple, Union
|
|
26
27
|
|
|
@@ -363,3 +364,15 @@ def search_command_text(search_result: SearchResult) -> str:
|
|
|
363
364
|
return "- " + "\n- ".join(sorted(related_tables))
|
|
364
365
|
else:
|
|
365
366
|
return str(search_result)
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
def table_count(sql_stmt_str: str, table_name: str | None = None):
|
|
370
|
+
tables = get_all_tables(sql_stmt_str)
|
|
371
|
+
counter = Counter()
|
|
372
|
+
if table_name:
|
|
373
|
+
counter[table_name] = sql_stmt_str.count(table_name.lower())
|
|
374
|
+
return [(table_name, counter[table_name])]
|
|
375
|
+
else:
|
|
376
|
+
for table in tables:
|
|
377
|
+
counter[table] += sql_stmt_str.count(table.lower())
|
|
378
|
+
return [(table, counter[table]) for table in sorted(counter, key=lambda x: counter[x], reverse=True)]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|