xloya commented on code in PR #5728:
URL: https://github.com/apache/gravitino/pull/5728#discussion_r1872825622


##########
core/src/main/java/org/apache/gravitino/storage/relational/mapper/ModelVersionAliasSQLProviderFactory.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.mapper;
+
+import com.google.common.collect.ImmutableMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType;
+import 
org.apache.gravitino.storage.relational.mapper.provider.base.ModelVersionAliasRelBaseSQLProvider;
+import 
org.apache.gravitino.storage.relational.mapper.provider.postgresql.ModelVersionAliasRelPostgreSQLProvider;
+import org.apache.gravitino.storage.relational.po.ModelVersionAliasRelPO;
+import org.apache.gravitino.storage.relational.session.SqlSessionFactoryHelper;
+import org.apache.ibatis.annotations.Param;
+
+public class ModelVersionAliasSQLProviderFactory {
+
+  static class ModelVersionAliasRelMySQLProvider extends 
ModelVersionAliasRelBaseSQLProvider {}
+
+  static class ModelVersionAliasRelH2Provider extends 
ModelVersionAliasRelBaseSQLProvider {}
+
+  private static final Map<JDBCBackendType, 
ModelVersionAliasRelBaseSQLProvider>
+      MODEL_VERSION_META_SQL_PROVIDER_MAP =
+          ImmutableMap.of(
+              JDBCBackendType.MYSQL, new ModelVersionAliasRelMySQLProvider(),
+              JDBCBackendType.H2, new ModelVersionAliasRelH2Provider(),
+              JDBCBackendType.POSTGRESQL, new 
ModelVersionAliasRelPostgreSQLProvider());
+
+  public static ModelVersionAliasRelBaseSQLProvider getProvider() {
+    String databaseId =
+        SqlSessionFactoryHelper.getInstance()
+            .getSqlSessionFactory()
+            .getConfiguration()
+            .getDatabaseId();
+
+    JDBCBackendType jdbcBackendType = JDBCBackendType.fromString(databaseId);
+    return MODEL_VERSION_META_SQL_PROVIDER_MAP.get(jdbcBackendType);
+  }
+
+  public static String insertModelVersionAliasRel(

Review Comment:
   Should make the `Rel` to `Rels` for the both method name and the param? 
Because we need insert a list here.



##########
core/src/main/java/org/apache/gravitino/storage/relational/service/ModelVersionMetaService.java:
##########
@@ -0,0 +1,288 @@
+/*
+ * 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.service;
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.exceptions.NoSuchEntityException;
+import org.apache.gravitino.meta.ModelEntity;
+import org.apache.gravitino.meta.ModelVersionEntity;
+import org.apache.gravitino.storage.relational.mapper.ModelMetaMapper;
+import 
org.apache.gravitino.storage.relational.mapper.ModelVersionAliasRelMapper;
+import org.apache.gravitino.storage.relational.mapper.ModelVersionMetaMapper;
+import org.apache.gravitino.storage.relational.po.ModelPO;
+import org.apache.gravitino.storage.relational.po.ModelVersionAliasRelPO;
+import org.apache.gravitino.storage.relational.po.ModelVersionPO;
+import org.apache.gravitino.storage.relational.utils.ExceptionUtils;
+import org.apache.gravitino.storage.relational.utils.POConverters;
+import org.apache.gravitino.storage.relational.utils.SessionUtils;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.apache.gravitino.utils.NamespaceUtil;
+import org.glassfish.jersey.internal.guava.Lists;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ModelVersionMetaService {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ModelVersionMetaService.class);
+
+  private static final ModelVersionMetaService INSTANCE = new 
ModelVersionMetaService();
+
+  public static ModelVersionMetaService getInstance() {
+    return INSTANCE;
+  }
+
+  private ModelVersionMetaService() {}
+
+  public List<ModelVersionEntity> listModelVersionsByNamespace(Namespace ns) {
+    NamespaceUtil.checkModelVersion(ns);
+
+    NameIdentifier modelIdent = NameIdentifier.of(ns.levels());
+    // Will throw a NoSuchEntityException if the model does not exist.
+    ModelEntity modelEntity = 
ModelMetaService.getInstance().getModelByIdentifier(modelIdent);
+
+    List<ModelVersionPO> modelVersionPOs =
+        SessionUtils.getWithoutCommit(
+            ModelVersionMetaMapper.class,
+            mapper -> mapper.listModelVersionMetasByModelId(modelEntity.id()));
+
+    if (modelVersionPOs.isEmpty()) {
+      return Collections.emptyList();
+    }
+
+    // Get the aliases for all the model versions.
+    List<ModelVersionAliasRelPO> aliasRelPOs =
+        SessionUtils.getWithoutCommit(
+            ModelVersionAliasRelMapper.class,
+            mapper -> 
mapper.selectModelVersionAliasRelByModelId(modelEntity.id()));
+    Multimap<Integer, ModelVersionAliasRelPO> aliasRelPOsByModelVersion =
+        ArrayListMultimap.create();
+    aliasRelPOs.forEach(r -> 
aliasRelPOsByModelVersion.put(r.getModelVersion(), r));
+
+    return modelVersionPOs.stream()
+        .map(
+            m -> {
+              List<ModelVersionAliasRelPO> versionAliasRelPOs =
+                  
Lists.newArrayList(aliasRelPOsByModelVersion.get(m.getModelVersion()));
+              return POConverters.fromModelVersionPO(modelIdent, m, 
versionAliasRelPOs);
+            })
+        .collect(Collectors.toList());
+  }
+
+  public ModelVersionEntity getModelVersionByIdentifier(NameIdentifier ident) {
+    NameIdentifierUtil.checkModelVersion(ident);
+
+    NameIdentifier modelIdent = NameIdentifier.of(ident.namespace().levels());
+    // Will throw a NoSuchEntityException if the model does not exist.
+    ModelEntity modelEntity = 
ModelMetaService.getInstance().getModelByIdentifier(modelIdent);
+
+    Integer modelVersion;
+    try {
+      modelVersion = Integer.valueOf(ident.name());

Review Comment:
   What situation the `ident.name()` will be a Integer, and why use this as the 
model version property? Is the identity like `metalake.catalog.schema.model.1`?



-- 
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: commits-unsubscr...@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to