Skip to content

Commit

Permalink
[Improve][File Connector]Improve xml read code & fix can not use true…
Browse files Browse the repository at this point in the history
… for a boolean option (#6930)
  • Loading branch information
EricJoy2048 authored Jun 13, 2024
1 parent 1f33145 commit c13a563
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,9 @@ private String getXPathExpression(String tableRowIdentification) {

/** 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) {
Expand All @@ -265,7 +266,7 @@ private void preCheckAndInitializeConfiguration() {
BaseSourceConfigOptions.XML_USE_ATTR_FORMAT.key()));
}

this.delimiter = getPrimitiveConfigValue(BaseSourceConfigOptions.FIELD_DELIMITER);
this.delimiter = readonlyConfig.get(BaseSourceConfigOptions.FIELD_DELIMITER);

this.dateFormat =
getComplexDateConfigValue(
Expand All @@ -282,21 +283,6 @@ private void preCheckAndInitializeConfiguration() {
.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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

{
xml_row_tag = "RECORD"
xml_use_attr_format = true
xml_use_attr_format = "true"
schema = {
fields {
c_bytes = "tinyint"
Expand Down

0 comments on commit c13a563

Please sign in to comment.