use of com.netflix.metacat.common.server.connectors.exception.TableNotFoundException in project metacat by Netflix.
the class HiveConnectorPartitionService method getPartitions.
/**
* {@inheritDoc}.
*/
@Override
public List<PartitionInfo> getPartitions(final ConnectorRequestContext requestContext, final QualifiedName tableName, final PartitionListRequest partitionsRequest) {
try {
final List<Partition> partitions = getPartitions(tableName, partitionsRequest.getFilter(), partitionsRequest.getPartitionNames(), partitionsRequest.getSort(), partitionsRequest.getPageable());
final Table table = metacatHiveClient.getTableByName(tableName.getDatabaseName(), tableName.getTableName());
final TableInfo tableInfo = hiveMetacatConverters.toTableInfo(tableName, table);
final List<PartitionInfo> partitionInfos = new ArrayList<>();
for (Partition partition : partitions) {
partitionInfos.add(hiveMetacatConverters.toPartitionInfo(tableInfo, partition));
}
return partitionInfos;
} catch (NoSuchObjectException exception) {
throw new TableNotFoundException(tableName, exception);
} catch (MetaException | InvalidObjectException e) {
throw new InvalidMetaException("Invalid metadata for " + tableName, e);
} catch (TException e) {
throw new ConnectorException(String.format("Failed get partitions for hive table %s", tableName), e);
}
}
use of com.netflix.metacat.common.server.connectors.exception.TableNotFoundException in project metacat by Netflix.
the class HiveConnectorPartitionService method getPartitionKeys.
/**
* {@inheritDoc}.
*/
@Override
public List<String> getPartitionKeys(final ConnectorRequestContext requestContext, final QualifiedName tableName, final PartitionListRequest partitionsRequest, final TableInfo tableInfo) {
final String filterExpression = partitionsRequest.getFilter();
final List<String> partitionIds = partitionsRequest.getPartitionNames();
List<String> names = Lists.newArrayList();
final Pageable pageable = partitionsRequest.getPageable();
try {
if (filterExpression != null || (partitionIds != null && !partitionIds.isEmpty())) {
final Table table = metacatHiveClient.getTableByName(tableName.getDatabaseName(), tableName.getTableName());
for (Partition partition : getPartitions(tableName, filterExpression, partitionIds, partitionsRequest.getSort(), pageable)) {
names.add(getNameOfPartition(table, partition));
}
} else {
names = metacatHiveClient.getPartitionNames(tableName.getDatabaseName(), tableName.getTableName());
return ConnectorUtils.paginate(names, pageable);
}
} catch (NoSuchObjectException exception) {
throw new TableNotFoundException(tableName, exception);
} catch (MetaException | InvalidObjectException e) {
throw new InvalidMetaException("Invalid metadata for " + tableName, e);
} catch (TException e) {
throw new ConnectorException(String.format("Failed get partitions keys for hive table %s", tableName), e);
}
return names;
}
use of com.netflix.metacat.common.server.connectors.exception.TableNotFoundException in project metacat by Netflix.
the class HiveConnectorTableService method rename.
/**
* {@inheritDoc}.
*/
@Override
public void rename(final ConnectorRequestContext context, final QualifiedName oldName, final QualifiedName newName) {
if (!allowRenameTable) {
throw new ConnectorException("Renaming tables is disabled in catalog " + catalogName, null);
}
try {
if (onRenameConvertToExternal) {
//
// If this is a managed table(EXTERNAL=FALSE), then convert it to an external table before renaming it.
// We do not want the metastore to move the location/data.
//
final Table table = metacatHiveClient.getTableByName(oldName.getDatabaseName(), oldName.getTableName());
Map<String, String> parameters = table.getParameters();
if (parameters == null) {
parameters = Maps.newHashMap();
table.setParameters(parameters);
}
if (!parameters.containsKey(PARAMETER_EXTERNAL) || parameters.get(PARAMETER_EXTERNAL).equalsIgnoreCase("FALSE")) {
parameters.put(PARAMETER_EXTERNAL, "TRUE");
metacatHiveClient.alterTable(oldName.getDatabaseName(), oldName.getTableName(), table);
}
}
metacatHiveClient.rename(oldName.getDatabaseName(), oldName.getTableName(), newName.getDatabaseName(), newName.getTableName());
} catch (NoSuchObjectException exception) {
throw new TableNotFoundException(oldName, exception);
} catch (MetaException exception) {
throw new InvalidMetaException(newName, exception);
} catch (TException exception) {
throw new ConnectorException("Failed renaming from hive table" + oldName.toString() + " to hive talbe " + newName.toString(), exception);
}
}
use of com.netflix.metacat.common.server.connectors.exception.TableNotFoundException in project metacat by Netflix.
the class DruidConnectorTableService method get.
/**
* {@inheritDoc}
*/
@Override
public TableInfo get(@Nonnull final ConnectorRequestContext context, @Nonnull final QualifiedName name) {
log.debug("Get table metadata for qualified name {} for request {}", name, context);
try {
final ObjectNode node = this.druidClient.getLatestDataByName(name.getTableName());
final DataSource dataSource = DruidConverterUtil.getDatasourceFromLatestSegmentJsonObject(node);
return this.druidConnectorInfoConverter.getTableInfoFromDatasource(dataSource);
} catch (MetacatException e) {
log.error(String.format("Table %s not found.", name), e);
throw new TableNotFoundException(name);
} catch (HttpClientErrorException e) {
log.error(String.format("Failed getting table %s.", name), e);
if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) {
throw new TableNotFoundException(name);
} else {
throw new InvalidMetadataException(String.format("Invalid table %s. %s", name, e.getMessage()));
}
}
}
use of com.netflix.metacat.common.server.connectors.exception.TableNotFoundException in project metacat by Netflix.
the class CassandraConnectorTableService method get.
/**
* {@inheritDoc}
*/
@Override
public TableInfo get(@Nonnull @NonNull final ConnectorRequestContext context, @Nonnull @NonNull final QualifiedName name) {
final String keyspace = name.getDatabaseName();
final String table = name.getTableName();
log.debug("Attempting to get metadata for Cassandra table {}.{} for request {}", keyspace, table, context);
try {
final KeyspaceMetadata keyspaceMetadata = this.getCluster().getMetadata().getKeyspace(keyspace);
if (keyspaceMetadata == null) {
throw new DatabaseNotFoundException(name);
}
final TableMetadata tableMetadata = keyspaceMetadata.getTable(table);
if (tableMetadata == null) {
throw new TableNotFoundException(name);
}
final TableInfo tableInfo = this.getTableInfo(name, tableMetadata);
log.debug("Successfully got metadata for Cassandra table {}.{} for request {}", keyspace, table, context);
return tableInfo;
} catch (final DriverException de) {
log.error(de.getMessage(), de);
throw this.getExceptionMapper().toConnectorException(de, name);
}
}
Aggregations