use of com.netflix.metacat.common.server.connectors.exception.InvalidMetaException in project metacat by Netflix.
the class HiveConnectorPartitionService method getPartitionsByNames.
protected Map<String, PartitionHolder> getPartitionsByNames(final Table table, final List<String> partitionNames) {
final String databasename = table.getDbName();
final String tablename = table.getTableName();
try {
final List<Partition> partitions = metacatHiveClient.getPartitions(databasename, tablename, partitionNames);
return partitions.stream().map(PartitionHolder::new).collect(Collectors.toMap(part -> {
try {
return Warehouse.makePartName(table.getPartitionKeys(), part.getPartition().getValues());
} catch (Exception e) {
throw new InvalidMetaException("One or more partition names are invalid.", e);
}
}, Function.identity()));
} catch (Exception e) {
throw new InvalidMetaException("One or more partition names are invalid.", e);
}
}
use of com.netflix.metacat.common.server.connectors.exception.InvalidMetaException 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.InvalidMetaException in project metacat by Netflix.
the class HiveConnectorTableService method create.
/**
* Create a table.
*
* @param requestContext The request context
* @param tableInfo The resource metadata
*/
@Override
public void create(final ConnectorRequestContext requestContext, final TableInfo tableInfo) {
final QualifiedName tableName = tableInfo.getName();
try {
final Table table = hiveMetacatConverters.fromTableInfo(tableInfo);
updateTable(requestContext, table, tableInfo);
metacatHiveClient.createTable(table);
} catch (AlreadyExistsException exception) {
throw new TableAlreadyExistsException(tableName, exception);
} catch (MetaException | InvalidObjectException exception) {
// the NoSuchObjectException is converted into InvalidObjectException in hive client
if (exception.getMessage().startsWith(tableName.getDatabaseName())) {
throw new DatabaseNotFoundException(QualifiedName.ofDatabase(tableName.getCatalogName(), tableName.getDatabaseName()), exception);
} else {
// table name or column invalid defintion exception
throw new InvalidMetaException(tableName, exception);
}
} catch (TException exception) {
throw new ConnectorException(String.format("Failed create hive table %s", tableName), exception);
}
}
use of com.netflix.metacat.common.server.connectors.exception.InvalidMetaException 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.InvalidMetaException in project metacat by Netflix.
the class PolarisConnectorDatabaseService method create.
/**
* {@inheritDoc}.
*/
@Override
public void create(final ConnectorRequestContext context, final DatabaseInfo databaseInfo) {
final QualifiedName name = databaseInfo.getName();
// check exists then create in non-transactional optimistic manner
if (exists(context, name)) {
throw new DatabaseAlreadyExistsException(name);
}
try {
final String location = databaseInfo.getUri() == null ? this.defaultLocationPrefix + name.getDatabaseName() + DEFAULT_LOCATION_SUFFIX : databaseInfo.getUri();
this.polarisStoreService.createDatabase(name.getDatabaseName(), location);
} catch (DataIntegrityViolationException exception) {
throw new InvalidMetaException(name, exception);
} catch (Exception exception) {
throw new ConnectorException(String.format("Failed creating polaris database %s", name), exception);
}
}
Aggregations