Search in sources :

Example 1 with SqlDropAlias

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);
}
Also used : SqlDropAlias(org.apache.drill.exec.planner.sql.parser.SqlDropAlias) AliasRegistry(org.apache.drill.exec.alias.AliasRegistry) Aliases(org.apache.drill.exec.alias.Aliases) SqlLiteral(org.apache.calcite.sql.SqlLiteral)

Aggregations

SqlLiteral (org.apache.calcite.sql.SqlLiteral)1 AliasRegistry (org.apache.drill.exec.alias.AliasRegistry)1 Aliases (org.apache.drill.exec.alias.Aliases)1 SqlDropAlias (org.apache.drill.exec.planner.sql.parser.SqlDropAlias)1