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

[BEAM-3382] Enforce strictly positive natural numbers for AfterCount timers #4300

Merged
merged 1 commit into from Dec 23, 2017

Conversation

mariapython
Copy link
Contributor

No description provided.

@mariapython
Copy link
Contributor Author

R: @aaltay

Copy link
Member

@aaltay aaltay left a comment

Choose a reason for hiding this comment

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

BEAM-3153 in the title does not seem to be directly related to this change, you can have a different issue for this change.

@@ -378,6 +378,8 @@ class AfterCount(TriggerFn):
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn())

def __init__(self, count):
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps also have a JIRA issue, so that this can be fixed in other sdks.

@@ -378,6 +378,8 @@ class AfterCount(TriggerFn):
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn())

def __init__(self, count):
if count == 0:
raise ValueError("count (%s) must be a non-zero natural number." % count)
Copy link
Member

Choose a reason for hiding this comment

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

  • Make the error statement match the condition. The condition is not checking for natural numbers either. For example 2.3 would not raise this error even though it is not a natural number. You can rephrase it as must be a positive number.

  • For string formatting of numbers, you can use %d instead of %s.

@@ -378,6 +378,8 @@ class AfterCount(TriggerFn):
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn())

def __init__(self, count):
if count == 0:
Copy link
Member

Choose a reason for hiding this comment

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

This is checking for non-zero numbers instead of the positive number. You can change this to count > 0 to check for positive numbers.

@mariapython mariapython changed the title [BEAM-3153] Enforce strictly positive natural numbers for AfterCount timers [BEAM-3382] Enforce strictly positive natural numbers for AfterCount timers Dec 21, 2017
Copy link
Contributor Author

@mariapython mariapython left a comment

Choose a reason for hiding this comment

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

Thanks, Ahmet. PTAL.


aaltay wrote:
BEAM-3153 in the title does not seem to be directly related to this change, you can have a different issue for this change.

Done.

@@ -378,6 +378,8 @@ class AfterCount(TriggerFn):
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn())

def __init__(self, count):
if count == 0:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

aaltay wrote:
This is checking for non-zero numbers instead of the positive number. You can change this to count > 0 to check for positive numbers.

Done.

@@ -378,6 +378,8 @@ class AfterCount(TriggerFn):
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn())

def __init__(self, count):
if count == 0:
raise ValueError("count (%s) must be a non-zero natural number." % count)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

aaltay wrote:

  • Make the error statement match the condition. The condition is not checking for natural numbers either. For example 2.3 would not raise this error even though it is not a natural number. You can rephrase it as must be a positive number.

  • For string formatting of numbers, you can use %d instead of %s.

The reason why I didn't check for non-int was that the proto enforced integers, so 2.3 wouldn't be accepted. But the message was not clear, and as you say, it is cleaner to match the error statement, so I modified it per your suggestion.

@@ -378,6 +378,8 @@ class AfterCount(TriggerFn):
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn())

def __init__(self, count):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

aaltay wrote:
Perhaps also have a JIRA issue, so that this can be fixed in other sdks.

I am not sure if it affects other SDKs, but I have now filed BEAM-3382 for sdk-py-core

@@ -378,6 +378,8 @@ class AfterCount(TriggerFn):
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn())

def __init__(self, count):
if not isinstance(count, int) or count < 1:
Copy link
Member

Choose a reason for hiding this comment

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

isinstance(count, int) is over limiting, For example both isinstance(3l, int) and isinstance(3.0, int) would result in False. Even though there is no reason to accept them as valid arguments. I do not not think we need to type check things. Checking for the count < 1 should be enough here.

Copy link
Contributor Author

@mariapython mariapython left a comment

Choose a reason for hiding this comment

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

Thanks, PTAL.

@@ -378,6 +378,8 @@ class AfterCount(TriggerFn):
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn())

def __init__(self, count):
if not isinstance(count, int) or count < 1:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

aaltay wrote:
isinstance(count, int) is over limiting, For example both isinstance(3l, int) and isinstance(3.0, int) would result in False. Even though there is no reason to accept them as valid arguments. I do not not think we need to type check things. Checking for the count < 1 should be enough here.

I am not sure if you mean count = "thirty one" or count = "three followed by letter L"
The first is rightfully True and the second is rightfully False, so I don't see the problem with that statement.
count < 1 is not restrictive enough, a user could enter 3.4 and they would only get an obscure message thrown by the protobuf. With the checking above, they get a clear reason of their error.

Copy link
Member

Choose a reason for hiding this comment

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

I meant a long value as in type(3L) = <type 'long'>. I do not see any reason for not letting users to pass long values here.

Copy link
Contributor Author

@mariapython mariapython left a comment

Choose a reason for hiding this comment

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

Thanks, PTAL.

@@ -378,6 +378,8 @@ class AfterCount(TriggerFn):
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn())

def __init__(self, count):
if not isinstance(count, int) or count < 1:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

aaltay wrote:
I meant a long value as in type(3L) = <type 'long'>. I do not see any reason for not letting users to pass long values here.

It makes sense. I have just incorporated the right change so that long types are allowed while enforcing non-fractional numbers.

Copy link
Contributor Author

@mariapython mariapython left a comment

Choose a reason for hiding this comment

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

Thanks, PTAL.

@@ -378,6 +378,8 @@ class AfterCount(TriggerFn):
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn())

def __init__(self, count):
if not isinstance(count, int) or count < 1:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

aaltay wrote:
I meant a long value as in type(3L) = <type 'long'>. I do not see any reason for not letting users to pass long values here.

It makes sense. I have just incorporated the right change so that long types are allowed while enforcing non-fractional numbers.

Copy link
Member

@aaltay aaltay left a comment

Choose a reason for hiding this comment

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

mariapython wrote:
Thanks, PTAL.

Done.

@@ -378,6 +378,8 @@ class AfterCount(TriggerFn):
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn())

def __init__(self, count):
if not isinstance(count, int) or count < 1:
Copy link
Member

Choose a reason for hiding this comment

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

mariapython wrote:
It makes sense. I have just incorporated the right change so that long types are allowed while enforcing non-fractional numbers.

This will still fail for float types like 3.0 but I think that is fine, we do not need to make more changes here.

@@ -378,6 +378,8 @@ class AfterCount(TriggerFn):
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn())

def __init__(self, count):
if count == 0:
raise ValueError("count (%s) must be a non-zero natural number." % count)
Copy link
Member

Choose a reason for hiding this comment

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

mariapython wrote:
The reason why I didn't check for non-int was that the proto enforced integers, so 2.3 wouldn't be accepted. But the message was not clear, and as you say, it is cleaner to match the error statement, so I modified it per your suggestion.

Could you change there error string to count (%d) must be a positive integer. ?

@@ -378,6 +378,8 @@ class AfterCount(TriggerFn):
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn())

def __init__(self, count):
Copy link
Member

Choose a reason for hiding this comment

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

mariapython wrote:
I am not sure if it affects other SDKs, but I have now filed BEAM-3382 for sdk-py-core

Done.

@@ -378,6 +378,8 @@ class AfterCount(TriggerFn):
COUNT_TAG = _CombiningValueStateTag('count', combiners.CountCombineFn())

def __init__(self, count):
if count == 0:
raise ValueError("count (%s) must be a non-zero natural number." % count)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

aaltay wrote:
Could you change there error string to count (%d) must be a positive integer. ?

Done.

@aaltay
Copy link
Member

aaltay commented Dec 23, 2017

LGTM, I can merge after tests pass.

@aaltay
Copy link
Member

aaltay commented Dec 23, 2017

retest this please

@aaltay
Copy link
Member

aaltay commented Dec 23, 2017

Tests seemingly failed for unrelated timeouts. I want to rerun tests again. Asked Jenkins to re-trigger the tests.

@aaltay aaltay merged commit 312c4ab into apache:master Dec 23, 2017
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.

None yet

2 participants