use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class S3ConnectorInfoConverter method fromDatabaseInfo.
@Override
public Database fromDatabaseInfo(final DatabaseInfo databaseInfo) {
final Database result = new Database();
final QualifiedName databaseName = databaseInfo.getName();
result.setName(databaseName.getDatabaseName());
final Source source = new Source();
source.setName(databaseName.getCatalogName());
result.setSource(source);
return result;
}
use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class S3ConnectorPartitionService method _getConnectorPartitions.
@SuppressWarnings("checkstyle:methodname")
private List<PartitionInfo> _getConnectorPartitions(final QualifiedName tableName, final String filterExpression, final List<String> partitionIds, final Sort sort, final Pageable pageable, final boolean includePartitionDetails) {
// batch exists
final boolean isBatched = !Strings.isNullOrEmpty(filterExpression) && filterExpression.contains(FIELD_BATCHID);
// Support for dateCreated
final boolean hasDateCreated = !Strings.isNullOrEmpty(filterExpression) && filterExpression.contains(FIELD_DATE_CREATED);
String dateCreatedSqlCriteria = null;
if (hasDateCreated) {
dateCreatedSqlCriteria = getDateCreatedSqlCriteria(filterExpression);
}
// Table
final Table table = getTable(tableName);
final Collection<String> singlePartitionExprs = getSinglePartitionExprs(filterExpression);
final List<Partition> partitions = partitionDao.getPartitions(table.getId(), partitionIds, singlePartitionExprs, dateCreatedSqlCriteria, sort, Strings.isNullOrEmpty(filterExpression) ? pageable : null);
final FilterPartition filter = new FilterPartition();
List<PartitionInfo> result = partitions.stream().filter(partition -> {
Map<String, String> values = null;
if (hasDateCreated) {
values = Maps.newHashMap();
values.put(FIELD_DATE_CREATED, (partition.getCreatedDate().getTime() / 1000) + "");
}
return Strings.isNullOrEmpty(filterExpression) || filter.evaluatePartitionExpression(filterExpression, partition.getName(), partition.getUri(), isBatched, values);
}).map(partition -> infoConverter.toPartitionInfo(tableName, table, partition)).collect(Collectors.toList());
//
if (pageable != null && pageable.isPageable() && !Strings.isNullOrEmpty(filterExpression)) {
int limit = pageable.getOffset() + pageable.getLimit();
if (result.size() < limit) {
limit = result.size();
}
if (pageable.getOffset() > limit) {
result = Lists.newArrayList();
} else {
result = result.subList(pageable.getOffset(), limit);
}
}
return result;
}
use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class TagV1Resource method removeTableTags.
/**
* {@inheritDoc}
*/
@Override
public void removeTableTags(final String catalogName, final String databaseName, final String tableName, final Boolean deleteAll, final Set<String> tags) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final QualifiedName name = requestWrapper.qualifyName(() -> QualifiedName.ofTable(catalogName, databaseName, tableName));
requestWrapper.processRequest(name, "TagV1Resource.removeTableTags", () -> {
if (!tableService.exists(name)) {
// Delete tags if exists
tagService.delete(name, false);
throw new TableNotFoundException(name);
}
final TableDto oldTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
tagService.removeTableTags(name, deleteAll, tags, true);
final TableDto currentTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
eventBus.postAsync(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, currentTable));
return null;
});
}
use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class TagV1Resource method setTableTags.
/**
* {@inheritDoc}
*/
@Override
public Set<String> setTableTags(final String catalogName, final String databaseName, final String tableName, final Set<String> tags) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final QualifiedName name = requestWrapper.qualifyName(() -> QualifiedName.ofTable(catalogName, databaseName, tableName));
return requestWrapper.processRequest(name, "TagV1Resource.setTableTags", () -> {
if (!tableService.exists(name)) {
throw new TableNotFoundException(name);
}
final TableDto oldTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
final Set<String> result = tagService.setTableTags(name, tags, true);
final TableDto currentTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
eventBus.postAsync(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, currentTable));
return result;
});
}
use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class S3ConnectorPartitionService method update.
@Override
public void update(@Nonnull final ConnectorContext context, @Nonnull final PartitionInfo partitionInfo) {
final QualifiedName name = partitionInfo.getName();
log.debug("Start: Update partition {}", name);
final QualifiedName tableName = QualifiedName.ofTable(catalogName, name.getDatabaseName(), name.getTableName());
// Table
final Table table = getTable(tableName);
final List<Partition> partitions = partitionDao.getPartitions(table.getId(), Lists.newArrayList(name.getPartitionName()), null, null, null, null);
if (partitions.isEmpty()) {
throw new PartitionNotFoundException(tableName, name.getPartitionName());
}
partitionDao.save(infoConverter.fromPartitionInfo(partitionInfo));
log.debug("End: Update partition {}", name);
}
Aggregations