use of com.facebook.presto.common.type.TypeSignature in project presto by prestodb.
the class DecimalOperators method decimalMultiplyOperator.
private static SqlScalarFunction decimalMultiplyOperator() {
TypeSignature decimalLeftSignature = parseTypeSignature("decimal(a_precision, a_scale)", ImmutableSet.of("a_precision", "a_scale"));
TypeSignature decimalRightSignature = parseTypeSignature("decimal(b_precision, b_scale)", ImmutableSet.of("b_precision", "b_scale"));
TypeSignature decimalResultSignature = parseTypeSignature("decimal(r_precision, r_scale)", ImmutableSet.of("r_precision", "r_scale"));
Signature signature = SignatureBuilder.builder().kind(SCALAR).operatorType(MULTIPLY).longVariableConstraints(longVariableExpression("r_precision", "min(38, a_precision + b_precision)"), longVariableExpression("r_scale", "a_scale + b_scale")).argumentTypes(decimalLeftSignature, decimalRightSignature).returnType(decimalResultSignature).build();
return SqlScalarFunction.builder(DecimalOperators.class, MULTIPLY).signature(signature).deterministic(true).choice(choice -> choice.implementation(methodsGroup -> methodsGroup.methods("multiplyShortShortShort", "multiplyShortShortLong", "multiplyLongLongLong", "multiplyShortLongLong", "multiplyLongShortLong"))).build();
}
use of com.facebook.presto.common.type.TypeSignature in project presto by prestodb.
the class TestFunctionAndTypeManager method testExactMatchBeforeCoercion.
@Test
public void testExactMatchBeforeCoercion() {
FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
boolean foundOperator = false;
for (SqlFunction function : functionAndTypeManager.listOperators()) {
OperatorType operatorType = tryGetOperatorType(function.getSignature().getName()).get();
if (operatorType == CAST || operatorType == SATURATED_FLOOR_CAST) {
continue;
}
if (!function.getSignature().getTypeVariableConstraints().isEmpty()) {
continue;
}
if (function.getSignature().getArgumentTypes().stream().anyMatch(TypeSignature::isCalculated)) {
continue;
}
BuiltInFunctionHandle exactOperator = (BuiltInFunctionHandle) functionAndTypeManager.resolveOperator(operatorType, fromTypeSignatures(function.getSignature().getArgumentTypes()));
assertEquals(exactOperator.getSignature(), function.getSignature());
foundOperator = true;
}
assertTrue(foundOperator);
}
use of com.facebook.presto.common.type.TypeSignature in project presto by prestodb.
the class TestSignatureBinder method testBindLiteralForDecimal.
@Test
public void testBindLiteralForDecimal() {
TypeSignature leftType = parseTypeSignature("decimal(p1,s1)", ImmutableSet.of("p1", "s1"));
TypeSignature rightType = parseTypeSignature("decimal(p2,s2)", ImmutableSet.of("p2", "s2"));
Signature function = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(leftType, rightType).build();
assertThat(function).boundTo("decimal(2,1)", "decimal(1,0)").produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of("p1", 2L, "s1", 1L, "p2", 1L, "s2", 0L)));
}
use of com.facebook.presto.common.type.TypeSignature in project presto by prestodb.
the class TestSignatureBinder method testBindDifferentLiteralParameters.
@Test
public void testBindDifferentLiteralParameters() {
TypeSignature argType = parseTypeSignature("decimal(p,s)", ImmutableSet.of("p", "s"));
Signature function = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(argType, argType).build();
assertThat(function).boundTo("decimal(2,1)", "decimal(3,1)").fails();
}
use of com.facebook.presto.common.type.TypeSignature in project presto by prestodb.
the class TestSignatureBinder method testNoVariableReuseAcrossTypes.
@Test(expectedExceptions = UnsupportedOperationException.class)
public void testNoVariableReuseAcrossTypes() {
Set<String> literalParameters = ImmutableSet.of("p1", "p2", "s");
TypeSignature leftType = parseTypeSignature("decimal(p1,s)", literalParameters);
TypeSignature rightType = parseTypeSignature("decimal(p2,s)", literalParameters);
Signature function = functionSignature().returnType(BOOLEAN.getTypeSignature()).argumentTypes(leftType, rightType).build();
assertThat(function).boundTo("decimal(2,1)", "decimal(3,1)").produces(new BoundVariables(ImmutableMap.of(), ImmutableMap.of()));
}
Aggregations