Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.

Commit e235a6e

Browse files
committed
feat: Add support for additional types
1 parent 509a0c6 commit e235a6e

5 files changed

Lines changed: 242 additions & 3 deletions

File tree

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

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ public abstract class Type {
3131
private Type() {}
3232

3333
/**
34-
* This type is a marker type that allows types to be used as the input to the SUM aggregate
35-
* function.
34+
* These types are marker types that allow types to be used as the input to aggregate function.
3635
*/
3736
public abstract static class SumAggregateInput extends Type {}
3837

38+
public abstract static class MinAggregateInput extends Type {}
39+
40+
public abstract static class MaxAggregateInput extends Type {}
41+
42+
public abstract static class HllAggregateInput extends Type {}
43+
3944
abstract com.google.bigtable.admin.v2.Type toProto();
4045

4146
static Type fromProto(com.google.bigtable.admin.v2.Type source) {
@@ -91,6 +96,36 @@ public static Aggregate sum(SumAggregateInput inputType) {
9196
return Aggregate.create(inputType, Aggregate.Aggregator.Sum.create());
9297
}
9398

99+
/** Creates an Aggregate type with a MIN aggregator and Int64 input type. */
100+
public static Aggregate int64Min() {
101+
return min(bigEndianInt64());
102+
}
103+
104+
/** Creates an Aggregate type with a MIN aggregator and specified input type. */
105+
public static Aggregate min(MinAggregateInput inputType) {
106+
return Aggregate.create(inputType, Aggregate.Aggregator.Min.create());
107+
}
108+
109+
/** Creates an Aggregate type with a MAX aggregator and Int64 input type. */
110+
public static Aggregate int64Max() {
111+
return max(bigEndianInt64());
112+
}
113+
114+
/** Creates an Aggregate type with a MAX aggregator and specified input type. */
115+
public static Aggregate max(MaxAggregateInput inputType) {
116+
return Aggregate.create(inputType, Aggregate.Aggregator.Max.create());
117+
}
118+
119+
/** Creates an Aggregate type with a HLL aggregator and Int64 input type. */
120+
public static Aggregate rawBytesHll() {
121+
return hll(rawBytes());
122+
}
123+
124+
/** Creates an Aggregate type with a HLL aggregator and specified input type. */
125+
public static Aggregate hll(HllAggregateInput inputType) {
126+
return Aggregate.create(inputType, Aggregate.Aggregator.Hll.create());
127+
}
128+
94129
/** Represents a string of bytes with a specific encoding. */
95130
@AutoValue
96131
public abstract static class Bytes extends Type {
@@ -250,6 +285,44 @@ void buildTo(com.google.bigtable.admin.v2.Type.Aggregate.Builder builder) {
250285
}
251286
}
252287

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

@@ -271,6 +344,15 @@ static Aggregate fromProto(com.google.bigtable.admin.v2.Type.Aggregate source) {
271344
case SUM:
272345
aggregator = Aggregator.Sum.create();
273346
break;
347+
case MIN:
348+
aggregator = Aggregator.Min.create();
349+
break;
350+
case MAX:
351+
aggregator = Aggregator.Max.create();
352+
break;
353+
case HLL:
354+
aggregator = Aggregator.Hll.create();
355+
break;
274356
case AGGREGATOR_NOT_SET:
275357
throw new UnsupportedOperationException();
276358
}

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.rawBytesHll())
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.rawBytesHll()));
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 bytesHllType() {
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
}

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ public void modifyFamilies() {
8080
.addFamily("cf3")
8181
.addFamily("cf4", Type.int64Sum())
8282
.addFamily("cf5", GCRules.GCRULES.maxVersions(1), Type.int64Sum())
83+
.addFamily("cf6", Type.int64Min())
84+
.addFamily("cf7", GCRules.GCRULES.maxVersions(1), Type.int64Min())
85+
.addFamily("cf8", Type.int64Max())
86+
.addFamily("cf9", GCRules.GCRULES.maxVersions(1), Type.int64Max())
87+
.addFamily("cf10", Type.rawBytesHll())
88+
.addFamily("cf11", GCRules.GCRULES.maxVersions(1), Type.rawBytesHll())
8389
.updateFamily("cf1", GCRules.GCRULES.maxVersions(5))
8490
.dropFamily("cf3")
8591
.toProto(PROJECT_ID, INSTANCE_ID);
@@ -119,6 +125,48 @@ public void modifyFamilies() {
119125
com.google.bigtable.admin.v2.ColumnFamily.newBuilder()
120126
.setGcRule(GCRules.GCRULES.maxVersions(1).toProto())
121127
.setValueType(Type.int64Sum().toProto())))
128+
.addModifications(
129+
com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification.newBuilder()
130+
.setId("cf6")
131+
.setCreate(
132+
com.google.bigtable.admin.v2.ColumnFamily.newBuilder()
133+
.setGcRule(GcRule.getDefaultInstance())
134+
.setValueType(Type.int64Min().toProto())))
135+
.addModifications(
136+
com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification.newBuilder()
137+
.setId("cf7")
138+
.setCreate(
139+
com.google.bigtable.admin.v2.ColumnFamily.newBuilder()
140+
.setGcRule(GCRules.GCRULES.maxVersions(1).toProto())
141+
.setValueType(Type.int64Min().toProto())))
142+
.addModifications(
143+
com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification.newBuilder()
144+
.setId("cf8")
145+
.setCreate(
146+
com.google.bigtable.admin.v2.ColumnFamily.newBuilder()
147+
.setGcRule(GcRule.getDefaultInstance())
148+
.setValueType(Type.int64Max().toProto())))
149+
.addModifications(
150+
com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification.newBuilder()
151+
.setId("cf9")
152+
.setCreate(
153+
com.google.bigtable.admin.v2.ColumnFamily.newBuilder()
154+
.setGcRule(GCRules.GCRULES.maxVersions(1).toProto())
155+
.setValueType(Type.int64Max().toProto())))
156+
.addModifications(
157+
com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification.newBuilder()
158+
.setId("cf10")
159+
.setCreate(
160+
com.google.bigtable.admin.v2.ColumnFamily.newBuilder()
161+
.setGcRule(GcRule.getDefaultInstance())
162+
.setValueType(Type.rawBytesHll().toProto())))
163+
.addModifications(
164+
com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification.newBuilder()
165+
.setId("cf11")
166+
.setCreate(
167+
com.google.bigtable.admin.v2.ColumnFamily.newBuilder()
168+
.setGcRule(GCRules.GCRULES.maxVersions(1).toProto())
169+
.setValueType(Type.rawBytesHll().toProto())))
122170
.addModifications(
123171
com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification.newBuilder()
124172
.setId("cf1")

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,61 @@ public void intSumFromProtoToProto() {
7777
assertThat(Type.fromProto(proto)).isEqualTo(Type.int64Sum());
7878
assertThat(Type.fromProto(proto).toProto()).isEqualTo(proto);
7979
}
80+
81+
@Test
82+
public void int64Min() {
83+
Type type = Type.int64Min();
84+
assertThat(type.toProto()).isEqualTo(TypeProtos.intMinType());
85+
}
86+
87+
@Test
88+
public void min() {
89+
Type type = Type.min(Type.bigEndianInt64());
90+
assertThat(type.toProto()).isEqualTo(TypeProtos.intMinType());
91+
}
92+
93+
@Test
94+
public void intMinFromProtoToProto() {
95+
com.google.bigtable.admin.v2.Type proto = TypeProtos.intMinType();
96+
assertThat(Type.fromProto(proto)).isEqualTo(Type.int64Min());
97+
assertThat(Type.fromProto(proto).toProto()).isEqualTo(proto);
98+
}
99+
100+
@Test
101+
public void int64Max() {
102+
Type type = Type.int64Max();
103+
assertThat(type.toProto()).isEqualTo(TypeProtos.intMaxType());
104+
}
105+
106+
@Test
107+
public void max() {
108+
Type type = Type.max(Type.bigEndianInt64());
109+
assertThat(type.toProto()).isEqualTo(TypeProtos.intMaxType());
110+
}
111+
112+
@Test
113+
public void intMaxFromProtoToProto() {
114+
com.google.bigtable.admin.v2.Type proto = TypeProtos.intMaxType();
115+
assertThat(Type.fromProto(proto)).isEqualTo(Type.int64Max());
116+
assertThat(Type.fromProto(proto).toProto()).isEqualTo(proto);
117+
}
118+
119+
@Test
120+
public void bytesHll() {
121+
Type type = Type.rawBytesHll();
122+
assertThat(type.toProto()).isEqualTo(TypeProtos.bytesHllType());
123+
}
124+
125+
@Test
126+
public void hll() {
127+
Type type = Type.hll(Type.rawBytes());
128+
assertThat(type.toProto()).isEqualTo(TypeProtos.bytesHllType());
129+
}
130+
131+
@Test
132+
public void bytesHllFromProtoToProto() {
133+
com.google.bigtable.admin.v2.Type proto = TypeProtos.bytesHllType();
134+
assertThat(Type.fromProto(proto)).isEqualTo(Type.rawBytesHll());
135+
assertThat(Type.fromProto(proto).toProto()).isEqualTo(proto);
136+
}
80137
}

0 commit comments

Comments
 (0)