From 96c2f3dd9dbfc1c7b7d8daa0ad7c2a9c66ce6cc0 Mon Sep 17 00:00:00 2001 From: Yuxuan Guo Date: Mon, 4 Dec 2023 19:52:36 -0600 Subject: [PATCH] fix by repalcing HashSet with TreeSet (#12047) --- .../sql/parsers/rewriter/ExprMinMaxRewriter.java | 16 ++++------------ .../parsers/rewriter/ExprMinMaxRewriterTest.java | 2 +- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/pinot-common/src/main/java/org/apache/pinot/sql/parsers/rewriter/ExprMinMaxRewriter.java b/pinot-common/src/main/java/org/apache/pinot/sql/parsers/rewriter/ExprMinMaxRewriter.java index 2e08118a430c..2363ae5c42ac 100644 --- a/pinot-common/src/main/java/org/apache/pinot/sql/parsers/rewriter/ExprMinMaxRewriter.java +++ b/pinot-common/src/main/java/org/apache/pinot/sql/parsers/rewriter/ExprMinMaxRewriter.java @@ -20,12 +20,11 @@ import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; +import java.util.TreeSet; import org.apache.pinot.common.request.Expression; import org.apache.pinot.common.request.Function; import org.apache.pinot.common.request.PinotQuery; @@ -162,15 +161,8 @@ private boolean updateExprMinMaxFunctionMap(List exprMinMaxMeasuring int size = exprMinMaxFunctionIDMap.size(); int id = exprMinMaxFunctionIDMap.computeIfAbsent(exprMinMaxMeasuringExpressions, (k) -> size); - AtomicBoolean added = new AtomicBoolean(true); - - exprMinMaxFunctionMap.compute(exprMinMaxMeasuringExpressions, (k, v) -> { - if (v == null) { - v = new HashSet<>(); - } - added.set(v.add(exprMinMaxProjectionExpression)); - return v; - }); + boolean added = exprMinMaxFunctionMap.computeIfAbsent(exprMinMaxMeasuringExpressions, k -> new TreeSet<>()) + .add(exprMinMaxProjectionExpression); String operator = function.getOperator(); function.setOperator(CommonConstants.RewriterConstants.CHILD_AGGREGATION_NAME_PREFIX + operator); @@ -179,6 +171,6 @@ private boolean updateExprMinMaxFunctionMap(List exprMinMaxMeasuring operands.add(0, exprMinMaxProjectionExpression); operands.add(0, RequestUtils.getLiteralExpression(id)); - return added.get(); + return added; } } diff --git a/pinot-common/src/test/java/org/apache/pinot/sql/parsers/rewriter/ExprMinMaxRewriterTest.java b/pinot-common/src/test/java/org/apache/pinot/sql/parsers/rewriter/ExprMinMaxRewriterTest.java index adae1cf5abe2..d44b9d7abfd2 100644 --- a/pinot-common/src/test/java/org/apache/pinot/sql/parsers/rewriter/ExprMinMaxRewriterTest.java +++ b/pinot-common/src/test/java/org/apache/pinot/sql/parsers/rewriter/ExprMinMaxRewriterTest.java @@ -43,7 +43,7 @@ public void testQueryRewrite() { "SELECT CHILD_EXPR_MIN(0,col5,col5,col1,col2), " + "CHILD_EXPR_MIN(0,col6,col6,col1,col2), " + "CHILD_EXPR_MAX(0,col6,col6,col1,col2)," - + "PARENT_EXPR_MIN(0,2,col1,col2,col6,col5)," + + "PARENT_EXPR_MIN(0,2,col1,col2,col5,col6)," + "PARENT_EXPR_MAX(0,2,col1,col2,col6) FROM myTable"); }