use of com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity in project metacat by Netflix.
the class PolarisConnectorTableService method get.
/**
* {@inheritDoc}.
*/
@Override
public TableInfo get(final ConnectorRequestContext requestContext, final QualifiedName name) {
try {
final PolarisTableEntity polarisTableEntity = polarisStoreService.getTable(name.getDatabaseName(), name.getTableName()).orElseThrow(() -> new TableNotFoundException(name));
final TableInfo info = polarisTableMapper.toInfo(polarisTableEntity);
final String tableLoc = HiveTableUtil.getIcebergTableMetadataLocation(info);
return getIcebergTable(name, tableLoc, info, requestContext.isIncludeMetadata(), connectorContext.getConfig().isIcebergCacheEnabled());
} catch (TableNotFoundException | IllegalArgumentException exception) {
log.error(String.format("Not found exception for polaris table %s", name), exception);
throw exception;
} catch (ConnectorException connectorException) {
log.error("Encountered connector exception for polaris table {}. {}", name, connectorException);
throw connectorException;
} catch (Exception exception) {
final String msg = String.format("Failed getting polaris table %s", name);
log.error(msg, exception);
throw exception;
}
}
use of com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity in project metacat by Netflix.
the class PolarisConnectorTableService method rename.
/**
* {@inheritDoc}.
*/
@Override
public void rename(final ConnectorRequestContext context, final QualifiedName oldName, final QualifiedName newName) {
// check exists then rename in non-transactional optimistic manner
if (exists(context, newName)) {
throw new TableAlreadyExistsException(newName);
}
try {
final PolarisTableEntity table = polarisStoreService.getTable(oldName.getDatabaseName(), oldName.getTableName()).orElseThrow(() -> new TableNotFoundException(oldName));
polarisStoreService.saveTable(table.toBuilder().tblName(newName.getTableName()).build());
} catch (TableNotFoundException exception) {
log.error(String.format("Not found exception for polaris table %s", oldName), exception);
throw exception;
} catch (DataIntegrityViolationException exception) {
throw new InvalidMetaException(oldName, exception);
} catch (Exception exception) {
final String msg = String.format("Failed renaming polaris table %s", oldName);
log.error(msg, exception);
throw new ConnectorException(msg, exception);
}
}
use of com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity in project metacat by Netflix.
the class PolarisConnectorTableService method update.
/**
* {@inheritDoc}.
*/
@Override
public void update(final ConnectorRequestContext requestContext, final TableInfo tableInfo) {
final QualifiedName name = tableInfo.getName();
final Config conf = connectorContext.getConfig();
try {
final Map<String, String> newTableMetadata = tableInfo.getMetadata();
if (MapUtils.isEmpty(newTableMetadata)) {
final String message = String.format("No parameters defined for iceberg table %s", name);
log.warn(message);
throw new InvalidMetaException(name, message, null);
}
final String prevLoc = newTableMetadata.get(DirectSqlTable.PARAM_PREVIOUS_METADATA_LOCATION);
final String newLoc = newTableMetadata.get(DirectSqlTable.PARAM_METADATA_LOCATION);
if (StringUtils.isBlank(prevLoc) || StringUtils.isBlank(newLoc)) {
final String message = String.format("Invalid metadata for %s. Provided previous %s or new %s location is empty.", name, prevLoc, newLoc);
log.error(message);
throw new InvalidMetaException(name, message, null);
}
if (conf.isIcebergPreviousMetadataLocationCheckEnabled() && !icebergTableHandler.doesMetadataLocationExist(name, prevLoc)) {
final String message = String.format("Provided previous metadata location: %s for table: %s does not exist.", name, prevLoc);
log.error(message);
throw new InvalidMetaException(name, message, null);
}
// optimistically attempt to update metadata location
final boolean updated = polarisStoreService.updateTableMetadataLocation(name.getDatabaseName(), name.getTableName(), prevLoc, newLoc);
// if succeeded then done, else try to figure out why and throw corresponding exception
if (updated) {
requestContext.setIgnoreErrorsAfterUpdate(true);
return;
}
final PolarisTableEntity table = polarisStoreService.getTable(name.getDatabaseName(), name.getTableName()).orElseThrow(() -> new TableNotFoundException(name));
final String existingLoc = table.getMetadataLocation();
if (StringUtils.isBlank(existingLoc)) {
final String message = String.format("Invalid metadata location for %s existing location is empty.", name);
log.error(message);
throw new TablePreconditionFailedException(name, message, existingLoc, prevLoc);
}
if (StringUtils.equalsIgnoreCase(existingLoc, newLoc)) {
log.warn("Existing metadata location is the same as new. Existing: {}, New: {}", existingLoc, newLoc);
return;
}
if (!Objects.equals(existingLoc, prevLoc)) {
final String message = String.format("Invalid metadata location for %s expected: %s, provided: %s", name, existingLoc, prevLoc);
log.error(message);
throw new TablePreconditionFailedException(name, message, existingLoc, prevLoc);
}
} catch (TableNotFoundException | InvalidMetaException | TablePreconditionFailedException exception) {
throw exception;
} catch (DataIntegrityViolationException exception) {
throw new InvalidMetaException(name, exception);
} catch (Exception exception) {
final String msg = String.format("Failed updating polaris table %s", tableInfo.getName());
log.error(msg, exception);
throw new ConnectorException(msg, exception);
}
}
use of com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity in project metacat by Netflix.
the class PolarisConnectorTableService method list.
/**
* {@inheritDoc}.
*/
@Override
public List<TableInfo> list(final ConnectorRequestContext requestContext, final QualifiedName name, @Nullable final QualifiedName prefix, @Nullable final Sort sort, @Nullable final Pageable pageable) {
try {
final String tableFilter = (prefix != null && prefix.isTableDefinition()) ? prefix.getTableName() : "";
final List<PolarisTableEntity> tbls = polarisStoreService.getTableEntities(name.getDatabaseName(), tableFilter);
if (sort != null) {
ConnectorUtils.sort(tbls, sort, Comparator.comparing(t -> t.getTblName()));
}
return ConnectorUtils.paginate(tbls, pageable).stream().map(t -> polarisTableMapper.toInfo(t)).collect(Collectors.toList());
} catch (Exception exception) {
final String msg = String.format("Failed polaris list tables %s using prefix %s", name, prefix);
log.error(msg, exception);
throw new ConnectorException(msg, exception);
}
}
use of com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity in project metacat by Netflix.
the class PolarisStoreConnector method getTableEntities.
/**
* Fetch table entities for given database.
* @param databaseName database name
* @param tableNamePrefix table name prefix. can be empty.
* @return table entities in the database.
*/
@Override
@Transactional(propagation = Propagation.SUPPORTS)
public List<PolarisTableEntity> getTableEntities(final String databaseName, final String tableNamePrefix) {
final int pageFetchSize = 1000;
final List<PolarisTableEntity> retval = new ArrayList<>();
final String tblPrefix = tableNamePrefix == null ? "" : tableNamePrefix;
Pageable page = PageRequest.of(0, pageFetchSize, Sort.by("tblName").ascending());
Slice<PolarisTableEntity> tbls;
boolean hasNext;
do {
tbls = tblRepo.findAllTablesByDbNameAndTablePrefix(databaseName, tblPrefix, page);
retval.addAll(tbls.toList());
hasNext = tbls.hasNext();
if (hasNext) {
page = tbls.nextPageable();
}
} while (hasNext);
return retval;
}
Aggregations