2525import com .google .common .base .Function ;
2626import com .google .common .base .MoreObjects ;
2727import com .google .common .collect .ImmutableList ;
28+ import com .google .common .collect .ImmutableMap ;
2829import com .google .common .collect .Lists ;
2930import java .io .Serializable ;
3031import java .util .List ;
@@ -68,7 +69,7 @@ public Dataset apply(DatasetInfo datasetInfo) {
6869 private final Long lastModified ;
6970 private final String location ;
7071 private final String selfLink ;
71- private final Labels labels ;
72+ private final Map < String , String > labels ;
7273
7374 /**
7475 * A builder for {@code DatasetInfo} objects.
@@ -156,7 +157,7 @@ static final class BuilderImpl extends Builder {
156157 private Long lastModified ;
157158 private String location ;
158159 private String selfLink ;
159- private Labels labels = Labels . ZERO ;
160+ private Map < String , String > labels ;
160161
161162 BuilderImpl () {}
162163
@@ -172,7 +173,9 @@ static final class BuilderImpl extends Builder {
172173 this .lastModified = datasetInfo .lastModified ;
173174 this .location = datasetInfo .location ;
174175 this .selfLink = datasetInfo .selfLink ;
175- this .labels = datasetInfo .labels ;
176+ this .labels = datasetInfo .labels != null
177+ ? ImmutableMap .copyOf (datasetInfo .labels )
178+ : null ;
176179 }
177180
178181 BuilderImpl (com .google .api .services .bigquery .model .Dataset datasetPb ) {
@@ -196,7 +199,9 @@ public Acl apply(Dataset.Access accessPb) {
196199 this .lastModified = datasetPb .getLastModifiedTime ();
197200 this .location = datasetPb .getLocation ();
198201 this .selfLink = datasetPb .getSelfLink ();
199- this .labels = Labels .fromPb (datasetPb .getLabels ());
202+ this .labels = datasetPb .getLabels () != null
203+ ? ImmutableMap .copyOf (datasetPb .getLabels ())
204+ : null ;
200205 }
201206
202207
@@ -272,16 +277,9 @@ Builder setSelfLink(String selfLink) {
272277 return this ;
273278 }
274279
275- /**
276- * Sets the labels applied to this dataset.
277- *
278- * <p>When used with {@link BigQuery#update(DatasetInfo, DatasetOption...)}, setting {@code
279- * labels} to {@code null} removes all labels; otherwise all keys that are mapped to {@code
280- * null} values are removed and other keys are updated to their respective values.
281- */
282280 @ Override
283281 public Builder setLabels (Map <String , String > labels ) {
284- this .labels = Labels . fromUser (labels );
282+ this .labels = ImmutableMap . copyOf (labels );
285283 return this ;
286284 }
287285
@@ -413,7 +411,7 @@ public String getSelfLink() {
413411 * @see <a href="https://cloud.google.com/bigquery/docs/labeling-datasets">Labeling Datasets</a>
414412 */
415413 public Map <String , String > getLabels () {
416- return labels . userMap () ;
414+ return labels ;
417415 }
418416
419417 /**
@@ -496,7 +494,9 @@ public Dataset.Access apply(Acl acl) {
496494 }
497495 }));
498496 }
499- datasetPb .setLabels (labels .toPb ());
497+ if (labels != null ) {
498+ datasetPb .setLabels (labels );
499+ }
500500 return datasetPb ;
501501 }
502502
0 commit comments