use of io.trino.sql.analyzer.TypeSignatureProvider in project trino by trinodb.
the class SignatureBinder method appendConstraintSolvers.
private boolean appendConstraintSolvers(ImmutableList.Builder<TypeConstraintSolver> resultBuilder, TypeSignature formalTypeSignature, TypeSignatureProvider actualTypeSignatureProvider, boolean allowCoercion) {
if (FunctionType.NAME.equalsIgnoreCase(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 = typeManager.getType(actualTypeSignatureProvider.getTypeSignature());
for (TypeSignature castToSignature : typeVariableConstraint.getCastableTo()) {
appendTypeRelationshipConstraintSolver(resultBuilder, castToSignature, actualTypeSignatureProvider, EXPLICIT_COERCION_TO);
}
for (TypeSignature castFromSignature : typeVariableConstraint.getCastableFrom()) {
appendTypeRelationshipConstraintSolver(resultBuilder, castFromSignature, actualTypeSignatureProvider, EXPLICIT_COERCION_FROM);
}
if (typeVariableConstraint.getVariadicBound() != null && !typeVariableConstraint.getVariadicBound().equalsIgnoreCase(actualType.getTypeSignature().getBase())) {
return actualType == UNKNOWN;
}
resultBuilder.add(new TypeParameterSolver(formalTypeSignature.getBase(), actualType, typeVariableConstraint.isComparableRequired(), typeVariableConstraint.isOrderableRequired(), Optional.ofNullable(typeVariableConstraint.getVariadicBound())));
return true;
}
Type actualType = typeManager.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.isEmpty()) {
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 io.trino.sql.analyzer.TypeSignatureProvider in project trino by trinodb.
the class TestMinMaxByAggregation method testMaxDoubleLongArray.
@Test
public void testMaxDoubleLongArray() {
List<TypeSignatureProvider> parameterTypes = fromTypes(new ArrayType(BIGINT), DOUBLE);
assertAggregation(FUNCTION_RESOLUTION, QualifiedName.of("max_by"), parameterTypes, null, createArrayBigintBlock(asList(asList(3L, 4L), null, asList(2L, 2L))), createDoublesBlock(1.0, 2.0, null));
assertAggregation(FUNCTION_RESOLUTION, QualifiedName.of("max_by"), parameterTypes, asList(2L, 2L), createArrayBigintBlock(asList(asList(3L, 4L), null, asList(2L, 2L))), createDoublesBlock(0.0, 1.0, 2.0));
}
use of io.trino.sql.analyzer.TypeSignatureProvider in project trino by trinodb.
the class TestMinMaxByAggregation method testMaxLongArrayLongArray.
@Test
public void testMaxLongArrayLongArray() {
List<TypeSignatureProvider> parameterTypes = fromTypes(new ArrayType(BIGINT), new ArrayType(BIGINT));
assertAggregation(FUNCTION_RESOLUTION, QualifiedName.of("max_by"), parameterTypes, asList(3L, 3L), createArrayBigintBlock(asList(asList(3L, 3L), null, asList(1L, 2L))), createArrayBigintBlock(asList(asList(3L, 4L), null, asList(2L, 2L))));
}
use of io.trino.sql.analyzer.TypeSignatureProvider in project trino by trinodb.
the class TestMinMaxByAggregation method testMaxLongArraySlice.
@Test
public void testMaxLongArraySlice() {
List<TypeSignatureProvider> parameterTypes = fromTypes(VARCHAR, new ArrayType(BIGINT));
assertAggregation(FUNCTION_RESOLUTION, QualifiedName.of("max_by"), parameterTypes, "a", createStringsBlock("a", "b", "c"), createArrayBigintBlock(asList(asList(3L, 4L), null, asList(2L, 2L))));
}
use of io.trino.sql.analyzer.TypeSignatureProvider in project trino by trinodb.
the class TestMinMaxByAggregation method testMinBooleanLongArray.
@Test
public void testMinBooleanLongArray() {
List<TypeSignatureProvider> parameterTypes = fromTypes(new ArrayType(BIGINT), BOOLEAN);
assertAggregation(FUNCTION_RESOLUTION, QualifiedName.of("min_by"), parameterTypes, null, createArrayBigintBlock(asList(asList(3L, 4L), null, null)), createBooleansBlock(true, false, true));
}
Aggregations