Skip to content
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

feat(document-readers): add mysql implements #379

Merged
merged 4 commits into from
Jan 18, 2025

Conversation

brianxiadong
Copy link
Contributor

MySQL Document Reader Implementation

功能描述 | Feature Description

实现了基于Spring AI的MySQL文档读取器,支持从MySQL数据库读取数据并转换为文档格式。

Implemented a MySQL document reader based on Spring AI, supporting reading data from MySQL database and converting it to document format.

主要特性 | Key Features

  • 使用纯JDBC实现,无需额外依赖
    Pure JDBC implementation, no additional dependencies required
  • 支持自定义内容列和元数据列
    Support for custom content and metadata columns
  • 完善的错误处理和资源自动关闭
    Comprehensive error handling and automatic resource cleanup
  • 支持自定义SQL查询
    Support for custom SQL queries

技术实现 | Technical Implementation

  • 使用JDBC直接连接MySQL数据库
    Using JDBC to connect MySQL database directly
  • 支持灵活的字段映射配置
    Supporting flexible field mapping configuration
  • 实现了自动资源管理和异常处理
    Implemented automatic resource management and exception handling
  • 提供了完整的单元测试
    Provided comprehensive unit tests

测试覆盖 | Test Coverage

  • 基本功能测试:文档读取和转换
    Basic functionality tests: document reading and conversion
  • 错误处理测试:无效连接和查询
    Error handling tests: invalid connections and queries
  • 资源管理测试:连接关闭和清理
    Resource management tests: connection closing and cleanup

文档完善 | Documentation

  • 提供了详细的中英文README
    Provided detailed bilingual README
  • 包含了完整的使用示例
    Included complete usage examples
  • 添加了配置参数说明
    Added configuration parameter descriptions
  • 补充了注意事项和最佳实践
    Supplemented with notes and best practices

代码规范 | Code Standards

  • 遵循阿里巴巴Java开发规范
    Following Alibaba Java Development Guidelines
  • 添加了完整的代码注释
    Added complete code comments
  • 实现了统一的异常处理
    Implemented unified exception handling
  • 保持了代码的简洁性和可维护性
    Maintained code simplicity and maintainability

<artifactId>spring-ai-core</artifactId>
</dependency>

<!-- MySQL JDBC Driver -->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里需要引入版本吗?我记得 spring ai alibaba 引入 spring boot parent bom,里面是有 mysql jar 包的,可以复用?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

替换成了mysql-connector-j


### MySQLResource 参数 | Parameters

| 参数 Parameter | 说明 Description | 默认值 Default |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

来个默认值?就是 127.0.0.1:3306 root root?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

</dependency>
</dependencies>

</project>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以空行结尾

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

import org.springframework.ai.document.Document;
import org.springframework.ai.document.DocumentReader;

import java.sql.*;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要用全量引入,用增量引入

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

@brianxiadong brianxiadong requested a review from yuluo-yx January 17, 2025 15:11
@chickenlj chickenlj merged commit ddebd2a into alibaba:main Jan 18, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants