use of com.netflix.metacat.common.dto.TableDto in project metacat by Netflix.
the class TableServiceImpl method updateAndReturn.
/**
* {@inheritDoc}
*/
@Override
public TableDto updateAndReturn(final QualifiedName name, final TableDto tableDto) {
validate(name);
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final ConnectorTableService service = connectorManager.getTableService(name);
final TableDto oldTable = get(name, GetTableServiceParameters.builder().disableOnReadMetadataIntercetor(false).includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).build()).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 ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
service.update(connectorRequestContext, 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);
final long start = registry.clock().wallTime();
userMetadataService.saveMetadata(metacatRequestContext.getUserName(), tableDto, true);
final long duration = registry.clock().wallTime() - start;
log.info("Time taken to save user metadata for table {} is {} ms", name, duration);
registry.timer(registry.createId(Metrics.TimerSaveTableMetadata.getMetricName()).withTags(name.parts())).record(duration, TimeUnit.MILLISECONDS);
}
final TableDto updatedDto = get(name, GetTableServiceParameters.builder().disableOnReadMetadataIntercetor(false).includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).build()).orElseThrow(() -> new IllegalStateException("should exist"));
eventBus.postAsync(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, updatedDto));
return updatedDto;
}
use of com.netflix.metacat.common.dto.TableDto in project metacat by Netflix.
the class ElasticSearchEventHandlers method metacatCreateTablePostEventHandler.
/**
* Subscriber.
*
* @param event event
*/
@EventListener
public void metacatCreateTablePostEventHandler(final MetacatCreateTablePostEvent event) {
log.debug("Received CreateTableEvent {}", event);
this.tableCreateEventsDelayTimer.record(System.currentTimeMillis() - event.getRequestContext().getTimestamp(), TimeUnit.MILLISECONDS);
this.tableCreateTimer.record(() -> {
final TableDto dto = event.getTable();
final ElasticSearchDoc doc = new ElasticSearchDoc(dto.getName().toString(), dto, event.getRequestContext().getUserName(), false);
es.save(ElasticSearchDoc.Type.table.name(), doc.getId(), doc);
});
}
use of com.netflix.metacat.common.dto.TableDto in project metacat by Netflix.
the class ElasticSearchEventHandlers method metacatUpdateTablePostEventHandler.
/**
* Subscriber.
*
* @param event event
*/
@EventListener
public void metacatUpdateTablePostEventHandler(final MetacatUpdateTablePostEvent event) {
log.debug("Received UpdateTableEvent {}", event);
this.tableUpdateEventsDelayTimer.record(System.currentTimeMillis() - event.getRequestContext().getTimestamp(), TimeUnit.MILLISECONDS);
this.tableUpdateTimer.record(() -> {
final TableDto dto = event.getCurrentTable();
final ElasticSearchDoc doc = new ElasticSearchDoc(dto.getName().toString(), dto, event.getRequestContext().getUserName(), false);
final ElasticSearchDoc oldDoc = es.get(ElasticSearchDoc.Type.table.name(), doc.getId());
es.save(ElasticSearchDoc.Type.table.name(), doc.getId(), doc);
if (oldDoc == null || oldDoc.getDto() == null || !Objects.equals(((TableDto) oldDoc.getDto()).getDataMetadata(), dto.getDataMetadata())) {
updateEntitiesWithSameUri(ElasticSearchDoc.Type.table.name(), dto, event.getRequestContext().getUserName());
}
});
}
use of com.netflix.metacat.common.dto.TableDto in project metacat by Netflix.
the class ElasticSearchEventHandlers method updateEntitiesWithSameUri.
private void updateEntitiesWithSameUri(final String metadataType, final TableDto dto, final String userName) {
if (dto.isDataExternal()) {
final List<String> ids = es.getTableIdsByUri(metadataType, dto.getDataUri()).stream().filter(s -> !s.equals(dto.getName().toString())).collect(Collectors.toList());
if (!ids.isEmpty()) {
final ObjectNode node = metacatJsonLocator.emptyObjectNode();
node.set(ElasticSearchDoc.Field.DATA_METADATA, dto.getDataMetadata());
node.put(ElasticSearchDoc.Field.USER, userName);
node.put(ElasticSearchDoc.Field.TIMESTAMP, java.time.Instant.now().toEpochMilli());
es.updates(ElasticSearchDoc.Type.table.name(), ids, node);
}
}
}
use of com.netflix.metacat.common.dto.TableDto in project metacat by Netflix.
the class CatalogThriftHiveMetastore method drop_partition_with_environment_context.
/**
* {@inheritDoc}
*/
@Override
public boolean drop_partition_with_environment_context(final String dbName, final String tblName, final List<String> partVals, final boolean deleteData, @Nullable final EnvironmentContext environmentContext) throws TException {
return requestWrapper("drop_partition_with_environment_context", new Object[] { dbName, tblName, partVals, deleteData, environmentContext }, () -> {
final TableDto tableDto = getTableDto(dbName, tblName);
final String partName = hiveConverters.getNameFromPartVals(tableDto, partVals);
final QualifiedName partitionName = getPartitionDtoByName(tableDto, partName).getName();
if (deleteData) {
log.warn("Ignoring command to delete data for {}/{}/{}/{}", catalogName, tableDto.getName().getDatabaseName(), tableDto.getName().getTableName(), partitionName.getPartitionName());
}
partV1.deletePartitions(catalogName, tableDto.getName().getDatabaseName(), tableDto.getName().getTableName(), ImmutableList.of(partitionName.getPartitionName()));
return true;
});
}
Aggregations