Search in sources :

Example 1 with AliasRegistry

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

Example 2 with AliasRegistry

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);
}
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)

Example 3 with AliasRegistry

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

Aggregations

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