This is an automated email from the ASF dual-hosted git repository. hanahmily pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb-java-client.git
The following commit(s) were added to refs/heads/main by this push: new eb0504e Support in and notIn for stringArray (#27) eb0504e is described below commit eb0504e3b4751528a9656409f582047a207140d0 Author: Jiajing LU <lujiajing1...@gmail.com> AuthorDate: Sat Dec 17 21:52:59 2022 +0800 Support in and notIn for stringArray (#27) * support in and notIn for stringArray --- .../banyandb/v1/client/PairQueryCondition.java | 34 ++++++++++++-- .../v1/client/BanyanDBClientStreamQueryTest.java | 54 ++++++++++++++-------- 2 files changed, 67 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/apache/skywalking/banyandb/v1/client/PairQueryCondition.java b/src/main/java/org/apache/skywalking/banyandb/v1/client/PairQueryCondition.java index 5a14a64..c0a328c 100644 --- a/src/main/java/org/apache/skywalking/banyandb/v1/client/PairQueryCondition.java +++ b/src/main/java/org/apache/skywalking/banyandb/v1/client/PairQueryCondition.java @@ -227,10 +227,11 @@ public abstract class PairQueryCondition<T> extends AbstractCriteria { /** * Build a query condition for {@link List} of {@link String} as the type - * and {@link BanyandbModel.Condition.BinaryOp#BINARY_OP_HAVING} as the relation + * and {@link BanyandbModel.Condition.BinaryOp#BINARY_OP_HAVING} as the relation, + * i.e. val is a subset. * * @param tagName name of the tag - * @param val value of the tag + * @param val value of the tag, a subset of the tagName's value * @return a query that `[String] having values` */ public static PairQueryCondition<List<String>> having(String tagName, List<String> val) { @@ -239,7 +240,8 @@ public abstract class PairQueryCondition<T> extends AbstractCriteria { /** * Build a query condition for {@link List} of {@link String} as the type - * and {@link BanyandbModel.Condition.BinaryOp#BINARY_OP_NOT_HAVING} as the relation + * and {@link BanyandbModel.Condition.BinaryOp#BINARY_OP_NOT_HAVING} as the relation, + * i.e. val is not a subset. * * @param tagName name of the tag * @param val value of the tag @@ -248,6 +250,32 @@ public abstract class PairQueryCondition<T> extends AbstractCriteria { public static PairQueryCondition<List<String>> notHaving(String tagName, List<String> val) { return new StringArrayQueryCondition(tagName, BanyandbModel.Condition.BinaryOp.BINARY_OP_NOT_HAVING, val); } + + /** + * Build a query condition for {@link List} of {@link String} as the type + * and {@link BanyandbModel.Condition.BinaryOp#BINARY_OP_IN} as the relation, + * i.e. intersection of the val and the stored tagName's value must not be empty. + * + * @param tagName name of the tag + * @param val value of the tag + * @return a query that `[String] in values` + */ + public static PairQueryCondition<List<String>> in(String tagName, List<String> val) { + return new StringArrayQueryCondition(tagName, BanyandbModel.Condition.BinaryOp.BINARY_OP_IN, val); + } + + /** + * Build a query condition for {@link List} of {@link String} as the type + * and {@link BanyandbModel.Condition.BinaryOp#BINARY_OP_NOT_IN} as the relation, + * i.e. intersection of the val and the stored tagName's value must be empty. + * + * @param tagName name of the tag + * @param val value of the tag + * @return a query that `[String] not in values` + */ + public static PairQueryCondition<List<String>> notIn(String tagName, List<String> val) { + return new StringArrayQueryCondition(tagName, BanyandbModel.Condition.BinaryOp.BINARY_OP_NOT_IN, val); + } } /** diff --git a/src/test/java/org/apache/skywalking/banyandb/v1/client/BanyanDBClientStreamQueryTest.java b/src/test/java/org/apache/skywalking/banyandb/v1/client/BanyanDBClientStreamQueryTest.java index cd78db8..9ed482e 100644 --- a/src/test/java/org/apache/skywalking/banyandb/v1/client/BanyanDBClientStreamQueryTest.java +++ b/src/test/java/org/apache/skywalking/banyandb/v1/client/BanyanDBClientStreamQueryTest.java @@ -149,6 +149,7 @@ public class BanyanDBClientStreamQueryTest extends AbstractBanyanDBClientTest { .and(PairQueryCondition.StringQueryCondition.match("endpoint_id", endpointId)) .and(PairQueryCondition.LongQueryCondition.ge("duration", minDuration)) .and(PairQueryCondition.LongQueryCondition.le("duration", maxDuration)) + .and(PairQueryCondition.StringArrayQueryCondition.in("trace_id", Lists.newArrayList("aaa", "bbb"))) .setOrderBy(new StreamQuery.OrderBy("start_time", AbstractQuery.Sort.ASC)); client.query(query); @@ -166,11 +167,12 @@ public class BanyanDBClientStreamQueryTest extends AbstractBanyanDBClientTest { " op: LOGICAL_OP_AND\n" + " left {\n" + " condition {\n" + - " name: \"duration\"\n" + - " op: BINARY_OP_LE\n" + + " name: \"trace_id\"\n" + + " op: BINARY_OP_IN\n" + " value {\n" + - " int {\n" + - " value: 100\n" + + " str_array {\n" + + " value: \"aaa\"\n" + + " value: \"bbb\"\n" + " }\n" + " }\n" + " }\n" + @@ -181,10 +183,10 @@ public class BanyanDBClientStreamQueryTest extends AbstractBanyanDBClientTest { " left {\n" + " condition {\n" + " name: \"duration\"\n" + - " op: BINARY_OP_GE\n" + + " op: BINARY_OP_LE\n" + " value {\n" + " int {\n" + - " value: 10\n" + + " value: 100\n" + " }\n" + " }\n" + " }\n" + @@ -194,11 +196,11 @@ public class BanyanDBClientStreamQueryTest extends AbstractBanyanDBClientTest { " op: LOGICAL_OP_AND\n" + " left {\n" + " condition {\n" + - " name: \"endpoint_id\"\n" + - " op: BINARY_OP_MATCH\n" + + " name: \"duration\"\n" + + " op: BINARY_OP_GE\n" + " value {\n" + - " str {\n" + - " value: \"/check_0\"\n" + + " int {\n" + + " value: 10\n" + " }\n" + " }\n" + " }\n" + @@ -208,11 +210,11 @@ public class BanyanDBClientStreamQueryTest extends AbstractBanyanDBClientTest { " op: LOGICAL_OP_AND\n" + " left {\n" + " condition {\n" + - " name: \"service_instance_id\"\n" + - " op: BINARY_OP_EQ\n" + + " name: \"endpoint_id\"\n" + + " op: BINARY_OP_MATCH\n" + " value {\n" + " str {\n" + - " value: \"service_id_b_1\"\n" + + " value: \"/check_0\"\n" + " }\n" + " }\n" + " }\n" + @@ -222,11 +224,11 @@ public class BanyanDBClientStreamQueryTest extends AbstractBanyanDBClientTest { " op: LOGICAL_OP_AND\n" + " left {\n" + " condition {\n" + - " name: \"service_id\"\n" + + " name: \"service_instance_id\"\n" + " op: BINARY_OP_EQ\n" + " value {\n" + " str {\n" + - " value: \"service_id_b\"\n" + + " value: \"service_id_b_1\"\n" + " }\n" + " }\n" + " }\n" + @@ -236,11 +238,27 @@ public class BanyanDBClientStreamQueryTest extends AbstractBanyanDBClientTest { " op: LOGICAL_OP_AND\n" + " left {\n" + " condition {\n" + - " name: \"state\"\n" + + " name: \"service_id\"\n" + " op: BINARY_OP_EQ\n" + " value {\n" + - " int {\n" + - " value: 1\n" + + " str {\n" + + " value: \"service_id_b\"\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " right {\n" + + " le {\n" + + " op: LOGICAL_OP_AND\n" + + " left {\n" + + " condition {\n" + + " name: \"state\"\n" + + " op: BINARY_OP_EQ\n" + + " value {\n" + + " int {\n" + + " value: 1\n" + + " }\n" + + " }\n" + " }\n" + " }\n" + " }\n" +