use of org.apache.drill.exec.alias.AliasRegistry in project drill by apache.
the class CreateAliasHandler method getPlan.
@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ForemanSetupException, IOException {
checkAliasesEnabled();
SqlCreateAlias node = unwrap(sqlNode, SqlCreateAlias.class);
String alias = SchemaPath.getCompoundPath(node.getAlias().names.toArray(new String[0])).toExpr();
String aliasTarget = ((SqlLiteral) node.getAliasKind()).toValue();
AliasRegistry aliasRegistry = getAliasRegistry(aliasTarget);
String value = getValue(node, aliasTarget);
boolean replace = ((SqlLiteral) node.getReplace()).booleanValue();
Aliases aliases = getAliases(node, aliasRegistry);
if (!aliases.put(alias, value, replace)) {
throw UserException.validationError().message("Alias with given name [%s] already exists", alias).build(logger);
}
return DirectPlan.createDirectPlan(context, true, String.format("%s alias '%s' for '%s' created successfully", StringUtils.capitalize(aliasTarget.toLowerCase(Locale.ROOT)), alias, value));
}
use of org.apache.drill.exec.alias.AliasRegistry in project drill by apache.
the class DropAliasHandler method getPlan.
@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ForemanSetupException, IOException {
checkAliasesEnabled();
SqlDropAlias node = unwrap(sqlNode, SqlDropAlias.class);
String alias = SchemaPath.getCompoundPath(node.getAlias().names.toArray(new String[0])).toExpr();
String aliasTarget = ((SqlLiteral) node.getAliasKind()).toValue();
AliasRegistry aliasRegistry = getAliasRegistry(aliasTarget);
Aliases aliases = getAliases(node, aliasRegistry);
boolean checkIfExists = ((SqlLiteral) node.getIfExists()).booleanValue();
boolean removed = aliases.remove(alias);
if (!removed && !checkIfExists) {
throw UserException.validationError().message("No alias found with given name [%s]", alias).build(logger);
}
String message = removed ? String.format("%s alias '%s' dropped successfully", StringUtils.capitalize(aliasTarget.toLowerCase(Locale.ROOT)), alias) : String.format("No %s alias found with given name [%s]", aliasTarget.toLowerCase(Locale.ROOT), alias);
return DirectPlan.createDirectPlan(context, removed, message);
}
use of org.apache.drill.exec.alias.AliasRegistry in project drill by apache.
the class DropAllAliasesHandler method getPlan.
@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ForemanSetupException, IOException {
checkAliasesEnabled();
SqlDropAllAliases node = unwrap(sqlNode, SqlDropAllAliases.class);
String aliasTarget = ((SqlLiteral) node.getAliasKind()).toValue();
AliasRegistry aliasRegistry = getAliasRegistry(aliasTarget);
boolean isPublicAlias = ((SqlLiteral) node.getIsPublic()).booleanValue();
if (isPublicAlias) {
deletePublicAliases(node.getUser(), aliasRegistry);
} else {
deleteUserAliases(node.getUser(), aliasRegistry);
}
return DirectPlan.createDirectPlan(context, true, String.format("%s aliases dropped successfully", StringUtils.capitalize(aliasTarget.toLowerCase(Locale.ROOT))));
}
Aggregations