use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class ConnectorTableServiceProxy method delete.
/**
* Calls the connector table service delete method.
* @param name table name
*/
@CacheEvict(key = "'table.' + #name")
public void delete(final QualifiedName name) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final ConnectorTableService service = connectorManager.getTableService(name);
log.info("Drop table {}", name);
final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
service.delete(connectorRequestContext, name);
}
use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class ConnectorTableServiceProxy method get.
/**
* Returns table if <code>useCache</code> is true and object exists in the cache. If <code>useCache</code> is false
* or object does not exists in the cache, it is retrieved from the store.
* @param name table name
* @param getTableServiceParameters get table parameters
* @param useCache true, if table can be retrieved from cache
* @return table dto
*/
@Cacheable(key = "'table.' + #name", condition = "#useCache")
public TableInfo get(final QualifiedName name, final GetTableServiceParameters getTableServiceParameters, final boolean useCache) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
connectorRequestContext.setIncludeMetadata(getTableServiceParameters.isIncludeMetadataFromConnector());
final ConnectorTableService service = connectorManager.getTableService(name);
return service.get(connectorRequestContext, name);
}
use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class MViewServiceImpl method list.
/**
* {@inheritDoc}
*/
@Override
public List<NameDateDto> list(final QualifiedName name) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final QualifiedName viewDbName = QualifiedName.ofDatabase(name.getCatalogName(), VIEW_DB_NAME);
final ConnectorTableService service = connectorManager.getTableService(viewDbName);
List<QualifiedName> tableNames = Lists.newArrayList();
try {
final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
tableNames = service.listNames(connectorRequestContext, viewDbName, null, null, null);
} catch (Exception ignored) {
// ignore. Return an empty list if database 'franklinviews' does not exist
}
if (!name.isDatabaseDefinition() && name.isCatalogDefinition()) {
return tableNames.stream().map(viewName -> {
final NameDateDto dto = new NameDateDto();
dto.setName(viewName);
return dto;
}).collect(Collectors.toList());
} else {
final String prefix = String.format("%s_%s_", name.getDatabaseName(), MoreObjects.firstNonNull(name.getTableName(), ""));
return tableNames.stream().filter(qualifiedTableName -> qualifiedTableName.getTableName().startsWith(prefix)).map(qualifiedTableName -> {
final NameDateDto dto = new NameDateDto();
dto.setName(QualifiedName.ofView(qualifiedTableName.getCatalogName(), name.getDatabaseName(), name.getTableName(), qualifiedTableName.getTableName().substring(prefix.length())));
return dto;
}).collect(Collectors.toList());
}
}
use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class MViewServiceImpl method createAndSnapshotPartitions.
/**
* Creates the materialized view using the schema of the give table
* Assumes that the "franklinviews" database name already exists in the given catalog.
*/
@Override
public TableDto createAndSnapshotPartitions(final QualifiedName name, final boolean snapshot, @Nullable final String filter) {
final TableDto result;
// Get the table
log.info("Get the table {}", name);
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
eventBus.post(new MetacatCreateMViewPreEvent(name, metacatRequestContext, this, snapshot, filter));
final Optional<TableDto> oTable = tableService.get(name, GetTableServiceParameters.builder().includeDataMetadata(false).includeDefinitionMetadata(false).disableOnReadMetadataIntercetor(// turn off for optimization
true).includeInfo(true).build());
if (oTable.isPresent()) {
final TableDto table = oTable.get();
final String viewName = createViewName(name);
final QualifiedName targetName = QualifiedName.ofTable(name.getCatalogName(), VIEW_DB_NAME, viewName);
// Get the view table if it exists
log.info("Check if the view table {} exists.", targetName);
Optional<TableDto> oViewTable = Optional.empty();
try {
// read the original view back
oViewTable = tableService.get(targetName, GetTableServiceParameters.builder().includeDataMetadata(false).includeDefinitionMetadata(false).disableOnReadMetadataIntercetor(false).includeInfo(true).build());
} catch (NotFoundException ignored) {
}
if (!oViewTable.isPresent()) {
log.info("Creating view {}.", targetName);
//
if (MetacatServiceHelper.isIcebergTable(table)) {
table.getFields().forEach(f -> f.setSource_type(null));
}
result = tableService.copy(table, targetName);
} else {
result = oViewTable.get();
}
if (snapshot) {
snapshotPartitions(name, filter);
}
eventBus.post(new MetacatCreateMViewPostEvent(name, metacatRequestContext, this, result, snapshot, filter));
} else {
throw new TableNotFoundException(name);
}
return result;
}
use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class DatabaseServiceImpl method create.
/**
* {@inheritDoc}
*/
@Override
public DatabaseDto create(final QualifiedName name, final DatabaseDto dto) {
validate(name);
log.info("Creating schema {}", name);
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
eventBus.post(new MetacatCreateDatabasePreEvent(name, metacatRequestContext, this));
final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
connectorManager.getDatabaseService(name).create(connectorRequestContext, converterUtil.fromDatabaseDto(dto));
if (dto.getDefinitionMetadata() != null) {
log.info("Saving user metadata for schema {}", name);
userMetadataService.saveDefinitionMetadata(name, metacatRequestContext.getUserName(), Optional.of(dto.getDefinitionMetadata()), true);
}
final DatabaseDto createdDto = get(name, GetDatabaseServiceParameters.builder().disableOnReadMetadataIntercetor(true).includeUserMetadata(dto.getDefinitionMetadata() != null).includeTableNames(true).build());
eventBus.post(new MetacatCreateDatabasePostEvent(name, metacatRequestContext, this, createdDto));
return createdDto;
}
Aggregations