Search in sources :

Example 6 with PolarisDatabaseEntity

use of com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity in project metacat by Netflix.

the class PolarisConnectorDatabaseService method get.

/**
 * {@inheritDoc}.
 */
@Override
public DatabaseInfo get(final ConnectorRequestContext context, final QualifiedName name) {
    try {
        final PolarisDatabaseMapper mapper = new PolarisDatabaseMapper(name.getCatalogName());
        final PolarisDatabaseEntity db = polarisStoreService.getDatabase(name.getDatabaseName()).orElseThrow(() -> new DatabaseNotFoundException(name));
        return mapper.toInfo(db);
    } catch (DatabaseNotFoundException exception) {
        log.error(String.format("Not found exception for polaris database %s", name), exception);
        throw exception;
    } catch (Exception exception) {
        throw new ConnectorException(String.format("Failed get polaris database %s", name), exception);
    }
}
Also used : DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) PolarisDatabaseMapper(com.netflix.metacat.connector.polaris.mappers.PolarisDatabaseMapper) PolarisDatabaseEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity) DatabaseAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 7 with PolarisDatabaseEntity

use of com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity in project metacat by Netflix.

the class PolarisConnectorDatabaseService method list.

/**
 * {@inheritDoc}.
 */
@Override
public List<DatabaseInfo> list(final ConnectorRequestContext context, final QualifiedName name, @Nullable final QualifiedName prefix, @Nullable final Sort sort, @Nullable final Pageable pageable) {
    try {
        final PolarisDatabaseMapper mapper = new PolarisDatabaseMapper(name.getCatalogName());
        List<PolarisDatabaseEntity> dbs = polarisStoreService.getAllDatabases();
        if (prefix != null) {
            dbs = dbs.stream().filter(n -> QualifiedName.ofDatabase(name.getCatalogName(), n.getDbName()).startsWith(prefix)).collect(Collectors.toCollection(ArrayList::new));
        }
        if (sort != null) {
            ConnectorUtils.sort(dbs, sort, Comparator.comparing(p -> p.getDbName()));
        }
        return ConnectorUtils.paginate(dbs, pageable).stream().map(d -> mapper.toInfo(d)).collect(Collectors.toList());
    } catch (Exception exception) {
        throw new ConnectorException(String.format("Failed databases list polaris prefix %s", prefix), exception);
    }
}
Also used : ConnectorDatabaseService(com.netflix.metacat.common.server.connectors.ConnectorDatabaseService) DatabaseAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException) Pageable(com.netflix.metacat.common.dto.Pageable) PolarisDatabaseMapper(com.netflix.metacat.connector.polaris.mappers.PolarisDatabaseMapper) QualifiedName(com.netflix.metacat.common.QualifiedName) Collectors(java.util.stream.Collectors) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) ArrayList(java.util.ArrayList) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) DatabaseInfo(com.netflix.metacat.common.server.connectors.model.DatabaseInfo) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) ConnectorUtils(com.netflix.metacat.common.server.connectors.ConnectorUtils) Comparator(java.util.Comparator) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) PolarisStoreService(com.netflix.metacat.connector.polaris.store.PolarisStoreService) PolarisDatabaseEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity) Nullable(javax.annotation.Nullable) Sort(com.netflix.metacat.common.dto.Sort) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) ArrayList(java.util.ArrayList) PolarisDatabaseMapper(com.netflix.metacat.connector.polaris.mappers.PolarisDatabaseMapper) PolarisDatabaseEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity) DatabaseAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 8 with PolarisDatabaseEntity

use of com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity in project metacat by Netflix.

the class PolarisStoreConnector method getAllDatabases.

/**
 * Fetches all database entities.
 *
 * @return Polaris Database entities
 */
@Override
@Transactional(propagation = Propagation.SUPPORTS)
public List<PolarisDatabaseEntity> getAllDatabases() {
    final int pageFetchSize = 1000;
    final List<PolarisDatabaseEntity> retval = new ArrayList<>();
    Pageable page = PageRequest.of(0, pageFetchSize);
    boolean hasNext;
    do {
        final Slice<PolarisDatabaseEntity> dbs = dbRepo.getDatabases(page);
        retval.addAll(dbs.toList());
        hasNext = dbs.hasNext();
        if (hasNext) {
            page = dbs.nextPageable();
        }
    } while (hasNext);
    return retval;
}
Also used : Pageable(org.springframework.data.domain.Pageable) ArrayList(java.util.ArrayList) PolarisDatabaseEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

PolarisDatabaseEntity (com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity)8 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)3 DatabaseAlreadyExistsException (com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException)3 DatabaseNotFoundException (com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException)3 InvalidMetaException (com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)3 Test (org.junit.jupiter.api.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)3 QualifiedName (com.netflix.metacat.common.QualifiedName)2 PolarisDatabaseMapper (com.netflix.metacat.connector.polaris.mappers.PolarisDatabaseMapper)2 PolarisTableEntity (com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity)2 ArrayList (java.util.ArrayList)2 Pageable (com.netflix.metacat.common.dto.Pageable)1 Sort (com.netflix.metacat.common.dto.Sort)1 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)1 ConnectorDatabaseService (com.netflix.metacat.common.server.connectors.ConnectorDatabaseService)1 ConnectorRequestContext (com.netflix.metacat.common.server.connectors.ConnectorRequestContext)1 ConnectorUtils (com.netflix.metacat.common.server.connectors.ConnectorUtils)1 DatabaseInfo (com.netflix.metacat.common.server.connectors.model.DatabaseInfo)1 PolarisStoreService (com.netflix.metacat.connector.polaris.store.PolarisStoreService)1