mchades commented on code in PR #12602: URL: https://github.com/apache/gravitino/pull/12602#discussion_r3902476452
########## core/src/main/java/org/apache/gravitino/storage/relational/po/SemanticModelPO.java: ########## @@ -0,0 +1,225 @@ +/* + * 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.gravitino.storage.relational.po; + +import static org.apache.gravitino.storage.relational.utils.POConverters.DEFAULT_DELETED_AT; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.google.common.base.Preconditions; +import java.util.Collections; +import java.util.Map; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import org.apache.gravitino.Entity; +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.Namespace; +import org.apache.gravitino.json.JsonUtils; +import org.apache.gravitino.meta.AuditInfo; +import org.apache.gravitino.meta.NamespacedEntityId; +import org.apache.gravitino.meta.SemanticModelEntity; +import org.apache.gravitino.semantic.SemanticModelDefinition; +import org.apache.gravitino.storage.relational.service.EntityIdService; + +/** The persistent object for Semantic Model identity metadata and its current version snapshot. */ +@Getter +@EqualsAndHashCode(exclude = "semanticModelVersionInfoPO") +@ToString +public class SemanticModelPO { + + /** The initial version allocated to a newly created Semantic Model. */ + public static final Integer INITIAL_VERSION = 1; + + private Long semanticModelId; + private String semanticModelName; + private Long metalakeId; + private Long catalogId; + private Long schemaId; + private String auditInfo; + private Integer currentVersion; + private Integer lastVersion; + private Long deletedAt; + private SemanticModelVersionInfoPO semanticModelVersionInfoPO; + + /** Creates an empty persistent object for MyBatis. */ + public SemanticModelPO() {} + + /** A Lombok builder for {@link SemanticModelPO}. */ + public static class SemanticModelPOBuilder { + // Lombok generates the builder methods. + } + + @lombok.Builder(setterPrefix = "with") + private SemanticModelPO( + Long semanticModelId, + String semanticModelName, + Long metalakeId, + Long catalogId, + Long schemaId, + String auditInfo, + Integer currentVersion, + Integer lastVersion, + Long deletedAt, + SemanticModelVersionInfoPO semanticModelVersionInfoPO) { + Preconditions.checkArgument(semanticModelId != null, "Semantic Model id is required"); + Preconditions.checkArgument(semanticModelName != null, "Semantic Model name is required"); + Preconditions.checkArgument(metalakeId != null, "Metalake id is required"); + Preconditions.checkArgument(catalogId != null, "Catalog id is required"); + Preconditions.checkArgument(schemaId != null, "Schema id is required"); + Preconditions.checkArgument(auditInfo != null, "Audit info is required"); + Preconditions.checkArgument(currentVersion != null, "Current version is required"); + Preconditions.checkArgument(lastVersion != null, "Last version is required"); + Preconditions.checkArgument(deletedAt != null, "Deleted at is required"); + + this.semanticModelId = semanticModelId; + this.semanticModelName = semanticModelName; + this.metalakeId = metalakeId; + this.catalogId = catalogId; + this.schemaId = schemaId; + this.auditInfo = auditInfo; + this.currentVersion = currentVersion; + this.lastVersion = lastVersion; + this.deletedAt = deletedAt; + this.semanticModelVersionInfoPO = semanticModelVersionInfoPO; + } + + /** + * Converts a persistent object and its current version snapshot to a Semantic Model entity. + * + * @param semanticModelPO The persistent object to convert. + * @param namespace The Semantic Model namespace. + * @return The converted Semantic Model entity. + */ + public static SemanticModelEntity fromSemanticModelPO( Review Comment: I checked the analogous versioned entities more closely. `ViewPO` and `FunctionPO` keep their `from`, `initialize`, and version-snapshot conversion methods on the PO itself, and `JobPO` follows the same co-located pattern. `POConverters` is therefore not the universal convention and is already a large utility class. Semantic Model follows the View/Function pattern because its identity and version snapshot are built together. The shared JSON representation is already reused through `SemanticModelDefinitionDTO`, so I propose keeping these conversions on `SemanticModelPO`. -- 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]
