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

Logging field specification and value extraction errors #519

Merged
merged 5 commits into from
Mar 13, 2018

Conversation

lorenaqendro
Copy link
Contributor

Description

  • add exception when illegal args are included in the recipe
  • add exception when the field cannot be computed
  • change color of error log in the data export runner
  • renaming in percentile field
  • update tests

Fixes #269

Checklist

  • Created new test(s) (if applicable)
  • Updated tests
  • Updated the README / documentation (if applicable)

- add exception when the field cannot be computed
- change color of error log in the data export runner
- renaming in percentile field
Copy link
Contributor

@arya-hemanshu arya-hemanshu left a comment

Choose a reason for hiding this comment

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

Looks good in general, please look at the comments.

try {
value = ((SingleValueField) field).valueForSubject(subject, timeStamp);
} catch (IncomputableFieldException e){
// Keep calm and continue processing ... we will back-off
continue;
} catch (ClassCastException cce) {
throw new IllegalArgumentException("Parameters for BackOffField must be of type SingleValueField.");
Copy link
Contributor

Choose a reason for hiding this comment

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

I think exception here is redundant, as we are already catching that in initialize

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Catching a different one here.

Copy link
Contributor

Choose a reason for hiding this comment

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

which one? I think we are looping over the same fields which are added through intialize method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ClassCastException here and ClassNotFoundException in initialize().

Copy link
Contributor

Choose a reason for hiding this comment

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

my bad, i was always reading class. Need to start reading class names more thoroughly :)

@@ -71,11 +71,11 @@ protected void initialize(){
try {
Field field = fieldRecipe.toField();
if (!(field instanceof SingleValueField))
throw new IncomputableFieldException("Parameters for DescriptiveStatisticsField must be of type SingleValueField");
throw new IllegalArgumentException("Parameters for DescriptiveStatisticsField must be of type SingleValueField");
Copy link
Contributor

Choose a reason for hiding this comment

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

Earlier we were trying to cast to field and then throwing as cast exception, here we are using a different approach for same thing, it feels to me a little inconsistent

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 wouldn't say it's inconsistent as it expresses a different way of doing the same thing, which does not manifest inconsistency in the behaviour itself. I would say that both ways are acceptable. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

It's the consistency of writing code i was talking about not the intended behaviour. It just looks more neat. However it's okay if you would prefer this way


try {
singleValueFields = new ArrayList<>();

for (FieldRecipe fieldRecipe: fields) {
Field field = fieldRecipe.toField();
if (!(field instanceof SingleValueField))
throw new IncomputableFieldException("Parameters for LinearCombinationField must be of type SingleValueField");
throw new IllegalArgumentException("Parameters for LinearCombinationField must be of type SingleValueField");
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good if we follow the same approach of cast and catching the exception, just to be consistent

throw new IncomputableFieldException(String.format("No attribute found for provider %s and label %s", attribute.provider, attribute.label));
} else {
attributeObject = attr;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't that the attributeObject will always be null when this field is called as the object is private and is not initialised. Can we write it like

            Attribute attr = AttributeUtils.getByProviderAndLabel(attribute.provider, attribute.label);
            if (null == attr) {
                throw new IncomputableFieldException(String.format("No attribute found for provider %s and label %s", attribute.provider, attribute.label));
            } 

        return attr;

and remove the above attributeObject

if (timedValues.isEmpty()) {
throw new IncomputableFieldException(String.format("No TimedValue found for attribute %s", getAttribute().getLabel()));
}
arr.addAll(timedValues.stream().map(timedValue -> {
JSONObject pair = new JSONObject();
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's empty we can just return after throwing the exception

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 won't get far after the exception is thrown. What I can do is create the json array object after so we don't waste one.

if (timedValue.isEmpty()) {
throw new IncomputableFieldException(String.format("No TimedValue found for attribute %s", getAttribute().getLabel()));
}

Copy link
Contributor

Choose a reason for hiding this comment

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

we can return from here if it is empty

@@ -69,8 +69,12 @@ public void write(Writer writer, List<Subject> subjects, List<Field> fields, Boo
try {
property.put(field.getLabel(), ((SingleValueField) field).valueForSubject(subject, timeStamp));
} catch (IncomputableFieldException e) {
log.warn("Could not compute Field {} for Subject {}, reason: {}", field.getLabel(), subject.getLabel(), e.getMessage());
log.warn("\u001b[0;33m" + "Could not compute Field {} for Subject {}, reason: {}" + "\u001b[m",
field.getLabel(), subject.getLabel(), e.getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good if we could have a constant class containing these formats, so that we dont have to write them again and again when required, we could just refer to those constants.

@lorenaqendro
Copy link
Contributor Author

@arya-hemanshu can you have another look?

Copy link
Contributor

@arya-hemanshu arya-hemanshu left a comment

Choose a reason for hiding this comment

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

looks good to merge

@lorenaqendro lorenaqendro merged commit 3de0887 into master Mar 13, 2018
@lorenaqendro lorenaqendro deleted the lq-269-log_err_math_op_strings branch March 13, 2018 10:26
@lorenaqendro lorenaqendro added this to the Release Candidate milestone Mar 14, 2018
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.

2 participants