use of com.netflix.metacat.common.dto.TableDto in project metacat by Netflix.
the class TableServiceImpl method get.
@Override
public Optional<TableDto> get(@Nonnull final QualifiedName name, final boolean includeInfo, final boolean includeDefinitionMetadata, final boolean includeDataMetadata) {
validate(name);
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
final ConnectorTableService service = connectorManager.getTableService(name.getCatalogName());
final TableDto table;
if (includeInfo) {
try {
table = converterUtil.toTableDto(service.get(connectorContext, name));
} catch (NotFoundException ignored) {
return Optional.empty();
}
} else {
table = new TableDto();
table.setName(name);
}
if (includeDefinitionMetadata) {
final Optional<ObjectNode> definitionMetadata = userMetadataService.getDefinitionMetadata(name);
if (definitionMetadata.isPresent()) {
table.setDefinitionMetadata(definitionMetadata.get());
}
}
if (includeDataMetadata) {
TableDto dto = table;
if (!includeInfo) {
try {
dto = converterUtil.toTableDto(service.get(connectorContext, name));
} catch (NotFoundException ignored) {
}
}
if (dto != null && dto.getSerde() != null) {
final Optional<ObjectNode> dataMetadata = userMetadataService.getDataMetadata(dto.getSerde().getUri());
if (dataMetadata.isPresent()) {
table.setDataMetadata(dataMetadata.get());
}
}
}
return Optional.of(table);
}
use of com.netflix.metacat.common.dto.TableDto in project metacat by Netflix.
the class MViewServiceImpl method getOpt.
@Override
public Optional<TableDto> getOpt(@Nonnull final QualifiedName name) {
final QualifiedName viewQName = QualifiedName.ofTable(name.getCatalogName(), VIEW_DB_NAME, createViewName(name));
final Optional<TableDto> result = tableService.get(viewQName, false);
//
if (result.isPresent()) {
final TableDto table = result.get();
table.setName(name);
final QualifiedName tableName = QualifiedName.ofTable(name.getCatalogName(), name.getDatabaseName(), name.getTableName());
final Optional<ObjectNode> definitionMetadata = userMetadataService.getDefinitionMetadata(tableName);
if (definitionMetadata.isPresent()) {
userMetadataService.populateMetadata(table, definitionMetadata.get(), null);
}
}
return result;
}
use of com.netflix.metacat.common.dto.TableDto in project metacat by Netflix.
the class MetacatServiceHelper method postPostUpdateEvent.
/**
* Calls the right method of the event bus for the given qualified name.
*
* @param name name
* @param metacatRequestContext context
* @param oldDTo dto
* @param currentDto dto
*/
public void postPostUpdateEvent(final QualifiedName name, final MetacatRequestContext metacatRequestContext, final BaseDto oldDTo, final BaseDto currentDto) {
if (name.isPartitionDefinition()) {
final List<PartitionDto> dtos = Lists.newArrayList();
if (currentDto != null) {
dtos.add((PartitionDto) currentDto);
}
// This request neither added nor updated partitions
final PartitionsSaveResponseDto partitionsSaveResponseDto = new PartitionsSaveResponseDto();
this.eventBus.postAsync(new MetacatSaveTablePartitionPostEvent(name, metacatRequestContext, this, dtos, partitionsSaveResponseDto));
} else if (name.isTableDefinition()) {
final MetacatUpdateTablePostEvent event = new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, (TableDto) oldDTo, (TableDto) currentDto);
this.eventBus.postAsync(event);
} else if (name.isDatabaseDefinition()) {
this.eventBus.postAsync(new MetacatUpdateDatabasePostEvent(name, metacatRequestContext, this));
} else {
throw new IllegalArgumentException(String.format("Invalid name %s", name));
}
}
use of com.netflix.metacat.common.dto.TableDto in project metacat by Netflix.
the class CatalogThriftHiveMetastore method get_partitions_by_filter.
/**
* {@inheritDoc}
*/
@Override
public List<Partition> get_partitions_by_filter(final String dbName, final String tblName, final String filter, final short maxParts) throws TException {
return requestWrapper("get_partitions_by_filter", new Object[] { dbName, tblName, filter, maxParts }, () -> {
final String databaseName = normalizeIdentifier(dbName);
final String tableName = normalizeIdentifier(tblName);
final TableDto tableDto = v1.getTable(catalogName, databaseName, tableName, true, false, false);
final Integer maxValues = maxParts > 0 ? Short.toUnsignedInt(maxParts) : null;
final List<PartitionDto> metacatPartitions = partV1.getPartitions(catalogName, dbName, tblName, filter, null, null, null, maxValues, false);
final List<Partition> result = Lists.newArrayListWithCapacity(metacatPartitions.size());
for (PartitionDto partition : metacatPartitions) {
result.add(hiveConverters.metacatToHivePartition(partition, tableDto));
}
return result;
});
}
use of com.netflix.metacat.common.dto.TableDto in project metacat by Netflix.
the class HiveConvertersImpl method hiveToMetacatTable.
/**
* {@inheritDoc}
*/
@Override
public TableDto hiveToMetacatTable(final QualifiedName name, final Table table) {
final TableDto dto = new TableDto();
dto.setSerde(toStorageDto(table.getSd(), table.getOwner()));
dto.setAudit(new AuditDto());
dto.setName(name);
if (table.isSetCreateTime()) {
dto.getAudit().setCreatedDate(epochSecondsToDate(table.getCreateTime()));
}
dto.setMetadata(table.getParameters());
final List<FieldSchema> nonPartitionColumns = table.getSd().getCols();
final List<FieldSchema> partitionColumns = table.getPartitionKeys();
final List<FieldDto> allFields = Lists.newArrayListWithCapacity(nonPartitionColumns.size() + partitionColumns.size());
nonPartitionColumns.stream().map(field -> this.hiveToMetacatField(field, false)).forEachOrdered(allFields::add);
partitionColumns.stream().map(field -> this.hiveToMetacatField(field, true)).forEachOrdered(allFields::add);
dto.setFields(allFields);
return dto;
}
Aggregations