You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "jerqi (via GitHub)" <gi...@apache.org> on 2026/01/27 14:44:29 UTC
[PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
jerqi opened a new pull request, #9815:
URL: https://github.com/apache/gravitino/pull/9815
<!--
1. Title: [#<issue>] <type>(<scope>): <subject>
Examples:
- "[#123] feat(operator): support xxx"
- "[#233] fix: check null before access result in xxx"
- "[MINOR] refactor: fix typo in variable name"
- "[MINOR] docs: fix typo in README"
- "[#255] test: fix flaky test NameOfTheTest"
Reference: https://www.conventionalcommits.org/en/v1.0.0/
2. If the PR is unfinished, please mark this PR as draft.
-->
### What changes were proposed in this pull request?
(Please outline the changes and how this PR fixes the issue.)
### Why are the changes needed?
(Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, describe the bug.)
Fix: #(issue)
### Does this PR introduce _any_ user-facing change?
(Please list the user-facing changes introduced by your change, including
1. Change in user-facing APIs.
2. Addition or removal of property keys.)
### How was this patch tested?
(Please test your changes, and provide instructions on how to test it:
1. If you add a feature or fix a bug, add a test to cover your changes.
2. If you fix a flaky test, repeat it for many times to prove it works.)
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "qqqttt123 (via GitHub)" <gi...@apache.org>.
qqqttt123 commented on PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#issuecomment-3815708610
cc @qqqttt123
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "qqqttt123 (via GitHub)" <gi...@apache.org>.
qqqttt123 commented on code in PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#discussion_r2741304922
##########
core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/OwnerMetaPostgreSQLProvider.java:
##########
@@ -135,4 +35,10 @@ public String deleteOwnerMetasByLegacyTimeline(
+ OWNER_TABLE_NAME
+ " WHERE deleted_at > 0 AND deleted_at < #{legacyTimeline} LIMIT #{limit})";
}
+
+ @Override
+ protected String softDeleteSQL(Optional<String> tableAlias) {
+ // PostgreSQL doesn't support alias prefix in SET clause
+ return " SET deleted_at = CAST(EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) * 1000 AS BIGINT) ";
Review Comment:
It will repeat many times. Every PostgresSQLProvider will repeat for many times. I want to reduce the similar code by using method.
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "qqqttt123 (via GitHub)" <gi...@apache.org>.
qqqttt123 commented on code in PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#discussion_r2741307937
##########
core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/OwnerMetaPostgreSQLProvider.java:
##########
@@ -135,4 +35,10 @@ public String deleteOwnerMetasByLegacyTimeline(
+ OWNER_TABLE_NAME
+ " WHERE deleted_at > 0 AND deleted_at < #{legacyTimeline} LIMIT #{limit})";
}
+
+ @Override
+ protected String softDeleteSQL(Optional<String> tableAlias) {
+ // PostgreSQL doesn't support alias prefix in SET clause
+ return " SET deleted_at = CAST(EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) * 1000 AS BIGINT) ";
Review Comment:
Complex SQL is hard to read, too.
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on code in PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#discussion_r2745561287
##########
core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/CatalogSchemaExistsSQLHelper.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.provider.base;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.gravitino.storage.relational.mapper.CatalogMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.FilesetMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.ModelMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.SchemaMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.TableMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.TopicMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.ViewMetaMapper;
+
+/** Helper class to generate EXISTS SQL for catalog/schema related soft delete operations. */
+public class CatalogSchemaExistsSQLHelper {
+
+ private CatalogSchemaExistsSQLHelper() {}
+
+ /**
+ * Generates EXISTS SQL clause for catalog or schema related entities.
+ *
+ * @param tableAlias the alias of the main table (e.g., "ot", "sect")
+ * @param objectIdColumn the column name for metadata object id (e.g., "metadata_object_id")
+ * @param objectTypeColumn the column name for metadata object type (e.g., "metadata_object_type",
+ * "type")
+ * @param columnName the column to filter on (e.g., "catalog_id", "schema_id")
+ * @param paramName the parameter name for MyBatis (e.g., "catalogId", "schemaId")
+ * @param includeCatalog whether to include catalog entity in the SQL
+ * @return the EXISTS SQL clause
+ */
+ public static String generateExistsSQL(
+ String tableAlias,
+ String objectIdColumn,
+ String objectTypeColumn,
+ String columnName,
+ String paramName,
+ boolean includeCatalog) {
+ List<EntityConfig> entities = new ArrayList<>();
+ if (includeCatalog) {
+ entities.add(new EntityConfig(CatalogMetaMapper.TABLE_NAME, "ct", "catalog_id", "CATALOG"));
+ }
+ entities.add(new EntityConfig(SchemaMetaMapper.TABLE_NAME, "st", "schema_id", "SCHEMA"));
+ entities.add(new EntityConfig(TopicMetaMapper.TABLE_NAME, "tt", "topic_id", "TOPIC"));
+ entities.add(new EntityConfig(TableMetaMapper.TABLE_NAME, "tat", "table_id", "TABLE"));
+ entities.add(
+ new EntityConfig(FilesetMetaMapper.META_TABLE_NAME, "ft", "fileset_id", "FILESET"));
+ entities.add(new EntityConfig(ModelMetaMapper.TABLE_NAME, "mt", "model_id", "MODEL"));
+ entities.add(new EntityConfig(ViewMetaMapper.TABLE_NAME, "vt", "view_id", "VIEW"));
+
+ StringBuilder sql = new StringBuilder();
+ for (int i = 0; i < entities.size(); i++) {
+ if (i > 0) {
+ sql.append(" UNION");
+ }
+ EntityConfig entity = entities.get(i);
+ sql.append(
+ existsClause(
+ entity, tableAlias, objectIdColumn, objectTypeColumn, columnName, paramName));
+ }
+ return sql.toString();
+ }
+
+ private static String existsClause(
+ EntityConfig entity,
+ String tableAlias,
+ String objectIdColumn,
+ String objectTypeColumn,
+ String columnName,
+ String paramName) {
+ return String.format(
+ " SELECT %s.%s FROM %s %s"
+ + " WHERE %s.%s = #{%s}"
+ + " AND %s.%s = %s.%s"
+ + " AND %s.%s = '%s'",
+ entity.alias,
+ columnName,
+ entity.tableName,
+ entity.alias,
+ entity.alias,
+ columnName,
+ paramName,
+ entity.alias,
+ entity.objectIdColumn,
+ tableAlias,
+ objectIdColumn,
+ tableAlias,
+ objectTypeColumn,
+ entity.objectType);
+ }
Review Comment:
OK, I reverted.
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#issuecomment-3833492279
@mchades Do u have other suggestion?
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on code in PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#discussion_r2745360324
##########
core/src/main/java/org/apache/gravitino/storage/relational/service/ViewMetaService.java:
##########
@@ -0,0 +1,332 @@
+/*
+ * 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 static org.apache.gravitino.metrics.source.MetricsSource.GRAVITINO_RELATIONAL_STORE_METRIC_NAME;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.HasIdentifier;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.exceptions.NoSuchEntityException;
+import org.apache.gravitino.meta.GenericEntity;
+import org.apache.gravitino.meta.NamespacedEntityId;
+import org.apache.gravitino.metrics.Monitored;
+import org.apache.gravitino.storage.relational.mapper.OwnerMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.SecurableObjectMapper;
+import org.apache.gravitino.storage.relational.mapper.TagMetadataObjectRelMapper;
+import org.apache.gravitino.storage.relational.mapper.ViewMetaMapper;
+import org.apache.gravitino.storage.relational.po.ViewPO;
+import org.apache.gravitino.storage.relational.utils.ExceptionUtils;
+import org.apache.gravitino.storage.relational.utils.SessionUtils;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.apache.gravitino.utils.NamespaceUtil;
+
+/** The service class for view metadata. It provides the basic database operations for view. */
+public class ViewMetaService {
+ private static final ViewMetaService INSTANCE = new ViewMetaService();
+
+ public static ViewMetaService getInstance() {
+ return INSTANCE;
+ }
+
+ private ViewMetaService() {}
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getViewIdBySchemaIdAndName")
+ public Long getViewIdBySchemaIdAndName(Long schemaId, String viewName) {
+ Long viewId =
+ SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class,
+ mapper -> mapper.selectViewIdBySchemaIdAndName(schemaId, viewName));
+
+ if (viewId == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.VIEW.name().toLowerCase(),
+ viewName);
+ }
+ return viewId;
+ }
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getViewPOBySchemaIdAndName")
+ public ViewPO getViewPOBySchemaIdAndName(Long schemaId, String viewName) {
+ ViewPO viewPO =
+ SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class,
+ mapper -> mapper.selectViewMetaBySchemaIdAndName(schemaId, viewName));
+
+ if (viewPO == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.VIEW.name().toLowerCase(),
+ viewName);
+ }
+ return viewPO;
+ }
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "listViewPOsByNamespace")
+ public List<ViewPO> listViewPOsByNamespace(Namespace namespace) {
+ NamespaceUtil.checkView(namespace);
+
+ Long schemaId =
+ EntityIdService.getEntityId(
+ NameIdentifier.of(namespace.levels()), Entity.EntityType.SCHEMA);
+ return SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class, mapper -> mapper.listViewPOsBySchemaId(schemaId));
+ }
+
+ @Monitored(metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME, baseMetricName = "insertView")
+ public void insertView(ViewPO viewPO, boolean overwrite) throws IOException {
+ try {
+ SessionUtils.doWithCommit(
+ ViewMetaMapper.class,
+ mapper -> {
+ if (overwrite) {
+ mapper.insertViewMetaOnDuplicateKeyUpdate(viewPO);
+ } else {
+ mapper.insertViewMeta(viewPO);
+ }
+ });
+ } catch (RuntimeException re) {
+ ExceptionUtils.checkSQLException(re, Entity.EntityType.VIEW, viewPO.getViewName());
+ throw re;
+ }
+ }
+
+ @Monitored(metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME, baseMetricName = "updateView")
+ public void updateView(ViewPO oldViewPO, ViewPO newViewPO) throws IOException {
Review Comment:
OK, I fixed similar issues for the whole file.
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "qqqttt123 (via GitHub)" <gi...@apache.org>.
qqqttt123 commented on code in PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#discussion_r2757094413
##########
core/src/main/java/org/apache/gravitino/storage/relational/service/ViewMetaService.java:
##########
@@ -0,0 +1,332 @@
+/*
+ * 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 static org.apache.gravitino.metrics.source.MetricsSource.GRAVITINO_RELATIONAL_STORE_METRIC_NAME;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.HasIdentifier;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.exceptions.NoSuchEntityException;
+import org.apache.gravitino.meta.GenericEntity;
+import org.apache.gravitino.meta.NamespacedEntityId;
+import org.apache.gravitino.metrics.Monitored;
+import org.apache.gravitino.storage.relational.mapper.OwnerMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.SecurableObjectMapper;
+import org.apache.gravitino.storage.relational.mapper.TagMetadataObjectRelMapper;
+import org.apache.gravitino.storage.relational.mapper.ViewMetaMapper;
+import org.apache.gravitino.storage.relational.po.ViewPO;
+import org.apache.gravitino.storage.relational.utils.ExceptionUtils;
+import org.apache.gravitino.storage.relational.utils.SessionUtils;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.apache.gravitino.utils.NamespaceUtil;
+
+/** The service class for view metadata. It provides the basic database operations for view. */
+public class ViewMetaService {
+ private static final ViewMetaService INSTANCE = new ViewMetaService();
+
+ public static ViewMetaService getInstance() {
+ return INSTANCE;
+ }
+
+ private ViewMetaService() {}
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getViewIdBySchemaIdAndName")
+ public Long getViewIdBySchemaIdAndName(Long schemaId, String viewName) {
+ Long viewId =
+ SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class,
+ mapper -> mapper.selectViewIdBySchemaIdAndName(schemaId, viewName));
+
+ if (viewId == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.VIEW.name().toLowerCase(),
+ viewName);
+ }
+ return viewId;
+ }
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getViewPOBySchemaIdAndName")
+ public ViewPO getViewPOBySchemaIdAndName(Long schemaId, String viewName) {
+ ViewPO viewPO =
+ SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class,
+ mapper -> mapper.selectViewMetaBySchemaIdAndName(schemaId, viewName));
+
+ if (viewPO == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.VIEW.name().toLowerCase(),
+ viewName);
+ }
+ return viewPO;
+ }
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "listViewPOsByNamespace")
+ public List<ViewPO> listViewPOsByNamespace(Namespace namespace) {
+ NamespaceUtil.checkView(namespace);
+
+ Long schemaId =
+ EntityIdService.getEntityId(
+ NameIdentifier.of(namespace.levels()), Entity.EntityType.SCHEMA);
+ return SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class, mapper -> mapper.listViewPOsBySchemaId(schemaId));
Review Comment:
OK, I changed.
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades commented on code in PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#discussion_r2745288699
##########
core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/CatalogSchemaExistsSQLHelper.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.provider.base;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.gravitino.storage.relational.mapper.CatalogMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.FilesetMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.ModelMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.SchemaMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.TableMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.TopicMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.ViewMetaMapper;
+
+/** Helper class to generate EXISTS SQL for catalog/schema related soft delete operations. */
+public class CatalogSchemaExistsSQLHelper {
+
+ private CatalogSchemaExistsSQLHelper() {}
+
+ /**
+ * Generates EXISTS SQL clause for catalog or schema related entities.
+ *
+ * @param tableAlias the alias of the main table (e.g., "ot", "sect")
+ * @param objectIdColumn the column name for metadata object id (e.g., "metadata_object_id")
+ * @param objectTypeColumn the column name for metadata object type (e.g., "metadata_object_type",
+ * "type")
+ * @param columnName the column to filter on (e.g., "catalog_id", "schema_id")
+ * @param paramName the parameter name for MyBatis (e.g., "catalogId", "schemaId")
+ * @param includeCatalog whether to include catalog entity in the SQL
+ * @return the EXISTS SQL clause
+ */
+ public static String generateExistsSQL(
+ String tableAlias,
+ String objectIdColumn,
+ String objectTypeColumn,
+ String columnName,
+ String paramName,
+ boolean includeCatalog) {
+ List<EntityConfig> entities = new ArrayList<>();
+ if (includeCatalog) {
+ entities.add(new EntityConfig(CatalogMetaMapper.TABLE_NAME, "ct", "catalog_id", "CATALOG"));
+ }
+ entities.add(new EntityConfig(SchemaMetaMapper.TABLE_NAME, "st", "schema_id", "SCHEMA"));
+ entities.add(new EntityConfig(TopicMetaMapper.TABLE_NAME, "tt", "topic_id", "TOPIC"));
+ entities.add(new EntityConfig(TableMetaMapper.TABLE_NAME, "tat", "table_id", "TABLE"));
+ entities.add(
+ new EntityConfig(FilesetMetaMapper.META_TABLE_NAME, "ft", "fileset_id", "FILESET"));
+ entities.add(new EntityConfig(ModelMetaMapper.TABLE_NAME, "mt", "model_id", "MODEL"));
+ entities.add(new EntityConfig(ViewMetaMapper.TABLE_NAME, "vt", "view_id", "VIEW"));
+
+ StringBuilder sql = new StringBuilder();
+ for (int i = 0; i < entities.size(); i++) {
+ if (i > 0) {
+ sql.append(" UNION");
+ }
+ EntityConfig entity = entities.get(i);
+ sql.append(
+ existsClause(
+ entity, tableAlias, objectIdColumn, objectTypeColumn, columnName, paramName));
+ }
+ return sql.toString();
+ }
+
+ private static String existsClause(
+ EntityConfig entity,
+ String tableAlias,
+ String objectIdColumn,
+ String objectTypeColumn,
+ String columnName,
+ String paramName) {
+ return String.format(
+ " SELECT %s.%s FROM %s %s"
+ + " WHERE %s.%s = #{%s}"
+ + " AND %s.%s = %s.%s"
+ + " AND %s.%s = '%s'",
+ entity.alias,
+ columnName,
+ entity.tableName,
+ entity.alias,
+ entity.alias,
+ columnName,
+ paramName,
+ entity.alias,
+ entity.objectIdColumn,
+ tableAlias,
+ objectIdColumn,
+ tableAlias,
+ objectTypeColumn,
+ entity.objectType);
+ }
Review Comment:
I feel that this abstraction, while reducing duplicate code, has decreased the readability of the code and lost flexibility. It's hard to be reused by other developers. WDYT? @yuqi1129
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on code in PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#discussion_r2745361948
##########
core/src/main/java/org/apache/gravitino/storage/relational/service/ViewMetaService.java:
##########
@@ -0,0 +1,332 @@
+/*
+ * 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 static org.apache.gravitino.metrics.source.MetricsSource.GRAVITINO_RELATIONAL_STORE_METRIC_NAME;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.HasIdentifier;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.exceptions.NoSuchEntityException;
+import org.apache.gravitino.meta.GenericEntity;
+import org.apache.gravitino.meta.NamespacedEntityId;
+import org.apache.gravitino.metrics.Monitored;
+import org.apache.gravitino.storage.relational.mapper.OwnerMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.SecurableObjectMapper;
+import org.apache.gravitino.storage.relational.mapper.TagMetadataObjectRelMapper;
+import org.apache.gravitino.storage.relational.mapper.ViewMetaMapper;
+import org.apache.gravitino.storage.relational.po.ViewPO;
+import org.apache.gravitino.storage.relational.utils.ExceptionUtils;
+import org.apache.gravitino.storage.relational.utils.SessionUtils;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.apache.gravitino.utils.NamespaceUtil;
+
+/** The service class for view metadata. It provides the basic database operations for view. */
+public class ViewMetaService {
+ private static final ViewMetaService INSTANCE = new ViewMetaService();
+
+ public static ViewMetaService getInstance() {
+ return INSTANCE;
+ }
+
+ private ViewMetaService() {}
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getViewIdBySchemaIdAndName")
+ public Long getViewIdBySchemaIdAndName(Long schemaId, String viewName) {
+ Long viewId =
+ SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class,
+ mapper -> mapper.selectViewIdBySchemaIdAndName(schemaId, viewName));
+
+ if (viewId == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.VIEW.name().toLowerCase(),
+ viewName);
+ }
+ return viewId;
+ }
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getViewPOBySchemaIdAndName")
+ public ViewPO getViewPOBySchemaIdAndName(Long schemaId, String viewName) {
+ ViewPO viewPO =
+ SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class,
+ mapper -> mapper.selectViewMetaBySchemaIdAndName(schemaId, viewName));
+
+ if (viewPO == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.VIEW.name().toLowerCase(),
+ viewName);
+ }
+ return viewPO;
+ }
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "listViewPOsByNamespace")
+ public List<ViewPO> listViewPOsByNamespace(Namespace namespace) {
+ NamespaceUtil.checkView(namespace);
+
+ Long schemaId =
+ EntityIdService.getEntityId(
+ NameIdentifier.of(namespace.levels()), Entity.EntityType.SCHEMA);
+ return SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class, mapper -> mapper.listViewPOsBySchemaId(schemaId));
Review Comment:
OK, this should be a private method. I changed it.
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades commented on code in PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#discussion_r2745196816
##########
core/src/main/java/org/apache/gravitino/storage/relational/service/ViewMetaService.java:
##########
@@ -0,0 +1,332 @@
+/*
+ * 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 static org.apache.gravitino.metrics.source.MetricsSource.GRAVITINO_RELATIONAL_STORE_METRIC_NAME;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.HasIdentifier;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.exceptions.NoSuchEntityException;
+import org.apache.gravitino.meta.GenericEntity;
+import org.apache.gravitino.meta.NamespacedEntityId;
+import org.apache.gravitino.metrics.Monitored;
+import org.apache.gravitino.storage.relational.mapper.OwnerMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.SecurableObjectMapper;
+import org.apache.gravitino.storage.relational.mapper.TagMetadataObjectRelMapper;
+import org.apache.gravitino.storage.relational.mapper.ViewMetaMapper;
+import org.apache.gravitino.storage.relational.po.ViewPO;
+import org.apache.gravitino.storage.relational.utils.ExceptionUtils;
+import org.apache.gravitino.storage.relational.utils.SessionUtils;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.apache.gravitino.utils.NamespaceUtil;
+
+/** The service class for view metadata. It provides the basic database operations for view. */
+public class ViewMetaService {
+ private static final ViewMetaService INSTANCE = new ViewMetaService();
+
+ public static ViewMetaService getInstance() {
+ return INSTANCE;
+ }
+
+ private ViewMetaService() {}
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getViewIdBySchemaIdAndName")
+ public Long getViewIdBySchemaIdAndName(Long schemaId, String viewName) {
+ Long viewId =
+ SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class,
+ mapper -> mapper.selectViewIdBySchemaIdAndName(schemaId, viewName));
+
+ if (viewId == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.VIEW.name().toLowerCase(),
+ viewName);
+ }
+ return viewId;
+ }
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getViewPOBySchemaIdAndName")
+ public ViewPO getViewPOBySchemaIdAndName(Long schemaId, String viewName) {
+ ViewPO viewPO =
+ SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class,
+ mapper -> mapper.selectViewMetaBySchemaIdAndName(schemaId, viewName));
+
+ if (viewPO == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.VIEW.name().toLowerCase(),
+ viewName);
+ }
+ return viewPO;
+ }
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "listViewPOsByNamespace")
+ public List<ViewPO> listViewPOsByNamespace(Namespace namespace) {
+ NamespaceUtil.checkView(namespace);
+
+ Long schemaId =
+ EntityIdService.getEntityId(
+ NameIdentifier.of(namespace.levels()), Entity.EntityType.SCHEMA);
+ return SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class, mapper -> mapper.listViewPOsBySchemaId(schemaId));
Review Comment:
I would suggest you follow the code pattern as `tableMetaService` and other `xxxMetaService` like:
https://github.com/apache/gravitino/blob/e7b6b0ca7b05902237e41fd861772e9eb20dc8d2/core/src/main/java/org/apache/gravitino/storage/relational/service/TableMetaService.java#L104-L108
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades commented on code in PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#discussion_r2745295298
##########
core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/OwnerMetaPostgreSQLProvider.java:
##########
@@ -135,4 +35,10 @@ public String deleteOwnerMetasByLegacyTimeline(
+ OWNER_TABLE_NAME
+ " WHERE deleted_at > 0 AND deleted_at < #{legacyTimeline} LIMIT #{limit})";
}
+
+ @Override
+ protected String softDeleteSQL(Optional<String> tableAlias) {
+ // PostgreSQL doesn't support alias prefix in SET clause
+ return " SET deleted_at = CAST(EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) * 1000 AS BIGINT) ";
Review Comment:
I would suggest you handle the code refactor in a separate PR. Follow the original code structure in this PR, which will make it clearer.
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#discussion_r2741205257
##########
core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/OwnerMetaPostgreSQLProvider.java:
##########
@@ -135,4 +35,10 @@ public String deleteOwnerMetasByLegacyTimeline(
+ OWNER_TABLE_NAME
+ " WHERE deleted_at > 0 AND deleted_at < #{legacyTimeline} LIMIT #{limit})";
}
+
+ @Override
+ protected String softDeleteSQL(Optional<String> tableAlias) {
+ // PostgreSQL doesn't support alias prefix in SET clause
+ return " SET deleted_at = CAST(EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) * 1000 AS BIGINT) ";
Review Comment:
It can reduce redundant codes, but possibly it will break the SQL integrity, making the whole SQL less intuitive. So will it repeat many times?
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#issuecomment-3811157736
Could u take a look at this pull request?
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "qqqttt123 (via GitHub)" <gi...@apache.org>.
qqqttt123 commented on code in PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#discussion_r2741174993
##########
core/src/main/java/org/apache/gravitino/storage/relational/JDBCBackend.java:
##########
@@ -200,6 +204,14 @@ public <E extends Entity & HasIdentifier> void insert(E e, boolean overwritten)
JobTemplateMetaService.getInstance().insertJobTemplate((JobTemplateEntity) e, overwritten);
} else if (e instanceof JobEntity) {
JobMetaService.getInstance().insertJob((JobEntity) e, overwritten);
+ } else if (e instanceof GenericEntity) {
+ GenericEntity genericEntity = (GenericEntity) e;
+ if (genericEntity.type() == Entity.EntityType.VIEW) {
+ ViewMetaService.getInstance().insertView(genericEntity, overwritten);
+ } else {
+ throw new UnsupportedEntityTypeException(
+ "Unsupported entity type: %s for insert operation", genericEntity.type());
+ }
Review Comment:
To prevent others from incorrect modification.
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "bharos (via GitHub)" <gi...@apache.org>.
bharos commented on code in PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#discussion_r2740202044
##########
core/src/main/java/org/apache/gravitino/storage/relational/JDBCBackend.java:
##########
@@ -200,6 +204,14 @@ public <E extends Entity & HasIdentifier> void insert(E e, boolean overwritten)
JobTemplateMetaService.getInstance().insertJobTemplate((JobTemplateEntity) e, overwritten);
} else if (e instanceof JobEntity) {
JobMetaService.getInstance().insertJob((JobEntity) e, overwritten);
+ } else if (e instanceof GenericEntity) {
+ GenericEntity genericEntity = (GenericEntity) e;
+ if (genericEntity.type() == Entity.EntityType.VIEW) {
+ ViewMetaService.getInstance().insertView(genericEntity, overwritten);
+ } else {
+ throw new UnsupportedEntityTypeException(
+ "Unsupported entity type: %s for insert operation", genericEntity.type());
+ }
Review Comment:
Is this exception redundant ?
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on code in PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#discussion_r2745559771
##########
core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/OwnerMetaPostgreSQLProvider.java:
##########
@@ -135,4 +35,10 @@ public String deleteOwnerMetasByLegacyTimeline(
+ OWNER_TABLE_NAME
+ " WHERE deleted_at > 0 AND deleted_at < #{legacyTimeline} LIMIT #{limit})";
}
+
+ @Override
+ protected String softDeleteSQL(Optional<String> tableAlias) {
+ // PostgreSQL doesn't support alias prefix in SET clause
+ return " SET deleted_at = CAST(EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) * 1000 AS BIGINT) ";
Review Comment:
OK, I feel deleteSQL won't affect the code readabililty.
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades commented on code in PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#discussion_r2745260155
##########
core/src/main/java/org/apache/gravitino/storage/relational/service/ViewMetaService.java:
##########
@@ -0,0 +1,332 @@
+/*
+ * 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 static org.apache.gravitino.metrics.source.MetricsSource.GRAVITINO_RELATIONAL_STORE_METRIC_NAME;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.HasIdentifier;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.exceptions.NoSuchEntityException;
+import org.apache.gravitino.meta.GenericEntity;
+import org.apache.gravitino.meta.NamespacedEntityId;
+import org.apache.gravitino.metrics.Monitored;
+import org.apache.gravitino.storage.relational.mapper.OwnerMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.SecurableObjectMapper;
+import org.apache.gravitino.storage.relational.mapper.TagMetadataObjectRelMapper;
+import org.apache.gravitino.storage.relational.mapper.ViewMetaMapper;
+import org.apache.gravitino.storage.relational.po.ViewPO;
+import org.apache.gravitino.storage.relational.utils.ExceptionUtils;
+import org.apache.gravitino.storage.relational.utils.SessionUtils;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.apache.gravitino.utils.NamespaceUtil;
+
+/** The service class for view metadata. It provides the basic database operations for view. */
+public class ViewMetaService {
+ private static final ViewMetaService INSTANCE = new ViewMetaService();
+
+ public static ViewMetaService getInstance() {
+ return INSTANCE;
+ }
+
+ private ViewMetaService() {}
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getViewIdBySchemaIdAndName")
+ public Long getViewIdBySchemaIdAndName(Long schemaId, String viewName) {
+ Long viewId =
+ SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class,
+ mapper -> mapper.selectViewIdBySchemaIdAndName(schemaId, viewName));
+
+ if (viewId == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.VIEW.name().toLowerCase(),
+ viewName);
+ }
+ return viewId;
+ }
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getViewPOBySchemaIdAndName")
+ public ViewPO getViewPOBySchemaIdAndName(Long schemaId, String viewName) {
+ ViewPO viewPO =
+ SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class,
+ mapper -> mapper.selectViewMetaBySchemaIdAndName(schemaId, viewName));
+
+ if (viewPO == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.VIEW.name().toLowerCase(),
+ viewName);
+ }
+ return viewPO;
+ }
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "listViewPOsByNamespace")
+ public List<ViewPO> listViewPOsByNamespace(Namespace namespace) {
+ NamespaceUtil.checkView(namespace);
+
+ Long schemaId =
+ EntityIdService.getEntityId(
+ NameIdentifier.of(namespace.levels()), Entity.EntityType.SCHEMA);
+ return SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class, mapper -> mapper.listViewPOsBySchemaId(schemaId));
+ }
+
+ @Monitored(metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME, baseMetricName = "insertView")
+ public void insertView(ViewPO viewPO, boolean overwrite) throws IOException {
+ try {
+ SessionUtils.doWithCommit(
+ ViewMetaMapper.class,
+ mapper -> {
+ if (overwrite) {
+ mapper.insertViewMetaOnDuplicateKeyUpdate(viewPO);
+ } else {
+ mapper.insertViewMeta(viewPO);
+ }
+ });
+ } catch (RuntimeException re) {
+ ExceptionUtils.checkSQLException(re, Entity.EntityType.VIEW, viewPO.getViewName());
+ throw re;
+ }
+ }
+
+ @Monitored(metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME, baseMetricName = "updateView")
+ public void updateView(ViewPO oldViewPO, ViewPO newViewPO) throws IOException {
Review Comment:
this method should be private
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades commented on code in PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#discussion_r2745270245
##########
core/src/main/java/org/apache/gravitino/storage/relational/service/ViewMetaService.java:
##########
@@ -0,0 +1,332 @@
+/*
+ * 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 static org.apache.gravitino.metrics.source.MetricsSource.GRAVITINO_RELATIONAL_STORE_METRIC_NAME;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.HasIdentifier;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.exceptions.NoSuchEntityException;
+import org.apache.gravitino.meta.GenericEntity;
+import org.apache.gravitino.meta.NamespacedEntityId;
+import org.apache.gravitino.metrics.Monitored;
+import org.apache.gravitino.storage.relational.mapper.OwnerMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.SecurableObjectMapper;
+import org.apache.gravitino.storage.relational.mapper.TagMetadataObjectRelMapper;
+import org.apache.gravitino.storage.relational.mapper.ViewMetaMapper;
+import org.apache.gravitino.storage.relational.po.ViewPO;
+import org.apache.gravitino.storage.relational.utils.ExceptionUtils;
+import org.apache.gravitino.storage.relational.utils.SessionUtils;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.apache.gravitino.utils.NamespaceUtil;
+
+/** The service class for view metadata. It provides the basic database operations for view. */
+public class ViewMetaService {
+ private static final ViewMetaService INSTANCE = new ViewMetaService();
+
+ public static ViewMetaService getInstance() {
+ return INSTANCE;
+ }
+
+ private ViewMetaService() {}
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getViewIdBySchemaIdAndName")
+ public Long getViewIdBySchemaIdAndName(Long schemaId, String viewName) {
+ Long viewId =
+ SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class,
+ mapper -> mapper.selectViewIdBySchemaIdAndName(schemaId, viewName));
+
+ if (viewId == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.VIEW.name().toLowerCase(),
+ viewName);
+ }
+ return viewId;
+ }
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getViewPOBySchemaIdAndName")
+ public ViewPO getViewPOBySchemaIdAndName(Long schemaId, String viewName) {
+ ViewPO viewPO =
+ SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class,
+ mapper -> mapper.selectViewMetaBySchemaIdAndName(schemaId, viewName));
+
+ if (viewPO == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.VIEW.name().toLowerCase(),
+ viewName);
+ }
+ return viewPO;
+ }
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "listViewPOsByNamespace")
+ public List<ViewPO> listViewPOsByNamespace(Namespace namespace) {
+ NamespaceUtil.checkView(namespace);
+
+ Long schemaId =
+ EntityIdService.getEntityId(
+ NameIdentifier.of(namespace.levels()), Entity.EntityType.SCHEMA);
+ return SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class, mapper -> mapper.listViewPOsBySchemaId(schemaId));
+ }
+
+ @Monitored(metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME, baseMetricName = "insertView")
+ public void insertView(ViewPO viewPO, boolean overwrite) throws IOException {
+ try {
+ SessionUtils.doWithCommit(
+ ViewMetaMapper.class,
+ mapper -> {
+ if (overwrite) {
+ mapper.insertViewMetaOnDuplicateKeyUpdate(viewPO);
+ } else {
+ mapper.insertViewMeta(viewPO);
+ }
+ });
+ } catch (RuntimeException re) {
+ ExceptionUtils.checkSQLException(re, Entity.EntityType.VIEW, viewPO.getViewName());
+ throw re;
+ }
+ }
+
+ @Monitored(metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME, baseMetricName = "updateView")
+ public void updateView(ViewPO oldViewPO, ViewPO newViewPO) throws IOException {
+ try {
+ Integer updateResult =
+ SessionUtils.doWithCommitAndFetchResult(
+ ViewMetaMapper.class, mapper -> mapper.updateViewMeta(newViewPO, oldViewPO));
+ if (updateResult == 0) {
+ throw new IOException("Failed to update the view: " + oldViewPO.getViewName());
+ }
+ } catch (RuntimeException re) {
+ ExceptionUtils.checkSQLException(re, Entity.EntityType.VIEW, newViewPO.getViewName());
+ throw re;
+ }
+ }
+
+ @Monitored(metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME, baseMetricName = "deleteView")
+ public boolean deleteView(Long viewId) {
+ AtomicInteger deleteResult = new AtomicInteger(0);
+ SessionUtils.doMultipleWithCommit(
+ () ->
+ deleteResult.set(
+ SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class, mapper -> mapper.softDeleteViewMetasByViewId(viewId))),
+ () -> {
+ if (deleteResult.get() > 0) {
+ SessionUtils.doWithoutCommit(
+ OwnerMetaMapper.class,
+ mapper ->
+ mapper.softDeleteOwnerRelByMetadataObjectIdAndType(
+ viewId, MetadataObject.Type.VIEW.name()));
+ SessionUtils.doWithoutCommit(
+ SecurableObjectMapper.class,
+ mapper ->
+ mapper.softDeleteObjectRelsByMetadataObject(
+ viewId, MetadataObject.Type.VIEW.name()));
+ SessionUtils.doWithoutCommit(
+ TagMetadataObjectRelMapper.class,
+ mapper ->
+ mapper.softDeleteTagMetadataObjectRelsByMetadataObject(
+ viewId, MetadataObject.Type.VIEW.name()));
+ }
+ });
+ return deleteResult.get() > 0;
+ }
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "deleteViewMetasByLegacyTimeline")
+ public int deleteViewMetasByLegacyTimeline(Long legacyTimeline, int limit) {
+ return SessionUtils.doWithCommitAndFetchResult(
+ ViewMetaMapper.class,
+ mapper -> mapper.deleteViewMetasByLegacyTimeline(legacyTimeline, limit));
+ }
+
+ private void fillViewPOBuilderParentEntityId(ViewPO.Builder builder, Namespace namespace) {
+ NamespaceUtil.checkView(namespace);
+ NamespacedEntityId namespacedEntityId =
+ EntityIdService.getEntityIds(
+ NameIdentifier.of(namespace.levels()), Entity.EntityType.SCHEMA);
+ builder.withMetalakeId(namespacedEntityId.namespaceIds()[0]);
+ builder.withCatalogId(namespacedEntityId.namespaceIds()[1]);
+ builder.withSchemaId(namespacedEntityId.entityId());
+ }
+
+ public ViewPO.Builder createViewPOBuilder(Namespace namespace) {
+ ViewPO.Builder builder = ViewPO.builder();
+ fillViewPOBuilderParentEntityId(builder, namespace);
+ return builder;
+ }
+
+ /**
+ * List views as GenericEntity by namespace.
+ *
+ * @param namespace The namespace to list views from.
+ * @return A list of GenericEntity representing views.
+ */
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "listViewsByNamespace")
+ public List<GenericEntity> listViewsByNamespace(Namespace namespace) {
+ List<ViewPO> viewPOs = listViewPOsByNamespace(namespace);
+ return viewPOs.stream()
+ .map(
+ viewPO ->
+ GenericEntity.builder()
+ .withId(viewPO.getViewId())
+ .withName(viewPO.getViewName())
+ .withEntityType(Entity.EntityType.VIEW)
+ .build())
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * Get a view as GenericEntity by identifier.
+ *
+ * @param identifier The identifier of the view.
+ * @return The GenericEntity representing the view.
+ */
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getViewByIdentifier")
+ public GenericEntity getViewByIdentifier(NameIdentifier identifier) {
+ NameIdentifierUtil.checkView(identifier);
+
+ Long schemaId =
+ EntityIdService.getEntityId(
+ NameIdentifierUtil.getSchemaIdentifier(identifier), Entity.EntityType.SCHEMA);
+ ViewPO viewPO = getViewPOBySchemaIdAndName(schemaId, identifier.name());
+
+ return GenericEntity.builder()
+ .withId(viewPO.getViewId())
+ .withName(viewPO.getViewName())
+ .withEntityType(Entity.EntityType.VIEW)
+ .build();
+ }
+
+ /**
+ * Insert a view from GenericEntity.
+ *
+ * @param entity The GenericEntity representing the view.
+ * @param overwrite Whether to overwrite an existing view.
+ * @throws IOException If an I/O error occurs.
+ */
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "insertViewFromEntity")
+ public void insertView(GenericEntity entity, boolean overwrite) throws IOException {
+ Namespace namespace = entity.namespace();
+ NamespaceUtil.checkView(namespace);
+
+ ViewPO.Builder builder = createViewPOBuilder(namespace);
+ ViewPO viewPO =
+ builder
+ .withViewId(entity.id())
+ .withViewName(entity.name())
+ .withCurrentVersion(1L)
+ .withLastVersion(1L)
+ .withDeletedAt(0L)
+ .build();
+
+ insertView(viewPO, overwrite);
+ }
+
+ /**
+ * Update a view.
+ *
+ * @param ident The identifier of the view.
+ * @param updater The function to update the view entity.
+ * @return The updated GenericEntity.
+ * @throws IOException If an I/O error occurs.
+ */
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "updateViewByIdentifier")
+ public <E extends HasIdentifier> GenericEntity updateView(
+ NameIdentifier ident, Function<E, E> updater) throws IOException {
+ NameIdentifierUtil.checkView(ident);
+
+ Long schemaId =
+ EntityIdService.getEntityId(
+ NameIdentifierUtil.getSchemaIdentifier(ident), Entity.EntityType.SCHEMA);
+ ViewPO oldViewPO = getViewPOBySchemaIdAndName(schemaId, ident.name());
+
+ GenericEntity oldEntity =
+ GenericEntity.builder()
+ .withId(oldViewPO.getViewId())
+ .withName(oldViewPO.getViewName())
+ .withEntityType(Entity.EntityType.VIEW)
+ .build();
+
+ GenericEntity newEntity = (GenericEntity) updater.apply((E) oldEntity);
+
+ ViewPO newViewPO =
+ ViewPO.builder()
+ .withViewId(oldViewPO.getViewId())
+ .withViewName(newEntity.name())
+ .withMetalakeId(oldViewPO.getMetalakeId())
+ .withCatalogId(oldViewPO.getCatalogId())
+ .withSchemaId(oldViewPO.getSchemaId())
+ .withCurrentVersion(oldViewPO.getCurrentVersion())
+ .withLastVersion(oldViewPO.getLastVersion())
Review Comment:
Should you update the version?
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#discussion_r2735708179
##########
core/src/main/java/org/apache/gravitino/storage/relational/po/ViewPO.java:
##########
@@ -0,0 +1,172 @@
+/*
+ * 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 com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+import lombok.Getter;
+
+@Getter
+public class ViewPO {
+ private Long viewId;
+ private String viewName;
+ private Long metalakeId;
+ private Long catalogId;
+ private Long schemaId;
+ private Long currentVersion;
+ private Long lastVersion;
+ private Long deletedAt;
+
+ public Long getViewId() {
+ return viewId;
+ }
+
+ public String getViewName() {
+ return viewName;
+ }
+
+ public Long getMetalakeId() {
+ return metalakeId;
+ }
+
+ public Long getCatalogId() {
+ return catalogId;
+ }
+
+ public Long getSchemaId() {
+ return schemaId;
+ }
+
+ public Long getCurrentVersion() {
+ return currentVersion;
+ }
+
+ public Long getLastVersion() {
+ return lastVersion;
+ }
+
+ public Long getDeletedAt() {
+ return deletedAt;
+ }
+
Review Comment:
The ViewPO class has redundant getter methods since @Getter annotation is present at the class level (line 25). The explicit getter methods (lines 36-66) should be removed to reduce code duplication and improve maintainability.
```suggestion
```
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "qqqttt123 (via GitHub)" <gi...@apache.org>.
qqqttt123 commented on code in PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#discussion_r2741304922
##########
core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/OwnerMetaPostgreSQLProvider.java:
##########
@@ -135,4 +35,10 @@ public String deleteOwnerMetasByLegacyTimeline(
+ OWNER_TABLE_NAME
+ " WHERE deleted_at > 0 AND deleted_at < #{legacyTimeline} LIMIT #{limit})";
}
+
+ @Override
+ protected String softDeleteSQL(Optional<String> tableAlias) {
+ // PostgreSQL doesn't support alias prefix in SET clause
+ return " SET deleted_at = CAST(EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) * 1000 AS BIGINT) ";
Review Comment:
It will repeat many times. Every PostgresSQLProvider will repeat for many times.
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on code in PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#discussion_r2745563803
##########
core/src/main/java/org/apache/gravitino/storage/relational/service/ViewMetaService.java:
##########
@@ -0,0 +1,332 @@
+/*
+ * 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 static org.apache.gravitino.metrics.source.MetricsSource.GRAVITINO_RELATIONAL_STORE_METRIC_NAME;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.HasIdentifier;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.exceptions.NoSuchEntityException;
+import org.apache.gravitino.meta.GenericEntity;
+import org.apache.gravitino.meta.NamespacedEntityId;
+import org.apache.gravitino.metrics.Monitored;
+import org.apache.gravitino.storage.relational.mapper.OwnerMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.SecurableObjectMapper;
+import org.apache.gravitino.storage.relational.mapper.TagMetadataObjectRelMapper;
+import org.apache.gravitino.storage.relational.mapper.ViewMetaMapper;
+import org.apache.gravitino.storage.relational.po.ViewPO;
+import org.apache.gravitino.storage.relational.utils.ExceptionUtils;
+import org.apache.gravitino.storage.relational.utils.SessionUtils;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.apache.gravitino.utils.NamespaceUtil;
+
+/** The service class for view metadata. It provides the basic database operations for view. */
+public class ViewMetaService {
+ private static final ViewMetaService INSTANCE = new ViewMetaService();
+
+ public static ViewMetaService getInstance() {
+ return INSTANCE;
+ }
+
+ private ViewMetaService() {}
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getViewIdBySchemaIdAndName")
+ public Long getViewIdBySchemaIdAndName(Long schemaId, String viewName) {
+ Long viewId =
+ SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class,
+ mapper -> mapper.selectViewIdBySchemaIdAndName(schemaId, viewName));
+
+ if (viewId == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.VIEW.name().toLowerCase(),
+ viewName);
+ }
+ return viewId;
+ }
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getViewPOBySchemaIdAndName")
+ public ViewPO getViewPOBySchemaIdAndName(Long schemaId, String viewName) {
+ ViewPO viewPO =
+ SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class,
+ mapper -> mapper.selectViewMetaBySchemaIdAndName(schemaId, viewName));
+
+ if (viewPO == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.VIEW.name().toLowerCase(),
+ viewName);
+ }
+ return viewPO;
+ }
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "listViewPOsByNamespace")
+ public List<ViewPO> listViewPOsByNamespace(Namespace namespace) {
+ NamespaceUtil.checkView(namespace);
+
+ Long schemaId =
+ EntityIdService.getEntityId(
+ NameIdentifier.of(namespace.levels()), Entity.EntityType.SCHEMA);
+ return SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class, mapper -> mapper.listViewPOsBySchemaId(schemaId));
+ }
+
+ @Monitored(metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME, baseMetricName = "insertView")
+ public void insertView(ViewPO viewPO, boolean overwrite) throws IOException {
+ try {
+ SessionUtils.doWithCommit(
+ ViewMetaMapper.class,
+ mapper -> {
+ if (overwrite) {
+ mapper.insertViewMetaOnDuplicateKeyUpdate(viewPO);
+ } else {
+ mapper.insertViewMeta(viewPO);
+ }
+ });
+ } catch (RuntimeException re) {
+ ExceptionUtils.checkSQLException(re, Entity.EntityType.VIEW, viewPO.getViewName());
+ throw re;
+ }
+ }
+
+ @Monitored(metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME, baseMetricName = "updateView")
+ public void updateView(ViewPO oldViewPO, ViewPO newViewPO) throws IOException {
+ try {
+ Integer updateResult =
+ SessionUtils.doWithCommitAndFetchResult(
+ ViewMetaMapper.class, mapper -> mapper.updateViewMeta(newViewPO, oldViewPO));
+ if (updateResult == 0) {
+ throw new IOException("Failed to update the view: " + oldViewPO.getViewName());
+ }
+ } catch (RuntimeException re) {
+ ExceptionUtils.checkSQLException(re, Entity.EntityType.VIEW, newViewPO.getViewName());
+ throw re;
+ }
+ }
+
+ @Monitored(metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME, baseMetricName = "deleteView")
+ public boolean deleteView(Long viewId) {
+ AtomicInteger deleteResult = new AtomicInteger(0);
+ SessionUtils.doMultipleWithCommit(
+ () ->
+ deleteResult.set(
+ SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class, mapper -> mapper.softDeleteViewMetasByViewId(viewId))),
+ () -> {
+ if (deleteResult.get() > 0) {
+ SessionUtils.doWithoutCommit(
+ OwnerMetaMapper.class,
+ mapper ->
+ mapper.softDeleteOwnerRelByMetadataObjectIdAndType(
+ viewId, MetadataObject.Type.VIEW.name()));
+ SessionUtils.doWithoutCommit(
+ SecurableObjectMapper.class,
+ mapper ->
+ mapper.softDeleteObjectRelsByMetadataObject(
+ viewId, MetadataObject.Type.VIEW.name()));
+ SessionUtils.doWithoutCommit(
+ TagMetadataObjectRelMapper.class,
+ mapper ->
+ mapper.softDeleteTagMetadataObjectRelsByMetadataObject(
+ viewId, MetadataObject.Type.VIEW.name()));
+ }
+ });
+ return deleteResult.get() > 0;
+ }
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "deleteViewMetasByLegacyTimeline")
+ public int deleteViewMetasByLegacyTimeline(Long legacyTimeline, int limit) {
+ return SessionUtils.doWithCommitAndFetchResult(
+ ViewMetaMapper.class,
+ mapper -> mapper.deleteViewMetasByLegacyTimeline(legacyTimeline, limit));
+ }
+
+ private void fillViewPOBuilderParentEntityId(ViewPO.Builder builder, Namespace namespace) {
+ NamespaceUtil.checkView(namespace);
+ NamespacedEntityId namespacedEntityId =
+ EntityIdService.getEntityIds(
+ NameIdentifier.of(namespace.levels()), Entity.EntityType.SCHEMA);
+ builder.withMetalakeId(namespacedEntityId.namespaceIds()[0]);
+ builder.withCatalogId(namespacedEntityId.namespaceIds()[1]);
+ builder.withSchemaId(namespacedEntityId.entityId());
+ }
+
+ public ViewPO.Builder createViewPOBuilder(Namespace namespace) {
+ ViewPO.Builder builder = ViewPO.builder();
+ fillViewPOBuilderParentEntityId(builder, namespace);
+ return builder;
+ }
+
+ /**
+ * List views as GenericEntity by namespace.
+ *
+ * @param namespace The namespace to list views from.
+ * @return A list of GenericEntity representing views.
+ */
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "listViewsByNamespace")
+ public List<GenericEntity> listViewsByNamespace(Namespace namespace) {
+ List<ViewPO> viewPOs = listViewPOsByNamespace(namespace);
+ return viewPOs.stream()
+ .map(
+ viewPO ->
+ GenericEntity.builder()
+ .withId(viewPO.getViewId())
+ .withName(viewPO.getViewName())
+ .withEntityType(Entity.EntityType.VIEW)
+ .build())
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * Get a view as GenericEntity by identifier.
+ *
+ * @param identifier The identifier of the view.
+ * @return The GenericEntity representing the view.
+ */
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getViewByIdentifier")
+ public GenericEntity getViewByIdentifier(NameIdentifier identifier) {
+ NameIdentifierUtil.checkView(identifier);
+
+ Long schemaId =
+ EntityIdService.getEntityId(
+ NameIdentifierUtil.getSchemaIdentifier(identifier), Entity.EntityType.SCHEMA);
+ ViewPO viewPO = getViewPOBySchemaIdAndName(schemaId, identifier.name());
+
+ return GenericEntity.builder()
+ .withId(viewPO.getViewId())
+ .withName(viewPO.getViewName())
+ .withEntityType(Entity.EntityType.VIEW)
+ .build();
+ }
+
+ /**
+ * Insert a view from GenericEntity.
+ *
+ * @param entity The GenericEntity representing the view.
+ * @param overwrite Whether to overwrite an existing view.
+ * @throws IOException If an I/O error occurs.
+ */
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "insertViewFromEntity")
+ public void insertView(GenericEntity entity, boolean overwrite) throws IOException {
+ Namespace namespace = entity.namespace();
+ NamespaceUtil.checkView(namespace);
+
+ ViewPO.Builder builder = createViewPOBuilder(namespace);
+ ViewPO viewPO =
+ builder
+ .withViewId(entity.id())
+ .withViewName(entity.name())
+ .withCurrentVersion(1L)
+ .withLastVersion(1L)
+ .withDeletedAt(0L)
+ .build();
+
+ insertView(viewPO, overwrite);
+ }
+
+ /**
+ * Update a view.
+ *
+ * @param ident The identifier of the view.
+ * @param updater The function to update the view entity.
+ * @return The updated GenericEntity.
+ * @throws IOException If an I/O error occurs.
+ */
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "updateViewByIdentifier")
+ public <E extends HasIdentifier> GenericEntity updateView(
+ NameIdentifier ident, Function<E, E> updater) throws IOException {
+ NameIdentifierUtil.checkView(ident);
+
+ Long schemaId =
+ EntityIdService.getEntityId(
+ NameIdentifierUtil.getSchemaIdentifier(ident), Entity.EntityType.SCHEMA);
+ ViewPO oldViewPO = getViewPOBySchemaIdAndName(schemaId, ident.name());
+
+ GenericEntity oldEntity =
+ GenericEntity.builder()
+ .withId(oldViewPO.getViewId())
+ .withName(oldViewPO.getViewName())
+ .withEntityType(Entity.EntityType.VIEW)
+ .build();
+
+ GenericEntity newEntity = (GenericEntity) updater.apply((E) oldEntity);
+
+ ViewPO newViewPO =
+ ViewPO.builder()
+ .withViewId(oldViewPO.getViewId())
+ .withViewName(newEntity.name())
+ .withMetalakeId(oldViewPO.getMetalakeId())
+ .withCatalogId(oldViewPO.getCatalogId())
+ .withSchemaId(oldViewPO.getSchemaId())
+ .withCurrentVersion(oldViewPO.getCurrentVersion())
+ .withLastVersion(oldViewPO.getLastVersion())
Review Comment:
I think we don't update the version now. If necessary, you can update. I should keep the logic simple.
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades commented on code in PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#discussion_r2754226124
##########
core/src/main/java/org/apache/gravitino/storage/relational/service/ViewMetaService.java:
##########
@@ -0,0 +1,332 @@
+/*
+ * 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 static org.apache.gravitino.metrics.source.MetricsSource.GRAVITINO_RELATIONAL_STORE_METRIC_NAME;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.HasIdentifier;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.exceptions.NoSuchEntityException;
+import org.apache.gravitino.meta.GenericEntity;
+import org.apache.gravitino.meta.NamespacedEntityId;
+import org.apache.gravitino.metrics.Monitored;
+import org.apache.gravitino.storage.relational.mapper.OwnerMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.SecurableObjectMapper;
+import org.apache.gravitino.storage.relational.mapper.TagMetadataObjectRelMapper;
+import org.apache.gravitino.storage.relational.mapper.ViewMetaMapper;
+import org.apache.gravitino.storage.relational.po.ViewPO;
+import org.apache.gravitino.storage.relational.utils.ExceptionUtils;
+import org.apache.gravitino.storage.relational.utils.SessionUtils;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.apache.gravitino.utils.NamespaceUtil;
+
+/** The service class for view metadata. It provides the basic database operations for view. */
+public class ViewMetaService {
+ private static final ViewMetaService INSTANCE = new ViewMetaService();
+
+ public static ViewMetaService getInstance() {
+ return INSTANCE;
+ }
+
+ private ViewMetaService() {}
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getViewIdBySchemaIdAndName")
+ public Long getViewIdBySchemaIdAndName(Long schemaId, String viewName) {
+ Long viewId =
+ SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class,
+ mapper -> mapper.selectViewIdBySchemaIdAndName(schemaId, viewName));
+
+ if (viewId == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.VIEW.name().toLowerCase(),
+ viewName);
+ }
+ return viewId;
+ }
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getViewPOBySchemaIdAndName")
+ public ViewPO getViewPOBySchemaIdAndName(Long schemaId, String viewName) {
+ ViewPO viewPO =
+ SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class,
+ mapper -> mapper.selectViewMetaBySchemaIdAndName(schemaId, viewName));
+
+ if (viewPO == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.VIEW.name().toLowerCase(),
+ viewName);
+ }
+ return viewPO;
+ }
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "listViewPOsByNamespace")
+ public List<ViewPO> listViewPOsByNamespace(Namespace namespace) {
+ NamespaceUtil.checkView(namespace);
+
+ Long schemaId =
+ EntityIdService.getEntityId(
+ NameIdentifier.of(namespace.levels()), Entity.EntityType.SCHEMA);
+ return SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class, mapper -> mapper.listViewPOsBySchemaId(schemaId));
Review Comment:
This comment has not been addressed.
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on code in PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#discussion_r2756974783
##########
core/src/main/java/org/apache/gravitino/storage/relational/service/ViewMetaService.java:
##########
@@ -0,0 +1,332 @@
+/*
+ * 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 static org.apache.gravitino.metrics.source.MetricsSource.GRAVITINO_RELATIONAL_STORE_METRIC_NAME;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.HasIdentifier;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.exceptions.NoSuchEntityException;
+import org.apache.gravitino.meta.GenericEntity;
+import org.apache.gravitino.meta.NamespacedEntityId;
+import org.apache.gravitino.metrics.Monitored;
+import org.apache.gravitino.storage.relational.mapper.OwnerMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.SecurableObjectMapper;
+import org.apache.gravitino.storage.relational.mapper.TagMetadataObjectRelMapper;
+import org.apache.gravitino.storage.relational.mapper.ViewMetaMapper;
+import org.apache.gravitino.storage.relational.po.ViewPO;
+import org.apache.gravitino.storage.relational.utils.ExceptionUtils;
+import org.apache.gravitino.storage.relational.utils.SessionUtils;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.apache.gravitino.utils.NamespaceUtil;
+
+/** The service class for view metadata. It provides the basic database operations for view. */
+public class ViewMetaService {
+ private static final ViewMetaService INSTANCE = new ViewMetaService();
+
+ public static ViewMetaService getInstance() {
+ return INSTANCE;
+ }
+
+ private ViewMetaService() {}
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getViewIdBySchemaIdAndName")
+ public Long getViewIdBySchemaIdAndName(Long schemaId, String viewName) {
+ Long viewId =
+ SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class,
+ mapper -> mapper.selectViewIdBySchemaIdAndName(schemaId, viewName));
+
+ if (viewId == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.VIEW.name().toLowerCase(),
+ viewName);
+ }
+ return viewId;
+ }
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getViewPOBySchemaIdAndName")
+ public ViewPO getViewPOBySchemaIdAndName(Long schemaId, String viewName) {
+ ViewPO viewPO =
+ SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class,
+ mapper -> mapper.selectViewMetaBySchemaIdAndName(schemaId, viewName));
+
+ if (viewPO == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.VIEW.name().toLowerCase(),
+ viewName);
+ }
+ return viewPO;
+ }
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "listViewPOsByNamespace")
+ public List<ViewPO> listViewPOsByNamespace(Namespace namespace) {
+ NamespaceUtil.checkView(namespace);
+
+ Long schemaId =
+ EntityIdService.getEntityId(
+ NameIdentifier.of(namespace.levels()), Entity.EntityType.SCHEMA);
+ return SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class, mapper -> mapper.listViewPOsBySchemaId(schemaId));
Review Comment:
Sorry, I reverted this modification by mistake. I added it back. Could u take a look again?
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades commented on code in PR #9815:
URL: https://github.com/apache/gravitino/pull/9815#discussion_r2757029766
##########
core/src/main/java/org/apache/gravitino/storage/relational/service/ViewMetaService.java:
##########
@@ -0,0 +1,332 @@
+/*
+ * 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 static org.apache.gravitino.metrics.source.MetricsSource.GRAVITINO_RELATIONAL_STORE_METRIC_NAME;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.HasIdentifier;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.exceptions.NoSuchEntityException;
+import org.apache.gravitino.meta.GenericEntity;
+import org.apache.gravitino.meta.NamespacedEntityId;
+import org.apache.gravitino.metrics.Monitored;
+import org.apache.gravitino.storage.relational.mapper.OwnerMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.SecurableObjectMapper;
+import org.apache.gravitino.storage.relational.mapper.TagMetadataObjectRelMapper;
+import org.apache.gravitino.storage.relational.mapper.ViewMetaMapper;
+import org.apache.gravitino.storage.relational.po.ViewPO;
+import org.apache.gravitino.storage.relational.utils.ExceptionUtils;
+import org.apache.gravitino.storage.relational.utils.SessionUtils;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.apache.gravitino.utils.NamespaceUtil;
+
+/** The service class for view metadata. It provides the basic database operations for view. */
+public class ViewMetaService {
+ private static final ViewMetaService INSTANCE = new ViewMetaService();
+
+ public static ViewMetaService getInstance() {
+ return INSTANCE;
+ }
+
+ private ViewMetaService() {}
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getViewIdBySchemaIdAndName")
+ public Long getViewIdBySchemaIdAndName(Long schemaId, String viewName) {
+ Long viewId =
+ SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class,
+ mapper -> mapper.selectViewIdBySchemaIdAndName(schemaId, viewName));
+
+ if (viewId == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.VIEW.name().toLowerCase(),
+ viewName);
+ }
+ return viewId;
+ }
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "getViewPOBySchemaIdAndName")
+ public ViewPO getViewPOBySchemaIdAndName(Long schemaId, String viewName) {
+ ViewPO viewPO =
+ SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class,
+ mapper -> mapper.selectViewMetaBySchemaIdAndName(schemaId, viewName));
+
+ if (viewPO == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.VIEW.name().toLowerCase(),
+ viewName);
+ }
+ return viewPO;
+ }
+
+ @Monitored(
+ metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
+ baseMetricName = "listViewPOsByNamespace")
+ public List<ViewPO> listViewPOsByNamespace(Namespace namespace) {
+ NamespaceUtil.checkView(namespace);
+
+ Long schemaId =
+ EntityIdService.getEntityId(
+ NameIdentifier.of(namespace.levels()), Entity.EntityType.SCHEMA);
+ return SessionUtils.getWithoutCommit(
+ ViewMetaMapper.class, mapper -> mapper.listViewPOsBySchemaId(schemaId));
Review Comment:
It seems the issue is still not resolved; the method in tableMetaService provides two code paths for enabling and disabling the cache. I think you should align with that pattern.
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9746] feat(core,storage): Support generic view storage [gravitino]
Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi merged PR #9815:
URL: https://github.com/apache/gravitino/pull/9815
--
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-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org