Search in sources :

Example 16 with TableDto

use of com.netflix.metacat.common.dto.TableDto in project metacat by Netflix.

the class CatalogThriftHiveMetastore method get_table.

/**
 * {@inheritDoc}
 */
@Override
public Table get_table(final String dbname, final String tblName) throws TException {
    return requestWrapper("get_table", new Object[] { dbname, tblName }, () -> {
        final String databaseName = normalizeIdentifier(dbname);
        final String tableName = normalizeIdentifier(tblName);
        final TableDto dto = v1.getTable(catalogName, databaseName, tableName, true, true, true);
        return hiveConverters.metacatToHiveTable(dto);
    });
}
Also used : TableDto(com.netflix.metacat.common.dto.TableDto)

Example 17 with TableDto

use of com.netflix.metacat.common.dto.TableDto in project metacat by Netflix.

the class CatalogThriftHiveMetastore method create_table_with_environment_context.

/**
 * {@inheritDoc}
 */
@Override
public void create_table_with_environment_context(final Table tbl, @Nullable final EnvironmentContext environmentContext) throws TException {
    requestWrapper("create_table_with_environment_context", new Object[] { tbl, environmentContext }, () -> {
        final String dbname = normalizeIdentifier(tbl.getDbName());
        final String tblName = normalizeIdentifier(tbl.getTableName());
        final QualifiedName name = QualifiedName.ofTable(catalogName, dbname, tblName);
        final TableDto dto = hiveConverters.hiveToMetacatTable(name, tbl);
        v1.createTable(catalogName, dbname, tblName, dto);
        return null;
    });
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) TableDto(com.netflix.metacat.common.dto.TableDto)

Example 18 with TableDto

use of com.netflix.metacat.common.dto.TableDto 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)

Example 19 with TableDto

use of com.netflix.metacat.common.dto.TableDto in project metacat by Netflix.

the class MetacatServiceHelper method postPreUpdateEvent.

/**
 * Calls the right method of the event bus for the given qualified name.
 *
 * @param name                  name
 * @param metacatRequestContext context
 * @param dto                   dto
 */
public void postPreUpdateEvent(final QualifiedName name, final MetacatRequestContext metacatRequestContext, final BaseDto dto) {
    if (name.isPartitionDefinition()) {
        final PartitionsSaveRequestDto partitionsSaveRequestDto = new PartitionsSaveRequestDto();
        if (dto != null) {
            partitionsSaveRequestDto.setPartitions(ImmutableList.of((PartitionDto) dto));
        }
        this.eventBus.postSync(new MetacatSaveTablePartitionPreEvent(name, metacatRequestContext, this, partitionsSaveRequestDto));
    } else if (name.isViewDefinition()) {
        this.eventBus.postSync(new MetacatUpdateMViewPreEvent(name, metacatRequestContext, this, (TableDto) dto));
    } else if (name.isTableDefinition()) {
        this.eventBus.postSync(new MetacatUpdateTablePreEvent(name, metacatRequestContext, this, (TableDto) dto, (TableDto) dto));
    } else if (name.isDatabaseDefinition()) {
        eventBus.postSync(new MetacatUpdateDatabasePreEvent(name, metacatRequestContext, this));
    } else {
        throw new IllegalArgumentException(String.format("Invalid name %s", name));
    }
}
Also used : PartitionsSaveRequestDto(com.netflix.metacat.common.dto.PartitionsSaveRequestDto) MetacatUpdateMViewPreEvent(com.netflix.metacat.common.server.events.MetacatUpdateMViewPreEvent) MetacatUpdateDatabasePreEvent(com.netflix.metacat.common.server.events.MetacatUpdateDatabasePreEvent) MetacatSaveTablePartitionPreEvent(com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPreEvent) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) TableDto(com.netflix.metacat.common.dto.TableDto) MetacatUpdateTablePreEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePreEvent)

Example 20 with TableDto

use of com.netflix.metacat.common.dto.TableDto in project metacat by Netflix.

the class MViewServiceImpl method updateAndReturn.

/**
 * {@inheritDoc}
 */
@Override
public TableDto updateAndReturn(final QualifiedName name, final TableDto tableDto) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    eventBus.postSync(new MetacatUpdateMViewPreEvent(name, metacatRequestContext, this, tableDto));
    final QualifiedName viewQName = QualifiedName.ofTable(name.getCatalogName(), VIEW_DB_NAME, createViewName(name));
    log.info("Updating view {}.", viewQName);
    tableService.update(viewQName, tableDto);
    final TableDto updatedDto = getOpt(name, GetTableServiceParameters.builder().includeInfo(true).includeDefinitionMetadata(false).includeDataMetadata(false).disableOnReadMetadataIntercetor(false).build()).orElseThrow(() -> new IllegalStateException("should exist"));
    eventBus.postAsync(new MetacatUpdateMViewPostEvent(name, metacatRequestContext, this, updatedDto));
    return updatedDto;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) MetacatUpdateMViewPreEvent(com.netflix.metacat.common.server.events.MetacatUpdateMViewPreEvent) QualifiedName(com.netflix.metacat.common.QualifiedName) TableDto(com.netflix.metacat.common.dto.TableDto) MetacatUpdateMViewPostEvent(com.netflix.metacat.common.server.events.MetacatUpdateMViewPostEvent)

Aggregations

TableDto (com.netflix.metacat.common.dto.TableDto)50 QualifiedName (com.netflix.metacat.common.QualifiedName)19 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)17 PartitionDto (com.netflix.metacat.common.dto.PartitionDto)13 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)9 EventListener (org.springframework.context.event.EventListener)9 MetacatUpdateTablePostEvent (com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent)7 Partition (org.apache.hadoop.hive.metastore.api.Partition)7 DatabaseDto (com.netflix.metacat.common.dto.DatabaseDto)6 ConnectorTableService (com.netflix.metacat.common.server.connectors.ConnectorTableService)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 ConnectorRequestContext (com.netflix.metacat.common.server.connectors.ConnectorRequestContext)5 MetacatDeleteTablePostEvent (com.netflix.metacat.common.server.events.MetacatDeleteTablePostEvent)5 Splitter (com.google.common.base.Splitter)4 Strings (com.google.common.base.Strings)4 Lists (com.google.common.collect.Lists)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 FieldDto (com.netflix.metacat.common.dto.FieldDto)3 PartitionsSaveRequestDto (com.netflix.metacat.common.dto.PartitionsSaveRequestDto)3