Support in and notIn for stringArray (#27)
* support in and notIn for stringArray
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 @@
/**
* 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 @@
/**
* 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 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 @@
.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 @@
" 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 @@
" 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 @@
" 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 @@
" 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 @@
" 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 @@
" 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" +