private ReflectionParametricScalar( Signature signature, String description, boolean hidden, Map<Signature, Implementation> exactImplementations, List<Implementation> specializedImplementations, List<Implementation> implementations, boolean deterministic) { super(signature.getName(), signature.getTypeParameterRequirements(), signature.getReturnType().toString(), signature.getArgumentTypes().stream() .map(TypeSignature::toString) .collect(toImmutableList())); this.description = description; this.hidden = hidden; this.exactImplementations = ImmutableMap.copyOf(requireNonNull(exactImplementations, "exactImplementations is null")); this.specializedImplementations = ImmutableList.copyOf(requireNonNull(specializedImplementations, "specializedImplementations is null")); this.implementations = ImmutableList.copyOf(requireNonNull(implementations, "implementations is null")); this.deterministic = deterministic; }
public SimpleSqlScalarFunction( Signature signature, String description, boolean hidden, MethodHandle methodHandle, Optional<MethodHandle> instanceFactory, boolean deterministic, boolean nullable, List<Boolean> nullableArguments, Set<String> literalParameters) { super(signature.getName(), ImmutableList.of(), signature.getReturnType().toString(), signature.getArgumentTypes().stream() .map(TypeSignature::toString) .collect(ImmutableCollectors.toImmutableList()), false, literalParameters); checkArgument(signature.getTypeParameterRequirements().isEmpty(), "%s is parametric", signature); this.description = description; this.hidden = hidden; this.methodHandle = requireNonNull(methodHandle, "methodHandle is null"); this.instanceFactory = requireNonNull(instanceFactory, "instanceFactory is null"); this.deterministic = deterministic; this.nullable = nullable; this.nullableArguments = requireNonNull(nullableArguments, "nullableArguments is null"); }
public WindowFunctionSupplier getWindowFunctionImplementation(Signature signature) { checkArgument(signature.getKind() == WINDOW || signature.getKind() == AGGREGATE, "%s is not a window function", signature); checkArgument(signature.getTypeParameterRequirements().isEmpty(), "%s has unbound type parameters", signature); Iterable<SqlFunction> candidates = functions.get(QualifiedName.of(signature.getName())); // search for exact match for (SqlFunction operator : candidates) { Type returnType = typeManager.getType(signature.getReturnType()); List<Type> argumentTypes = resolveTypes(signature.getArgumentTypes(), typeManager); Map<String, Type> boundTypeParameters = operator.getSignature().bindTypeParameters(returnType, argumentTypes, false, typeManager); if (boundTypeParameters != null) { try { return specializedWindowCache.getUnchecked(new SpecializedFunctionKey(operator, boundTypeParameters, signature.getArgumentTypes().size())); } catch (UncheckedExecutionException e) { throw Throwables.propagate(e.getCause()); } } } throw new PrestoException(FUNCTION_IMPLEMENTATION_MISSING, format("%s not found", signature)); }
if (implementation.getSignature().getTypeParameterRequirements().isEmpty()) { exactImplementations.put(implementation.getSignature(), implementation); continue;
public InternalAggregationFunction getAggregateFunctionImplementation(Signature signature) { checkArgument(signature.getKind() == AGGREGATE || signature.getKind() == APPROXIMATE_AGGREGATE, "%s is not an aggregate function", signature); checkArgument(signature.getTypeParameterRequirements().isEmpty(), "%s has unbound type parameters", signature); Iterable<SqlFunction> candidates = functions.get(QualifiedName.of(signature.getName())); // search for exact match for (SqlFunction operator : candidates) { Type returnType = typeManager.getType(signature.getReturnType()); List<Type> argumentTypes = resolveTypes(signature.getArgumentTypes(), typeManager); Map<String, Type> boundTypeParameters = operator.getSignature().bindTypeParameters(returnType, argumentTypes, false, typeManager); if (boundTypeParameters != null) { try { return specializedAggregationCache.getUnchecked(new SpecializedFunctionKey(operator, boundTypeParameters, signature.getArgumentTypes().size())); } catch (UncheckedExecutionException e) { throw Throwables.propagate(e.getCause()); } } } throw new PrestoException(FUNCTION_IMPLEMENTATION_MISSING, format("%s not found", signature)); }
name, Joiner.on(", ").join(function.getSignature().getArgumentTypes()), Joiner.on(", ").join(function.getSignature().getTypeParameterRequirements())));
callName.equals(mangleOperatorName(GREATER_THAN)) ? mangleOperatorName(LESS_THAN) : mangleOperatorName(LESS_THAN_OR_EQUAL), SCALAR, call.getSignature().getTypeParameterRequirements(), call.getSignature().getReturnType(), swapPair(call.getSignature().getArgumentTypes()),
public ScalarFunctionImplementation getScalarFunctionImplementation(Signature signature) checkArgument(signature.getTypeParameterRequirements().isEmpty(), "%s has unbound type parameters", signature); Iterable<SqlFunction> candidates = functions.get(QualifiedName.of(signature.getName()));
@Test public void testExactMatchBeforeCoercion() { TypeRegistry typeManager = new TypeRegistry(); FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), true); boolean foundOperator = false; for (SqlFunction function : registry.listOperators()) { OperatorType operatorType = unmangleOperator(function.getSignature().getName()); if (operatorType == OperatorType.CAST) { continue; } if (!function.getSignature().getTypeParameterRequirements().isEmpty()) { continue; } if (function.getSignature().getArgumentTypes().stream().anyMatch(TypeSignature::isCalculated)) { continue; } Signature exactOperator = registry.resolveOperator(operatorType, resolveTypes(function.getSignature().getArgumentTypes(), typeManager)); assertEquals(exactOperator, function.getSignature()); foundOperator = true; } assertTrue(foundOperator); }