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

Translate Processor - Added file_path functionality for local files #3034

Merged
merged 4 commits into from
Jul 19, 2023

Conversation

vishalboin
Copy link
Contributor

Description

Added implementation for file_path option for local files. Fixed some bugs. Changed target_type to type. Test cases for added features.

Issues Resolved

#1914

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added
  • Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@vishalboin vishalboin changed the title Translate Processor - Added file_path option functionality Translate Processor - Added file_path functionality for local files Jul 17, 2023
//todo
mappingsConfig = translateProcessorConfig.getCombinedParameterConfigs();
Optional.ofNullable(mappingsConfig)
.ifPresent(configs -> configs.forEach(MappingsParameterConfig::parseMappings));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to stop the pipeline if only file_path option is present and the file is invalid?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. If the mappings provided in the file_path option are not configured properly, pipeline will fail during the config check. This behavior is irrespective of only file_path option provided or both file_path and mappings options provided.

graytaylor0
graytaylor0 previously approved these changes Jul 19, 2023
Comment on lines +12 to +13
@JsonProperty("mappings")
@Valid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these annotations doing anything? This isn't a part of the user configuration right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeahh.
@JsonProperty : The file provided will consist of option mappings, under which translations will be provided. Since I am using a different variable name fileMappingConfigs in the FilePathPraser.Class, @JsonProperty is required to indicate that mappings filed should be mapped to fileMappingConfigs

@Valid : The type of fileMappingConfigs is List<MappingParameterConfig>. MappingParameterConfig.Class consists of validation checks for the options provided under mappings like source, targets. To validate those checks we need to provide the @Valid annotation.

return (Objects.nonNull(mappingsParameterConfigs) && !mappingsParameterConfigs.isEmpty()) || Objects.nonNull(filePath);
}

@AssertTrue(message = "\"mappings\" option should not be empty.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the @NotEmpty annotation not working?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works. But in this particular case, the pipeline should succeed even if only file_path option is provided. @NotEmpty annotation checks if the field is either empty or null. So if the mappings option is not provided it fails, even if file_path option is provided. This check I provided is required because if the user configures mappings: option but there are no sub-options configured, the pipeline should fail. Like in the scenario below:

 processor:
   - translate:
       file_path: "/path/to/file.yaml"
       mappings:
       

Optional<List<MappingsParameterConfig>> optionalCombinedConfigs = fileParser.getCombinedMappings(mappingsParameterConfigs);
optionalCombinedConfigs.ifPresent(combinedConfigs -> combinedParameterConfigs = combinedConfigs);
return Optional.ofNullable(combinedParameterConfigs).map(configs -> true).orElse(false);
} catch (IOException ex) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we log this error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will address this in the next PR.

@@ -71,6 +73,8 @@ private boolean readFileMappings(String filePath) {
optionalCombinedConfigs.ifPresent(combinedConfigs -> combinedParameterConfigs = combinedConfigs);
return Optional.ofNullable(combinedParameterConfigs).map(configs -> true).orElse(false);
} catch (IOException ex) {
Logger LOG = LoggerFactory.getLogger(TranslateProcessor.class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should declare these at the top private static final Logger LOG = ...

@kkondaka kkondaka merged commit 958c15e into opensearch-project:main Jul 19, 2023
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants