-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat(nl2sql): 在查询中实现时间表达式处理 #2231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- 添加了一种新方法来处理用户查询中的相对时间表达式,并将其转换为特定日期。 - 引入了用于时间转换的新提示模板。 - 更新了 PlannerNode 以利用已处理的查询进行规划。 - 增强了 BaseNl2SqlService 以处理查询重写期间的时间表达式。 - 添加了时间表达式处理功能的单元测试。
- 添加了一种新方法来处理用户查询中的相对时间表达式,并将其转换为特定日期。 - 引入了用于时间转换的新提示模板。 - 更新了 PlannerNode 以利用已处理的查询进行规划。 - 增强了 BaseNl2SqlService 以处理查询重写期间的时间表达式。 - 添加了时间表达式处理功能的单元测试。
Please resolve conflicts |
- 更新了 Nl2sqlConfiguration,将 DatasourceService 包含在 TableRelationNode 中。 - 在 TableRelationNode 中实现了基于代理 ID 动态检索数据库配置的方法。 - 增强的 BaseNl2SqlService 支持使用特定数据库配置进行模式选择,从而改进查询处理。 - 为模式添加了示例数据扩充,以帮助在查询处理期间理解模型。
Please fix CI |
- 将vectorStoreService.getDocuments的参数匹配器更改为使用anyString()而不是eq(query),以便更灵活地进行测试。 - 更新了aiService.call的返回值,以便在多个测试用例中包含对processTimeExpressions的查询。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements time expression processing in Natural Language to SQL (NL2SQL) queries, allowing the system to convert relative time expressions (like "today", "this month", "last year") into specific dates and time ranges before SQL generation.
Key changes include:
- Added a dedicated time conversion prompt template with examples
- Integrated time expression processing into the query rewrite workflow
- Modified test cases to accommodate the additional AI service call for time processing
- Enhanced schema selection with sample data enrichment capabilities
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
BaseNl2SqlService.java | Added processTimeExpressions method and sample data enrichment logic for schema selection |
time-conversion.txt | New prompt template for converting relative time expressions to specific dates |
PromptHelper.java | Added buildTimeConversionPrompt method to generate time conversion prompts |
PromptConstant.java | Added getTimeConversionPromptTemplate method for accessing the time conversion template |
BaseNl2SqlServiceTest.java | Updated test mocks to handle additional AI service calls for time processing |
TableRelationNode.java | Enhanced with agent-specific database configuration support |
PlannerNode.java | Modified to use processed queries with time expressions converted |
Nl2sqlConfiguration.java | Updated constructor call to include datasourceService dependency |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
// TODO 调试AgentID不一致,暂时手动处理 | ||
agentDatasources = datasourceService.getAgentDatasources(agentId - 999999); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hardcoded magic number 999999 and TODO comment indicate a temporary workaround. Consider implementing a proper agent ID mapping mechanism or configuration property instead of this hardcoded offset.
// TODO 调试AgentID不一致,暂时手动处理 | |
agentDatasources = datasourceService.getAgentDatasources(agentId - 999999); | |
// Use configurable agentIdOffset to handle AgentID inconsistency | |
agentDatasources = datasourceService.getAgentDatasources(agentId - agentIdOffset); |
Copilot uses AI. Check for mistakes.
.filter(sample -> sample != null && !sample.trim().isEmpty()) | ||
.distinct() | ||
.limit(5) // 最多保留5个样例值 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic number 5 for sample limit should be extracted to a named constant or configuration property to improve maintainability and allow easy adjustment.
.filter(sample -> sample != null && !sample.trim().isEmpty()) | |
.distinct() | |
.limit(5) // 最多保留5个样例值 | |
.limit(SAMPLE_LIMIT_PER_COLUMN) // 最多保留5个样例值 |
Copilot uses AI. Check for mistakes.
} | ||
expressionList.addAll(dateTimeList); | ||
logger.debug("Processed {} datetime expressions", dateTimeList.size()); | ||
// 时间处理已经在查询重写阶段完成,这里不再需要处理 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The comment is in Chinese. Consider using English comments for consistency with the rest of the codebase, or establish a clear language policy for code comments.
// 时间处理已经在查询重写阶段完成,这里不再需要处理 | |
// Time expressions have already been processed in the query rewrite phase; no further handling needed here |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* feat(nl2sql):在查询中实现时间表达式处理 - 添加了一种新方法来处理用户查询中的相对时间表达式,并将其转换为特定日期。 - 引入了用于时间转换的新提示模板。 - 更新了 PlannerNode 以利用已处理的查询进行规划。 - 增强了 BaseNl2SqlService 以处理查询重写期间的时间表达式。 - 添加了时间表达式处理功能的单元测试。 * feat(nl2sql):在查询中实现时间表达式处理 - 添加了一种新方法来处理用户查询中的相对时间表达式,并将其转换为特定日期。 - 引入了用于时间转换的新提示模板。 - 更新了 PlannerNode 以利用已处理的查询进行规划。 - 增强了 BaseNl2SqlService 以处理查询重写期间的时间表达式。 - 添加了时间表达式处理功能的单元测试。 * feat(nl2sql): 增强 TableRelationNode 和 BaseNl2SqlService 以进行动态数据源处理 - 更新了 Nl2sqlConfiguration,将 DatasourceService 包含在 TableRelationNode 中。 - 在 TableRelationNode 中实现了基于代理 ID 动态检索数据库配置的方法。 - 增强的 BaseNl2SqlService 支持使用特定数据库配置进行模式选择,从而改进查询处理。 - 为模式添加了示例数据扩充,以帮助在查询处理期间理解模型。 * refactor(nl2sql): clean up whitespace in TableRelationNode and BaseNl2SqlService * chore(tests): add license header to AiTimeProcessorTest.java * feat(nl2sql): 移除测试类 * refactor(tests): 更新 BaseNl2SqlServiceTest 中的模拟行为 - 将vectorStoreService.getDocuments的参数匹配器更改为使用anyString()而不是eq(query),以便更灵活地进行测试。 - 更新了aiService.call的返回值,以便在多个测试用例中包含对processTimeExpressions的查询。 * refactor(tests): spring-javaformat:apply * rename var * fix bugs after merge --------- Co-authored-by: VLSMB <2047857654@qq.com>
Describe what this PR does / why we need it
Does this pull request fix one issue?
Describe how you did it
Describe how to verify it
Special notes for reviews