use of com.facebook.presto.common.type.TypeSignature in project presto by prestodb.
the class TestMySqlFunctionNamespaceManager method testReturnTypeTooLong.
@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Return type exceeds max length of 30000.*")
public void testReturnTypeTooLong() {
TypeSignature returnType = parseTypeSignature(dummyString(30001));
createFunction(createFunctionTangent(returnType), false);
}
use of com.facebook.presto.common.type.TypeSignature in project presto by prestodb.
the class SignatureBinder method appendConstraintSolversForArguments.
private boolean appendConstraintSolversForArguments(ImmutableList.Builder<TypeConstraintSolver> resultBuilder, List<? extends TypeSignatureProvider> actualTypes) {
boolean variableArity = declaredSignature.isVariableArity();
List<TypeSignature> formalTypeSignatures = declaredSignature.getArgumentTypes();
if (variableArity) {
if (actualTypes.size() < formalTypeSignatures.size() - 1) {
return false;
}
formalTypeSignatures = expandVarargFormalTypeSignature(formalTypeSignatures, actualTypes.size());
}
if (formalTypeSignatures.size() != actualTypes.size()) {
return false;
}
for (int i = 0; i < formalTypeSignatures.size(); i++) {
if (!appendTypeRelationshipConstraintSolver(resultBuilder, formalTypeSignatures.get(i), actualTypes.get(i), allowCoercion)) {
return false;
}
}
return appendConstraintSolvers(resultBuilder, formalTypeSignatures, actualTypes, allowCoercion);
}
use of com.facebook.presto.common.type.TypeSignature in project presto by prestodb.
the class SignatureBinder method checkNoLiteralVariableUsageAcrossTypes.
private static void checkNoLiteralVariableUsageAcrossTypes(TypeSignature typeSignature, Map<String, TypeSignature> existingUsages) {
List<TypeSignatureParameter> variables = typeSignature.getParameters().stream().filter(TypeSignatureParameter::isVariable).collect(toList());
for (TypeSignatureParameter variable : variables) {
TypeSignature existing = existingUsages.get(variable.getVariable());
if (existing != null && !existing.equals(typeSignature)) {
throw new UnsupportedOperationException("Literal parameters may not be shared across different types");
}
existingUsages.put(variable.getVariable(), typeSignature);
}
for (TypeSignatureParameter parameter : typeSignature.getParameters()) {
if (parameter.isLongLiteral() || parameter.isVariable()) {
continue;
}
checkNoLiteralVariableUsageAcrossTypes(parameter.getTypeSignatureOrNamedTypeSignature().get(), existingUsages);
}
}
use of com.facebook.presto.common.type.TypeSignature in project presto by prestodb.
the class SignatureBinder method appendConstraintSolvers.
private boolean appendConstraintSolvers(ImmutableList.Builder<TypeConstraintSolver> resultBuilder, TypeSignature formalTypeSignature, TypeSignatureProvider actualTypeSignatureProvider, boolean allowCoercion) {
if (FunctionType.NAME.equals(formalTypeSignature.getBase())) {
List<TypeSignature> formalTypeParameterTypeSignatures = formalTypeSignature.getTypeParametersAsTypeSignatures();
resultBuilder.add(new FunctionSolver(getLambdaArgumentTypeSignatures(formalTypeSignature), formalTypeParameterTypeSignatures.get(formalTypeParameterTypeSignatures.size() - 1), actualTypeSignatureProvider));
return true;
}
if (actualTypeSignatureProvider.hasDependency()) {
return false;
}
if (formalTypeSignature.getParameters().isEmpty()) {
TypeVariableConstraint typeVariableConstraint = typeVariableConstraints.get(formalTypeSignature.getBase());
if (typeVariableConstraint == null) {
return true;
}
Type actualType = functionAndTypeManager.getType(actualTypeSignatureProvider.getTypeSignature());
resultBuilder.add(new TypeParameterSolver(formalTypeSignature.getBase(), actualType, typeVariableConstraint));
return true;
}
Type actualType = functionAndTypeManager.getType(actualTypeSignatureProvider.getTypeSignature());
if (isTypeWithLiteralParameters(formalTypeSignature)) {
resultBuilder.add(new TypeWithLiteralParametersSolver(formalTypeSignature, actualType));
return true;
}
List<TypeSignatureProvider> actualTypeParametersTypeSignatureProvider;
if (UNKNOWN.equals(actualType)) {
actualTypeParametersTypeSignatureProvider = Collections.nCopies(formalTypeSignature.getParameters().size(), new TypeSignatureProvider(UNKNOWN.getTypeSignature()));
} else {
actualTypeParametersTypeSignatureProvider = fromTypes(actualType.getTypeParameters());
}
ImmutableList.Builder<TypeSignature> formalTypeParameterTypeSignatures = ImmutableList.builder();
for (TypeSignatureParameter formalTypeParameter : formalTypeSignature.getParameters()) {
Optional<TypeSignature> typeSignature = formalTypeParameter.getTypeSignatureOrNamedTypeSignature();
if (!typeSignature.isPresent()) {
throw new UnsupportedOperationException("Types with both type parameters and literal parameters at the same time are not supported");
}
formalTypeParameterTypeSignatures.add(typeSignature.get());
}
return appendConstraintSolvers(resultBuilder, formalTypeParameterTypeSignatures.build(), actualTypeParametersTypeSignatureProvider, allowCoercion && isCovariantTypeBase(formalTypeSignature.getBase()));
}
use of com.facebook.presto.common.type.TypeSignature in project presto by prestodb.
the class SignatureBinder method applyBoundVariables.
public static Type applyBoundVariables(FunctionAndTypeManager functionAndTypeManager, TypeSignature typeSignature, BoundVariables boundVariables) {
String baseType = typeSignature.getBase();
if (boundVariables.containsTypeVariable(baseType)) {
checkState(typeSignature.getParameters().isEmpty(), "Type parameters cannot have parameters");
Type type = boundVariables.getTypeVariable(baseType);
if (type instanceof TypeWithName) {
return ((TypeWithName) type).getType();
}
return type;
}
List<TypeSignatureParameter> parameters = typeSignature.getParameters().stream().map(typeSignatureParameter -> applyBoundVariables(typeSignatureParameter, boundVariables)).collect(toList());
return functionAndTypeManager.getParameterizedType(baseType, parameters);
}
Aggregations