Search in sources :

Example 1 with SqlCreateAlias

use of org.apache.drill.exec.planner.sql.parser.SqlCreateAlias 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)

Aggregations

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