mongo-2-sql 0.1.4__tar.gz → 0.1.6__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.
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/LICENSE +2 -2
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/PKG-INFO +78 -33
- mongo_2_sql-0.1.4/src/mongo_2_sql.egg-info/PKG-INFO → mongo_2_sql-0.1.6/README.md +632 -613
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/pyproject.toml +7 -1
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/core/expr_parser_base.py +5 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/core/stage_base.py +0 -1
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/main.py +1 -1
- mongo_2_sql-0.1.6/src/mongo_2_sql/stages/add_fields/expr.py +421 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/stages/add_fields/stage.py +2 -2
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/stages/group/expr.py +0 -7
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/stages/project/expr.py +51 -51
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/stages/project/stage.py +3 -8
- mongo_2_sql-0.1.4/README.md → mongo_2_sql-0.1.6/src/mongo_2_sql.egg-info/PKG-INFO +658 -591
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql.egg-info/SOURCES.txt +2 -3
- mongo_2_sql-0.1.6/tests/test.py +412 -0
- mongo_2_sql-0.1.6/tests/test1.py +74 -0
- mongo_2_sql-0.1.4/tests/test.py +0 -209
- mongo_2_sql-0.1.4/tests/test1.py +0 -45
- mongo_2_sql-0.1.4/tests/test_all_examples.py +0 -133
- mongo_2_sql-0.1.4/tests/test_complex_pipelines.py +0 -287
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/setup.cfg +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/__init__.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/converter.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/core/__init__.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/core/ast_base.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/core/cte_manager.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/core/cte_stage_base.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/core/expr_base.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/core/expr_registry.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/core/expression_resolver.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/core/pipeline_runtime.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/core/stage_loader.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/renderer/__init__.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/renderer/sqlite.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/stages/__init__.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/stages/add_fields/__init__.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/stages/group/__init__.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/stages/group/stage.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/stages/limit/__init__.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/stages/limit/stage.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/stages/lookup/__init__.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/stages/lookup/stage.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/stages/match/__init__.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/stages/match/expr.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/stages/match/stage.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/stages/project/__init__.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/stages/sort/__init__.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/stages/sort/stage.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/stages/unwind/__init__.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/stages/unwind/stage.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql/utils.py +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql.egg-info/dependency_links.txt +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql.egg-info/entry_points.txt +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql.egg-info/requires.txt +0 -0
- {mongo_2_sql-0.1.4 → mongo_2_sql-0.1.6}/src/mongo_2_sql.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2026
|
|
3
|
+
Copyright (c) 2026 baobingbo
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mongo-2-sql
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.6
|
|
4
4
|
Summary: A library to convert MongoDB aggregation pipelines to SQL parser
|
|
5
5
|
Author-email: Bao Bingbo <baob2@outlook.com>
|
|
6
6
|
License: MIT License
|
|
7
|
+
Project-URL: Homepage, https://github.com/baobingbo/mongo-2-sql
|
|
8
|
+
Project-URL: Documentation, https://github.com/baobingbo/mongo-2-sql#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/baobingbo/mongo-2-sql.git
|
|
10
|
+
Project-URL: Issues, https://github.com/baobingbo/mongo-2-sql/issues
|
|
7
11
|
Classifier: Development Status :: 4 - Beta
|
|
8
12
|
Classifier: Intended Audience :: Developers
|
|
9
13
|
Classifier: License :: OSI Approved :: MIT License
|
|
@@ -24,42 +28,62 @@ Dynamic: license-file
|
|
|
24
28
|
|
|
25
29
|
Mongo to SQL 是一个将 MongoDB 聚合管道转换为 SQL 查询语句的工具。
|
|
26
30
|
|
|
27
|
-
##
|
|
31
|
+
## 项目仓库
|
|
28
32
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
#### 1. CTE(公用表表达式)统一处理
|
|
32
|
-
- **$addFields、$project、$group 阶段现在使用 CTE 方式处理**
|
|
33
|
-
- 将复杂的聚合管道拆分为多个SQL片段,使用 WITH 子句拼接
|
|
34
|
-
- 自动管理 CTE 命名和依赖关系
|
|
35
|
-
- 适用于多次投影、多层分组等复杂场景
|
|
36
|
-
|
|
37
|
-
#### 2. 表达式解析器统一架构
|
|
38
|
-
- **ExpressionResolver**: 统一的表达式解析器入口,避免 stage 之间相互 import
|
|
39
|
-
- **BaseExpressionParser**: 基础表达式解析器基类,减少代码重复
|
|
40
|
-
- 提供通用操作符集合、字段引用解析、值转换等基础功能
|
|
33
|
+
- **GitHub**: [baobingbo/mongo-2-sql](https://github.com/baobingbo/mongo-2-sql)
|
|
41
34
|
|
|
42
|
-
|
|
43
|
-
- 使用 sqlparse 库自动格式化 SQL
|
|
44
|
-
- SELECT、FROM、WHERE、GROUP BY 等关键字独占一行
|
|
45
|
-
- 字段列表缩进对齐,提高可读性
|
|
46
|
-
- WHERE 子句添加注释提示可扩展性
|
|
35
|
+
## 版本更新 v0.1.6
|
|
47
36
|
|
|
48
|
-
|
|
49
|
-
- 支持字段重命名语法: `{"new_name": "$old_name"}`
|
|
50
|
-
- 聚合后字段引用自动处理(无需添加表前缀)
|
|
51
|
-
- 支持包含模式和排除模式
|
|
52
|
-
|
|
53
|
-
#### 5. Stage 解耦架构
|
|
54
|
-
- 各 stage 表达式解析器通过统一的 ExpressionResolver 进行交互
|
|
55
|
-
- 避免模块之间的循环依赖
|
|
56
|
-
- 更易于扩展和维护
|
|
57
|
-
|
|
58
|
-
### 问题修复
|
|
37
|
+
### 新增功能
|
|
59
38
|
|
|
60
|
-
|
|
61
|
-
-
|
|
62
|
-
-
|
|
39
|
+
#### 1. $addFields 阶段表达式与字面量语义
|
|
40
|
+
- `$addFields` 使用独立的 `AddFieldsExpressionParser`,不再复用 `$project` 的解析逻辑,避免跨阶段耦合
|
|
41
|
+
- `$addFields` 支持三类值:
|
|
42
|
+
- **字面量值**: 如 `{"score": 1}`, `{ "flag": true }`, `{ "text": "hello" }`,会直接转换为 `1 AS score`、`TRUE AS flag`、`'hello' AS text`
|
|
43
|
+
- **字段引用**: 如 `{ "cat": "$category" }`,会转换为 `t.category AS cat`
|
|
44
|
+
- **表达式**: 如 `{ "total": { "$add": [1, "$price"] } }` 或 `{ "isBig": { "$gt": ["$amount", 100] } }`
|
|
45
|
+
- **仅 `$project` 阶段中**,`{"field": 1}` / `{"field": 0}` 仍然表示"包含/排除字段";其他阶段(包括 `$addFields`)中,`1` 始终被视为字面量数值 1
|
|
46
|
+
|
|
47
|
+
#### 2. $addFields 阶段多种解析方式增强
|
|
48
|
+
在 `stages/add_fields/expr.py` 中新增了以下操作符的解析支持:
|
|
49
|
+
|
|
50
|
+
**算术操作符**:
|
|
51
|
+
- `$add` - 加法运算(对应 SQL: `+`)
|
|
52
|
+
- `$subtract` - 减法运算(对应 SQL: `-`)
|
|
53
|
+
- `$multiply` - 乘法运算(对应 SQL: `*`)
|
|
54
|
+
- `$divide` - 除法运算(对应 SQL: `/`)
|
|
55
|
+
- `$mod` - 取模运算(对应 SQL: `%`)
|
|
56
|
+
|
|
57
|
+
**字符串操作符**:
|
|
58
|
+
- `$concat` - 字符串连接(对应 SQL: `CONCAT()`)
|
|
59
|
+
- `$toLower` - 转小写(对应 SQL: `LOWER()`)
|
|
60
|
+
- `$toUpper` - 转大写(对应 SQL: `UPPER()`)
|
|
61
|
+
- `$substr` - 子字符串截取(对应 SQL: `SUBSTR()`)
|
|
62
|
+
|
|
63
|
+
**日期操作符**:
|
|
64
|
+
- `$dateToString` - 日期格式化(对应 SQL: `STRFTIME()`)
|
|
65
|
+
- `$year` - 提取年份
|
|
66
|
+
- `$month` - 提取月份
|
|
67
|
+
- `$dayOfMonth` - 提取日期
|
|
68
|
+
- `$hour` - 提取小时
|
|
69
|
+
- `$minute` - 提取分钟
|
|
70
|
+
- `$second` - 提取秒
|
|
71
|
+
|
|
72
|
+
**条件操作符**:
|
|
73
|
+
- `$cond` - 条件判断(对应 SQL: `CASE WHEN`)
|
|
74
|
+
- `$ifNull` - 空值处理(对应 SQL: `COALESCE()`)
|
|
75
|
+
|
|
76
|
+
**比较操作符**:
|
|
77
|
+
- `$eq` - 等于(对应 SQL: `=`)
|
|
78
|
+
- `$ne` - 不等于(对应 SQL: `!=`)
|
|
79
|
+
- `$gt` - 大于(对应 SQL: `>`)
|
|
80
|
+
- `$gte` - 大于等于(对应 SQL: `>=`)
|
|
81
|
+
- `$lt` - 小于(对应 SQL: `<`)
|
|
82
|
+
- `$lte` - 小于等于(对应 SQL: `<=`)
|
|
83
|
+
|
|
84
|
+
**数组操作符**:
|
|
85
|
+
- `$size` - 数组长度(对应 SQL: `JSON_ARRAY_LENGTH()`)
|
|
86
|
+
- `$arrayElemAt` - 数组元素访问(对应 SQL: `JSON_EXTRACT()`)
|
|
63
87
|
|
|
64
88
|
## 功能特性
|
|
65
89
|
|
|
@@ -583,6 +607,27 @@ MIT License - 详见 [LICENSE](LICENSE) 文件
|
|
|
583
607
|
|
|
584
608
|
## 变更日志
|
|
585
609
|
|
|
610
|
+
### v0.1.6 (2026-03-15)
|
|
611
|
+
|
|
612
|
+
**新增功能:**
|
|
613
|
+
- $addFields 阶段独立解析器(AddFieldsExpressionParser),与 project 解耦
|
|
614
|
+
- $addFields 支持字面量值、字段引用、表达式三类语义
|
|
615
|
+
- 统一数值 1 为字面量(仅 $project 阶段保留包含/排除语义)
|
|
616
|
+
- $addFields 阶段新增多种操作符解析支持:
|
|
617
|
+
- 算术操作符:$add, $subtract, $multiply, $divide, $mod
|
|
618
|
+
- 字符串操作符:$concat, $toLower, $toUpper, $substr
|
|
619
|
+
- 日期操作符:$dateToString, $year, $month, $dayOfMonth, $hour, $minute, $second
|
|
620
|
+
- 条件操作符:$cond, $ifNull
|
|
621
|
+
- 比较操作符:$eq, $ne, $gt, $gte, $lt, $lte
|
|
622
|
+
- 数组操作符:$size, $arrayElemAt
|
|
623
|
+
|
|
624
|
+
### v0.1.5 (2025-02-23)
|
|
625
|
+
|
|
626
|
+
**新增功能:**
|
|
627
|
+
- addFields阶段独立解析器(AddFieldsExpressionParser),与 project 解耦
|
|
628
|
+
- 支持字面量值、字段引用、表达式三类语义
|
|
629
|
+
- 统一数值 1 为字面量(仅 $project 阶段保留包含/排除语义)
|
|
630
|
+
|
|
586
631
|
### v0.1.4 (2025-02-13)
|
|
587
632
|
|
|
588
633
|
**新增功能:**
|