use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class MetacatV1Resource method createDatabase.
@Override
public void createDatabase(final String catalogName, final String databaseName, final DatabaseCreateRequestDto databaseCreateRequestDto) {
final QualifiedName name = requestWrapper.qualifyName(() -> QualifiedName.ofDatabase(catalogName, databaseName));
requestWrapper.processRequest(name, "createDatabase", () -> {
final DatabaseDto newDto = new DatabaseDto();
newDto.setName(name);
if (databaseCreateRequestDto != null) {
newDto.setDefinitionMetadata(databaseCreateRequestDto.getDefinitionMetadata());
}
databaseService.create(name, newDto);
return null;
});
}
use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class PartitionV1Resource method savePartitions.
/**
* {@inheritDoc}
*/
@Override
public PartitionsSaveResponseDto savePartitions(final String catalogName, final String databaseName, final String tableName, final String viewName, final PartitionsSaveRequestDto partitionsSaveRequestDto) {
final QualifiedName name = requestWrapper.qualifyName(() -> QualifiedName.ofView(catalogName, databaseName, tableName, viewName));
return requestWrapper.processRequest(name, "saveMViewPartition", () -> {
final PartitionsSaveResponseDto result;
if (partitionsSaveRequestDto == null || partitionsSaveRequestDto.getPartitions() == null || partitionsSaveRequestDto.getPartitions().isEmpty()) {
result = new PartitionsSaveResponseDto();
} else {
result = mViewService.savePartitions(name, partitionsSaveRequestDto, true);
// This metadata is actually for the view, if it is present update that
if (partitionsSaveRequestDto.getDefinitionMetadata() != null || partitionsSaveRequestDto.getDataMetadata() != null) {
final TableDto dto = v1.getMView(catalogName, databaseName, tableName, viewName);
dto.setDefinitionMetadata(partitionsSaveRequestDto.getDefinitionMetadata());
dto.setDataMetadata(partitionsSaveRequestDto.getDataMetadata());
v1.updateMView(catalogName, databaseName, tableName, viewName, dto);
}
}
return result;
});
}
use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class MysqlUserMetadataService method _deleteDefinitionMetadatas.
@SuppressWarnings("checkstyle:methodname")
private Void _deleteDefinitionMetadatas(final Connection conn, @Nullable final List<QualifiedName> names) throws SQLException {
if (names != null && !names.isEmpty()) {
final List<String> paramVariables = names.stream().map(s -> "?").collect(Collectors.toList());
final String[] aNames = names.stream().map(QualifiedName::toString).toArray(String[]::new);
new QueryRunner().update(conn, String.format(SQL.DELETE_DEFINITION_METADATA, Joiner.on(",").skipNulls().join(paramVariables)), (Object[]) aNames);
}
return null;
}
use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class HiveConnectorFastPartitionService method getPartitionCount.
/**
* Number of partitions for the given table.
*
* @param tableName tableName
* @return Number of partitions
*/
@Override
public int getPartitionCount(@Nonnull @NonNull final ConnectorContext requestContext, @Nonnull @NonNull final QualifiedName tableName) {
final long start = registry.clock().monotonicTime();
final Map<String, String> tags = new HashMap<String, String>();
tags.put("request", HiveMetrics.getPartitionCount.name());
final Integer result;
final DataSource dataSource = DataSourceManager.get().get(catalogName);
try (Connection conn = dataSource.getConnection()) {
// Handler for reading the result set
final ResultSetHandler<Integer> handler = rs -> {
int count = 0;
while (rs.next()) {
count = rs.getInt("count");
}
return count;
};
result = new QueryRunner().query(conn, SQL_GET_PARTITION_COUNT, handler, tableName.getDatabaseName(), tableName.getTableName());
} catch (SQLException e) {
throw new ConnectorException("getPartitionCount", e);
} finally {
final long duration = registry.clock().monotonicTime() - start;
log.debug("### Time taken to complete getPartitionCount is {} ms", duration);
this.registry.timer(requestTimerId.withTags(tags)).record(duration, TimeUnit.MILLISECONDS);
}
return result;
}
use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class HiveConnectorTableService method list.
/**
* {@inheritDoc}.
*/
@Override
public List<TableInfo> list(@Nonnull @NonNull final ConnectorContext requestContext, @Nonnull @NonNull final QualifiedName name, @Nullable final QualifiedName prefix, @Nullable final Sort sort, @Nullable final Pageable pageable) {
try {
final List<TableInfo> tableInfos = Lists.newArrayList();
for (String tableName : metacatHiveClient.getAllTables(name.getDatabaseName())) {
final QualifiedName qualifiedName = QualifiedName.ofDatabase(name.getCatalogName(), tableName);
if (!qualifiedName.toString().startsWith(prefix.toString())) {
continue;
}
final Table table = metacatHiveClient.getTableByName(name.getDatabaseName(), tableName);
tableInfos.add(hiveMetacatConverters.toTableInfo(name, table));
}
//supporting sort by name only
if (sort != null) {
ConnectorUtils.sort(tableInfos, sort, Comparator.comparing(p -> p.getName().getTableName()));
}
return ConnectorUtils.paginate(tableInfos, pageable);
} catch (MetaException exception) {
throw new DatabaseNotFoundException(name, exception);
} catch (TException exception) {
throw new ConnectorException(String.format("Failed list hive table %s", name), exception);
}
}
Aggregations