Skip to content

Commit de7b86a

Browse files
authored
[fix][hive-source][bug] fix An error occurred reading an empty directory (#5427)
* [fix][hive-source][bug] fix An error occurred reading an empty directory * [fix][hive-source][bug] fix An error occurred reading an empty directory
1 parent cef03f6 commit de7b86a

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/reader/AbstractReadStrategy.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
2525
import org.apache.seatunnel.connectors.seatunnel.file.config.BaseSourceConfig;
2626
import org.apache.seatunnel.connectors.seatunnel.file.config.HadoopConf;
27-
import org.apache.seatunnel.connectors.seatunnel.file.exception.FileConnectorErrorCode;
28-
import org.apache.seatunnel.connectors.seatunnel.file.exception.FileConnectorException;
2927
import org.apache.seatunnel.connectors.seatunnel.file.sink.util.FileSystemUtils;
3028

3129
import org.apache.hadoop.conf.Configuration;
@@ -153,15 +151,9 @@ public List<String> getFileNamesByPath(HadoopConf hadoopConf, String path) throw
153151
}
154152
}
155153
}
156-
157-
if (fileNames.isEmpty()) {
158-
throw new FileConnectorException(
159-
FileConnectorErrorCode.FILE_LIST_EMPTY,
160-
"The target file list is empty,"
161-
+ "SeaTunnel will not be able to sync empty table, "
162-
+ "please check the configuration parameters such as: [file_filter_pattern]");
154+
if (this.fileNames.isEmpty()) {
155+
log.error("The current directory is empty " + path);
163156
}
164-
165157
return fileNames;
166158
}
167159

@@ -196,10 +188,12 @@ public SeaTunnelRowType getActualSeaTunnelRowTypeInfo() {
196188

197189
protected Map<String, String> parsePartitionsByPath(String path) {
198190
LinkedHashMap<String, String> partitions = new LinkedHashMap<>();
199-
Arrays.stream(path.split("/", -1))
200-
.filter(split -> split.contains("="))
201-
.map(split -> split.split("=", -1))
202-
.forEach(kv -> partitions.put(kv[0], kv[1]));
191+
if (path != null && !path.isEmpty()) {
192+
Arrays.stream(path.split("/", -1))
193+
.filter(split -> split.contains("="))
194+
.map(split -> split.split("=", -1))
195+
.forEach(kv -> partitions.put(kv[0], kv[1]));
196+
}
203197
return partitions;
204198
}
205199

seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/reader/ExcelReadStrategy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ public void setSeaTunnelRowTypeInfo(SeaTunnelRowType seaTunnelRowType) {
136136
"Schmea information is not set or incorrect schmea settings");
137137
}
138138
SeaTunnelRowType userDefinedRowTypeWithPartition =
139-
mergePartitionTypes(fileNames.get(0), seaTunnelRowType);
139+
mergePartitionTypes(
140+
fileNames.size() > 0 ? fileNames.get(0) : null, seaTunnelRowType);
140141
// column projection
141142
if (pluginConfig.hasPath(BaseSourceConfig.READ_COLUMNS.key())) {
142143
// get the read column index from user-defined row type

seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/reader/TextReadStrategy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ public SeaTunnelRowType getSeaTunnelRowTypeInfo(HadoopConf hadoopConf, String pa
138138
@Override
139139
public void setSeaTunnelRowTypeInfo(SeaTunnelRowType seaTunnelRowType) {
140140
SeaTunnelRowType userDefinedRowTypeWithPartition =
141-
mergePartitionTypes(fileNames.get(0), seaTunnelRowType);
141+
mergePartitionTypes(
142+
fileNames.size() > 0 ? fileNames.get(0) : null, seaTunnelRowType);
142143
if (pluginConfig.hasPath(BaseSourceConfig.DELIMITER.key())) {
143144
fieldDelimiter = pluginConfig.getString(BaseSourceConfig.DELIMITER.key());
144145
} else {

0 commit comments

Comments
 (0)