public TryCastFunction() { super(new Signature( "TRY_CAST", FunctionKind.SCALAR, ImmutableList.of(typeVariable("F"), typeVariable("T")), ImmutableList.of(), parseTypeSignature("T"), ImmutableList.of(parseTypeSignature("F")), false)); }
public OperatorImplementationDependency(OperatorType operator, TypeSignature returnType, List<TypeSignature> argumentTypes, Optional<InvocationConvention> invocationConvention) { super(internalOperator(operator, returnType, argumentTypes), invocationConvention); this.operator = requireNonNull(operator, "operator 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); }
@Override public final WindowFunction createWindowFunction(List<Integer> argumentChannels) { requireNonNull(argumentChannels, "inputs is null"); checkArgument(argumentChannels.size() == signature.getArgumentTypes().size(), "Expected %s arguments for function %s, but got %s", signature.getArgumentTypes().size(), signature.getName(), argumentChannels.size()); return newWindowFunction(argumentChannels); }
private JsonStringToMapCast() { super(new Signature( JSON_STRING_TO_MAP_NAME, SCALAR, ImmutableList.of(comparableTypeParameter("K"), typeVariable("V")), ImmutableList.of(), parseTypeSignature("map(K,V)"), ImmutableList.of(parseTypeSignature(StandardTypes.VARCHAR)), false)); }
protected SqlOperator(OperatorType operatorType, List<TypeVariableConstraint> typeVariableConstraints, List<LongVariableConstraint> longVariableConstraints, TypeSignature returnType, List<TypeSignature> argumentTypes) { // TODO This should take Signature! super(new Signature( mangleOperatorName(operatorType), FunctionKind.SCALAR, typeVariableConstraints, longVariableConstraints, returnType, argumentTypes, false)); }
@Test public void testMultiScalarParse() { Signature expectedSignature1 = new Signature( "static_method_scalar_1", FunctionKind.SCALAR, DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature())); Signature expectedSignature2 = new Signature( "static_method_scalar_2", FunctionKind.SCALAR, BIGINT.getTypeSignature(), ImmutableList.of(BIGINT.getTypeSignature())); List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinitions(MultiScalarFunction.class); assertEquals(functions.size(), 2); ParametricScalar scalar1 = (ParametricScalar) functions.stream().filter(signature -> signature.getSignature().equals(expectedSignature1)).collect(toImmutableList()).get(0); ParametricScalar scalar2 = (ParametricScalar) functions.stream().filter(signature -> signature.getSignature().equals(expectedSignature2)).collect(toImmutableList()).get(0); assertImplementationCount(scalar1, 1, 0, 0); assertImplementationCount(scalar2, 1, 0, 0); assertEquals(scalar1.getSignature(), expectedSignature1); assertTrue(scalar1.isDeterministic()); assertFalse(scalar1.isHidden()); assertEquals(scalar1.getDescription(), "Simple scalar with single implementation based on method 1"); assertEquals(scalar2.getSignature(), expectedSignature2); assertFalse(scalar2.isDeterministic()); assertTrue(scalar2.isHidden()); assertEquals(scalar2.getDescription(), "Simple scalar with single implementation based on method 2"); }
protected AbstractGreatestLeast(String name, OperatorType operatorType) { super(new Signature( name, FunctionKind.SCALAR, ImmutableList.of(orderableTypeParameter("E")), ImmutableList.of(), parseTypeSignature("E"), ImmutableList.of(parseTypeSignature("E")), true)); this.operatorType = requireNonNull(operatorType, "operatorType is null"); }
public WindowFunctionSupplier getWindowFunctionImplementation(Signature signature) { checkArgument(signature.getKind() == WINDOW || signature.getKind() == AGGREGATE, "%s is not a window function", signature); checkArgument(signature.getTypeVariableConstraints().isEmpty(), "%s has unbound type parameters", signature); try { return specializedWindowCache.getUnchecked(getSpecializedFunctionKey(signature)); } catch (UncheckedExecutionException e) { throwIfInstanceOf(e.getCause(), PrestoException.class); throw e; } }
private JsonToMapCast() { super(OperatorType.CAST, ImmutableList.of(comparableTypeParameter("K"), typeVariable("V")), ImmutableList.of(), parseTypeSignature("map(K,V)"), ImmutableList.of(parseTypeSignature(StandardTypes.JSON))); }
@Test public void testIdentityCast() { TypeRegistry typeManager = new TypeRegistry(); FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig()); Signature exactOperator = registry.getCoercion(HYPER_LOG_LOG, HYPER_LOG_LOG); assertEquals(exactOperator.getName(), mangleOperatorName(OperatorType.CAST.name())); assertEquals(transform(exactOperator.getArgumentTypes(), Functions.toStringFunction()), ImmutableList.of(StandardTypes.HYPER_LOG_LOG)); assertEquals(exactOperator.getReturnType().getBase(), StandardTypes.HYPER_LOG_LOG); }
public static Signature comparisonExpressionSignature(ComparisonExpression.Operator operator, Type leftType, Type rightType) { for (OperatorType operatorType : OperatorType.values()) { if (operatorType.name().equals(operator.name())) { return internalOperator(operator.name(), parseTypeSignature(StandardTypes.BOOLEAN), leftType.getTypeSignature(), rightType.getTypeSignature()); } } return internalScalarFunction(operator.name(), parseTypeSignature(StandardTypes.BOOLEAN), leftType.getTypeSignature(), rightType.getTypeSignature()); }
private RowHashCodeOperator() { super(HASH_CODE, ImmutableList.of(comparableWithVariadicBound("T", "row")), ImmutableList.of(), parseTypeSignature(StandardTypes.BIGINT), ImmutableList.of(parseTypeSignature("T"))); }
private static SqlScalarFunction genericIntegerTypeToDecimalSaturatedFloorCast(Type integerType) { return SqlScalarFunction.builder(DecimalSaturatedFloorCasts.class) .signature(Signature.builder() .kind(SCALAR) .operatorType(SATURATED_FLOOR_CAST) .argumentTypes(integerType.getTypeSignature()) .returnType(parseTypeSignature("decimal(result_precision,result_scale)", ImmutableSet.of("result_precision", "result_scale"))) .build()) .deterministic(true) .choice(choice -> choice .implementation(methodsGroup -> methodsGroup .methods("genericIntegerTypeToShortDecimal", "genericIntegerTypeToLongDecimal") .withExtraParameters((context) -> { int resultPrecision = toIntExact(context.getLiteral("result_precision")); int resultScale = toIntExact(context.getLiteral("result_scale")); return ImmutableList.of(resultPrecision, resultScale); }))) .build(); }
public MethodsGroupBuilder methods(List<String> methodNames) { requireNonNull(methodNames, "methodNames is null"); checkArgument(!methodNames.isEmpty(), "methods list is empty"); methodNames.forEach(methodName -> this.methodWithExplicitJavaTypes(methodName, nCopies(signature.getArgumentTypes().size(), Optional.empty()))); return this; }
@Override protected Void visitFunctionCall(FunctionCall functionCall, Analysis analysis) { requireNonNull(analysis, "analysis is null"); Signature signature = analysis.getFunctionSignature(functionCall); if (signature != null && signature.getKind() == WINDOW && !functionCall.getWindow().isPresent()) { throw new SemanticException(WINDOW_REQUIRES_OVER, functionCall, "Window function %s requires an OVER clause", signature.getName()); } return super.visitFunctionCall(functionCall, analysis); } }
@Test public void testTypeParameters() throws Throwable { Signature signature = Signature.builder() .name("foo") .kind(SCALAR) .typeVariableConstraints(comparableWithVariadicBound("V", VARCHAR)) .returnType(parseTypeSignature("V")) .argumentTypes(parseTypeSignature("V")) .build(); SqlScalarFunction function = SqlScalarFunction.builder(TestMethods.class) .signature(signature) .deterministic(true) .choice(choice -> choice .implementation(methodsGroup -> methodsGroup.methods("varcharToVarchar"))) .build(); ScalarFunctionImplementation functionImplementation = function.specialize(BOUND_VARIABLES, 1, TYPE_REGISTRY, REGISTRY); Slice slice = (Slice) functionImplementation.getMethodHandle().invoke(INPUT_SLICE); assertEquals(slice, VARCHAR_TO_VARCHAR_RETURN_VALUE); }
private static boolean isRowNumberSignature(Signature signature) { return signature.equals(ROW_NUMBER_SIGNATURE); } }
@Override public InternalAggregationFunction specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) { Type inputType = typeManager.getType(getOnlyElement(applyBoundVariables(getSignature().getArgumentTypes(), boundVariables))); Type outputType = typeManager.getType(applyBoundVariables(getSignature().getReturnType(), boundVariables)); return generateAggregation(inputType, outputType); }
private QuantileDigestAggregationFunction(TypeSignature... typeSignatures) { super( NAME, ImmutableList.of(comparableTypeParameter("V")), ImmutableList.of(), parseTypeSignature("qdigest(V)"), ImmutableList.copyOf(typeSignatures)); }