优化SQL查询的行数限制、数据导出工单统计语句实现方法,CTE语句支持和新增SQL详情展示功能 #3044
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
优化SQL查询的行数限制实现方法与新增SQL详情展示功能
功能描述
提交主要包含两个核心功能的优化与新增:
所有修改均已通过基本测试,兼容多种数据库引擎。
修改内容
1. 依赖更新
requirements.txt:添加sqlglot依赖,用于SQL方言解析和处理2. 数据库模型修改
sql/models.py:添加original_sql字段,用于存储原始SQL语句3. SQL处理逻辑优化
sql/offlinedownload.py:修改引用新的方法包装count语句,提高准确性和通用性sql/query.py:添加判断逻辑使用limit和count语句sql/utils/sql_utils.py:新增SqlglotUtils工具类,统一处理SQL的limit和count语句以及方言适配的判断4. 数据库引擎增强
sql/engines/odps.py:添加CTE支持,去除冗余limit代码sql/engines/goinception.py:修复SQL脱敏问题sql/engines/mssql.py:添加CTE语法支持sql/engines/mysql.py:添加CTE语法支持sql/engines/oracle.py:添加CTE语法支持sql/engines/pgsql.py:添加CTE语法支持5. 前端界面改进
sql/templates/sqlexportsubmit.html:添加工单导出参数和original_sql内容sql/templates/sqlquery.html:新增SQL详情弹出框,展示原始SQL和执行SQL6. 测试用例更新
sql/tests.py:更新或添加测试用例sql/test_offlinedownload.py:更新或添加测试用例sql/utils/test_sql_utils.py:更新或添加测试用例7. sql变更
测试验证
本次修改已对以下数据库进行实际的测试:
✅ 支持SELECT和CTE查询及数据导出工单
✅ 支持SELECT查询及数据导出工单
展开显示原语句和执行语句及复制

SQL详情显示原语句和执行语句及复制
