public SignatureBuilder argumentTypes(TypeSignature... argumentTypes) { return argumentTypes(asList(requireNonNull(argumentTypes, "argumentTypes is Null"))); }
public SignatureBuilder argumentTypes(TypeSignature... argumentTypes) { return argumentTypes(asList(requireNonNull(argumentTypes, "argumentTypes is Null"))); }
public static SignatureBuilder modulusSignatureBuilder() { 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")); return Signature.builder() .longVariableConstraints( longVariableExpression("r_precision", "min(b_precision - b_scale, a_precision - a_scale) + max(a_scale, b_scale)"), longVariableExpression("r_scale", "max(a_scale, b_scale)")) .argumentTypes(decimalLeftSignature, decimalRightSignature) .returnType(decimalResultSignature); }
public static SignatureBuilder modulusSignatureBuilder() { 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")); return Signature.builder() .longVariableConstraints( longVariableExpression("r_precision", "min(b_precision - b_scale, a_precision - a_scale) + max(a_scale, b_scale)"), longVariableExpression("r_scale", "max(a_scale, b_scale)")) .argumentTypes(decimalLeftSignature, decimalRightSignature) .returnType(decimalResultSignature); }
private static SignatureBuilder functionSignature(List<String> arguments, String returnType, List<TypeVariableConstraint> typeVariableConstraints) { ImmutableSet<String> literalParameters = ImmutableSet.of("p", "s", "p1", "s1", "p2", "s2", "p3", "s3"); List<TypeSignature> argumentSignatures = arguments.stream() .map((signature) -> TypeSignature.parseTypeSignature(signature, literalParameters)) .collect(toImmutableList()); return new SignatureBuilder() .returnType(TypeSignature.parseTypeSignature(returnType, literalParameters)) .argumentTypes(argumentSignatures) .typeVariableConstraints(typeVariableConstraints) .kind(SCALAR); }
private static SignatureBuilder functionSignature(List<String> arguments, String returnType, List<TypeVariableConstraint> typeVariableConstraints) { ImmutableSet<String> literalParameters = ImmutableSet.of("p", "s", "p1", "s1", "p2", "s2", "p3", "s3"); List<TypeSignature> argumentSignatures = arguments.stream() .map((signature) -> TypeSignature.parseTypeSignature(signature, literalParameters)) .collect(toImmutableList()); return new SignatureBuilder() .returnType(TypeSignature.parseTypeSignature(returnType, literalParameters)) .argumentTypes(argumentSignatures) .typeVariableConstraints(typeVariableConstraints) .kind(SCALAR); }
@Test public void testBindUnparametrizedVarchar() { Signature function = functionSignature() .returnType(parseTypeSignature("boolean")) .argumentTypes(parseTypeSignature("varchar(x)", ImmutableSet.of("x"))) .build(); assertThat(function) .boundTo("varchar") .produces(new BoundVariables( ImmutableMap.of(), ImmutableMap.of("x", (long) Integer.MAX_VALUE))); }
private static PolymorphicScalarFunctionBuilder makeBinaryOperatorFunctionBuilder(OperatorType operatorType) { Signature signature = Signature.builder() .kind(SCALAR) .operatorType(operatorType) .argumentTypes(DECIMAL_SIGNATURE, DECIMAL_SIGNATURE) .returnType(parseTypeSignature(BOOLEAN)) .build(); return SqlScalarFunction.builder(DecimalInequalityOperators.class) .signature(signature) .deterministic(true); }
private static PolymorphicScalarFunctionBuilder makeBinaryOperatorFunctionBuilder(OperatorType operatorType) { Signature signature = Signature.builder() .kind(SCALAR) .operatorType(operatorType) .argumentTypes(DECIMAL_SIGNATURE, DECIMAL_SIGNATURE) .returnType(parseTypeSignature(BOOLEAN)) .build(); return SqlScalarFunction.builder(DecimalInequalityOperators.class) .signature(signature) .deterministic(true); }
@Test public void testBindUnparametrizedVarchar() { Signature function = functionSignature() .returnType(parseTypeSignature("boolean")) .argumentTypes(parseTypeSignature("varchar(x)", ImmutableSet.of("x"))) .build(); assertThat(function) .boundTo("varchar") .produces(new BoundVariables( ImmutableMap.of(), ImmutableMap.of("x", (long) Integer.MAX_VALUE))); }
@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(); }
@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(); }
@Test public void testBindUnknownToTypeParameter() { Signature function = functionSignature() .returnType(parseTypeSignature("T")) .argumentTypes(parseTypeSignature("T")) .typeVariableConstraints(ImmutableList.of(typeVariable("T"))) .build(); assertThat(function) .boundTo("unknown") .withCoercion() .produces(new BoundVariables( ImmutableMap.of("T", type("unknown")), ImmutableMap.of())); }
@Test public void testBindTypeVariablesBasedOnTheSecondArgument() { Signature function = functionSignature() .returnType(parseTypeSignature("T")) .argumentTypes(parseTypeSignature("array(T)"), parseTypeSignature("T")) .typeVariableConstraints(ImmutableList.of(typeVariable("T"))) .build(); assertThat(function) .boundTo("unknown", "decimal(2,1)") .withCoercion() .produces(new BoundVariables( ImmutableMap.of("T", type("decimal(2,1)")), ImmutableMap.of())); }
@Test public void testBindUnknownToConcreteArray() { Signature function = functionSignature() .returnType(parseTypeSignature(StandardTypes.BOOLEAN)) .argumentTypes(parseTypeSignature("array(boolean)")) .build(); assertThat(function) .boundTo("unknown") .withCoercion() .succeeds(); }
@Test public void testBindUnknownToConcreteArray() { Signature function = functionSignature() .returnType(parseTypeSignature(StandardTypes.BOOLEAN)) .argumentTypes(parseTypeSignature("array(boolean)")) .build(); assertThat(function) .boundTo("unknown") .withCoercion() .succeeds(); }
@Test public void testBindDoubleToBigint() { Signature function = functionSignature() .returnType(parseTypeSignature(StandardTypes.BOOLEAN)) .argumentTypes(parseTypeSignature(StandardTypes.DOUBLE), parseTypeSignature(StandardTypes.DOUBLE)) .build(); assertThat(function) .boundTo("double", "bigint") .withCoercion() .succeeds(); }
@Test public void testBindUnknown() { Signature function = functionSignature() .returnType(parseTypeSignature(StandardTypes.BOOLEAN)) .argumentTypes(parseTypeSignature("varchar(x)", ImmutableSet.of("x"))) .build(); assertThat(function) .boundTo("unknown") .fails(); assertThat(function) .boundTo("unknown") .withCoercion() .succeeds(); }
@Test public void testBindDoubleToBigint() { Signature function = functionSignature() .returnType(parseTypeSignature(StandardTypes.BOOLEAN)) .argumentTypes(parseTypeSignature(StandardTypes.DOUBLE), parseTypeSignature(StandardTypes.DOUBLE)) .build(); assertThat(function) .boundTo("double", "bigint") .withCoercion() .succeeds(); }
@Test public void testMismatchedArgumentCount() { Signature function = functionSignature() .returnType(parseTypeSignature(StandardTypes.BOOLEAN)) .argumentTypes(parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT)) .build(); assertThat(function) .boundTo("bigint", "bigint", "bigint") .fails(); assertThat(function) .boundTo("bigint") .fails(); }