Search in sources :

Example 1 with HiveSqlFunction

use of org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveSqlFunction in project hive by apache.

the class HiveCalciteUtil method checkMaterializable.

/**
 * Check if the expression is usable for query materialization, returning the first failing expression.
 */
public static RexCall checkMaterializable(RexNode expr) {
    RexCall failingCall = null;
    if (expr == null) {
        return null;
    }
    RexVisitor<Void> visitor = new RexVisitorImpl<Void>(true) {

        @Override
        public Void visitCall(org.apache.calcite.rex.RexCall call) {
            // non-deterministic functions as well as runtime constants are not materializable.
            SqlOperator op = call.getOperator();
            if (!op.isDeterministic() || op.isDynamicFunction() || (op instanceof HiveSqlFunction && ((HiveSqlFunction) op).isRuntimeConstant())) {
                throw new Util.FoundOne(call);
            }
            return super.visitCall(call);
        }
    };
    try {
        expr.accept(visitor);
    } catch (Util.FoundOne e) {
        failingCall = (RexCall) e.getNode();
    }
    return failingCall;
}
Also used : RexCall(org.apache.calcite.rex.RexCall) HiveSqlFunction(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveSqlFunction) SqlOperator(org.apache.calcite.sql.SqlOperator) RexUtil(org.apache.calcite.rex.RexUtil) SqlValidatorUtil(org.apache.calcite.sql.validate.SqlValidatorUtil) RelOptUtil(org.apache.calcite.plan.RelOptUtil) Util(org.apache.calcite.util.Util) RexVisitorImpl(org.apache.calcite.rex.RexVisitorImpl)

Example 2 with HiveSqlFunction

use of org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveSqlFunction in project hive by apache.

the class SqlFunctionConverter method getCalciteFn.

public static SqlOperator getCalciteFn(String hiveUdfName, List<RelDataType> calciteArgTypes, RelDataType calciteRetType, boolean deterministic, boolean runtimeConstant) throws CalciteSemanticException {
    SqlOperator calciteOp;
    CalciteUDFInfo uInf = getUDFInfo(hiveUdfName, calciteArgTypes, calciteRetType);
    switch(hiveUdfName) {
        // TODO: Perhaps we should do this for all functions, not just +,-
        case "-":
            calciteOp = new SqlMonotonicBinaryOperator("-", SqlKind.MINUS, 40, true, uInf.returnTypeInference, uInf.operandTypeInference, OperandTypes.MINUS_OPERATOR);
            break;
        case "+":
            calciteOp = new SqlMonotonicBinaryOperator("+", SqlKind.PLUS, 40, true, uInf.returnTypeInference, uInf.operandTypeInference, OperandTypes.PLUS_OPERATOR);
            break;
        default:
            calciteOp = hiveToCalcite.get(hiveUdfName);
            if (null == calciteOp) {
                calciteOp = new HiveSqlFunction(uInf.udfName, SqlKind.OTHER_FUNCTION, uInf.returnTypeInference, uInf.operandTypeInference, uInf.operandTypeChecker, SqlFunctionCategory.USER_DEFINED_FUNCTION, deterministic, runtimeConstant);
            }
            break;
    }
    return calciteOp;
}
Also used : HiveSqlFunction(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveSqlFunction) HiveFromUnixTimeSqlOperator(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveFromUnixTimeSqlOperator) HiveUnixTimestampSqlOperator(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveUnixTimestampSqlOperator) HiveDateSubSqlOperator(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveDateSubSqlOperator) HiveTruncSqlOperator(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTruncSqlOperator) HiveToUnixTimestampSqlOperator(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveToUnixTimestampSqlOperator) SqlOperator(org.apache.calcite.sql.SqlOperator) HiveToDateSqlOperator(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveToDateSqlOperator) HiveDateAddSqlOperator(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveDateAddSqlOperator) SqlMonotonicBinaryOperator(org.apache.calcite.sql.fun.SqlMonotonicBinaryOperator)

Example 3 with HiveSqlFunction

use of org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveSqlFunction in project hive by apache.

the class DataSketchesFunctions method registerAsHiveFunction.

private void registerAsHiveFunction(SketchFunctionDescriptor sfd) {
    if (sfd != null && sfd.getReturnRelDataType().isPresent()) {
        SqlFunction cdfFn = new HiveSqlFunction(sfd.name, SqlKind.OTHER_FUNCTION, ReturnTypes.explicit(sfd.getReturnRelDataType().get()), InferTypes.ANY_NULLABLE, OperandTypes.family(), SqlFunctionCategory.USER_DEFINED_FUNCTION, true, false);
        sfd.setCalciteFunction(cdfFn);
    }
}
Also used : HiveSqlFunction(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveSqlFunction) HiveSqlFunction(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveSqlFunction) SqlFunction(org.apache.calcite.sql.SqlFunction)

Aggregations

HiveSqlFunction (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveSqlFunction)3 SqlOperator (org.apache.calcite.sql.SqlOperator)2 RelOptUtil (org.apache.calcite.plan.RelOptUtil)1 RexCall (org.apache.calcite.rex.RexCall)1 RexUtil (org.apache.calcite.rex.RexUtil)1 RexVisitorImpl (org.apache.calcite.rex.RexVisitorImpl)1 SqlFunction (org.apache.calcite.sql.SqlFunction)1 SqlMonotonicBinaryOperator (org.apache.calcite.sql.fun.SqlMonotonicBinaryOperator)1 SqlValidatorUtil (org.apache.calcite.sql.validate.SqlValidatorUtil)1 Util (org.apache.calcite.util.Util)1 HiveDateAddSqlOperator (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveDateAddSqlOperator)1 HiveDateSubSqlOperator (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveDateSubSqlOperator)1 HiveFromUnixTimeSqlOperator (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveFromUnixTimeSqlOperator)1 HiveToDateSqlOperator (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveToDateSqlOperator)1 HiveToUnixTimestampSqlOperator (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveToUnixTimestampSqlOperator)1 HiveTruncSqlOperator (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTruncSqlOperator)1 HiveUnixTimestampSqlOperator (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveUnixTimestampSqlOperator)1