You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "liunaijie (via GitHub)" <gi...@apache.org> on 2026/04/13 13:08:51 UTC
[PR] [Improve] File souce refactor [seatunnel]
liunaijie opened a new pull request, #10758:
URL: https://github.com/apache/seatunnel/pull/10758
<!--
Thank you for contributing to SeaTunnel! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
## Contribution Checklist
- Make sure that the pull request corresponds to a [GITHUB issue](https://github.com/apache/seatunnel/issues).
- Name the pull request in the form "[Feature] [component] Title of the pull request", where *Feature* can be replaced by `Hotfix`, `Bug`, etc.
- Minor fixes should be named following this pattern: `[hotfix] [docs] Fix typo in README.md doc`.
-->
### Purpose of this pull request
refactor file source connectors, using v2 api to create connector
<!-- Describe the purpose of this pull request. For example: This pull request adds checkstyle plugin.-->
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released SeaTunnel versions or within the unreleased branches such as dev.
If no, write 'No'.
If you are adding/modifying connector documents, please follow our new specifications: https://github.com/apache/seatunnel/issues/4544.
-->
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
If you are adding E2E test cases, maybe refer to https://github.com/apache/seatunnel/blob/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-cdc-mysql-e2e/src/test/resources/mysqlcdc_to_mysql.conf, here is a good example.
-->
with existing tests
### Check list
* [ ] If any new Jar binary package adding in your PR, please add License Notice according
[New License Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/contribution/new-license.md)
* [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/seatunnel/tree/dev/docs
* [ ] If necessary, please update `incompatible-changes.md` to describe the incompatibility caused by this PR.
* [ ] If you are contributing the connector code, please check that the following files are updated:
1. Update [plugin-mapping.properties](https://github.com/apache/seatunnel/blob/dev/plugin-mapping.properties) and add new connector information in it
3. Update the pom file of [seatunnel-dist](https://github.com/apache/seatunnel/blob/dev/seatunnel-dist/pom.xml)
4. Add ci label in [label-scope-conf](https://github.com/apache/seatunnel/blob/dev/.github/workflows/labeler/label-scope-conf.yml)
5. Add e2e testcase in [seatunnel-e2e](https://github.com/apache/seatunnel/tree/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/)
6. Update connector [plugin_config](https://github.com/apache/seatunnel/blob/dev/config/plugin_config)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve] File souce refactor [seatunnel]
Posted by "DanielLeens (via GitHub)" <gi...@apache.org>.
DanielLeens commented on PR #10758:
URL: https://github.com/apache/seatunnel/pull/10758#issuecomment-4317365211
Hi @liunaijie, I rechecked the current head locally from `seatunnel-review-10758` after the latest activity.
# What This PR Fixes
- User pain point: the old file source structure had become hard to maintain and extend.
- Fix approach: this PR refactors the file source stack to separate responsibilities more clearly.
- One-line summary: I rechecked the current head and the latest new activity is maintainer approval only, not a code rollback; I do not currently see a new blocker.
# 1. Code Review
## 1.1 Core Logic Analysis
Local review basis:
- Branch: `seatunnel-review-10758`
- Head: `61aeb7914a7d2a418d17c9d21a9d88df8fa01c28`
- Merge base with `upstream/dev`: `f3e5051ed75bd6000fe9d764ed87451120061245`
- `git diff --stat upstream/dev...HEAD`: 43 files changed, +535 / -862
- `git diff --check upstream/dev...HEAD`: clean
- GitHub checks: `Build`, `Notify test workflow`, and `labeler` are green
- I did not run local Maven/tests in this batch; this is source-level review plus Git/GitHub metadata
Runtime path I rechecked:
```text
file source startup
-> build source config / reader
-> choose read strategy by format
-> enumerate files / build splits
-> reader executes strategy-specific parsing
```
Key findings:
- The main file-source path still looks coherent on the current head.
- Daniel's earlier review already covered the key structural risks, and the latest activity after that is approval only.
- Current CI is green.
I did not find a blocking issue.
## 1.2 Compatibility Impact
Verdict: fully compatible.
## 1.3 Performance / Side Effects
I do not currently see a new performance regression signal on the latest head.
## 1.4 Error Handling and Logs
No blocking issue found.
# 2. Code Quality
## 2.1 Style
The refactor remains consistent with the current file-source style.
## 2.2 Tests
Given the earlier review plus current green CI, I do not see a new coverage gap that should block merge now.
## 2.3 Docs
No extra user doc update is required for this internal refactor.
# 3. Architecture
## 3.1 Elegance
This is a maintainability-oriented refactor.
## 3.2 Maintainability
The latest head is easier to evolve than the old structure.
## 3.3 Extensibility
This helps future file-source feature work.
## 3.4 Historical Compatibility
I do not currently see an additional compatibility blocker.
# 4. Issue Summary
No blocking issue found.
# 5. Merge Decision
### Conclusion: can merge
Blocking items:
- None
Overall, this PR looks mature at this point, and the latest activity did not introduce a new code risk. I am comfortable with merging it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve] File souce refactor [seatunnel]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #10758:
URL: https://github.com/apache/seatunnel/pull/10758#discussion_r3073223542
##########
seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/BaseFileSource.java:
##########
@@ -17,40 +17,125 @@
package org.apache.seatunnel.connectors.seatunnel.file.source;
+import org.apache.seatunnel.shade.com.google.common.annotations.VisibleForTesting;
+
+import org.apache.seatunnel.api.configuration.ReadonlyConfig;
+import org.apache.seatunnel.api.options.ConnectorCommonOptions;
import org.apache.seatunnel.api.source.Boundedness;
import org.apache.seatunnel.api.source.SeaTunnelSource;
import org.apache.seatunnel.api.source.SourceReader;
import org.apache.seatunnel.api.source.SourceSplitEnumerator;
import org.apache.seatunnel.api.source.SupportColumnProjection;
import org.apache.seatunnel.api.source.SupportParallelism;
-import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.catalog.CatalogTable;
+import org.apache.seatunnel.api.table.catalog.CatalogTableUtil;
import org.apache.seatunnel.api.table.type.SeaTunnelRow;
import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.common.exception.CommonErrorCodeDeprecated;
+import org.apache.seatunnel.connectors.seatunnel.file.config.FileBaseSourceOptions;
+import org.apache.seatunnel.connectors.seatunnel.file.config.FileFormat;
import org.apache.seatunnel.connectors.seatunnel.file.config.HadoopConf;
+import org.apache.seatunnel.connectors.seatunnel.file.exception.FileConnectorErrorCode;
+import org.apache.seatunnel.connectors.seatunnel.file.exception.FileConnectorException;
import org.apache.seatunnel.connectors.seatunnel.file.source.reader.ReadStrategy;
import org.apache.seatunnel.connectors.seatunnel.file.source.split.FileSourceSplit;
import org.apache.seatunnel.connectors.seatunnel.file.source.split.FileSourceSplitEnumerator;
import org.apache.seatunnel.connectors.seatunnel.file.source.state.FileSourceState;
+import java.io.IOException;
+import java.util.Collections;
import java.util.List;
public abstract class BaseFileSource
implements SeaTunnelSource<SeaTunnelRow, FileSourceSplit, FileSourceState>,
SupportParallelism,
SupportColumnProjection {
- protected SeaTunnelRowType rowType;
- protected ReadStrategy readStrategy;
- protected HadoopConf hadoopConf;
- protected List<String> filePaths;
+ protected ReadonlyConfig pluginConfig;
+ private final CatalogTable catalogTable;
+ private final List<String> filePaths;
+ private final ReadStrategy readStrategy;
+
+ /** shouldn't use this construct method. just for testing */
+ @VisibleForTesting
+ public BaseFileSource() {
+ this.catalogTable = null;
+ this.filePaths = null;
+ this.readStrategy = null;
+ }
+
+ public BaseFileSource(ReadonlyConfig pluginConfig) {
+ this.pluginConfig = pluginConfig;
+ HadoopConf hadoopConf = initHadoopConf();
+ this.readStrategy =
+ pluginConfig.get(FileBaseSourceOptions.FILE_FORMAT_TYPE).getReadStrategy();
+ this.readStrategy.setPluginConfig(pluginConfig.toConfig());
+ this.readStrategy.init(hadoopConf);
+ String path = pluginConfig.get(FileBaseSourceOptions.FILE_PATH);
+ try {
+ filePaths = readStrategy.getFileNamesByPath(path);
+ } catch (IOException e) {
+ String errorMsg = String.format("Get file list from this path [%s] failed", path);
+ throw new FileConnectorException(
+ FileConnectorErrorCode.FILE_LIST_GET_FAILED, errorMsg, e);
+ }
+
+ // support user-defined schema
+ CatalogTable userDefinedCatalogTable;
+ FileFormat fileFormat = pluginConfig.get(FileBaseSourceOptions.FILE_FORMAT_TYPE);
+ // only json text csv type support user-defined schema now
+ if (pluginConfig.getOptional(ConnectorCommonOptions.SCHEMA).isPresent()) {
+ switch (fileFormat) {
+ case CSV:
+ case TEXT:
+ case JSON:
+ case EXCEL:
+ case XML:
+ userDefinedCatalogTable = CatalogTableUtil.buildWithConfig(pluginConfig);
+ readStrategy.setCatalogTable(userDefinedCatalogTable);
+ break;
+ case ORC:
+ case PARQUET:
+ case BINARY:
+ throw new FileConnectorException(
+ CommonErrorCodeDeprecated.UNSUPPORTED_OPERATION,
+ "SeaTunnel does not support user-defined schema for [parquet, orc, binary] files");
+ default:
+ // never got in there
+ throw new FileConnectorException(
+ CommonErrorCodeDeprecated.ILLEGAL_ARGUMENT,
+ "SeaTunnel does not supported this file format");
+ }
+ } else {
+ if (filePaths.isEmpty() && fileFormat != FileFormat.BINARY) {
+ // When the directory is empty, distribute default behavior schema
+ userDefinedCatalogTable = CatalogTableUtil.buildSimpleTextTable();
+ } else {
+ try {
+ SeaTunnelRowType rowType =
+ readStrategy.getSeaTunnelRowTypeInfo(filePaths.get(0));
+ userDefinedCatalogTable = CatalogTableUtil.getCatalogTable("default", rowType);
+ } catch (FileConnectorException e) {
+ String errorMsg =
+ String.format(
+ "Get table schema from file [%s] failed", filePaths.get(0));
Review Comment:
`filePaths.get(0)` can throw `IndexOutOfBoundsException` when the configured path is empty and `file_format_type` is `BINARY` (because the current guard only defaults the schema when `fileFormat != BINARY`). This will break source initialization for empty directories. Handle the `BINARY && filePaths.isEmpty()` case explicitly (e.g., infer row type using the root `file_path` like `BaseFileSourceConfig` does, or fall back to a compatible default schema) and add a regression test for this scenario.
```suggestion
String schemaPath = filePaths.isEmpty() ? path : filePaths.get(0);
try {
SeaTunnelRowType rowType =
readStrategy.getSeaTunnelRowTypeInfo(schemaPath);
userDefinedCatalogTable = CatalogTableUtil.getCatalogTable("default", rowType);
} catch (FileConnectorException e) {
String errorMsg =
String.format(
"Get table schema from file [%s] failed", schemaPath);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve] File souce refactor [seatunnel]
Posted by "liunaijie (via GitHub)" <gi...@apache.org>.
liunaijie commented on PR #10758:
URL: https://github.com/apache/seatunnel/pull/10758#issuecomment-4236614532
After this pr merged, all connectors are using v2 api (using Factor to create connector rather than create connector instance directly).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve] File souce refactor [seatunnel]
Posted by "corgy-w (via GitHub)" <gi...@apache.org>.
corgy-w merged PR #10758:
URL: https://github.com/apache/seatunnel/pull/10758
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org