Skip to content

Commit

Permalink
Wrap regex terms in eval only marker instead of rewriting into filter…
Browse files Browse the repository at this point in the history
… function
  • Loading branch information
apmoriarty committed Oct 17, 2024
1 parent 55e22cf commit c5bb43a
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

import datawave.query.Constants;
import datawave.query.jexl.JexlASTHelper;
import datawave.query.jexl.JexlNodeFactory;
import datawave.query.jexl.NodeTypeCount;
import datawave.query.jexl.nodes.QueryPropertyMarker;
import datawave.query.jexl.nodes.QueryPropertyMarker.MarkerType;
import datawave.query.jexl.visitors.pushdown.AnchorDetectionVisitor;

/**
* Rewrites regex terms as filter functions provided an anchor exists.
* Rewrites regex terms provided an anchor exists. Regex terms are wrapped in EvalOnly marker
* <p>
* An anchor is an executable term or subtree.
* <p>
Expand Down Expand Up @@ -175,8 +175,8 @@ public Object visit(ASTERNode node, Object data) {
String literal = (String) JexlASTHelper.getLiteralValue(node);

if (isNodeRewritableFromRules(field, literal)) {
JexlNode rewrite = JexlNodeFactory.buildFunctionNode("filter", "includeRegex", field, literal);
JexlNodes.replaceChild(node.jjtGetParent(), node, rewrite);
JexlNode marker = QueryPropertyMarker.create(node, MarkerType.EVALUATION_ONLY);
JexlNodes.replaceChild(node.jjtGetParent(), node, marker);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ private Object visitMarker(QueryPropertyMarker.Instance instance) {

switch (instance.getType()) {
case BOUNDED_RANGE:
case DELAYED:
case EVALUATION_ONLY:
case EXCEEDED_OR:
case EXCEEDED_TERM:
case EXCEEDED_VALUE:
return true;
case DELAYED:
case EVALUATION_ONLY:
default:
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ public void testRewriteRegexFromIncludes() throws Exception {
withQuery("ONLY_HEX == 'hexa' && TYPE =~ 'reg.*'");
withExpected(Sets.newHashSet(ShapesIngest.hexagonUid));
planAndExecuteQuery();
assertPlannedQuery("ONLY_HEX == 'hexa' && filter:includeRegex(TYPE, 'reg.*')");
assertPlannedQuery("ONLY_HEX == 'hexa' && ((_Eval_ = true) && (TYPE =~ 'reg.*'))");
}

@Test
Expand All @@ -909,6 +909,6 @@ public void testRewriteRegexWithExcludedFieldBecauseOfPatternMatch() throws Exce
withQuery("ONLY_HEX == 'hexa' && SHAPE =~ 'hexag.*'");
withExpected(Sets.newHashSet(ShapesIngest.hexagonUid));
planAndExecuteQuery();
assertPlannedQuery("ONLY_HEX == 'hexa' && filter:includeRegex(SHAPE, 'hexag.*')");
assertPlannedQuery("ONLY_HEX == 'hexa' && ((_Eval_ = true) && (SHAPE =~ 'hexag.*'))");
}
}
Loading

0 comments on commit c5bb43a

Please sign in to comment.