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

additional work to stop double wrapping nodes #1235

Conversation

apmoriarty
Copy link
Collaborator

The original implementation for removing extra reference expressions broke a few assumptions made by various visitors.

  • Added a visitor to fix reference expressions that do not have a parent reference node
  • Reworked implementation of RemoveExtraParensVisitor
  • Simplified delayed predicate pushdown

*
* Ensure that all {@link org.apache.commons.jexl2.parser.ASTReferenceExpression} nodes have a parent ASTReference.
*/
public class EnsureReferenceNodesVisitor extends BaseVisitor {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be a RebuildingVisitor?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I concur. If the plan is for a visitor to modify the tree, it should probably be a rebuilding visitor.

ASTJexlScript visitedScript = (ASTJexlScript) PullupUnexecutableNodesVisitor.pullupDelayedPredicates(script, true, config, indexedFields,
indexOnlyFields, nonEventFields, metadataHelper);
ASTJexlScript expectedScript = JexlASTHelper.parseJexlQuery(expected);
// assertTrue(TreeEqualityVisitor.isEqual(expectedScript, visitedScript));
Copy link
Collaborator

Choose a reason for hiding this comment

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

delete

@apmoriarty apmoriarty changed the title WIP: additional work to stop double wrapping nodes additional work to stop double wrapping nodes Aug 27, 2021
@@ -92,6 +92,9 @@ public ExpandMultiNormalizedTerms(ShardQueryConfiguration config, MetadataHelper
throw new DatawaveFatalQueryException(qe);
}

// inject reference nodes when needed
script = (T) EnsureReferenceNodesVisitor.ensureReferences(script);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need this here? Is a previous visitor breaking this contract?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ExpandMultiNormalizedTerms can produce a reference expression without a reference node

Copy link
Collaborator

Choose a reason for hiding this comment

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

But you call it before the visitor is actually called?


// This swap should be safe, the reference node should have a single child that is a reference expression
JexlNode source = ASTDelayedPredicate.getDelayedPredicateSource(marker);
JexlNode wrappedSource = JexlNodes.wrap(source);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Won't this simply add extra parens?

@@ -92,6 +92,9 @@ public RangeConjunctionRebuildingVisitor(ShardQueryConfiguration config, Scanner
throw new DatawaveFatalQueryException(qe);
}

// inject reference nodes when needed
script = (T) EnsureReferenceNodesVisitor.ensureReferences(script);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is some visitor breaking this contract such that we need to do this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The RangeConjunctionRebuildingVisitor can produce a reference expression without a reference node

Copy link
Collaborator

Choose a reason for hiding this comment

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

But you call it before the visitor is actually called?

Copy link
Collaborator

@jwomeara jwomeara left a comment

Choose a reason for hiding this comment

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

I still think that instead of adding in a new visitor to remove extra parens that we should use this as a tool to identify existing visitors which are double-wrapping nodes, and fix those visitors instead. Adding an extra visitor means more work to do during query planning and ultimately doesn't fix the root issue. That being said, we have already merged in broken code, which this apparently fixes... So, I will approve, but I ask that you create a ticket to fix the root cause, please.

*
* Ensure that all {@link org.apache.commons.jexl2.parser.ASTReferenceExpression} nodes have a parent ASTReference.
*/
public class EnsureReferenceNodesVisitor extends BaseVisitor {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I concur. If the plan is for a visitor to modify the tree, it should probably be a rebuilding visitor.


@Override
public Object visit(SimpleNode node, Object data) {
node.childrenAccept(this, data);
Copy link
Collaborator

Choose a reason for hiding this comment

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

How is this a short-circuit?

log.warn("Tried to pull up a delayed marker that had more than one child.");
}

// This swap should be safe, the reference node should have a single child that is a reference expression
Copy link
Collaborator

Choose a reason for hiding this comment

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

You check, but you have not guaranteed that the reference node has a single child. Consider throwing an exception if you encounter a reference node with multiple children, or just remove the check & logging since this should never happen.

@ivakegg
Copy link
Collaborator

ivakegg commented Aug 31, 2021

We determined there is a better way to go about fixing the root issues. We will revert the commit that has broken the code base.

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.

4 participants