You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/03/04 22:00:06 UTC
[GitHub] [iceberg] kbendick commented on a change in pull request #4266: Core: Convert REST request classes to Immutables
kbendick commented on a change in pull request #4266:
URL: https://github.com/apache/iceberg/pull/4266#discussion_r819945410
##########
File path: core/src/main/java/org/apache/iceberg/rest/requests/UpdateNamespacePropertiesRequest.java
##########
@@ -19,109 +19,35 @@
package org.apache.iceberg.rest.requests;
-import java.util.Collection;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
-import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
-import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
-import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
-import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet;
-import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.immutables.value.Value;
/**
* A REST request to set and/or remove properties on a namespace.
+ *
+ * Note that Immutable classes by definition don't have a default no-arg constructor (which is required for Jackson),
+ * therefore the @{@link JsonSerialize}/@{@link JsonDeserialize} annotations on the class will generate what's
+ * necessary for Jackson-binding to properly work with this class.
*/
-public class UpdateNamespacePropertiesRequest {
-
- private List<String> removals;
- private Map<String, String> updates;
-
- public UpdateNamespacePropertiesRequest() {
- // Required for Jackson deserialization.
- }
+@Value.Immutable
+@JsonSerialize(as = ImmutableUpdateNamespacePropertiesRequest.class)
+@JsonDeserialize(as = ImmutableUpdateNamespacePropertiesRequest.class)
+public abstract class UpdateNamespacePropertiesRequest {
- private UpdateNamespacePropertiesRequest(List<String> removals, Map<String, String> updates) {
- this.removals = removals;
- this.updates = updates;
- validate();
- }
+ public abstract List<String> removals();
- UpdateNamespacePropertiesRequest validate() {
- return this;
- }
-
- public List<String> removals() {
- return removals == null ? ImmutableList.of() : removals;
- }
-
- public Map<String, String> updates() {
- return updates == null ? ImmutableMap.of() : updates;
- }
+ public abstract Map<String, String> updates();
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
- .add("removals", removals)
- .add("updates", updates)
+ .add("removals", removals())
+ .add("updates", updates())
.toString();
}
-
- public static Builder builder() {
- return new Builder();
- }
-
- public static class Builder {
- private final ImmutableSet.Builder<String> removalsBuilder = ImmutableSet.builder();
- private final ImmutableMap.Builder<String, String> updatesBuilder = ImmutableMap.builder();
-
- private Builder() {
- }
-
- public Builder remove(String removal) {
- Preconditions.checkNotNull(removal,
- "Invalid property to remove: null");
- removalsBuilder.add(removal);
- return this;
- }
-
- public Builder removeAll(Collection<String> removals) {
- Preconditions.checkNotNull(removals,
- "Invalid list of properties to remove: null");
- Preconditions.checkArgument(!removals.contains(null),
- "Invalid property to remove: null");
- removalsBuilder.addAll(removals);
- return this;
- }
-
- public Builder update(String key, String value) {
- Preconditions.checkNotNull(key,
- "Invalid property to update: null");
- Preconditions.checkNotNull(value,
- "Invalid value to update for key [%s]: null. Use remove instead", key);
Review comment:
Is it possible to have a value of `null` in one of the map collections with immutables (like a configuration or annotation to put on the class maybe)?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org