Skip to content

Commit dd6583a

Browse files
authored
feat: Add support for new functions (#2287)
* feat: Add support for additional types * fix build * fix test * fix build * improve readability * fix a whoopsie * improve readability * improve readability * Update clirr-ignored-differences.xml * Update clirr-ignored-differences.xml * Update clirr-ignored-differences.xml * Update clirr-ignored-differences.xml
1 parent 0ce8a2a commit dd6583a

File tree

6 files changed

+298
-21
lines changed

6 files changed

+298
-21
lines changed

google-cloud-bigtable/clirr-ignored-differences.xml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,43 @@
210210
<className>com/google/cloud/bigtable/data/v2/models/ChangeStreamRecordAdapter$ChangeStreamRecordBuilder</className>
211211
<method>*</method>
212212
</difference>
213+
<!-- BetaApi was updated -->
214+
<difference>
215+
<differenceType>2000</differenceType>
216+
<className>com/google/cloud/bigtable/admin/v2/models/Type</className>
217+
</difference>
218+
<difference>
219+
<differenceType>2000</differenceType>
220+
<className>com/google/cloud/bigtable/admin/v2/models/Type$SumAggregateInput</className>
221+
</difference>
222+
<difference>
223+
<differenceType>5001</differenceType>
224+
<className>com/google/cloud/bigtable/admin/v2/models/Type$SumAggregateInput</className>
225+
<to>com/google/cloud/bigtable/admin/v2/models/Type</to>
226+
</difference>
227+
<difference>
228+
<differenceType>5001</differenceType>
229+
<className>com/google/cloud/bigtable/admin/v2/models/Type$Aggregate</className>
230+
<to>com/google/cloud/bigtable/admin/v2/models/Type</to>
231+
</difference>
232+
<difference>
233+
<differenceType>5001</differenceType>
234+
<className>com/google/cloud/bigtable/admin/v2/models/Type$Bytes</className>
235+
<to>com/google/cloud/bigtable/admin/v2/models/Type</to>
236+
</difference>
237+
<difference>
238+
<differenceType>5001</differenceType>
239+
<className>com/google/cloud/bigtable/admin/v2/models/Type$Int64</className>
240+
<to>com/google/cloud/bigtable/admin/v2/models/Type</to>
241+
</difference>
242+
<difference>
243+
<differenceType>5001</differenceType>
244+
<className>com/google/cloud/bigtable/admin/v2/models/Type$Int64</className>
245+
<to>com/google/cloud/bigtable/admin/v2/models/Type$SumAggregateInput</to>
246+
</difference>
247+
<difference>
248+
<differenceType>5001</differenceType>
249+
<className>com/google/cloud/bigtable/admin/v2/models/Type$Raw</className>
250+
<to>com/google/cloud/bigtable/admin/v2/models/Type</to>
251+
</difference>
213252
</differences>

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Type.java

Lines changed: 100 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,19 @@
2727
* @see com.google.bigtable.admin.v2.Type
2828
*/
2929
@BetaApi
30-
public abstract class Type {
31-
private Type() {}
32-
30+
public interface Type {
3331
/**
34-
* This type is a marker type that allows types to be used as the input to the SUM aggregate
35-
* function.
32+
* These types are marker types that allow types to be used as the input to aggregate function.
3633
*/
37-
public abstract static class SumAggregateInput extends Type {}
34+
public static interface SumAggregateInput extends Type {}
35+
36+
public static interface MinAggregateInput extends Type {}
37+
38+
public static interface MaxAggregateInput extends Type {}
3839

39-
abstract com.google.bigtable.admin.v2.Type toProto();
40+
public static interface HllAggregateInput extends Type {}
41+
42+
com.google.bigtable.admin.v2.Type toProto();
4043

4144
static Type fromProto(com.google.bigtable.admin.v2.Type source) {
4245
switch (source.getKindCase()) {
@@ -73,7 +76,7 @@ public static Bytes bytes(Bytes.Encoding encoding) {
7376
* Creates an Int64 type with a big-endian encoding. The bytes are then encoded in "raw" format.
7477
*/
7578
public static Int64 bigEndianInt64() {
76-
return Int64.create(Int64.Encoding.BigEndianBytes.create(Bytes.rawBytes()));
79+
return Int64.create(Int64.Encoding.BigEndianBytes.create(Type.rawBytes()));
7780
}
7881

7982
/** Creates an Int64 type with the specified encoding. */
@@ -91,9 +94,39 @@ public static Aggregate sum(SumAggregateInput inputType) {
9194
return Aggregate.create(inputType, Aggregate.Aggregator.Sum.create());
9295
}
9396

97+
/** Creates an Aggregate type with a MIN aggregator and Int64 input type. */
98+
public static Aggregate int64Min() {
99+
return min(bigEndianInt64());
100+
}
101+
102+
/** Creates an Aggregate type with a MIN aggregator and specified input type. */
103+
public static Aggregate min(MinAggregateInput inputType) {
104+
return Aggregate.create(inputType, Aggregate.Aggregator.Min.create());
105+
}
106+
107+
/** Creates an Aggregate type with a MAX aggregator and Int64 input type. */
108+
public static Aggregate int64Max() {
109+
return max(bigEndianInt64());
110+
}
111+
112+
/** Creates an Aggregate type with a MAX aggregator and specified input type. */
113+
public static Aggregate max(MaxAggregateInput inputType) {
114+
return Aggregate.create(inputType, Aggregate.Aggregator.Max.create());
115+
}
116+
117+
/** Creates an Aggregate type with a HLL aggregator and Int64 input type. */
118+
public static Aggregate int64Hll() {
119+
return hll(bigEndianInt64());
120+
}
121+
122+
/** Creates an Aggregate type with a HLL aggregator and specified input type. */
123+
public static Aggregate hll(HllAggregateInput inputType) {
124+
return Aggregate.create(inputType, Aggregate.Aggregator.Hll.create());
125+
}
126+
94127
/** Represents a string of bytes with a specific encoding. */
95128
@AutoValue
96-
public abstract static class Bytes extends Type {
129+
public abstract static class Bytes implements Type {
97130
public static Bytes create(Encoding encoding) {
98131
return new AutoValue_Type_Bytes(encoding);
99132
}
@@ -102,7 +135,7 @@ public static Bytes create(Encoding encoding) {
102135
public abstract Encoding getEncoding();
103136

104137
@Override
105-
com.google.bigtable.admin.v2.Type toProto() {
138+
public com.google.bigtable.admin.v2.Type toProto() {
106139
com.google.bigtable.admin.v2.Type.Builder builder =
107140
com.google.bigtable.admin.v2.Type.newBuilder();
108141
builder.getBytesTypeBuilder().setEncoding(getEncoding().toProto());
@@ -142,7 +175,7 @@ public static Raw create() {
142175
.build();
143176

144177
@Override
145-
com.google.bigtable.admin.v2.Type.Bytes.Encoding toProto() {
178+
public com.google.bigtable.admin.v2.Type.Bytes.Encoding toProto() {
146179
return PROTO_INSTANCE;
147180
}
148181
}
@@ -151,7 +184,8 @@ com.google.bigtable.admin.v2.Type.Bytes.Encoding toProto() {
151184

152185
/** Represents a 64-bit integer with a specific encoding. */
153186
@AutoValue
154-
public abstract static class Int64 extends SumAggregateInput {
187+
public abstract static class Int64
188+
implements SumAggregateInput, MinAggregateInput, MaxAggregateInput, HllAggregateInput {
155189
public static Int64 create(Encoding encoding) {
156190
return new AutoValue_Type_Int64(encoding);
157191
}
@@ -169,7 +203,7 @@ static Encoding fromProto(com.google.bigtable.admin.v2.Type.Int64.Encoding sourc
169203
return BigEndianBytes.create(
170204
Bytes.fromProto(source.getBigEndianBytes().getBytesType()));
171205
case ENCODING_NOT_SET:
172-
return BigEndianBytes.create(Bytes.rawBytes());
206+
return BigEndianBytes.create(Type.rawBytes());
173207
}
174208
throw new UnsupportedOperationException();
175209
}
@@ -185,7 +219,7 @@ public static BigEndianBytes create(Bytes bytes) {
185219
public abstract Bytes getBytes();
186220

187221
@Override
188-
com.google.bigtable.admin.v2.Type.Int64.Encoding toProto() {
222+
public com.google.bigtable.admin.v2.Type.Int64.Encoding toProto() {
189223
com.google.bigtable.admin.v2.Type.Int64.Encoding.Builder builder =
190224
com.google.bigtable.admin.v2.Type.Int64.Encoding.newBuilder();
191225
builder.getBigEndianBytesBuilder().setBytesType(getBytes().toProto().getBytesType());
@@ -195,7 +229,7 @@ com.google.bigtable.admin.v2.Type.Int64.Encoding toProto() {
195229
}
196230

197231
@Override
198-
com.google.bigtable.admin.v2.Type toProto() {
232+
public com.google.bigtable.admin.v2.Type toProto() {
199233
com.google.bigtable.admin.v2.Type.Builder builder =
200234
com.google.bigtable.admin.v2.Type.newBuilder();
201235
builder.getInt64TypeBuilder().setEncoding(getEncoding().toProto());
@@ -208,13 +242,13 @@ static Int64 fromProto(com.google.bigtable.admin.v2.Type.Int64 source) {
208242
}
209243

210244
@AutoValue
211-
public abstract static class Raw extends Type {
245+
public abstract static class Raw implements Type {
212246
public static Raw create() {
213247
return new AutoValue_Type_Raw();
214248
}
215249

216250
@Override
217-
com.google.bigtable.admin.v2.Type toProto() {
251+
public com.google.bigtable.admin.v2.Type toProto() {
218252
return com.google.bigtable.admin.v2.Type.getDefaultInstance();
219253
}
220254
}
@@ -226,7 +260,7 @@ com.google.bigtable.admin.v2.Type toProto() {
226260
* the `input_type` or `state_type`, and reads will always return the `state_type` .
227261
*/
228262
@AutoValue
229-
public abstract static class Aggregate extends Type {
263+
public abstract static class Aggregate implements Type {
230264
public static Aggregate create(Type inputType, Aggregator aggregator) {
231265
return new AutoValue_Type_Aggregate(inputType, aggregator);
232266
}
@@ -250,11 +284,49 @@ void buildTo(com.google.bigtable.admin.v2.Type.Aggregate.Builder builder) {
250284
}
251285
}
252286

287+
@AutoValue
288+
public abstract static class Min extends Aggregator {
289+
public static Min create() {
290+
return new AutoValue_Type_Aggregate_Aggregator_Min();
291+
}
292+
293+
@Override
294+
void buildTo(com.google.bigtable.admin.v2.Type.Aggregate.Builder builder) {
295+
builder.setMin(com.google.bigtable.admin.v2.Type.Aggregate.Min.getDefaultInstance());
296+
}
297+
}
298+
299+
@AutoValue
300+
public abstract static class Max extends Aggregator {
301+
public static Max create() {
302+
return new AutoValue_Type_Aggregate_Aggregator_Max();
303+
}
304+
305+
@Override
306+
void buildTo(com.google.bigtable.admin.v2.Type.Aggregate.Builder builder) {
307+
builder.setMax(com.google.bigtable.admin.v2.Type.Aggregate.Max.getDefaultInstance());
308+
}
309+
}
310+
311+
@AutoValue
312+
public abstract static class Hll extends Aggregator {
313+
public static Hll create() {
314+
return new AutoValue_Type_Aggregate_Aggregator_Hll();
315+
}
316+
317+
@Override
318+
void buildTo(com.google.bigtable.admin.v2.Type.Aggregate.Builder builder) {
319+
builder.setHllppUniqueCount(
320+
com.google.bigtable.admin.v2.Type.Aggregate.HyperLogLogPlusPlusUniqueCount
321+
.getDefaultInstance());
322+
}
323+
}
324+
253325
abstract void buildTo(com.google.bigtable.admin.v2.Type.Aggregate.Builder builder);
254326
}
255327

256328
@Override
257-
com.google.bigtable.admin.v2.Type toProto() {
329+
public com.google.bigtable.admin.v2.Type toProto() {
258330
com.google.bigtable.admin.v2.Type.Builder typeBuilder =
259331
com.google.bigtable.admin.v2.Type.newBuilder();
260332
com.google.bigtable.admin.v2.Type.Aggregate.Builder aggregateBuilder =
@@ -271,6 +343,15 @@ static Aggregate fromProto(com.google.bigtable.admin.v2.Type.Aggregate source) {
271343
case SUM:
272344
aggregator = Aggregator.Sum.create();
273345
break;
346+
case MIN:
347+
aggregator = Aggregator.Min.create();
348+
break;
349+
case MAX:
350+
aggregator = Aggregator.Max.create();
351+
break;
352+
case HLLPP_UNIQUE_COUNT:
353+
aggregator = Aggregator.Hll.create();
354+
break;
274355
case AGGREGATOR_NOT_SET:
275356
throw new UnsupportedOperationException();
276357
}

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,24 @@ public void testCreateTable() {
256256
ColumnFamily.newBuilder()
257257
.setGcRule(GcRule.getDefaultInstance())
258258
.setValueType(TypeProtos.intSumType())
259+
.build())
260+
.putColumnFamilies(
261+
"cf2",
262+
ColumnFamily.newBuilder()
263+
.setGcRule(GcRule.getDefaultInstance())
264+
.setValueType(TypeProtos.intMinType())
265+
.build())
266+
.putColumnFamilies(
267+
"cf3",
268+
ColumnFamily.newBuilder()
269+
.setGcRule(GcRule.getDefaultInstance())
270+
.setValueType(TypeProtos.intMaxType())
271+
.build())
272+
.putColumnFamilies(
273+
"cf4",
274+
ColumnFamily.newBuilder()
275+
.setGcRule(GcRule.getDefaultInstance())
276+
.setValueType(TypeProtos.intHllType())
259277
.build()))
260278
.build();
261279

@@ -267,7 +285,12 @@ public void testCreateTable() {
267285

268286
// Execute
269287
Table result =
270-
adminClient.createTable(CreateTableRequest.of(TABLE_ID).addFamily("cf1", Type.int64Sum()));
288+
adminClient.createTable(
289+
CreateTableRequest.of(TABLE_ID)
290+
.addFamily("cf1", Type.int64Sum())
291+
.addFamily("cf2", Type.int64Min())
292+
.addFamily("cf3", Type.int64Max())
293+
.addFamily("cf4", Type.int64Hll()));
271294

272295
// Verify
273296
assertThat(result).isEqualTo(Table.fromProto(expectedResponse));

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/TypeProtos.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,33 @@ public static com.google.bigtable.admin.v2.Type intSumType() {
4848
.setSum(com.google.bigtable.admin.v2.Type.Aggregate.Sum.getDefaultInstance()))
4949
.build();
5050
}
51+
52+
public static com.google.bigtable.admin.v2.Type intMinType() {
53+
return com.google.bigtable.admin.v2.Type.newBuilder()
54+
.setAggregateType(
55+
com.google.bigtable.admin.v2.Type.Aggregate.newBuilder()
56+
.setInputType(TypeProtos.int64Type())
57+
.setMin(com.google.bigtable.admin.v2.Type.Aggregate.Min.getDefaultInstance()))
58+
.build();
59+
}
60+
61+
public static com.google.bigtable.admin.v2.Type intMaxType() {
62+
return com.google.bigtable.admin.v2.Type.newBuilder()
63+
.setAggregateType(
64+
com.google.bigtable.admin.v2.Type.Aggregate.newBuilder()
65+
.setInputType(TypeProtos.int64Type())
66+
.setMax(com.google.bigtable.admin.v2.Type.Aggregate.Max.getDefaultInstance()))
67+
.build();
68+
}
69+
70+
public static com.google.bigtable.admin.v2.Type intHllType() {
71+
return com.google.bigtable.admin.v2.Type.newBuilder()
72+
.setAggregateType(
73+
com.google.bigtable.admin.v2.Type.Aggregate.newBuilder()
74+
.setInputType(TypeProtos.int64Type())
75+
.setHllppUniqueCount(
76+
com.google.bigtable.admin.v2.Type.Aggregate.HyperLogLogPlusPlusUniqueCount
77+
.getDefaultInstance()))
78+
.build();
79+
}
5180
}

0 commit comments

Comments
 (0)