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

[Improve][File Connector]Improve xml read code & fix can not use true for a boolean option #6930

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading