Search in sources :

Example 1 with CanAggregateDistinct

use of org.apache.hadoop.hive.ql.optimizer.calcite.functions.CanAggregateDistinct in project hive by apache.

the class SqlFunctionConverter method buildAST.

// TODO: 1) handle Agg Func Name translation 2) is it correct to add func
// args as child of func?
public static ASTNode buildAST(SqlOperator op, List<ASTNode> children) {
    HiveToken hToken = calciteToHiveToken.get(op);
    ASTNode node;
    if (hToken != null) {
        switch(op.kind) {
            case IN:
            case BETWEEN:
            case ROW:
            case IS_NOT_NULL:
            case IS_NULL:
            case CASE:
            case EXTRACT:
            case FLOOR:
            case CEIL:
            case LIKE:
            case OTHER_FUNCTION:
                node = (ASTNode) ParseDriver.adaptor.create(HiveParser.TOK_FUNCTION, "TOK_FUNCTION");
                node.addChild((ASTNode) ParseDriver.adaptor.create(hToken.type, hToken.text));
                break;
            default:
                node = (ASTNode) ParseDriver.adaptor.create(hToken.type, hToken.text);
        }
    } else {
        node = (ASTNode) ParseDriver.adaptor.create(HiveParser.TOK_FUNCTION, "TOK_FUNCTION");
        if (op.kind != SqlKind.CAST) {
            if (op.kind == SqlKind.MINUS_PREFIX) {
                node = (ASTNode) ParseDriver.adaptor.create(HiveParser.MINUS, "MINUS");
            } else if (op.kind == SqlKind.PLUS_PREFIX) {
                node = (ASTNode) ParseDriver.adaptor.create(HiveParser.PLUS, "PLUS");
            } else {
                // Handle COUNT/SUM/AVG function for the case of COUNT(*) and COUNT(DISTINCT)
                if (op instanceof HiveSqlCountAggFunction || op instanceof HiveSqlSumAggFunction || (op instanceof CalciteUDAF && op.getName().equalsIgnoreCase(SqlStdOperatorTable.AVG.getName()))) {
                    if (children.size() == 0) {
                        node = (ASTNode) ParseDriver.adaptor.create(HiveParser.TOK_FUNCTIONSTAR, "TOK_FUNCTIONSTAR");
                    } else {
                        CanAggregateDistinct distinctFunction = (CanAggregateDistinct) op;
                        if (distinctFunction.isDistinct()) {
                            node = (ASTNode) ParseDriver.adaptor.create(HiveParser.TOK_FUNCTIONDI, "TOK_FUNCTIONDI");
                        }
                    }
                }
                node.addChild((ASTNode) ParseDriver.adaptor.create(HiveParser.Identifier, op.getName()));
            }
        }
    }
    for (ASTNode c : children) {
        ParseDriver.adaptor.addChild(node, c);
    }
    return node;
}
Also used : HiveSqlCountAggFunction(org.apache.hadoop.hive.ql.optimizer.calcite.functions.HiveSqlCountAggFunction) CanAggregateDistinct(org.apache.hadoop.hive.ql.optimizer.calcite.functions.CanAggregateDistinct) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode) HiveSqlSumAggFunction(org.apache.hadoop.hive.ql.optimizer.calcite.functions.HiveSqlSumAggFunction)

Aggregations

CanAggregateDistinct (org.apache.hadoop.hive.ql.optimizer.calcite.functions.CanAggregateDistinct)1 HiveSqlCountAggFunction (org.apache.hadoop.hive.ql.optimizer.calcite.functions.HiveSqlCountAggFunction)1 HiveSqlSumAggFunction (org.apache.hadoop.hive.ql.optimizer.calcite.functions.HiveSqlSumAggFunction)1 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)1