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

Null Fastval should not output as 0 when used as numeric values #84

Closed
nelio2k opened this issue Jan 24, 2019 · 3 comments
Closed

Null Fastval should not output as 0 when used as numeric values #84

nelio2k opened this issue Jan 24, 2019 · 3 comments
Assignees
Labels

Comments

@nelio2k
Copy link
Collaborator

nelio2k commented Jan 24, 2019

Right now a NullValue Fastval outputs to 0 or 0.0 when its AsUint()/AsInt()/AsFloat64() is called.
Since 0 is commonly used as values, it could easily lead to an incorrect match. Consider the following test case that incorrectly matches:

	fe = &FilterExpression{}
	err = parser.ParseString("fieldpath.path IS NOT NULL", fe)
...
	userData := map[string]interface{}{
		"fieldpath": map[string]interface{}{
			"path": 0,
		},
	}
	udMarsh, _ := json.Marshal(userData)
	match, err := m.Match(udMarsh)
...

fieldpath.path is not null in this case but because the nil value on the right side of EqualsExpr inserted by the parser equates to 0 when matches with LHS's 0(int), this evaluation results in the incorrect value.

The simplest way to do it IMO is to make NullValue output MinInt64/MaxUint64/MaxFloat64 when AsInt()/AsUint()/AsFloat() is called. Chances are, those values are unlikely to exist in real world scenarios.

Another option is to do more complicated checks in CompareOp, which is more correct, but that will break the pretty symmetric function of the current code.

Thoughts, @brett19 ?

@brett19
Copy link
Collaborator

brett19 commented Jan 24, 2019

I imagine explicitly handling NULL and other special values in comparisons would probably be a valid implementation here. I'm not against the proposed alternative though.

@brett19
Copy link
Collaborator

brett19 commented Jan 24, 2019

You should leave this issue open, as I know you mentioned that you will likely improve the implementation of this to correctly special-case null values.

@nelio2k
Copy link
Collaborator Author

nelio2k commented Jan 24, 2019

Hmm I forgot GitHub auto closes issues. Reopening now.

@nelio2k nelio2k reopened this Jan 24, 2019
nelio2k added a commit to nelio2k/gojsonsm that referenced this issue Jul 18, 2019
- Add valid comparison between null/non-null values or missing/not-missing values
- Fix matcher Reset() where it wipes out old slots
- Added new test data
nelio2k added a commit to nelio2k/gojsonsm that referenced this issue Jul 18, 2019
- Add valid comparison between null/non-null values or missing/not-missing values
- Fix matcher Reset() where it wipes out old slots
- Added new test data
nelio2k added a commit to nelio2k/gojsonsm that referenced this issue Jul 18, 2019
- Add valid comparison between null/non-null values or missing/not-missing values
- Fix matcher Reset() where it wipes out old slots
- Added new test data
@nelio2k nelio2k mentioned this issue Jul 18, 2019
nelio2k added a commit to nelio2k/gojsonsm that referenced this issue Oct 1, 2019
…ensure that invalid type comparisons

           will result in a resolve state that is neither true nor false. This will help
           ensure a more well-defined matcher behavior and easier to be documented and understood.
           Based on the validity component, null comparisons (Issue couchbaselabs#84) can now be addressed
           correctly without the use of workarounds such as math.MaxUint or the like.
nelio2k added a commit to nelio2k/gojsonsm that referenced this issue Oct 11, 2019
…ensure that invalid type comparisons

           will result in a resolve state that is neither true nor false. This will help
           ensure a more well-defined matcher behavior and easier to be documented and understood.
           Based on the validity component, null comparisons (Issue couchbaselabs#84) can now be addressed
           correctly without the use of workarounds such as math.MaxUint or the like.
nelio2k added a commit to nelio2k/gojsonsm that referenced this issue Oct 24, 2019
…ensure that invalid type comparisons

           will result in a resolve state that is neither true nor false. This will help
           ensure a more well-defined matcher behavior and easier to be documented and understood.
           Based on the validity component, null comparisons (Issue couchbaselabs#84) can now be addressed
           correctly without the use of workarounds such as math.MaxUint or the like.
nelio2k added a commit to nelio2k/gojsonsm that referenced this issue Oct 28, 2019
…ensure that invalid type comparisons

           will result in a resolve state that is neither true nor false. This will help
           ensure a more well-defined matcher behavior and easier to be documented and understood.
           Based on the validity component, null comparisons (Issue couchbaselabs#84) can now be addressed
           correctly without the use of workarounds such as math.MaxUint or the like.
nelio2k added a commit to nelio2k/gojsonsm that referenced this issue Oct 28, 2019
…ensure that invalid type comparisons

           will result in a resolve state that is neither true nor false. This will help
           ensure a more well-defined matcher behavior and easier to be documented and understood.
           Based on the validity component, null comparisons (Issue couchbaselabs#84) can now be addressed
           correctly without the use of workarounds such as math.MaxUint or the like.
nelio2k added a commit to nelio2k/gojsonsm that referenced this issue Oct 28, 2019
…ensure that invalid type comparisons

           will result in a resolve state that is neither true nor false. This will help
           ensure a more well-defined matcher behavior and easier to be documented and understood.
           Based on the validity component, null comparisons (Issue couchbaselabs#84) can now be addressed
           correctly without the use of workarounds such as math.MaxUint or the like.
@nelio2k nelio2k closed this as completed in 47d764f Nov 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants