lidb 1.0.9__tar.gz → 1.1.0__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.
Potentially problematic release.
This version of lidb might be problematic. Click here for more details.
- {lidb-1.0.9 → lidb-1.1.0}/PKG-INFO +1 -1
- {lidb-1.0.9 → lidb-1.1.0}/lidb/__init__.py +3 -1
- {lidb-1.0.9 → lidb-1.1.0}/lidb/parse.py +47 -2
- {lidb-1.0.9 → lidb-1.1.0}/lidb.egg-info/PKG-INFO +1 -1
- {lidb-1.0.9 → lidb-1.1.0}/lidb.egg-info/SOURCES.txt +2 -1
- {lidb-1.0.9 → lidb-1.1.0}/pyproject.toml +1 -1
- lidb-1.1.0/tests/test_parse.py +18 -0
- {lidb-1.0.9 → lidb-1.1.0}/README.md +0 -0
- {lidb-1.0.9 → lidb-1.1.0}/lidb/database.py +0 -0
- {lidb-1.0.9 → lidb-1.1.0}/lidb/init.py +0 -0
- {lidb-1.0.9 → lidb-1.1.0}/lidb.egg-info/dependency_links.txt +0 -0
- {lidb-1.0.9 → lidb-1.1.0}/lidb.egg-info/requires.txt +0 -0
- {lidb-1.0.9 → lidb-1.1.0}/lidb.egg-info/top_level.txt +0 -0
- {lidb-1.0.9 → lidb-1.1.0}/setup.cfg +0 -0
- {lidb-1.0.9 → lidb-1.1.0}/tests/test_conf.py +0 -0
|
@@ -7,19 +7,29 @@ Created on 2024/11/6 下午7:25
|
|
|
7
7
|
Email: yundi.xxii@outlook.com
|
|
8
8
|
---------------------------------------------
|
|
9
9
|
"""
|
|
10
|
-
import sqlparse
|
|
11
10
|
import re
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Dict, Set
|
|
13
|
+
from urllib.parse import unquote
|
|
14
|
+
from collections import defaultdict
|
|
15
|
+
|
|
16
|
+
import polars
|
|
17
|
+
import polars as pl
|
|
18
|
+
import sqlparse
|
|
19
|
+
|
|
12
20
|
|
|
13
21
|
def format_sql(sql_content):
|
|
14
22
|
"""将sql语句进行规范化,并去除sql中的注释,输入和输出均为字符串"""
|
|
15
23
|
parse_str = sqlparse.format(sql_content, reindent=True, strip_comments=True)
|
|
16
24
|
return parse_str
|
|
17
25
|
|
|
26
|
+
|
|
18
27
|
def extract_temp_tables(with_clause):
|
|
19
28
|
"""从WITH子句中提取临时表名,输出为列表"""
|
|
20
29
|
temp_tables = re.findall(r'\b(\w+)\s*as\s*\(', with_clause, re.IGNORECASE)
|
|
21
30
|
return temp_tables
|
|
22
31
|
|
|
32
|
+
|
|
23
33
|
def extract_table_names_from_sql(sql_query):
|
|
24
34
|
"""从sql中提取对应的表名称,输出为列表"""
|
|
25
35
|
table_names = set()
|
|
@@ -34,7 +44,7 @@ def extract_table_names_from_sql(sql_query):
|
|
|
34
44
|
# 遍历解析后的语句块
|
|
35
45
|
for statement in parsed:
|
|
36
46
|
# 转换为字符串
|
|
37
|
-
statement_str = str(statement)# .lower()
|
|
47
|
+
statement_str = str(statement) # .lower()
|
|
38
48
|
|
|
39
49
|
# 将字符串中的特殊语法置空
|
|
40
50
|
statement_str = re.sub(r'(substring|extract)\s*\(((.|\s)*?)\)', '', statement_str)
|
|
@@ -62,4 +72,39 @@ def extract_table_names_from_sql(sql_query):
|
|
|
62
72
|
return table_names
|
|
63
73
|
|
|
64
74
|
|
|
75
|
+
def parse_hive_partition_structure(root_path: Path | str, file_pattern: str = "*.parquet") -> polars.DataFrame:
|
|
76
|
+
"""
|
|
77
|
+
通用Hive分区结构解析器
|
|
78
|
+
|
|
79
|
+
Args:
|
|
80
|
+
root_path: 根路径 (如 /data)
|
|
81
|
+
file_pattern: 文件匹配模式 (默认 "*.parquet")
|
|
82
|
+
|
|
83
|
+
Returns:
|
|
84
|
+
polars.DataFrame
|
|
85
|
+
"""
|
|
86
|
+
if isinstance(root_path, str):
|
|
87
|
+
root_path = Path(root_path)
|
|
88
|
+
|
|
89
|
+
partition_combinations = set()
|
|
90
|
+
|
|
91
|
+
for file_path in root_path.rglob(file_pattern):
|
|
92
|
+
relative_path = file_path.relative_to(root_path)
|
|
93
|
+
|
|
94
|
+
# 收集分区信息
|
|
95
|
+
partition_dict = {}
|
|
96
|
+
for part in relative_path.parts[:-1]: # 排除文件名
|
|
97
|
+
if '=' in part:
|
|
98
|
+
key, value = part.split('=', 1)
|
|
99
|
+
value = unquote(value)
|
|
100
|
+
|
|
101
|
+
partition_dict[key] = value
|
|
102
|
+
|
|
103
|
+
# 记录分区组合
|
|
104
|
+
combination = tuple(sorted(partition_dict.items()))
|
|
105
|
+
partition_combinations.add(combination)
|
|
106
|
+
|
|
107
|
+
# 转换为普通dict
|
|
108
|
+
res = [dict(combo) for combo in partition_combinations]
|
|
65
109
|
|
|
110
|
+
return pl.DataFrame(res)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Copyright (c) ZhangYundi.
|
|
2
|
+
# Licensed under the MIT License.
|
|
3
|
+
# Created on 2025/8/18 11:16
|
|
4
|
+
# Description:
|
|
5
|
+
|
|
6
|
+
import lidb
|
|
7
|
+
import logair
|
|
8
|
+
|
|
9
|
+
logger = logair.get_logger("lidb.test")
|
|
10
|
+
|
|
11
|
+
def test_parse_hive_partition_structure():
|
|
12
|
+
root_path = lidb.tb_path("mc")
|
|
13
|
+
file_pattern = "*.parquet"
|
|
14
|
+
result = lidb.parse.parse_hive_partition_structure(root_path, file_pattern)
|
|
15
|
+
logger.info(result["freq"].unique())
|
|
16
|
+
|
|
17
|
+
if __name__ == '__main__':
|
|
18
|
+
test_parse_hive_partition_structure()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|