From 5fe7a09aaf63c729eda026fa152c0a3b52bc3aba Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Thu, 12 Oct 2023 01:12:19 +0600 Subject: [PATCH] Allow getting schema field name (#3576) --- .../redis/clients/jedis/search/FieldName.java | 13 ++++++++----- .../jedis/search/schemafields/SchemaField.java | 8 ++++++++ .../clients/jedis/modules/search/UtilTest.java | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/main/java/redis/clients/jedis/search/FieldName.java b/src/main/java/redis/clients/jedis/search/FieldName.java index d9848ab594..68b1eb0e58 100644 --- a/src/main/java/redis/clients/jedis/search/FieldName.java +++ b/src/main/java/redis/clients/jedis/search/FieldName.java @@ -35,6 +35,14 @@ public FieldName as(String attribute) { return this; } + public final String getName() { + return name; + } + + public final String getAttribute() { + return attribute; + } + @Deprecated public int addCommandEncodedArguments(List args) { args.add(name); @@ -75,11 +83,6 @@ public void addParams(CommandArguments args) { addCommandArguments(args); } - @Deprecated // TODO: remove? - String getName() { - return name; - } - @Override public String toString() { return attribute == null ? name : (name + " AS " + attribute); diff --git a/src/main/java/redis/clients/jedis/search/schemafields/SchemaField.java b/src/main/java/redis/clients/jedis/search/schemafields/SchemaField.java index 473baea472..8678780da2 100644 --- a/src/main/java/redis/clients/jedis/search/schemafields/SchemaField.java +++ b/src/main/java/redis/clients/jedis/search/schemafields/SchemaField.java @@ -19,4 +19,12 @@ public SchemaField as(String attribute) { fieldName.as(attribute); return this; } + + public final FieldName getFieldName() { + return fieldName; + } + + public final String getName() { + return fieldName.getName(); + } } diff --git a/src/test/java/redis/clients/jedis/modules/search/UtilTest.java b/src/test/java/redis/clients/jedis/modules/search/UtilTest.java index d63c934a37..449f8ce420 100644 --- a/src/test/java/redis/clients/jedis/modules/search/UtilTest.java +++ b/src/test/java/redis/clients/jedis/modules/search/UtilTest.java @@ -1,9 +1,15 @@ package redis.clients.jedis.modules.search; +import static org.junit.Assert.assertEquals; + import org.junit.Assert; import org.junit.Test; + import redis.clients.jedis.search.RediSearchUtil; +import redis.clients.jedis.search.schemafields.NumericField; +import redis.clients.jedis.search.schemafields.SchemaField; + public class UtilTest { @Test @@ -13,4 +19,14 @@ public void floatArrayToByteArray() { byte[] expected = new byte[]{-51, -52, 76, 62}; Assert.assertArrayEquals(expected, bytes); } + + @Test + public void getSchemaFieldName() { + SchemaField field = NumericField.of("$.num").as("num"); + + assertEquals("$.num", field.getFieldName().getName()); + assertEquals("num", field.getFieldName().getAttribute()); + + assertEquals("$.num", field.getName()); + } }