diff --git a/core/src/main/java/org/opensearch/sql/calcite/udf/udaf/PercentileApproxFunction.java b/core/src/main/java/org/opensearch/sql/calcite/udf/udaf/PercentileApproxFunction.java index 9fadd083362..613291dcce1 100644 --- a/core/src/main/java/org/opensearch/sql/calcite/udf/udaf/PercentileApproxFunction.java +++ b/core/src/main/java/org/opensearch/sql/calcite/udf/udaf/PercentileApproxFunction.java @@ -62,7 +62,7 @@ public Object result(PencentileApproAccumulator acc) { float floatRet = (float) retValue; return floatRet; default: - return acc.value(); + return retValue; } } diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/StatsCommandIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/StatsCommandIT.java index d04d2753673..b06d2563958 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/StatsCommandIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/StatsCommandIT.java @@ -608,6 +608,26 @@ public void testStatsPercentile() throws IOException { verifyDataRows(response, rows(32838)); } + @Test + public void testStatsPercentileWithMin() throws IOException { + JSONObject response = + executeQuery( + String.format( + "source=%s | eval decimal=ceil(balance/100000.0) | stats percentile(decimal, 50)," + + " min(decimal)", + TEST_INDEX_BANK)); + String returnType = "bigint"; + if (isCalciteEnabled()) { + returnType = "double"; + } + + verifySchema( + response, + schema("percentile(decimal, 50)", null, returnType), + schema("min(decimal)", null, returnType)); + verifyDataRows(response, rows(1, 1)); + } + @Test public void testStatsPercentileWithNull() throws IOException { JSONObject response =