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