Package com.facebook.presto.metadata

Examples of com.facebook.presto.metadata.Signature


        return new FunctionCall(QualifiedName.of("test"), ImmutableList.<Expression>of());
    }

    private static Signature fakeFunctionHandle(String name)
    {
        return new Signature(name, UNKNOWN, ImmutableList.<Type>of(), false, false);
    }
View Full Code Here


    @Override
    public FunctionInfo specialize(Map<String, Type> types, int arity)
    {
        Type type = types.get("T");
        Signature signature = new Signature(NAME, StandardTypes.BIGINT, type.getName());
        InternalAggregationFunction aggregation = generateAggregation(type);
        return new FunctionInfo(signature, getDescription(), aggregation.getIntermediateType().getName(), aggregation, false);
    }
View Full Code Here

            if (source instanceof ProjectNode) {
                ProjectNode projectNode = (ProjectNode) source;
                for (Entry<Symbol, FunctionCall> entry : node.getAggregations().entrySet()) {
                    Symbol symbol = entry.getKey();
                    FunctionCall functionCall = entry.getValue();
                    Signature signature = node.getFunctions().get(symbol);
                    if (isCountConstant(projectNode, functionCall, signature)) {
                        aggregations.put(symbol, new FunctionCall(functionCall.getName(), null, functionCall.isDistinct(), ImmutableList.<Expression>of()));
                        functions.put(symbol, new Signature("count", StandardTypes.BIGINT));
                    }
                }
            }

            return new AggregationNode(
View Full Code Here

        protected RowExpression visitFunctionCall(FunctionCall node, Void context)
        {
            List<RowExpression> arguments = Lists.transform(node.getArguments(), processFunction(context));

            List<String> argumentTypes = Lists.transform(Lists.transform(arguments, typeGetter()), nameGetter());
            Signature signature = new Signature(node.getName().getSuffix(), types.get(node).getName(), argumentTypes);

            return call(signature, types.get(node), arguments);
        }
View Full Code Here

        @Override
        public RowExpression visitCall(CallExpression call, final Void context)
        {
            FunctionInfo function;
            Signature signature = call.getSignature();

            if (signature.getName().equals(CAST)) {
                if (call.getArguments().get(0).getType().equals(UnknownType.UNKNOWN)) {
                    return constantNull(call.getType());
                }
                function = registry.getCoercion(call.getArguments().get(0).getType(), call.getType());
            }
            else {
                switch (signature.getName()) {
                    // TODO: optimize these special forms
                    case IF:
                    case NULL_IF:
                    case SWITCH:
                    case TRY_CAST:
                    case IS_NULL:
                    case "IS_DISTINCT_FROM":
                    case COALESCE:
                    case "AND":
                    case "OR":
                    case IN:
                        return call;
                    default:
                        function = registry.getExactFunction(signature);
                        if (function == null) {
                            // TODO: temporary hack to deal with magic timestamp literal functions which don't have an "exact" form and need to be "resolved"
                            function = registry.resolveFunction(QualifiedName.of(signature.getName()), signature.getArgumentTypes(), false);
                        }
                }
            }

            List<RowExpression> arguments = Lists.transform(call.getArguments(), new Function<RowExpression, RowExpression>()
            {
                @Override
                public RowExpression apply(RowExpression input)
                {
                    return input.accept(Visitor.this, context);
                }
            });

            if (Iterables.all(arguments, instanceOf(ConstantExpression.class)) && function.isDeterministic()) {
                MethodHandle method = function.getMethodHandle();

                if (method.type().parameterCount() > 0 && method.type().parameterType(0) == ConnectorSession.class) {
                    method = method.bindTo(session);
                }

                List<Object> constantArguments = new ArrayList<>();
                for (RowExpression argument : arguments) {
                    Object value = ((ConstantExpression) argument).getValue();
                    // if any argument is null, return null
                    if (value == null) {
                        return constantNull(call.getType());
                    }
                    constantArguments.add(value);
                }

                try {
                    return constant(method.invokeWithArguments(constantArguments), call.getType());
                }
                catch (Throwable e) {
                    if (e instanceof InterruptedException) {
                        Thread.currentThread().interrupt();
                    }
                    throw Throwables.propagate(e);
                }
            }

            return call(signature, typeManager.getType(signature.getReturnType()), arguments);
        }
View Full Code Here

    public static ByteCodeNode generateInvocation(CompilerContext context, FunctionInfo function, List<ByteCodeNode> arguments, Binding binding)
    {
        MethodType methodType = binding.getType();

        Signature signature = function.getSignature();
        Class<?> unboxedReturnType = Primitives.unwrap(methodType.returnType());

        LabelNode end = new LabelNode("end");
        Block block = new Block(context)
                .setDescription("invoke " + signature);
View Full Code Here

    }

    // **************** sql operators ****************
    public static Signature notSignature()
    {
        return new Signature("not", StandardTypes.BOOLEAN, ImmutableList.of(StandardTypes.BOOLEAN));
    }
View Full Code Here

    }

    // **************** special forms (lazy evaluation, etc) ****************
    public static Signature ifSignature(Type returnType)
    {
        return new Signature(IF, returnType.getName());
    }
View Full Code Here

        return new Signature(IF, returnType.getName());
    }

    public static Signature nullIfSignature(Type returnType, Type firstType, Type secondType)
    {
        return new Signature(NULL_IF, returnType.getName(), firstType.getName(), secondType.getName());
    }
View Full Code Here

        return new Signature(NULL_IF, returnType.getName(), firstType.getName(), secondType.getName());
    }

    public static Signature switchSignature(Type returnType)
    {
        return new Signature(SWITCH, returnType.getName());
    }
View Full Code Here

TOP

Related Classes of com.facebook.presto.metadata.Signature

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.