Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3257737

Browse files
Neenu1995gcf-owl-bot[bot]
andauthoredJan 26, 2023
feat: add collation for Case sensitive string column (#2490)
* feat: add collation for Case sensitive string column * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore: fix typo Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent cd8b3ae commit 3257737

File tree

8 files changed

+198
-3
lines changed

8 files changed

+198
-3
lines changed
 

‎README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ implementation 'com.google.cloud:google-cloud-bigquery'
5959
If you are using Gradle without BOM, add this to your dependencies:
6060

6161
```Groovy
62-
implementation 'com.google.cloud:google-cloud-bigquery:2.20.2'
62+
implementation 'com.google.cloud:google-cloud-bigquery:2.21.0'
6363
```
6464

6565
If you are using SBT, add this to your dependencies:
6666

6767
```Scala
68-
libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.20.2"
68+
libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.21.0"
6969
```
7070

7171
## Authentication

‎google-cloud-bigquery/clirr-ignored-differences.xml

+10
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,14 @@
3434
<className>com/google/cloud/bigquery/Connection</className>
3535
<method>com.google.common.util.concurrent.ListenableFuture executeSelectAsync(java.lang.String, java.util.List, java.util.Map[])</method>
3636
</difference>
37+
<difference>
38+
<differenceType>7013</differenceType>
39+
<className>com/google/cloud/bigquery/DatasetInfo*</className>
40+
<method>*DefaultCollation(*)</method>
41+
</difference>
42+
<difference>
43+
<differenceType>7013</differenceType>
44+
<className>com/google/cloud/bigquery/TableInfo*</className>
45+
<method>*DefaultCollation(*)</method>
46+
</difference>
3747
</differences>

‎google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Dataset.java

+6
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ public Builder setDefaultPartitionExpirationMs(Long defaultPartitionExpirationMs
146146
return this;
147147
}
148148

149+
@Override
150+
public Builder setDefaultCollation(String defaultCollation) {
151+
infoBuilder.setDefaultCollation(defaultCollation);
152+
return this;
153+
}
154+
149155
@Override
150156
public Dataset build() {
151157
return new Dataset(bigquery, infoBuilder);

‎google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/DatasetInfo.java

+32
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public Dataset apply(DatasetInfo datasetInfo) {
7272
private final Labels labels;
7373
private final EncryptionConfiguration defaultEncryptionConfiguration;
7474
private final Long defaultPartitionExpirationMs;
75+
private final String defaultCollation;
7576

7677
/** A builder for {@code DatasetInfo} objects. */
7778
public abstract static class Builder {
@@ -148,6 +149,19 @@ public abstract Builder setDefaultEncryptionConfiguration(
148149
*/
149150
public abstract Builder setDefaultPartitionExpirationMs(Long defaultPartitionExpirationMs);
150151

152+
/**
153+
* Optional. Defines the default collation specification of future tables created in the
154+
* dataset. If a table is created in this dataset without table-level default collation, then
155+
* the table inherits the dataset default collation, which is applied to the string fields that
156+
* do not have explicit collation specified. A change to this field affects only tables created
157+
* afterwards, and does not alter the existing tables. The following values are supported:
158+
*
159+
* <p>* 'und:ci': undetermined locale, case insensitive. * '': empty string. Default to
160+
* case-sensitive behavior. (-- A wrapper is used here because it is possible to set the value
161+
* to the empty string. --) (-- api-linter: standard-fields=disabled --)
162+
*/
163+
public abstract Builder setDefaultCollation(String defaultCollation);
164+
151165
/** Creates a {@code DatasetInfo} object. */
152166
public abstract DatasetInfo build();
153167
}
@@ -168,6 +182,7 @@ static final class BuilderImpl extends Builder {
168182
private Labels labels = Labels.ZERO;
169183
private EncryptionConfiguration defaultEncryptionConfiguration;
170184
private Long defaultPartitionExpirationMs;
185+
private String defaultCollation;
171186

172187
BuilderImpl() {}
173188

@@ -186,6 +201,7 @@ static final class BuilderImpl extends Builder {
186201
this.labels = datasetInfo.labels;
187202
this.defaultEncryptionConfiguration = datasetInfo.defaultEncryptionConfiguration;
188203
this.defaultPartitionExpirationMs = datasetInfo.defaultPartitionExpirationMs;
204+
this.defaultCollation = datasetInfo.defaultCollation;
189205
}
190206

191207
BuilderImpl(com.google.api.services.bigquery.model.Dataset datasetPb) {
@@ -219,6 +235,7 @@ public Acl apply(Dataset.Access accessPb) {
219235
.build();
220236
}
221237
this.defaultPartitionExpirationMs = datasetPb.getDefaultPartitionExpirationMs();
238+
this.defaultCollation = datasetPb.getDefaultCollation();
222239
}
223240

224241
@Override
@@ -313,6 +330,12 @@ public Builder setDefaultPartitionExpirationMs(Long defaultPartitionExpirationMs
313330
return this;
314331
}
315332

333+
@Override
334+
public Builder setDefaultCollation(String defaultCollation) {
335+
this.defaultCollation = defaultCollation;
336+
return this;
337+
}
338+
316339
@Override
317340
public DatasetInfo build() {
318341
return new DatasetInfo(this);
@@ -334,6 +357,7 @@ public DatasetInfo build() {
334357
labels = builder.labels;
335358
defaultEncryptionConfiguration = builder.defaultEncryptionConfiguration;
336359
defaultPartitionExpirationMs = builder.defaultPartitionExpirationMs;
360+
defaultCollation = builder.defaultCollation;
337361
}
338362

339363
/** Returns the dataset identity. */
@@ -459,6 +483,10 @@ public Long getDefaultPartitionExpirationMs() {
459483
return defaultPartitionExpirationMs;
460484
}
461485

486+
public String getDefaultCollation() {
487+
return defaultCollation;
488+
}
489+
462490
/** Returns a builder for the dataset object. */
463491
public Builder toBuilder() {
464492
return new BuilderImpl(this);
@@ -481,6 +509,7 @@ public String toString() {
481509
.add("labels", labels)
482510
.add("defaultEncryptionConfiguration", defaultEncryptionConfiguration)
483511
.add("defaultPartitionExpirationMs", defaultPartitionExpirationMs)
512+
.add("defaultCollation", defaultCollation)
484513
.toString();
485514
}
486515

@@ -556,6 +585,9 @@ public Dataset.Access apply(Acl acl) {
556585
if (defaultPartitionExpirationMs != null) {
557586
datasetPb.setDefaultPartitionExpirationMs(defaultPartitionExpirationMs);
558587
}
588+
if (defaultCollation != null) {
589+
datasetPb.setDefaultCollation(defaultCollation);
590+
}
559591
return datasetPb;
560592
}
561593

‎google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Field.java

+28
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public TableFieldSchema apply(Field field) {
6363
private final Long scale;
6464
private final Long precision;
6565
private final String defaultValueExpression;
66+
private final String collation;
6667

6768
/**
6869
* Mode for a BigQuery Table field. {@link Mode#NULLABLE} fields can be set to {@code null},
@@ -87,6 +88,7 @@ public static final class Builder {
8788
private Long scale;
8889
private Long precision;
8990
private String defaultValueExpression;
91+
private String collation;
9092

9193
private Builder() {}
9294

@@ -101,6 +103,7 @@ private Builder(Field field) {
101103
this.scale = field.scale;
102104
this.precision = field.precision;
103105
this.defaultValueExpression = field.defaultValueExpression;
106+
this.collation = field.collation;
104107
}
105108

106109
/**
@@ -285,6 +288,19 @@ public Builder setDefaultValueExpression(String defaultValueExpression) {
285288
return this;
286289
}
287290

291+
/**
292+
* Optional. Field collation can be set only when the type of field is STRING. The following
293+
* values are supported:
294+
*
295+
* <p>* 'und:ci': undetermined locale, case insensitive. * '': empty string. Default to
296+
* case-sensitive behavior. (-- A wrapper is used here because it is possible to set the value
297+
* to the empty string. --)
298+
*/
299+
public Builder setCollation(String collation) {
300+
this.collation = collation;
301+
return this;
302+
}
303+
288304
/** Creates a {@code Field} object. */
289305
public Field build() {
290306
return new Field(this);
@@ -302,6 +318,7 @@ private Field(Builder builder) {
302318
this.scale = builder.scale;
303319
this.precision = builder.precision;
304320
this.defaultValueExpression = builder.defaultValueExpression;
321+
this.collation = builder.collation;
305322
}
306323

307324
/** Returns the field name. */
@@ -357,6 +374,10 @@ public String getDefaultValueExpression() {
357374
return defaultValueExpression;
358375
}
359376

377+
public String getCollation() {
378+
return collation;
379+
}
380+
360381
/**
361382
* Returns the list of sub-fields if {@link #getType()} is a {@link LegacySQLTypeName#RECORD}.
362383
* Returns {@code null} otherwise.
@@ -382,6 +403,7 @@ public String toString() {
382403
.add("scale", scale)
383404
.add("precision", precision)
384405
.add("defaultValueExpression", defaultValueExpression)
406+
.add("collation", collation)
385407
.toString();
386408
}
387409

@@ -468,6 +490,9 @@ TableFieldSchema toPb() {
468490
List<TableFieldSchema> fieldsPb = Lists.transform(getSubFields(), TO_PB_FUNCTION);
469491
fieldSchemaPb.setFields(fieldsPb);
470492
}
493+
if (collation != null) {
494+
fieldSchemaPb.setCollation(collation);
495+
}
471496
return fieldSchemaPb;
472497
}
473498

@@ -500,6 +525,9 @@ static Field fromPb(TableFieldSchema fieldSchemaPb) {
500525
? FieldList.of(Lists.transform(fieldSchemaPb.getFields(), FROM_PB_FUNCTION))
501526
: null;
502527
fieldBuilder.setType(LegacySQLTypeName.valueOf(fieldSchemaPb.getType()), subFields);
528+
if (fieldSchemaPb.getCollation() != null) {
529+
fieldBuilder.setCollation(fieldSchemaPb.getCollation());
530+
}
503531
return fieldBuilder.build();
504532
}
505533
}

‎google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Table.java

+6
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ public Builder setRequirePartitionFilter(Boolean requirePartitionFilter) {
156156
return this;
157157
}
158158

159+
@Override
160+
public Builder setDefaultCollation(String defaultCollation) {
161+
infoBuilder.setDefaultCollation(defaultCollation);
162+
return this;
163+
}
164+
159165
@Override
160166
public Table build() {
161167
return new Table(bigquery, infoBuilder);

‎google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableInfo.java

+22-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public Table apply(TableInfo tableInfo) {
7272
private final EncryptionConfiguration encryptionConfiguration;
7373
private final Labels labels;
7474
private final Boolean requirePartitionFilter;
75+
private final String defaultCollation;
7576

7677
/** A builder for {@code TableInfo} objects. */
7778
public abstract static class Builder {
@@ -135,6 +136,8 @@ public abstract static class Builder {
135136
public Builder setRequirePartitionFilter(Boolean requirePartitionFilter) {
136137
return this;
137138
}
139+
140+
public abstract Builder setDefaultCollation(String defaultCollation);
138141
}
139142

140143
static class BuilderImpl extends Builder {
@@ -155,6 +158,7 @@ static class BuilderImpl extends Builder {
155158
private EncryptionConfiguration encryptionConfiguration;
156159
private Labels labels = Labels.ZERO;
157160
private Boolean requirePartitionFilter;
161+
private String defaultCollation;
158162

159163
BuilderImpl() {}
160164

@@ -175,6 +179,7 @@ static class BuilderImpl extends Builder {
175179
this.encryptionConfiguration = tableInfo.encryptionConfiguration;
176180
this.labels = tableInfo.labels;
177181
this.requirePartitionFilter = tableInfo.requirePartitionFilter;
182+
this.defaultCollation = tableInfo.defaultCollation;
178183
}
179184

180185
BuilderImpl(Table tablePb) {
@@ -199,6 +204,7 @@ static class BuilderImpl extends Builder {
199204
}
200205
this.labels = Labels.fromPb(tablePb.getLabels());
201206
this.requirePartitionFilter = tablePb.getRequirePartitionFilter();
207+
this.defaultCollation = tablePb.getDefaultCollation();
202208
}
203209

204210
@Override
@@ -297,6 +303,12 @@ public Builder setRequirePartitionFilter(Boolean requirePartitionFilter) {
297303
return this;
298304
}
299305

306+
@Override
307+
public Builder setDefaultCollation(String defaultCollation) {
308+
this.defaultCollation = defaultCollation;
309+
return this;
310+
}
311+
300312
@Override
301313
public TableInfo build() {
302314
return new TableInfo(this);
@@ -318,8 +330,9 @@ public TableInfo build() {
318330
this.numRows = builder.numRows;
319331
this.definition = builder.definition;
320332
this.encryptionConfiguration = builder.encryptionConfiguration;
321-
labels = builder.labels;
333+
this.labels = builder.labels;
322334
this.requirePartitionFilter = builder.requirePartitionFilter;
335+
this.defaultCollation = builder.defaultCollation;
323336
}
324337

325338
/** Returns the hash of the table resource. */
@@ -422,6 +435,10 @@ public Boolean getRequirePartitionFilter() {
422435
return requirePartitionFilter;
423436
}
424437

438+
public String getDefaultCollation() {
439+
return defaultCollation;
440+
}
441+
425442
/** Returns a builder for the table object. */
426443
public Builder toBuilder() {
427444
return new BuilderImpl(this);
@@ -446,6 +463,7 @@ public String toString() {
446463
.add("encryptionConfiguration", encryptionConfiguration)
447464
.add("labels", labels)
448465
.add("requirePartitionFilter", requirePartitionFilter)
466+
.add("defaultCollation", defaultCollation)
449467
.toString();
450468
}
451469

@@ -507,6 +525,9 @@ Table toPb() {
507525
}
508526
tablePb.setLabels(labels.toPb());
509527
tablePb.setRequirePartitionFilter(requirePartitionFilter);
528+
if (defaultCollation != null) {
529+
tablePb.setDefaultCollation(defaultCollation);
530+
}
510531
return tablePb;
511532
}
512533

There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.