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

Add assertions on input types #62

Merged
merged 1 commit into from
May 23, 2018
Merged

Conversation

jameslamb
Copy link
Collaborator

This PR introduces assertthat as a dependency and adds a bunch of assertions on inputs. This will help in debugging and add extra protection against unintended queries being executed on users' ES clusters.

, assertthat::is.number(max_hits)
, max_hits >= 0
, assertthat::is.number(n_cores)
, n_cores >= 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you change the n_cores assertions to assertthat::is.count(n_cores)? is.count checks to make sure it's a single positive integer.

Unrelatedly, I wish is.count had a flag or something to allow 0, because checking for a single nonnegative integer is pretty tricky right now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah good call. I actually don't mind that they force you to break it into two things. More explicit is better than controlling with flags!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Definitely true that more explicit is better, but in my intuition 0 should technically be a valid "count" haha. So maybe that's the root of my complaint.

, assertthat::is.number(n_cores)
, n_cores >= 1
, assertthat::is.flag(break_on_duplicates)
, assertthat::is.flag(ignore_scroll_restriction)
Copy link
Collaborator

Choose a reason for hiding this comment

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

May want to check that these args aren't NA. Unfortunately assertthat::is.flag(NA) is TRUE because NAs are logical by default.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ah yep, good catch

, assertthat::is.string(use_na)
, use_na != ""
, assertthat::is.number(max_terms)
, max_terms > 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

is.count would work here too.

Copy link
Collaborator

@austin3dickey austin3dickey left a comment

Choose a reason for hiding this comment

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

LGTM! I suggested a few tweaks, and looks like you need to fix the failing build.

@jameslamb
Copy link
Collaborator Author

@austin3dickey I just made the changes you recommended. The build failing was just R CMD CHECK doing its thankless but important job! I had used query in a few places where the object is actually called query_body.

Should hopefully build 🤞

@jameslamb jameslamb force-pushed the added_assertions branch 2 times, most recently from 97e6199 to 4ae0726 Compare May 18, 2018 20:25
@codecov-io
Copy link

codecov-io commented May 18, 2018

Codecov Report

Merging #62 into master will decrease coverage by 1.09%.
The diff coverage is 67.39%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master      #62     +/-   ##
=========================================
- Coverage   69.52%   68.43%   -1.1%     
=========================================
  Files           3        4      +1     
  Lines         502      548     +46     
=========================================
+ Hits          349      375     +26     
- Misses        153      173     +20
Impacted Files Coverage Δ
R/utils.R 100% <100%> (ø)
R/elasticsearch_parsers.R 75.11% <100%> (+0.17%) ⬆️
R/elasticsearch_eda_funs.R 38.09% <21.05%> (-3.77%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 104c151...e7c66f5. Read the comment docs.

@jameslamb
Copy link
Collaborator Author

@austin3dickey this is building now and I made the recommended changes, so gonna merge it up. This will look (in a Github email) like I "dismissed your review", but I actually did do all the things.

Kind of wish this had tasks like Bitbucket

@jameslamb jameslamb dismissed austin3dickey’s stale review May 20, 2018 03:27

I took care of these changes, "dismissing" the review so I can merge

@jameslamb
Copy link
Collaborator Author

@austin3dickey ha joke's on me apparently I need one positive review no matter what to merge.

At your earliest convenience, no rush

, assertthat::is.string(use_na)
, use_na != ""
, assertthat::is.count(max_terms)
, max_terms > 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is redundant - is.count ensures it's 1 or greater

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

whoops, yep will fix

, assertthat::is.string(scroll)
, scroll != ""
, assertthat::is.count(max_hits)
, max_hits >= 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah this is the problem I was talking about earlier. This won't allow max_hits to be 0 because is.count ensures it's greater than 1 :( personally I think that's unintuitive

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

blegh oh right, now I understand. Ok I'm going to remove this one. max_hits = 0 is a plausible value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

also I agree that it's unintuitive

Copy link
Collaborator

@austin3dickey austin3dickey left a comment

Choose a reason for hiding this comment

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

Nice! As I mentioned, is.count(x) & x > 0 is redundant, but if you'd like to keep those lines in there to be explicit, that's fine. Note that max_hits can't be 0 with how this is currently written though.

@jameslamb
Copy link
Collaborator Author

ugh I think I know what this is. Trying locally, I was seeing a bunch of errors about multiple types not being allowed. The shakespeare data has mixed types :/

image

@jameslamb
Copy link
Collaborator Author

This is working now! Gonna ship it

@jameslamb jameslamb merged commit 14a92aa into uptake:master May 23, 2018
@jameslamb jameslamb deleted the added_assertions branch June 23, 2018 18:16
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