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