use of com.netflix.metacat.common.server.connectors.ConnectorTableService in project metacat by Netflix.
the class TableServiceImpl method updateAndReturn.
@Override
public TableDto updateAndReturn(@Nonnull final QualifiedName name, @Nonnull final TableDto tableDto) {
validate(name);
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final ConnectorTableService service = connectorManager.getTableService(name.getCatalogName());
final TableDto oldTable = get(name, true).orElseThrow(() -> new TableNotFoundException(name));
eventBus.postSync(new MetacatUpdateTablePreEvent(name, metacatRequestContext, this, oldTable, tableDto));
//Ignore if the operation is not supported, so that we can at least go ahead and save the user metadata
if (isTableInfoProvided(tableDto)) {
try {
log.info("Updating table {}", name);
final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
service.update(connectorContext, converterUtil.fromTableDto(tableDto));
} catch (UnsupportedOperationException ignored) {
}
}
// Merge in metadata if the user sent any
if (tableDto.getDataMetadata() != null || tableDto.getDefinitionMetadata() != null) {
log.info("Saving user metadata for table {}", name);
userMetadataService.saveMetadata(metacatRequestContext.getUserName(), tableDto, true);
}
final TableDto updatedDto = get(name, true).orElseThrow(() -> new IllegalStateException("should exist"));
eventBus.postAsync(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, updatedDto));
return updatedDto;
}
use of com.netflix.metacat.common.server.connectors.ConnectorTableService in project metacat by Netflix.
the class TableServiceImpl method create.
@Override
public TableDto create(@Nonnull final QualifiedName name, @Nonnull final TableDto tableDto) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
validate(name);
//
// Set the owner,if null, with the session user name.
//
setOwnerIfNull(tableDto, metacatRequestContext.getUserName());
log.info("Creating table {}", name);
eventBus.postSync(new MetacatCreateTablePreEvent(name, metacatRequestContext, this, tableDto));
final ConnectorTableService service = connectorManager.getTableService(name.getCatalogName());
final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
service.create(connectorContext, converterUtil.fromTableDto(tableDto));
if (tableDto.getDataMetadata() != null || tableDto.getDefinitionMetadata() != null) {
log.info("Saving user metadata for table {}", name);
userMetadataService.saveMetadata(metacatRequestContext.getUserName(), tableDto, false);
tag(name, tableDto.getDefinitionMetadata());
}
final TableDto dto = get(name, true).orElseThrow(() -> new IllegalStateException("Should exist"));
eventBus.postAsync(new MetacatCreateTablePostEvent(name, metacatRequestContext, this, dto));
return dto;
}
use of com.netflix.metacat.common.server.connectors.ConnectorTableService in project metacat by Netflix.
the class TableServiceImpl method get.
@Override
public Optional<TableDto> get(@Nonnull final QualifiedName name, final boolean includeInfo, final boolean includeDefinitionMetadata, final boolean includeDataMetadata) {
validate(name);
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
final ConnectorTableService service = connectorManager.getTableService(name.getCatalogName());
final TableDto table;
if (includeInfo) {
try {
table = converterUtil.toTableDto(service.get(connectorContext, name));
} catch (NotFoundException ignored) {
return Optional.empty();
}
} else {
table = new TableDto();
table.setName(name);
}
if (includeDefinitionMetadata) {
final Optional<ObjectNode> definitionMetadata = userMetadataService.getDefinitionMetadata(name);
if (definitionMetadata.isPresent()) {
table.setDefinitionMetadata(definitionMetadata.get());
}
}
if (includeDataMetadata) {
TableDto dto = table;
if (!includeInfo) {
try {
dto = converterUtil.toTableDto(service.get(connectorContext, name));
} catch (NotFoundException ignored) {
}
}
if (dto != null && dto.getSerde() != null) {
final Optional<ObjectNode> dataMetadata = userMetadataService.getDataMetadata(dto.getSerde().getUri());
if (dataMetadata.isPresent()) {
table.setDataMetadata(dataMetadata.get());
}
}
}
return Optional.of(table);
}
use of com.netflix.metacat.common.server.connectors.ConnectorTableService in project metacat by Netflix.
the class TableServiceImpl method getQualifiedNames.
@Override
public List<QualifiedName> getQualifiedNames(final String uri, final boolean prefixSearch) {
final List<QualifiedName> result = Lists.newArrayList();
connectorManager.getCatalogs().keySet().forEach(catalogName -> {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final ConnectorTableService service = connectorManager.getTableService(catalogName);
final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
try {
final Map<String, List<QualifiedName>> names = service.getTableNames(connectorContext, Lists.newArrayList(uri), prefixSearch);
final List<QualifiedName> qualifiedNames = names.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
result.addAll(qualifiedNames);
} catch (final UnsupportedOperationException uoe) {
log.debug("Catalog {} doesn't support getting table names by URI. Skipping", catalogName);
}
});
return result;
}
use of com.netflix.metacat.common.server.connectors.ConnectorTableService in project metacat by Netflix.
the class DatabaseServiceImpl method get.
@Override
public DatabaseDto get(@Nonnull final QualifiedName name, final boolean includeUserMetadata) {
validate(name);
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final MetacatCatalogConfig config = connectorManager.getCatalogConfig(name.getCatalogName());
final ConnectorDatabaseService service = connectorManager.getDatabaseService(name.getCatalogName());
final ConnectorTableService tableService = connectorManager.getTableService(name.getCatalogName());
final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
final List<QualifiedName> tableNames = tableService.listNames(connectorContext, name, null, null, null);
List<QualifiedName> viewNames = Collections.emptyList();
if (config.isIncludeViewsWithTables()) {
// TODO JdbcMetadata returns ImmutableList.of() for views. We should change it to fetch views.
try {
viewNames = service.listViewNames(connectorContext, name);
} catch (UnsupportedOperationException ignored) {
}
}
// Check to see if schema exists
if (tableNames.isEmpty() && viewNames.isEmpty() && !exists(name)) {
throw new DatabaseNotFoundException(name);
}
final DatabaseDto dto = converterUtil.toDatabaseDto(service.get(connectorContext, name));
dto.setType(connectorManager.getCatalogConfig(name).getType());
dto.setTables(Stream.concat(tableNames.stream(), viewNames.stream()).map(QualifiedName::getTableName).sorted(String.CASE_INSENSITIVE_ORDER).collect(Collectors.toList()));
if (includeUserMetadata) {
log.info("Populate user metadata for schema {}", name);
userMetadataService.populateMetadata(dto);
}
return dto;
}
Aggregations