amogh-jahagirdar commented on code in PR #7759: URL: https://github.com/apache/iceberg/pull/7759#discussion_r1218317957
########## core/src/main/java/org/apache/iceberg/view/ViewMetadata.java: ########## @@ -0,0 +1,144 @@ +/* + * 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.io.Serializable; +import java.util.List; +import java.util.Map; +import org.apache.iceberg.Schema; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; +import org.apache.iceberg.util.PropertyUtil; +import org.immutables.value.Value; + [email protected] +public abstract class ViewMetadata implements Serializable { + static final int SUPPORTED_VIEW_FORMAT_VERSION = 1; + + public abstract int formatVersion(); + + public abstract String location(); + + public abstract Integer currentSchemaId(); + + public abstract List<Schema> schemas(); + + public abstract int currentVersionId(); + + public abstract List<ViewVersion> versions(); + + public abstract List<ViewHistoryEntry> history(); + + public abstract Map<String, String> properties(); + + public ViewVersion version(int versionId) { + return versionsById().get(versionId); + } + + @Value.Lazy + public ViewVersion currentVersion() { + return versionsById().get(currentVersionId()); + } + + @Value.Derived + public Map<Integer, ViewVersion> versionsById() { + return indexVersions(versions()); + } + + @Value.Derived + public Map<Integer, Schema> schemasById() { + return indexSchemas(schemas()); + } + + @Value.Lazy + public Schema schema() { + return schemasById().get(currentSchemaId()); + } + + @Value.Default + int versionHistorySizeToKeep() { + return PropertyUtil.propertyAsInt( + properties(), + ViewProperties.VERSION_HISTORY_SIZE, + ViewProperties.VERSION_HISTORY_SIZE_DEFAULT); + } + + @Value.Check + protected ViewMetadata checkAndNormalize() { + Preconditions.checkArgument( + formatVersion() > 0 && formatVersion() <= ViewMetadata.SUPPORTED_VIEW_FORMAT_VERSION, + "Unsupported format version: %s", + formatVersion()); + + // TODO: should the size of versions() and history() always be equal to currentVersionId()? Review Comment: I think the answer should be no here. so we can remove the comment (I think), For example, Older view versions can be removed so the size of the list and the value of the version ID may not be the same (e.g. (versions list has 1 view with the latest view with id 3, so the size is 1 and currentVersionId() is 3). ########## core/src/test/resources/org.apache.iceberg.view/ViewMetadataInvalidCurrentSchema.json: ########## @@ -0,0 +1,80 @@ +{ Review Comment: The path for all the view json files in resources seems to be off should be core/src/test/resources/org/apache/iceberg/view/ViewMetadataInvalidCurrentSchema.json same with others. -- 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]
