Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate Polaris Entities #1128

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* 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.polaris.extension.persistence.impl.eclipselink.postgres;

import static org.apache.polaris.core.entity.PolarisEntitySubType.ANY_SUBTYPE;
import static org.apache.polaris.core.entity.PolarisEntityType.CATALOG;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import java.util.List;
import java.util.Map;
import org.apache.polaris.core.PolarisCallContext;
import org.apache.polaris.core.entity.PolarisBaseEntity;
import org.apache.polaris.core.entity.PolarisEntityCore;
import org.apache.polaris.core.persistence.dao.CatalogDao;
import org.apache.polaris.core.persistence.dao.entity.CreateCatalogResult;
import org.apache.polaris.core.persistence.dao.entity.DropEntityResult;
import org.apache.polaris.core.persistence.dao.entity.EntityResult;
import org.apache.polaris.core.persistence.dao.entity.ListEntitiesResult;
import org.apache.polaris.core.persistence.dao.entity.ResolvedEntityResult;
import org.apache.polaris.core.persistence.transactional.PolarisMetaStoreManagerImpl;

public class PostgresCatalogDaoImpl implements CatalogDao {
// TODO it uses PolarisMetaStoreManagerImpl now, we can change it later
PolarisMetaStoreManagerImpl metaStoreManager = new PolarisMetaStoreManagerImpl();

@Override
public CreateCatalogResult createCatalog(
@Nonnull PolarisCallContext callCtx,
@Nonnull PolarisBaseEntity catalog,
@Nonnull List<PolarisEntityCore> principalRoles) {
return metaStoreManager.createCatalog(callCtx, catalog, principalRoles);
}

@Nonnull
@Override
public EntityResult readEntityByName(@Nonnull PolarisCallContext callCtx, @Nonnull String name) {
return metaStoreManager.readEntityByName(callCtx, null, CATALOG, ANY_SUBTYPE, name);
}

@Nonnull
@Override
public EntityResult loadEntity(
@Nonnull PolarisCallContext callCtx, long entityCatalogId, long entityId) {
return metaStoreManager.loadEntity(callCtx, entityCatalogId, entityId, CATALOG);
}

@Nonnull
@Override
public ListEntitiesResult listEntities(@Nonnull PolarisCallContext callCtx) {
return metaStoreManager.listEntities(callCtx, null, CATALOG, ANY_SUBTYPE);
}

@Nonnull
@Override
public EntityResult updateEntityPropertiesIfNotChanged(
@Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity) {
return metaStoreManager.updateEntityPropertiesIfNotChanged(callCtx, null, entity);
}

@Nonnull
@Override
public DropEntityResult dropEntityIfExists(
@Nonnull PolarisCallContext callCtx,
@Nonnull PolarisEntityCore entityToDrop,
@Nullable Map<String, String> cleanupProperties,
boolean cleanup) {
return metaStoreManager.dropEntityIfExists(
callCtx, null, entityToDrop, cleanupProperties, cleanup);
}

@Nonnull
@Override
public ResolvedEntityResult loadResolvedEntityById(
@Nonnull PolarisCallContext callCtx, long entityCatalogId, long entityId) {
return metaStoreManager.loadResolvedEntityById(callCtx, entityCatalogId, entityId, CATALOG);
}

@Nonnull
@Override
public ResolvedEntityResult loadResolvedEntityByName(
@Nonnull PolarisCallContext callCtx,
long entityCatalogId,
long parentId,
@Nonnull String entityName) {
return metaStoreManager.loadResolvedEntityByName(
callCtx, entityCatalogId, parentId, CATALOG, entityName);
}

@Nonnull
@Override
public ResolvedEntityResult refreshResolvedEntity(
@Nonnull PolarisCallContext callCtx,
int entityVersion,
int entityGrantRecordsVersion,
long entityCatalogId,
long entityId) {
return metaStoreManager.refreshResolvedEntity(
callCtx, entityVersion, entityGrantRecordsVersion, CATALOG, entityCatalogId, entityId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* 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.polaris.extension.persistence.impl.eclipselink.postgres;

import static org.apache.polaris.core.entity.PolarisEntitySubType.ANY_SUBTYPE;
import static org.apache.polaris.core.entity.PolarisEntityType.CATALOG_ROLE;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import java.util.List;
import java.util.Map;
import org.apache.polaris.core.PolarisCallContext;
import org.apache.polaris.core.entity.PolarisBaseEntity;
import org.apache.polaris.core.entity.PolarisEntityCore;
import org.apache.polaris.core.persistence.dao.CatalogRoleDao;
import org.apache.polaris.core.persistence.dao.entity.DropEntityResult;
import org.apache.polaris.core.persistence.dao.entity.EntityResult;
import org.apache.polaris.core.persistence.dao.entity.ListEntitiesResult;
import org.apache.polaris.core.persistence.dao.entity.ResolvedEntityResult;
import org.apache.polaris.core.persistence.transactional.PolarisMetaStoreManagerImpl;

public class PostgresCatalogRoleDaoImpl implements CatalogRoleDao {
PolarisMetaStoreManagerImpl metaStoreManager = new PolarisMetaStoreManagerImpl();

@Override
public @Nonnull EntityResult readEntityByName(
@Nonnull PolarisCallContext callCtx,
@Nullable List<PolarisEntityCore> catalogPath,
@Nonnull String name) {
return metaStoreManager.readEntityByName(callCtx, catalogPath, CATALOG_ROLE, ANY_SUBTYPE, name);
}

@Nonnull
@Override
public EntityResult loadEntity(
@Nonnull PolarisCallContext callCtx, long entityCatalogId, long entityId) {
return metaStoreManager.loadEntity(callCtx, entityCatalogId, entityId, CATALOG_ROLE);
}

@Nonnull
@Override
public ListEntitiesResult listEntities(
@Nonnull PolarisCallContext callCtx, @Nullable List<PolarisEntityCore> catalogPath) {
return metaStoreManager.listEntities(callCtx, catalogPath, CATALOG_ROLE, ANY_SUBTYPE);
}

@Nonnull
@Override
public ResolvedEntityResult loadResolvedEntityById(
@Nonnull PolarisCallContext callCtx, long entityCatalogId, long entityId) {
return metaStoreManager.loadResolvedEntityById(
callCtx, entityCatalogId, entityId, CATALOG_ROLE);
}

@Nonnull
@Override
public ResolvedEntityResult loadResolvedEntityByName(
@Nonnull PolarisCallContext callCtx,
long entityCatalogId,
long parentId,
@Nonnull String entityName) {
return metaStoreManager.loadResolvedEntityByName(
callCtx, entityCatalogId, parentId, CATALOG_ROLE, entityName);
}

@Nonnull
@Override
public ResolvedEntityResult refreshResolvedEntity(
@Nonnull PolarisCallContext callCtx,
int entityVersion,
int entityGrantRecordsVersion,
long entityCatalogId,
long entityId) {
return metaStoreManager.refreshResolvedEntity(
callCtx, entityVersion, entityGrantRecordsVersion, CATALOG_ROLE, entityCatalogId, entityId);
}

@Nonnull
@Override
public EntityResult createEntityIfNotExists(
@Nonnull PolarisCallContext callCtx,
@Nullable List<PolarisEntityCore> catalogPath,
@Nonnull PolarisBaseEntity entity) {
return metaStoreManager.createEntityIfNotExists(callCtx, catalogPath, entity);
}

@Nonnull
@Override
public EntityResult updateEntityPropertiesIfNotChanged(
@Nonnull PolarisCallContext callCtx,
@Nullable List<PolarisEntityCore> catalogPath,
@Nonnull PolarisBaseEntity entity) {
return metaStoreManager.updateEntityPropertiesIfNotChanged(callCtx, catalogPath, entity);
}

@Nonnull
@Override
public DropEntityResult dropEntityIfExists(
@Nonnull PolarisCallContext callCtx,
@Nullable List<PolarisEntityCore> catalogPath,
@Nonnull PolarisEntityCore entityToDrop,
@Nullable Map<String, String> cleanupProperties,
boolean cleanup) {
return metaStoreManager.dropEntityIfExists(
callCtx, catalogPath, entityToDrop, cleanupProperties, cleanup);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* 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.polaris.extension.persistence.impl.eclipselink.postgres;

import static org.apache.polaris.core.entity.PolarisEntityType.NULL_TYPE;
import static org.apache.polaris.core.entity.PolarisEntityType.ROOT;

import jakarta.annotation.Nonnull;
import java.util.List;
import org.apache.polaris.core.PolarisCallContext;
import org.apache.polaris.core.entity.PolarisEntityId;
import org.apache.polaris.core.persistence.dao.CommonDao;
import org.apache.polaris.core.persistence.dao.entity.BaseResult;
import org.apache.polaris.core.persistence.dao.entity.ChangeTrackingResult;
import org.apache.polaris.core.persistence.dao.entity.EntityResult;
import org.apache.polaris.core.persistence.dao.entity.GenerateEntityIdResult;
import org.apache.polaris.core.persistence.dao.entity.ResolvedEntityResult;
import org.apache.polaris.core.persistence.transactional.PolarisMetaStoreManagerImpl;

public class PostgresCommonDaoImpl implements CommonDao {
PolarisMetaStoreManagerImpl metaStoreManager = new PolarisMetaStoreManagerImpl();

@Nonnull
@Override
public GenerateEntityIdResult generateNewEntityId(@Nonnull PolarisCallContext callCtx) {
return metaStoreManager.generateNewEntityId(callCtx);
}

@Nonnull
@Override
public BaseResult bootstrapPolarisService(@Nonnull PolarisCallContext callCtx) {
return metaStoreManager.bootstrapPolarisService(callCtx);
}

@Nonnull
@Override
public BaseResult purge(@Nonnull PolarisCallContext callCtx) {
return metaStoreManager.purge(callCtx);
}

@Nonnull
@Override
public ResolvedEntityResult loadResolvedEntityByName(
@Nonnull PolarisCallContext callCtx,
long entityCatalogId,
long parentId,
@Nonnull String entityName) {
return metaStoreManager.loadResolvedEntityByName(
callCtx, entityCatalogId, parentId, ROOT, entityName);
}

@Nonnull
@Override
public ChangeTrackingResult loadEntitiesChangeTracking(
@Nonnull PolarisCallContext callCtx, @Nonnull List<PolarisEntityId> entityIds) {
return metaStoreManager.loadEntitiesChangeTracking(callCtx, entityIds);
}

@Nonnull
@Override
public ResolvedEntityResult refreshResolvedEntity(
@Nonnull PolarisCallContext callCtx,
int entityVersion,
int entityGrantRecordsVersion,
long entityCatalogId,
long entityId) {
return metaStoreManager.refreshResolvedEntity(
callCtx, entityVersion, entityGrantRecordsVersion, ROOT, entityCatalogId, entityId);
}

@Nonnull
@Override
public EntityResult loadEntity(
@Nonnull PolarisCallContext callCtx, long entityCatalogId, long entityId) {
return metaStoreManager.loadEntity(callCtx, entityCatalogId, entityId, NULL_TYPE);
}
}
Loading