Skip to content

Commit

Permalink
Allow getting schema field name (#3576)
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 committed Oct 11, 2023
1 parent edd5a0a commit 5fe7a09
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/main/java/redis/clients/jedis/search/FieldName.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> args) {
args.add(name);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
16 changes: 16 additions & 0 deletions src/test/java/redis/clients/jedis/modules/search/UtilTest.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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());
}
}

0 comments on commit 5fe7a09

Please sign in to comment.