Search in sources :

Example 1 with HiveSqlAverageAggFunction

use of org.apache.hadoop.hive.ql.optimizer.calcite.functions.HiveSqlAverageAggFunction 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, RelDataType type) {
    HiveToken hToken = calciteToHiveToken.get(op);
    ASTNode node;
    if (hToken != null) {
        switch(op.kind) {
            case IN:
            case BETWEEN:
            case ROW:
            case ARRAY_VALUE_CONSTRUCTOR:
            case MAP_VALUE_CONSTRUCTOR:
            case IS_NOT_TRUE:
            case IS_TRUE:
            case IS_NOT_FALSE:
            case IS_FALSE:
            case IS_NOT_NULL:
            case IS_NULL:
            case CASE:
            case COALESCE:
            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 HiveSqlAverageAggFunction) {
                    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()));
            }
        }
    }
    node.setTypeInfo(TypeConverter.convert(type));
    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) HiveSqlAverageAggFunction(org.apache.hadoop.hive.ql.optimizer.calcite.functions.HiveSqlAverageAggFunction) HiveSqlSumAggFunction(org.apache.hadoop.hive.ql.optimizer.calcite.functions.HiveSqlSumAggFunction)

Aggregations

CanAggregateDistinct (org.apache.hadoop.hive.ql.optimizer.calcite.functions.CanAggregateDistinct)1 HiveSqlAverageAggFunction (org.apache.hadoop.hive.ql.optimizer.calcite.functions.HiveSqlAverageAggFunction)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