From bddfe76273b0020852aa5089ba924b36854af03e Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Tue, 28 Nov 2023 21:02:52 +0600 Subject: [PATCH] Access Reducer attributes --- .../clients/jedis/search/aggr/Reducer.java | 12 ++++++++ .../search/AggregationBuilderTest.java | 28 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/test/java/redis/clients/jedis/modules/search/AggregationBuilderTest.java diff --git a/src/main/java/redis/clients/jedis/search/aggr/Reducer.java b/src/main/java/redis/clients/jedis/search/aggr/Reducer.java index 21f7060ee7b..9cbfb5a00c7 100644 --- a/src/main/java/redis/clients/jedis/search/aggr/Reducer.java +++ b/src/main/java/redis/clients/jedis/search/aggr/Reducer.java @@ -29,6 +29,18 @@ public final Reducer as(String alias) { return this; } + public final String getName() { + return name; + } + + public final String getField() { + return field; + } + + public final String getAlias() { + return alias; + } + protected abstract List getOwnArgs(); public final void addArgs(List args) { diff --git a/src/test/java/redis/clients/jedis/modules/search/AggregationBuilderTest.java b/src/test/java/redis/clients/jedis/modules/search/AggregationBuilderTest.java new file mode 100644 index 00000000000..396ca3365e7 --- /dev/null +++ b/src/test/java/redis/clients/jedis/modules/search/AggregationBuilderTest.java @@ -0,0 +1,28 @@ +package redis.clients.jedis.modules.search; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.junit.Test; + +import redis.clients.jedis.search.aggr.Reducer; +import redis.clients.jedis.search.aggr.Reducers; + +public class AggregationBuilderTest { + + @Test + public void reducerObject() { + Reducer reducer = Reducers.sum("@count").as("total"); + assertEquals("SUM", reducer.getName()); + assertEquals("@count", reducer.getField()); + assertEquals("total", reducer.getAlias()); + } + + @Test + public void countObject() { + Reducer count = Reducers.count(); + assertEquals("COUNT", count.getName()); + assertNull(count.getField()); + assertNull(count.getAlias()); + } +}