use of com.facebook.presto.metadata.Signature in project presto by prestodb.
the class WindowAnnotationsParser method parse.
private static SqlWindowFunction parse(Class<? extends WindowFunction> clazz, WindowFunctionSignature window) {
List<TypeVariableConstraint> typeVariables = ImmutableList.of();
if (!window.typeVariable().isEmpty()) {
typeVariables = ImmutableList.of(typeVariable(window.typeVariable()));
}
List<TypeSignature> argumentTypes = Stream.of(window.argumentTypes()).map(TypeSignature::parseTypeSignature).collect(toImmutableList());
Signature signature = new Signature(window.name(), WINDOW, typeVariables, ImmutableList.of(), parseTypeSignature(window.returnType()), argumentTypes, false);
return new SqlWindowFunction(new ReflectionWindowFunctionSupplier<>(signature, clazz));
}
use of com.facebook.presto.metadata.Signature in project presto by prestodb.
the class DecimalOperators method decimalAddOperator.
private static SqlScalarFunction decimalAddOperator() {
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 = Signature.builder().kind(SCALAR).operatorType(ADD).longVariableConstraints(longVariableExpression("r_precision", "min(38, max(a_precision - a_scale, b_precision - b_scale) + max(a_scale, b_scale) + 1)"), longVariableExpression("r_scale", "max(a_scale, b_scale)")).argumentTypes(decimalLeftSignature, decimalRightSignature).returnType(decimalResultSignature).build();
return SqlScalarFunction.builder(DecimalOperators.class).signature(signature).implementation(b -> b.methods("addShortShortShort").withExtraParameters(DecimalOperators::calculateShortRescaleParameters)).implementation(b -> b.methods("addShortShortLong", "addLongLongLong", "addShortLongLong", "addLongShortLong").withExtraParameters(DecimalOperators::calculateLongRescaleParameters)).build();
}
use of com.facebook.presto.metadata.Signature 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 = Signature.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).signature(signature).implementation(b -> b.methods("multiplyShortShortShort", "multiplyShortShortLong", "multiplyLongLongLong", "multiplyShortLongLong", "multiplyLongShortLong")).build();
}
use of com.facebook.presto.metadata.Signature in project presto by prestodb.
the class SimplifyCountOverConstant method isCountOverConstant.
private static boolean isCountOverConstant(AggregationNode.Aggregation aggregation, Assignments inputs) {
Signature signature = aggregation.getSignature();
if (!signature.getName().equals("count") || signature.getArgumentTypes().size() != 1) {
return false;
}
Expression argument = aggregation.getCall().getArguments().get(0);
if (argument instanceof SymbolReference) {
argument = inputs.get(Symbol.from(argument));
}
return argument instanceof Literal && !(argument instanceof NullLiteral);
}
use of com.facebook.presto.metadata.Signature in project presto by prestodb.
the class SimplifyCountOverConstant method apply.
@Override
public Optional<PlanNode> apply(PlanNode node, Lookup lookup, PlanNodeIdAllocator idAllocator, SymbolAllocator symbolAllocator) {
if (!(node instanceof AggregationNode)) {
return Optional.empty();
}
AggregationNode parent = (AggregationNode) node;
PlanNode input = lookup.resolve(parent.getSource());
if (!(input instanceof ProjectNode)) {
return Optional.empty();
}
ProjectNode child = (ProjectNode) input;
boolean changed = false;
Map<Symbol, AggregationNode.Aggregation> assignments = new LinkedHashMap<>(parent.getAssignments());
for (Entry<Symbol, AggregationNode.Aggregation> entry : parent.getAssignments().entrySet()) {
Symbol symbol = entry.getKey();
AggregationNode.Aggregation aggregation = entry.getValue();
if (isCountOverConstant(aggregation, child.getAssignments())) {
changed = true;
assignments.put(symbol, new AggregationNode.Aggregation(new FunctionCall(QualifiedName.of("count"), ImmutableList.of()), new Signature("count", AGGREGATE, parseTypeSignature(StandardTypes.BIGINT))));
}
}
if (!changed) {
return Optional.empty();
}
return Optional.of(new AggregationNode(node.getId(), child, assignments, parent.getGroupingSets(), parent.getStep(), parent.getHashSymbol(), parent.getGroupIdSymbol()));
}
Aggregations