rdblue commented on code in PR #6559: URL: https://github.com/apache/iceberg/pull/6559#discussion_r1090874509
########## core/src/main/java/org/apache/iceberg/view/BaseSQLViewRepresentation.java: ########## @@ -0,0 +1,206 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iceberg.view; + +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import org.apache.iceberg.catalog.Namespace; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; + +public class BaseSQLViewRepresentation implements SQLViewRepresentation { + + private final String query; + private final String dialect; + private final String defaultCatalog; + private final int schemaId; + private final Namespace defaultNamespace; + private final List<String> fieldAliases; + private final List<String> fieldComments; + + public static Builder builder() { + return new Builder(); + } + + public static Builder buildFrom(SQLViewRepresentation representation) { + return builder() + .query(representation.query()) + .schemaId(representation.schemaId()) + .dialect(representation.dialect()) + .defaultCatalog(representation.defaultCatalog()) + .defaultNamespace(representation.defaultNamespace()) + .fieldAliases(representation.fieldAliases()) + .fieldComments(representation.fieldComments()); + } + + private BaseSQLViewRepresentation( + String query, + String dialect, + String defaultCatalog, + Namespace defaultNamespace, + int schemaId, + List<String> fieldAliases, + List<String> fieldComments) { + this.query = Preconditions.checkNotNull(query, "sql should not be null"); + this.dialect = Preconditions.checkNotNull(dialect, "dialect should not be null"); + this.defaultCatalog = + Preconditions.checkNotNull(defaultCatalog, "default catalog should not null"); + this.defaultNamespace = + Preconditions.checkNotNull(defaultNamespace, "default namespace should not be null"); + this.schemaId = Preconditions.checkNotNull(schemaId, "schema should not be null"); + this.fieldAliases = + Preconditions.checkNotNull(fieldAliases, "field aliases should not be null"); + this.fieldComments = + Preconditions.checkNotNull(fieldComments, "field comments should not be null"); + } + + @Override + public String query() { + return query; + } + + @Override + public String dialect() { + return dialect; + } + + @Override + public String defaultCatalog() { + return defaultCatalog; + } + + @Override + public Namespace defaultNamespace() { + return defaultNamespace; + } + + @Override + public int schemaId() { + return schemaId; + } + + @Override + public List<String> fieldComments() { + return fieldComments; + } + + @Override + public List<String> fieldAliases() { + return fieldAliases; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + BaseSQLViewRepresentation that = (BaseSQLViewRepresentation) o; + return Objects.equals(query, that.query) + && Objects.equals(dialect, that.dialect) + && Objects.equals(schemaId, that.schemaId) + && Objects.equals(defaultCatalog, that.defaultCatalog) + && Objects.equals(defaultNamespace, that.defaultNamespace) + && Objects.equals(fieldAliases, that.fieldAliases) + && Objects.equals(fieldComments, that.fieldComments); + } + + @Override + public int hashCode() { + return Objects.hash( + query, dialect, schemaId, defaultCatalog, defaultNamespace, fieldAliases, fieldComments); + } + + @Override + public String toString() { + return "BaseViewDefinition{" Review Comment: Can you use a helper rather than building this by hand? It's hard to read this way. We usually base these on `MoreObjects`. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
