Skip to content

Commit dc42c37

Browse files
authored
Support new Match Query proto. (#70)
1 parent 2cdda2c commit dc42c37

File tree

8 files changed

+104
-32
lines changed

8 files changed

+104
-32
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Release Notes.
88
### Features
99

1010
* Remove analyze DNS name to get/refresh IP for create connection.
11+
* Support new Match Query proto.
1112

1213
0.7.0-rc3
1314
------------------

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ IndexRule.Builder ir = IndexRule.newBuilder()
109109
.setName("trace_id"))
110110
.addTags("trace_id")
111111
.setType(IndexRule.Type.TYPE_INVERTED)
112-
.setAnalyzer(IndexRule.Analyzer.ANALYZER_UNSPECIFIED);
112+
.setAnalyzer("simple");
113113
client.define(ir.build());
114114
```
115115

src/main/java/org/apache/skywalking/banyandb/v1/client/PairQueryCondition.java

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.skywalking.banyandb.v1.client;
2020

2121
import org.apache.skywalking.banyandb.model.v1.BanyandbModel;
22+
import org.apache.skywalking.banyandb.model.v1.BanyandbModel.Condition.MatchOption;
2223

2324
import java.util.List;
2425

@@ -28,19 +29,33 @@
2829
public abstract class PairQueryCondition<T> extends AbstractCriteria {
2930
protected final BanyandbModel.Condition.BinaryOp op;
3031
private final TagAndValue<T> tagAndValue;
32+
private final MatchOption matchOption;
3133

3234
private PairQueryCondition(BanyandbModel.Condition.BinaryOp op, TagAndValue<T> tagAndValue) {
3335
this.op = op;
3436
this.tagAndValue = tagAndValue;
37+
this.matchOption = MatchOption.getDefaultInstance();
38+
}
39+
40+
private PairQueryCondition(BanyandbModel.Condition.BinaryOp op,
41+
TagAndValue<T> tagAndValue,
42+
MatchOption matchOption) {
43+
this.op = op;
44+
this.tagAndValue = tagAndValue;
45+
this.matchOption = matchOption;
3546
}
3647

3748
@Override
3849
public BanyandbModel.Criteria build() {
50+
BanyandbModel.Condition.Builder condition = BanyandbModel.Condition.newBuilder()
51+
.setName(this.tagAndValue.getTagName())
52+
.setOp(this.op)
53+
.setValue(this.tagAndValue.buildTypedTagValue());
54+
if (this.matchOption != null) {
55+
condition.setMatchOption(this.matchOption);
56+
}
3957
return BanyandbModel.Criteria.newBuilder()
40-
.setCondition(BanyandbModel.Condition.newBuilder()
41-
.setName(this.tagAndValue.getTagName())
42-
.setOp(this.op)
43-
.setValue(this.tagAndValue.buildTypedTagValue()).build())
58+
.setCondition(condition.build())
4459
.build();
4560
}
4661

@@ -138,6 +153,10 @@ private StringQueryCondition(String tagName, BanyandbModel.Condition.BinaryOp op
138153
super(op, new TagAndValue.StringTagPair(tagName, value));
139154
}
140155

156+
private StringQueryCondition(String tagName, BanyandbModel.Condition.BinaryOp op, String value, MatchOption matchOption) {
157+
super(op, new TagAndValue.StringTagPair(tagName, value), matchOption);
158+
}
159+
141160
/**
142161
* Build a query condition for {@link String} type
143162
* and {@link BanyandbModel.Condition.BinaryOp#BINARY_OP_EQ} as the relation
@@ -168,11 +187,24 @@ public static PairQueryCondition<String> ne(String tagName, String val) {
168187
*
169188
* @param tagName name of the tag
170189
* @param val value of the tag
171-
* @return a query that `String != value`
190+
* @return a query that `String match value`
172191
*/
173192
public static PairQueryCondition<String> match(String tagName, String val) {
174193
return new StringQueryCondition(tagName, BanyandbModel.Condition.BinaryOp.BINARY_OP_MATCH, val);
175194
}
195+
196+
/**
197+
* Build a query condition for {@link String} type
198+
* and {@link BanyandbModel.Condition.BinaryOp#BINARY_OP_MATCH} as the relation
199+
*
200+
* @param tagName name of the tag
201+
* @param val value of the tag
202+
* @param matchOption set the specific match options
203+
* @return a query that `match value`
204+
*/
205+
public static PairQueryCondition<String> match(String tagName, String val, MatchOption matchOption) {
206+
return new StringQueryCondition(tagName, BanyandbModel.Condition.BinaryOp.BINARY_OP_MATCH, val, matchOption);
207+
}
176208
}
177209

178210
/**

src/main/proto/banyandb/v1/banyandb-database.proto

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ message FieldSpec {
9494
EncodingMethod encoding_method = 3 [(validate.rules).enum.defined_only = true];
9595
// compression_method indicates how to compress data during writing
9696
CompressionMethod compression_method = 4 [(validate.rules).enum.defined_only = true];
97+
// aggregate_function indicates how to aggregate data
98+
model.v1.MeasureAggregate aggregate_function = 5;
9799
}
98100

99101
// Measure intends to store data point
@@ -113,6 +115,13 @@ message Measure {
113115
google.protobuf.Timestamp updated_at = 6;
114116
}
115117

118+
message MeasureAggregateFunction {
119+
// type indicates the type of function argument
120+
FieldType type = 1 [(validate.rules).enum.defined_only = true];
121+
// aggregate_function indicates specific function for measure data
122+
model.v1.MeasureAggregate aggregate_function = 2;
123+
}
124+
116125
// TopNAggregation generates offline TopN statistics for a measure's TopN approximation
117126
message TopNAggregation {
118127
// metadata is the identity of an aggregation
@@ -157,19 +166,18 @@ message IndexRule {
157166
Type type = 3 [(validate.rules).enum.defined_only = true];
158167
// updated_at indicates when the IndexRule is updated
159168
google.protobuf.Timestamp updated_at = 4;
160-
enum Analyzer {
161-
ANALYZER_UNSPECIFIED = 0;
162-
// Keyword analyzer is a “noop” analyzer which returns the entire input string as a single token.
163-
ANALYZER_KEYWORD = 1;
164-
// Standard analyzer provides grammar based tokenization
165-
ANALYZER_STANDARD = 2;
166-
// Simple analyzer breaks text into tokens at any non-letter character,
167-
// such as numbers, spaces, hyphens and apostrophes, discards non-letter characters,
168-
// and changes uppercase to lowercase.
169-
ANALYZER_SIMPLE = 3;
170-
}
169+
171170
// analyzer analyzes tag value to support the full-text searching for TYPE_INVERTED indices.
172-
Analyzer analyzer = 5;
171+
// available analyzers are:
172+
// - "standard" provides grammar based tokenization
173+
// - "simple" breaks text into tokens at any non-letter character,
174+
// such as numbers, spaces, hyphens and apostrophes, discards non-letter characters,
175+
// and changes uppercase to lowercase.
176+
// - "keyword" is a “noop” analyzer which returns the entire input string as a single token.
177+
// - "url" breaks test into tokens at any non-letter and non-digit character.
178+
string analyzer = 5;
179+
// no_sort indicates whether the index is not for sorting.
180+
bool no_sort = 6;
173181
}
174182

175183
// Subject defines which stream or measure would generate indices
@@ -200,6 +208,7 @@ message IndexRuleBinding {
200208
google.protobuf.Timestamp updated_at = 6;
201209
}
202210

211+
203212
message StreamRegistryServiceCreateRequest {
204213
banyandb.database.v1.Stream stream = 1;
205214
}

src/main/proto/banyandb/v1/banyandb-model.proto

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ import "google/protobuf/timestamp.proto";
2525
import "google/protobuf/struct.proto";
2626
import "validate/validate.proto";
2727

28-
message ID {
29-
string value = 1;
30-
}
31-
3228
message Str {
3329
string value = 1;
3430
}
@@ -57,7 +53,6 @@ message TagValue {
5753
Int int = 4;
5854
IntArray int_array = 5;
5955
bytes binary_data = 6;
60-
ID id = 7;
6156
}
6257
}
6358

@@ -84,6 +79,32 @@ enum AggregationFunction {
8479
AGGREGATION_FUNCTION_SUM = 5;
8580
}
8681

82+
enum MeasureAggregate {
83+
MEASURE_AGGREGATE_UNSPECIFIED = 0;
84+
// Calculate the minimum value of delta measures.
85+
MEASURE_AGGREGATE_MIN = 1;
86+
// Calculate the maximum value of delta measures.
87+
MEASURE_AGGREGATE_MAX = 2;
88+
// Count the number of delta measures.
89+
MEASURE_AGGREGATE_COUNT = 3;
90+
// Calculate the sum value of delta measures.
91+
MEASURE_AGGREGATE_SUM = 4;
92+
// Calculate the average value of delta measures.
93+
MEASURE_AGGREGATE_AVG = 5;
94+
// Calculate the percentage of delta measures, where the input matches with the condition.
95+
MEASURE_AGGREGATE_PERCENT = 6;
96+
// Calculate the ratio for measures, where the input matches with the condition.
97+
MEASURE_AGGREGATE_RATE = 7;
98+
// Calculate the histogram for delta measures.
99+
MEASURE_AGGREGATE_HISTOGRAM = 8;
100+
// Calculate the {p99, p95, p90, p75, p50} for delta measures.
101+
MEASURE_AGGREGATE_PERCENTILE2 = 9;
102+
// Calculate the apdex for delta measures.
103+
MEASURE_AGGREGATE_APDEX = 10;
104+
// Same like PERCENTILE2, little different on algorithm.
105+
MEASURE_AGGREGATE_PERCENTILE = 11;
106+
}
107+
87108
// Pair is the building block of a record which is equivalent to a key-value pair.
88109
// In the context of Trace, it could be metadata of a trace such as service_name, service_instance, etc.
89110
// Besides, other tags are organized in key-value pair in the underlying storage layer.
@@ -126,6 +147,16 @@ message Condition {
126147
string name = 1;
127148
BinaryOp op = 2;
128149
TagValue value = 3;
150+
message MatchOption {
151+
string analyzer = 1;
152+
enum Operator {
153+
OPERATOR_UNSPECIFIED = 0;
154+
OPERATOR_AND = 1;
155+
OPERATOR_OR = 2;
156+
}
157+
Operator operator = 2;
158+
}
159+
MatchOption match_option = 4;
129160
}
130161

131162
// tag_families are indexed.
@@ -168,7 +199,7 @@ message TagProjection {
168199
string name = 1;
169200
repeated string tags = 2;
170201
}
171-
repeated TagFamily tag_families = 1 [(validate.rules).repeated.min_items = 1];
202+
repeated TagFamily tag_families = 1;
172203
}
173204

174205
// TimeRange is a range query for uint64,
@@ -186,4 +217,4 @@ enum Status {
186217
STATUS_NOT_FOUND = 3;
187218
STATUS_EXPIRED_SCHEMA = 4;
188219
STATUS_INTERNAL_ERROR = 5;
189-
}
220+
}

src/test/java/org/apache/skywalking/banyandb/v1/client/BanyanDBClientTestCI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
public class BanyanDBClientTestCI {
3232
private static final String REGISTRY = "ghcr.io";
3333
private static final String IMAGE_NAME = "apache/skywalking-banyandb";
34-
private static final String TAG = "a528a5d99745c8fa978c135b8bda2685c50cda95";
34+
private static final String TAG = "9770bf48f9b88574683f56e2a137555cd68066d9";
3535

3636
private static final String IMAGE = REGISTRY + "/" + IMAGE_NAME + ":" + TAG;
3737

src/test/java/org/apache/skywalking/banyandb/v1/client/ITBanyanDBStreamQueryTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ private IndexRule buildIndexRule() {
213213
.setGroup("sw_record")
214214
.setName("trace_id"))
215215
.addTags("trace_id")
216-
.setType(IndexRule.Type.TYPE_INVERTED)
217-
.setAnalyzer(IndexRule.Analyzer.ANALYZER_UNSPECIFIED);
216+
.setType(IndexRule.Type.TYPE_INVERTED);
218217
return builder.build();
219218
}
220219

src/test/java/org/apache/skywalking/banyandb/v1/client/ITIndexRuleMetadataRegistryTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ public void testIndexRuleRegistry_createAndList() throws BanyanDBException {
8787
public void testIndexRuleRegistry_createAndUpdate() throws BanyanDBException {
8888
this.client.define(buildIndexRule());
8989
IndexRule before = client.findIndexRule("sw_record", "trace_id");
90-
Assert.assertEquals(IndexRule.Analyzer.ANALYZER_SIMPLE, before.getAnalyzer());
91-
IndexRule updatedIndexRule = before.toBuilder().setAnalyzer(IndexRule.Analyzer.ANALYZER_STANDARD).build();
90+
Assert.assertEquals("simple", before.getAnalyzer());
91+
IndexRule updatedIndexRule = before.toBuilder().setAnalyzer("standard").build();
9292
this.client.update(updatedIndexRule);
9393
IndexRule after = this.client.findIndexRule("sw_record", "trace_id");
9494
Assert.assertNotNull(after);
95-
Assert.assertEquals(IndexRule.Analyzer.ANALYZER_STANDARD, after.getAnalyzer());
95+
Assert.assertEquals("standard", after.getAnalyzer());
9696
}
9797

9898
@Test
@@ -111,7 +111,7 @@ private IndexRule buildIndexRule() {
111111
.setName("trace_id"))
112112
.addTags("trace_id")
113113
.setType(IndexRule.Type.TYPE_INVERTED)
114-
.setAnalyzer(IndexRule.Analyzer.ANALYZER_SIMPLE);
114+
.setAnalyzer("simple");
115115
return builder.build();
116116
}
117117
}

0 commit comments

Comments
 (0)