Skip to content

Add inverse check to NumericValueRule for non-numeric values on NumberType fields - #3993

Open
foster33 wants to merge 2 commits into
integrationfrom
task/fix-numericvaluerule-bug
Open

foster33 wants to merge 2 commits into
integrationfrom
task/fix-numericvaluerule-bug

Conversation

@foster33

@foster33 foster33 commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

NumericValueRule currently only checks one direction: a numeric range (<, >, <=, >=) applied to a field that is not a NumberType. It does not catch the inverse, a non-numeric literal applied to a field that IS a NumberType.

This issue shows up when a term like FOO:>60 is parsed. > is a legal term character, so the query becomes the JEXL equality FOO == '>60'. If FOO is a NumberType field, /validate returns no message and the query later fails during normalization.

This change adds the inverse check:

  • New FieldsWithNonNumericValuesVisitor collects fields compared (==, !=, <, >, <=, >=) against a string literal that NumberUtils.isCreatable rejects.
  • NumericValueRule runs the new visitor alongside the existing range check and emits Non-numeric values supplied for numeric field(s): ... for any such field whose TypeMetadata includes NumberType.

The TypeMetadata lookup cache is hoisted so both checks share it. The existing range check message and behavior are unchanged.

@foster33
foster33 marked this pull request as draft October 9, 2026 15:41
@foster33
foster33 marked this pull request as ready for review October 9, 2026 16:45
@foster33
foster33 requested a review from lbschanno October 9, 2026 16:57
* <p>
* All simple comparison operators are inspected (equality, inequality, and the four range operators).
* Null and numeric literals are ignored. This is the inverse of {@link FieldsWithNumericValuesVisitor};
* see also {@link FieldsWithNumericRangeVisitor} for the range only numeric case.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* see also {@link FieldsWithNumericRangeVisitor} for the range only numeric case.
* see also {@link FieldsWithNumericRangeValuesVisitor} for the range only numeric case.

import datawave.query.util.TypeMetadata;

/**
* A {@link QueryRule} implementation that checks a JEXL query for the usage of numeric values for non-numeric fields.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This class-level comment should be updated to include information about also checking for non-numeric values given for numeric fields.


import datawave.query.jexl.JexlASTHelper;

class FieldsWithNonNumericValuesVisitorTest {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice test coverage.

/**
* A {@link QueryRule} implementation that checks a JEXL query for the usage of numeric values for non-numeric fields.
*/
public class NumericValueRule extends ShardQueryRule {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Probably a bit of a pain to rename what with needing to update configuration files, but perhaps this should be renamed to NumericFieldsRule. Not a requirement, though.

This branch has not been deployed

No deployments
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