public static OperatorKey of(final SqlOperator operator) { return new OperatorKey(operator.getName(), operator.getSyntax()); }
@Override public DruidExpression toDruidExpression( final PlannerContext plannerContext, final RowSignature rowSignature, final RexNode rexNode ) { return OperatorConversions.convertCall( plannerContext, rowSignature, rexNode, operands -> { if (operands.size() < 2) { throw new ISE("WTF?! Got binary operator[%s] with %s args?", operator.getName(), operands.size()); } return DruidExpression.fromExpression( StringUtils.format( "(%s)", joiner.join( operands.stream() .map(DruidExpression::getExpression) .collect(Collectors.toList()) ) ) ); } ); } }
public static GenericUDF getHiveUDF(SqlOperator op, RelDataType dt, int argsLength) { String name = reverseOperatorMap.get(op); if (name == null) { name = op.getName(); } // Make sure we handle unary + and - correctly. if (argsLength == 1) { if ("+".equals(name)) { name = FunctionRegistry.UNARY_PLUS_FUNC_NAME; } else if ("-".equals(name)) { name = FunctionRegistry.UNARY_MINUS_FUNC_NAME; } } FunctionInfo hFn; try { hFn = name != null ? FunctionRegistry.getFunctionInfo(name) : null; } catch (SemanticException e) { LOG.warn("Failed to load udf " + name, e); hFn = null; } if (hFn == null) { try { hFn = handleExplicitCast(op, dt); } catch (SemanticException e) { LOG.warn("Failed to load udf " + name, e); hFn = null; } } return hFn == null ? null : hFn.getGenericUDF(); }
private void checkExpr(RexNode expr) { RexCall invalidCall = HiveCalciteUtil.checkMaterializable(expr); if (invalidCall != null) { fail(invalidCall.getOperator().getName() + " is not a deterministic function"); } }
private boolean isSqlCountCheck(final HiveFilter filter) { // look at hivesubqueryremoverule to see how is this filter created if(filter.getCondition() instanceof RexCall) { final RexCall condition = (RexCall)filter.getCondition(); if(condition.getKind() == SqlKind.LESS_THAN_OR_EQUAL) { final List<RexNode> operands = condition.getOperands(); if(operands.get(0) instanceof RexCall) { final RexCall op = (RexCall)operands.get(0); if(op.getOperator().getName().equals("sq_count_check")) { return true; } } } } return false; }
public static GenericUDF getHiveUDF(SqlOperator op, RelDataType dt, int argsLength) { String name = reverseOperatorMap.get(op); if (name == null) { name = op.getName(); } // Make sure we handle unary + and - correctly. if (argsLength == 1) { if (name == "+") { name = FunctionRegistry.UNARY_PLUS_FUNC_NAME; } else if (name == "-") { name = FunctionRegistry.UNARY_MINUS_FUNC_NAME; } } FunctionInfo hFn; try { hFn = name != null ? FunctionRegistry.getFunctionInfo(name) : null; } catch (SemanticException e) { LOG.warn("Failed to load udf " + name, e); hFn = null; } if (hFn == null) { try { hFn = handleExplicitCast(op, dt); } catch (SemanticException e) { LOG.warn("Failed to load udf " + name, e); hFn = null; } } return hFn == null ? null : hFn.getGenericUDF(); }
@Override public Void visitCall(RexCall call) { if(AnnotationUtils.getAnnotation(GenericUDFOPNotNull.class, Description.class).name().equals(call.getOperator().getName())) { if(call.getOperands().get(0) instanceof RexInputRef && !types.get(((RexInputRef)call.getOperands().get(0)).getIndex()).getType().isNullable()) { // No need to add not null filter for a constant. throw new Util.FoundOne(call); } } return super.visitCall(call); }
private SqlKind getOp(RexCall call) { SqlKind op = call.getKind(); if (call.getKind().equals(SqlKind.OTHER_FUNCTION) && SqlTypeUtil.inBooleanFamily(call.getType())) { SqlOperator sqlOp = call.getOperator(); String opName = (sqlOp != null) ? sqlOp.getName() : ""; if (opName.equalsIgnoreCase("in")) { op = SqlKind.IN; } } return op; }
@Override public Void visitCall(RexCall call) { if(AnnotationUtils.getAnnotation(GenericUDFOPNotNull.class, Description.class).name().equals(call.getOperator().getName())) { if(call.getOperands().get(0) instanceof RexInputRef && !types.get(((RexInputRef)call.getOperands().get(0)).getIndex()).getType().isNullable()) { // No need to add not null filter for a constant. throw new Util.FoundOne(call); } } return super.visitCall(call); } }
private SqlKind getOp(RexCall call) { SqlKind op = call.getKind(); if (call.getKind().equals(SqlKind.OTHER_FUNCTION) && SqlTypeUtil.inBooleanFamily(call.getType())) { SqlOperator sqlOp = call.getOperator(); String opName = (sqlOp != null) ? sqlOp.getName() : ""; if (opName.equalsIgnoreCase("in")) { op = SqlKind.IN; } } return op; }
public CalciteException handleUnresolvedFunction(SqlCall call, SqlFunction unresolvedFunction, List<RelDataType> argTypes, List<String> argNames) { // For builtins, we can give a better error message final List<SqlOperator> overloads = new ArrayList<>(); opTab.lookupOperatorOverloads(unresolvedFunction.getNameAsId(), null, SqlSyntax.FUNCTION, overloads); if (overloads.size() == 1) { SqlFunction fun = (SqlFunction) overloads.get(0); if ((fun.getSqlIdentifier() == null) && (fun.getSyntax() != SqlSyntax.FUNCTION_ID)) { final int expectedArgCount = fun.getOperandCountRange().getMin(); throw newValidationError(call, RESOURCE.invalidArgCount(call.getOperator().getName(), expectedArgCount)); } } AssignableOperandTypeChecker typeChecking = new AssignableOperandTypeChecker(argTypes, argNames); String signature = typeChecking.getAllowedSignatures( unresolvedFunction, unresolvedFunction.getName()); throw newValidationError(call, RESOURCE.validatorUnknownFunction(signature)); }
return call.getOperands().get(0).accept(this); } else if (op instanceof SqlUserDefinedFunction) { if (op.getName().equals("QUARTER")) { return visitFirstRexInputRef(call);
/** * Throws an error if there is an aggregate or windowed aggregate in the * given clause. * * @param aggFinder Finder for the particular kind(s) of aggregate function * @param node Parse tree * @param clause Name of clause: "WHERE", "GROUP BY", "ON" */ private void validateNoAggs(AggFinder aggFinder, SqlNode node, String clause) { final SqlCall agg = aggFinder.findAgg(node); if (agg == null) { return; } final SqlOperator op = agg.getOperator(); if (op == SqlStdOperatorTable.OVER) { throw newValidationError(agg, RESOURCE.windowedAggregateIllegalInClause(clause)); } else if (op.isGroup() || op.isGroupAuxiliary()) { throw newValidationError(agg, RESOURCE.groupFunctionMustAppearInGroupByClause(op.getName())); } else { throw newValidationError(agg, RESOURCE.aggregateIllegalInClause(clause)); } }
Pair<SqlNode, SqlNode> matchSqlFunc(SqlNode sourceFunc) { if (sourceFunc == null || sourceDS == null || targetDS == null) return null; if (sourceFunc instanceof SqlCall || sourceFunc instanceof SqlIdentifier) { String funcName = sourceFunc instanceof SqlCall ? ((SqlCall) sourceFunc).getOperator().getName() : sourceFunc.toString(); List<String> validDefIds = sourceDS.getFuncDefsByName(funcName); if (validDefIds != null) { for (String defId : validDefIds) { SqlNode sourceCandidate = sourceDS.getFuncDefSqlNode(defId); if (ExpressionComparator.isNodeEqual(sourceFunc, sourceCandidate, new ParamSqlNodeComparator())) { SqlNode targetTmpl = targetDS.getFuncDefSqlNode(defId); if (targetTmpl != null) return new Pair<>(sourceCandidate, targetDS.getFuncDefSqlNode(defId)); } } } } return null; }
.functionError() .message(String.format("%s does not support operand types (%s)", opBinding.getOperator().getName(), operandTypes)) .build(logger);
case TIMESTAMPADD: call = TimestampAddFunctionCall(); name = call.getOperator().getName(); args = new SqlNodeList(call.getOperandList(), getPos()); break; if (jj_2_669(2)) { call = TimestampDiffFunctionCall(); name = call.getOperator().getName(); args = new SqlNodeList(call.getOperandList(), getPos()); } else if (jj_2_670(2)) {
case TIMESTAMPADD: call = TimestampAddFunctionCall(); name = call.getOperator().getName(); args = new SqlNodeList(call.getOperandList(), getPos()); break; if (jj_2_669(2)) { call = TimestampDiffFunctionCall(); name = call.getOperator().getName(); args = new SqlNodeList(call.getOperandList(), getPos()); } else if (jj_2_670(2)) {