use of org.apache.drill.exec.planner.sql.parser.SqlDropAlias 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);
}
Aggregations