Skip to content

Commit

Permalink
#4476 Fix streaming analytic issue
Browse files Browse the repository at this point in the history
  • Loading branch information
stroomdev66 committed Sep 27, 2024
1 parent 80b77fe commit a8457b3
Show file tree
Hide file tree
Showing 3 changed files with 316 additions and 607 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,10 @@ public static ExpressionOperator simplify(final ExpressionOperator item) {
if (expressionItem == null) {
return null;
}
if (expressionItem instanceof final ExpressionOperator operator) {
return operator;
if (expressionItem instanceof ExpressionOperator) {
return (ExpressionOperator) expressionItem;
}
return ExpressionOperator.builder().op(Op.AND).children(List.of(expressionItem)).build();
return ExpressionOperator.builder().op(Op.AND).children(Collections.singletonList(expressionItem)).build();
}

private static ExpressionItem simplifyExpressionItem(final ExpressionItem item) {
Expand All @@ -319,7 +319,9 @@ private static ExpressionItem simplifyExpressionItem(final ExpressionItem item)
return null;
}

if (item instanceof final ExpressionOperator operator) {
if (item instanceof ExpressionOperator) {
final ExpressionOperator operator = (ExpressionOperator) item;

// Remove empty children.
final List<ExpressionItem> children = operator.getChildren();
if (children == null || children.isEmpty()) {
Expand All @@ -330,15 +332,16 @@ private static ExpressionItem simplifyExpressionItem(final ExpressionItem item)
for (final ExpressionItem child : children) {
final ExpressionItem simplifiedChild = simplifyExpressionItem(child);
if (simplifiedChild != null) {
if (simplifiedChild instanceof final ExpressionOperator childOperator) {
if (simplifiedChild instanceof ExpressionOperator) {
final ExpressionOperator childOperator = (ExpressionOperator) simplifiedChild;
if (childOperator.getChildren() != null && !childOperator.getChildren().isEmpty()) {
if (childOperator.getChildren().size() == 1) {
if (!Op.NOT.equals(operator.op())) {
// Simplify AND(AND()) or AND(OR()) or OR(AND()) or OR(OR())
simplifiedChildren.add(childOperator.getChildren().getFirst());
simplifiedChildren.add(childOperator.getChildren().get(0));
} else if (Op.NOT.equals(childOperator.op())) {
// Simplify NOT(NOT())
simplifiedChildren.add(childOperator.getChildren().getFirst());
simplifiedChildren.add(childOperator.getChildren().get(0));
} else {
simplifiedChildren.add(childOperator);
}
Expand Down
Loading

0 comments on commit a8457b3

Please sign in to comment.