Skip to content

Commit

Permalink
tvs.del support multi keys
Browse files Browse the repository at this point in the history
  • Loading branch information
hanwen.thw authored and yangbodong22011 committed Nov 9, 2023
1 parent 366ea1d commit 19dd05e
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 4 deletions.
31 changes: 31 additions & 0 deletions src/main/java/com/aliyun/tair/tairvector/TairVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,37 @@ public Long tvsdel(byte[] index, byte[] entityid) {
}
}

/**
* TVS.DEL TVS.DEL index entityid1 entityid2
* <p>
* delete entity from tair-vector module
*
* @param index index name
* @param entityids entity id
* @return Long integer-reply the number of fields that were removed from the tair-vector
* not including specified but no existing fields.
*/
public Long tvsdel(final String index, final String... entityids) {
Jedis jedis = getJedis();
try {
Object obj = jedis.sendCommand(ModuleCommand.TVSDEL, JoinParameters.joinParameters(SafeEncoder.encode(index), SafeEncoder.encodeMany(entityids)));
return BuilderFactory.LONG.build(obj);
} finally {
releaseJedis(jedis);
}
}

public Long tvsdel(byte[] index, byte[]... entityids) {
Jedis jedis = getJedis();
try {
Object obj = jedis.sendCommand(ModuleCommand.TVSDEL, JoinParameters.joinParameters(index, entityids));
return BuilderFactory.LONG.build(obj);
} finally {
releaseJedis(jedis);
}
}


/**
* TVS.HDEL TVS.HDEL index entityid attribute_key [attribute_key ...]
* <p>
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/aliyun/tair/tairvector/TairVectorCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,26 @@ public Long tvsdel(byte[] index, byte[] entityid) {
return BuilderFactory.LONG.build(obj);
}

/**
* TVS.DEL TVS.DEL index entityid1 entityi2
* <p>
* delete entity from tair-vector module
*
* @param index index name
* @param entityids entity id
* @return Long integer-reply the number of fields that were removed from the tair-vector
* not including specified but non existing fields.
*/
public Long tvsdel(final String index, final String... entityids) {
Object obj = jc.sendCommand(SafeEncoder.encode(index), ModuleCommand.TVSDEL, JoinParameters.joinParameters(SafeEncoder.encode(index), SafeEncoder.encodeMany(entityids)));
return BuilderFactory.LONG.build(obj);
}

public Long tvsdel(byte[] index, byte[]... entityids) {
Object obj = jc.sendCommand(index, ModuleCommand.TVSDEL, JoinParameters.joinParameters(index, entityids));
return BuilderFactory.LONG.build(obj);
}

/**
* TVS.HDEL TVS.HDEL index entityid attribute_key [attribute_key ...]
* <p>
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/aliyun/tair/tairvector/TairVectorPipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,27 @@ public Response<Long> tvsdel(byte[] index, byte[] entityid) {
return getResponse(BuilderFactory.LONG);
}


/**
* TVS.DEL TVS.DEL index entityid1 entityi2
* <p>
* delete entity from tair-vector module
*
* @param index index name
* @param entityids entity id
* @return Long integer-reply the number of fields that were removed from the tair-vector
* not including specified but non existing fields.
*/
public Response<Long> tvsdel(final String index, final String... entityids) {
getClient(index).sendCommand(ModuleCommand.TVSDEL, JoinParameters.joinParameters(SafeEncoder.encode(index), SafeEncoder.encodeMany(entityids)));
return getResponse(BuilderFactory.LONG);
}

public Response<Long> tvsdel(byte[] index, byte[]... entityids) {
getClient(SafeEncoder.encode(index)).sendCommand(ModuleCommand.TVSDEL, JoinParameters.joinParameters(index, entityids));
return getResponse(BuilderFactory.LONG);
}

/**
* TVS.HDEL TVS.HDEL index entityid attribute_key [attribute_key ...]
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ private void tvs_hset(byte[] entityid, byte[] vector, byte[] param_k, byte[] par
assertEquals(result, 2);
}

private long tvs_del_entity(String... entity) {
return tairVectorCluster.tvsdel(index, entity);
}

private long tvs_del_entity(byte[]... entity) {
return tairVectorCluster.tvsdel(SafeEncoder.encode(index), entity);
}

private long tvs_del_entity(String entity) {
return tairVectorCluster.tvsdel(index, entity);
}
Expand Down Expand Up @@ -189,6 +197,16 @@ public void tvs_del() {
long count_byte = tvs_del_entity(SafeEncoder.encode("second_entity"));
assertEquals(1, count_byte);

tairVectorCluster.tvsdelindex(index);
tvs_create_index_and_load_data();
count_string = tvs_del_entity("first_entity", "second_entity");
assertEquals(2, count_string);

tairVectorCluster.tvsdelindex(index);
tvs_create_index_and_load_data();
count_byte = tvs_del_entity(SafeEncoder.encode("first_entity"), SafeEncoder.encode("second_entity"));
assertEquals(2, count_byte);

tairVectorCluster.tvsdelindex(index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ private void tvs_hset(byte[] entityid, byte[] vector, byte[] param_k, byte[] par
tairVectorPipeline.tvshset(SafeEncoder.encode(index), entityid, vector, param_k, param_v);
}

private void tvs_del_entity(String... entity) {
tairVectorPipeline.tvsdel(index, entity);
}

private void tvs_del_entity(byte[]... entity) {
tairVectorPipeline.tvsdel(SafeEncoder.encode(index), entity);
}

private void tvs_del_entity(String entity) {
tairVectorPipeline.tvsdel(index, entity);
}
Expand Down Expand Up @@ -218,6 +226,20 @@ public void tvs_del() {
List<Object> objs = tairVectorPipeline.syncAndReturnAll();
assertEquals(1L, (long) objs.get(4));
assertEquals(1L, (long) objs.get(5));

tvs_hset("first_entity", "[0.12, 0.23, 0.56, 0.67, 0.78, 0.89, 0.01, 0.89]", "name", "sammy");
tvs_hset(SafeEncoder.encode("second_entity"), SafeEncoder.encode("[0.22, 0.33, 0.66, 0.77, 0.88, 0.89, 0.11, 0.89]"),
SafeEncoder.encode("name"), SafeEncoder.encode("tiddy"));
tvs_del_entity("first_entity", "second_entity");
objs = tairVectorPipeline.syncAndReturnAll();
assertEquals(2L, (long) objs.get(2));

tvs_hset("first_entity", "[0.12, 0.23, 0.56, 0.67, 0.78, 0.89, 0.01, 0.89]", "name", "sammy");
tvs_hset(SafeEncoder.encode("second_entity"), SafeEncoder.encode("[0.22, 0.33, 0.66, 0.77, 0.88, 0.89, 0.11, 0.89]"),
SafeEncoder.encode("name"), SafeEncoder.encode("tiddy"));
tvs_del_entity(SafeEncoder.encodeMany("first_entity", "second_entity"));
objs = tairVectorPipeline.syncAndReturnAll();
assertEquals(2L, (long) objs.get(2));
}

@Test
Expand Down
20 changes: 16 additions & 4 deletions src/test/java/com/aliyun/tair/tests/tairvector/TairVectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ private void tvs_hset(byte[] entityid, byte[] vector, byte[] param_k, byte[] par
assertTrue(result <= 2);
}

private long tvs_del_entity(String... entity) {
return tairVector.tvsdel(index, entity);
}

private long tvs_del_entity(byte[]... entity) {
return tairVector.tvsdel(SafeEncoder.encode(index), entity);
}

private long tvs_del_entity(String entity) {
return tairVector.tvsdel(index, entity);
}
Expand Down Expand Up @@ -263,11 +271,15 @@ public void tvs_del() {
SafeEncoder.encode("[0.22, 0.33, 0.66, 0.77, 0.88, 0.89, 0.11, 0.89]"),
SafeEncoder.encode("name"), SafeEncoder.encode("tiddy"));

long count_string = tvs_del_entity("first_entity_knn");
assertEquals(1, count_string);
long count_string = tvs_del_entity("first_entity_knn", "second_entity_knn");
assertEquals(2, count_string);

long count_byte = tvs_del_entity(SafeEncoder.encode("second_entity_knn"));
assertEquals(1, count_byte);
tvs_hset("first_entity_knn", "[0.12, 0.23, 0.56, 0.67, 0.78, 0.89, 0.01, 0.89]", "name", "sammy");
tvs_hset(SafeEncoder.encode("second_entity_knn"),
SafeEncoder.encode("[0.22, 0.33, 0.66, 0.77, 0.88, 0.89, 0.11, 0.89]"),
SafeEncoder.encode("name"), SafeEncoder.encode("tiddy"));
long count_byte = tvs_del_entity(SafeEncoder.encode("first_entity_knn"), SafeEncoder.encode("second_entity_knn"));
assertEquals(2, count_byte);
}

@Test
Expand Down

0 comments on commit 19dd05e

Please sign in to comment.