use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class HiveConvertersImpl method metacatToHiveTable.
/**
* {@inheritDoc}
*/
@Override
public Table metacatToHiveTable(final TableDto dto) {
final Table table = new Table();
String tableName = "";
String databaseName = "";
final QualifiedName name = dto.getName();
if (name != null) {
tableName = name.getTableName();
databaseName = name.getDatabaseName();
}
table.setTableName(tableName);
table.setDbName(databaseName);
final StorageDto storageDto = dto.getSerde();
String owner = "";
if (storageDto != null && storageDto.getOwner() != null) {
owner = storageDto.getOwner();
}
table.setOwner(owner);
final AuditDto auditDto = dto.getAudit();
if (auditDto != null && auditDto.getCreatedDate() != null) {
table.setCreateTime(dateToEpochSeconds(auditDto.getCreatedDate()));
}
Map<String, String> params = new HashMap<>();
if (dto.getMetadata() != null) {
params = dto.getMetadata();
}
table.setParameters(params);
updateTableTypeAndViewInfo(dto, table);
table.setSd(fromStorageDto(storageDto));
final StorageDescriptor sd = table.getSd();
final List<FieldDto> fields = dto.getFields();
if (fields == null) {
table.setPartitionKeys(Collections.emptyList());
sd.setCols(Collections.emptyList());
} else {
final List<FieldSchema> nonPartitionFields = Lists.newArrayListWithCapacity(fields.size());
final List<FieldSchema> partitionFields = Lists.newArrayListWithCapacity(fields.size());
for (FieldDto fieldDto : fields) {
final FieldSchema f = metacatToHiveField(fieldDto);
if (fieldDto.isPartition_key()) {
partitionFields.add(f);
} else {
nonPartitionFields.add(f);
}
}
table.setPartitionKeys(partitionFields);
sd.setCols(nonPartitionFields);
}
return table;
}
use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class HiveConvertersImpl method metacatToHiveDatabase.
/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings("unchecked")
public Database metacatToHiveDatabase(final DatabaseDto dto) {
final Database database = new Database();
String name = "";
String description = "";
final QualifiedName databaseName = dto.getName();
if (databaseName != null) {
name = databaseName.getDatabaseName();
// Since this is required setting it to the same as the DB name for now
description = databaseName.getDatabaseName();
}
database.setName(name);
database.setDescription(description);
String dbUri = dto.getUri();
if (Strings.isNullOrEmpty(dbUri)) {
dbUri = "";
}
database.setLocationUri(dbUri);
Map<String, String> metadata = dto.getMetadata();
if (metadata == null) {
metadata = Collections.EMPTY_MAP;
}
database.setParameters(metadata);
return database;
}
use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class MetacatController method createDatabase.
/**
* Creates the given database in the given catalog.
*
* @param catalogName catalog name
* @param databaseName database name
* @param databaseCreateRequestDto database create request
*/
@RequestMapping(method = RequestMethod.POST, path = "/catalog/{catalog-name}/database/{database-name}", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
@ApiOperation(position = 2, value = "Creates the given database in the given catalog", notes = "Given a catalog and a database name, creates the database in the catalog")
@ApiResponses({ @ApiResponse(code = HttpURLConnection.HTTP_CREATED, message = "The database was created"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "The requested catalog or database cannot be located") })
@Override
public void createDatabase(@ApiParam(value = "The name of the catalog", required = true) @PathVariable("catalog-name") final String catalogName, @ApiParam(value = "The name of the database", required = true) @PathVariable("database-name") final String databaseName, @ApiParam(value = "The database information") @Nullable @RequestBody(required = false) final DatabaseCreateRequestDto databaseCreateRequestDto) {
final QualifiedName name = this.requestWrapper.qualifyName(() -> QualifiedName.ofDatabase(catalogName, databaseName));
this.requestWrapper.processRequest(name, "createDatabase", () -> {
final DatabaseDto newDto = new DatabaseDto();
newDto.setName(name);
if (databaseCreateRequestDto != null) {
newDto.setDefinitionMetadata(databaseCreateRequestDto.getDefinitionMetadata());
}
this.databaseService.create(name, newDto);
return null;
});
}
use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class MetacatController method deleteDatabase.
/**
* Deletes the given database from the given catalog.
*
* @param catalogName catalog name
* @param databaseName database name
*/
@RequestMapping(method = RequestMethod.DELETE, path = "/catalog/{catalog-name}/database/{database-name}")
@ResponseStatus(HttpStatus.NO_CONTENT)
@ApiOperation(position = 4, value = "Deletes the given database from the given catalog", notes = "Given a catalog and database, deletes the database from the catalog")
@ApiResponses({ @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Database was successfully deleted"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "The requested catalog or database cannot be located") })
public void deleteDatabase(@ApiParam(value = "The name of the catalog", required = true) @PathVariable("catalog-name") final String catalogName, @ApiParam(value = "The name of the database", required = true) @PathVariable("database-name") final String databaseName) {
final QualifiedName name = this.requestWrapper.qualifyName(() -> QualifiedName.ofDatabase(catalogName, databaseName));
this.requestWrapper.processRequest(name, "deleteDatabase", () -> {
this.databaseService.delete(name);
return null;
});
}
use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class TagController method setTableTags.
/**
* Sets the tags on the given table.
*
* @param catalogName catalog name
* @param databaseName database name
* @param tableName table name
* @param tags set of tags
* @return set of tags
*/
@RequestMapping(method = RequestMethod.POST, path = "/catalog/{catalog-name}/database/{database-name}/table/{table-name}", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
@ApiOperation(position = 2, value = "Sets the tags on the given table", notes = "Sets the tags on the given table")
@ApiResponses({ @ApiResponse(code = HttpURLConnection.HTTP_CREATED, message = "The tags were successfully created on the table"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "The requested catalog or database or table cannot be located") })
public Set<String> setTableTags(@ApiParam(value = "The name of the catalog", required = true) @PathVariable("catalog-name") final String catalogName, @ApiParam(value = "The name of the database", required = true) @PathVariable("database-name") final String databaseName, @ApiParam(value = "The name of the table", required = true) @PathVariable("table-name") final String tableName, @ApiParam(value = "Set of tags", required = true) @RequestBody final Set<String> tags) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final QualifiedName name = this.requestWrapper.qualifyName(() -> QualifiedName.ofTable(catalogName, databaseName, tableName));
return this.requestWrapper.processRequest(name, "TagV1Resource.setTableTags", () -> {
// TODO: shouldn't this be in the tag service?
if (!this.tableService.exists(name)) {
throw new TableNotFoundException(name);
}
final TableDto oldTable = this.tableService.get(name, GetTableServiceParameters.builder().includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).disableOnReadMetadataIntercetor(false).build()).orElseThrow(IllegalStateException::new);
final Set<String> result = this.tagService.setTableTags(name, tags, true);
final TableDto currentTable = this.tableService.get(name, GetTableServiceParameters.builder().includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).disableOnReadMetadataIntercetor(false).build()).orElseThrow(IllegalStateException::new);
this.eventBus.postAsync(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, currentTable));
return result;
});
}
Aggregations