Search in sources :

Example 1 with ASTBuilder

use of org.apache.hadoop.hive.ql.optimizer.calcite.translator.ASTBuilder in project hive by apache.

the class ParseUtils method createChildColumnRef.

private static boolean createChildColumnRef(Tree child, String alias, List<ASTNode> newChildren, HashSet<String> aliases) {
    String colAlias = child.getText();
    if (!aliases.add(colAlias)) {
        // TODO: if a side of the union has 2 columns with the same name, noone on the higher
        // level can refer to them. We could change the alias in the original node.
        LOG.debug("Replacing SETCOLREF with ALLCOLREF because of duplicate alias " + colAlias);
        return false;
    }
    ASTBuilder selExpr = ASTBuilder.construct(HiveParser.TOK_SELEXPR, "TOK_SELEXPR");
    ASTBuilder toc = ASTBuilder.construct(HiveParser.TOK_TABLE_OR_COL, "TOK_TABLE_OR_COL");
    ASTBuilder id = ASTBuilder.construct(HiveParser.Identifier, colAlias);
    if (alias == null) {
        selExpr = selExpr.add(toc.add(id));
    } else {
        ASTBuilder dot = ASTBuilder.construct(HiveParser.DOT, ".");
        ASTBuilder aliasNode = ASTBuilder.construct(HiveParser.Identifier, alias);
        selExpr = selExpr.add(dot.add(toc.add(aliasNode)).add(id));
    }
    newChildren.add(selExpr.node());
    return true;
}
Also used : ASTBuilder(org.apache.hadoop.hive.ql.optimizer.calcite.translator.ASTBuilder)

Aggregations

ASTBuilder (org.apache.hadoop.hive.ql.optimizer.calcite.translator.ASTBuilder)1