This is an automated email from the ASF dual-hosted git repository.
wanghailin pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/seatunnel.git
The following commit(s) were added to refs/heads/dev by this push:
new c13a563994 [Improve][File Connector]Improve xml read code & fix can
not use true for a boolean option (#6930)
c13a563994 is described below
commit c13a5639947a5026ac03887cadce9c289c056902
Author: Eric <[email protected]>
AuthorDate: Thu Jun 13 15:04:57 2024 +0800
[Improve][File Connector]Improve xml read code & fix can not use true for a
boolean option (#6930)
---
.../file/source/reader/XmlReadStrategy.java | 22 ++++------------------
.../src/test/resources/xml/test_read_xml.conf | 2 +-
2 files changed, 5 insertions(+), 19 deletions(-)
diff --git
a/seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/reader/XmlReadStrategy.java
b/seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/reader/XmlReadStrategy.java
index d09431f12b..814a9fbdb5 100644
---
a/seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/reader/XmlReadStrategy.java
+++
b/seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/reader/XmlReadStrategy.java
@@ -252,8 +252,9 @@ public class XmlReadStrategy extends AbstractReadStrategy {
/** Performs pre-checks and initialization of the configuration for
reading XML files. */
private void preCheckAndInitializeConfiguration() {
- this.tableRowName =
getPrimitiveConfigValue(BaseSourceConfigOptions.XML_ROW_TAG);
- this.useAttrFormat =
getPrimitiveConfigValue(BaseSourceConfigOptions.XML_USE_ATTR_FORMAT);
+ ReadonlyConfig readonlyConfig =
ReadonlyConfig.fromConfig(pluginConfig);
+ this.tableRowName =
readonlyConfig.get(BaseSourceConfigOptions.XML_ROW_TAG);
+ this.useAttrFormat =
readonlyConfig.get(BaseSourceConfigOptions.XML_USE_ATTR_FORMAT);
// Check mandatory configurations
if (StringUtils.isEmpty(tableRowName) || useAttrFormat == null) {
@@ -265,7 +266,7 @@ public class XmlReadStrategy extends AbstractReadStrategy {
BaseSourceConfigOptions.XML_USE_ATTR_FORMAT.key()));
}
- this.delimiter =
getPrimitiveConfigValue(BaseSourceConfigOptions.FIELD_DELIMITER);
+ this.delimiter =
readonlyConfig.get(BaseSourceConfigOptions.FIELD_DELIMITER);
this.dateFormat =
getComplexDateConfigValue(
@@ -282,21 +283,6 @@ public class XmlReadStrategy extends AbstractReadStrategy {
.orElse(StandardCharsets.UTF_8.name());
}
- /**
- * Retrieves the value of a primitive configuration option.
- *
- * @param option the configuration option to retrieve the value for
- * @param <T> the type of the configuration option
- * @return the value of the configuration option, or the default value if
the option is not set
- */
- @SuppressWarnings("unchecked")
- private <T> T getPrimitiveConfigValue(Option<?> option) {
- if (!pluginConfig.hasPath(option.key())) {
- return (T) option.defaultValue();
- }
- return (T) pluginConfig.getAnyRef(option.key());
- }
-
/**
* Retrieves the complex date configuration value for the given option.
*
diff --git
a/seatunnel-connectors-v2/connector-file/connector-file-base/src/test/resources/xml/test_read_xml.conf
b/seatunnel-connectors-v2/connector-file/connector-file-base/src/test/resources/xml/test_read_xml.conf
index f81534b8b7..8e0aab2b0e 100644
---
a/seatunnel-connectors-v2/connector-file/connector-file-base/src/test/resources/xml/test_read_xml.conf
+++
b/seatunnel-connectors-v2/connector-file/connector-file-base/src/test/resources/xml/test_read_xml.conf
@@ -17,7 +17,7 @@
{
xml_row_tag = "RECORD"
- xml_use_attr_format = true
+ xml_use_attr_format = "true"
schema = {
fields {
c_bytes = "tinyint"