Search in sources :

Example 46 with QualifiedName

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;
}
Also used : Table(org.apache.hadoop.hive.metastore.api.Table) AuditDto(com.netflix.metacat.common.dto.AuditDto) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) QualifiedName(com.netflix.metacat.common.QualifiedName) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) StorageDto(com.netflix.metacat.common.dto.StorageDto) FieldDto(com.netflix.metacat.common.dto.FieldDto)

Example 47 with QualifiedName

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;
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) Database(org.apache.hadoop.hive.metastore.api.Database)

Example 48 with QualifiedName

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;
    });
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 49 with QualifiedName

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;
    });
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 50 with QualifiedName

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;
    });
}
Also used : MetacatUpdateTablePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) QualifiedName(com.netflix.metacat.common.QualifiedName) TableDto(com.netflix.metacat.common.dto.TableDto) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

QualifiedName (com.netflix.metacat.common.QualifiedName)144 List (java.util.List)52 Lists (com.google.common.collect.Lists)44 Collectors (java.util.stream.Collectors)41 Map (java.util.Map)38 Slf4j (lombok.extern.slf4j.Slf4j)36 Strings (com.google.common.base.Strings)35 Nullable (javax.annotation.Nullable)33 Pageable (com.netflix.metacat.common.dto.Pageable)29 Sort (com.netflix.metacat.common.dto.Sort)29 Nonnull (javax.annotation.Nonnull)29 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)28 TableDto (com.netflix.metacat.common.dto.TableDto)27 Maps (com.google.common.collect.Maps)25 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)25 DatabaseNotFoundException (com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException)24 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)24 Optional (java.util.Optional)22 Registry (com.netflix.spectator.api.Registry)21 Set (java.util.Set)21