Package com.facebook.presto.byteCode

Examples of com.facebook.presto.byteCode.ByteCodeNode


        Type valueType = expressionTypes.get(node.getValue());
        if (valueType.equals(UNKNOWN)) {
            return loadBoolean(true);
        }

        ByteCodeNode value = process(node.getValue(), context);

        // evaluate the expression, pop the produced value, and load the null flag
        Block block = new Block(context)
                .comment(node.toString())
                .append(value)
View Full Code Here


    @Override
    protected ByteCodeNode visitSearchedCaseExpression(SearchedCaseExpression node, final CompilerContext context)
    {
        Type type = expressionTypes.get(node);
        ByteCodeNode elseValue;
        if (node.getDefaultValue() != null) {
            elseValue = process(node.getDefaultValue(), context);
        }
        else {
            elseValue = typedNull(context, type.getJavaType());
View Full Code Here

    @Override
    protected ByteCodeNode visitSimpleCaseExpression(SimpleCaseExpression node, final CompilerContext context)
    {
        // process value, else, and all when clauses
        ByteCodeNode value = process(node.getOperand(), context);
        Type type = expressionTypes.get(node);
        ByteCodeNode elseValue;
        if (node.getDefaultValue() != null) {
            elseValue = process(node.getDefaultValue(), context);
        }
        else {
            elseValue = typedNull(context, type.getJavaType());
        }

        List<TypedWhenClause> whenClauses = ImmutableList.copyOf(transform(node.getWhenClauses(), new Function<WhenClause, TypedWhenClause>()
        {
            @Override
            public TypedWhenClause apply(WhenClause whenClause)
            {
                return new TypedWhenClause(context, whenClause);
            }
        }));

        // determine the type of the value and result
        Class<?> valueType = expressionTypes.get(node.getOperand()).getJavaType();

        // evaluate the value and store it in a variable
        LabelNode nullValue = new LabelNode("nullCondition");
        Variable tempVariable = context.createTempVariable(valueType);
        Block block = new Block(context)
                .append(value)
                .append(ifWasNullClearPopAndGoto(context, nullValue, void.class, valueType))
                .putVariable(tempVariable.getLocalVariableDefinition());

        ByteCodeNode getTempVariableNode = VariableInstruction.loadVariable(tempVariable.getLocalVariableDefinition());

        // build the statements
        elseValue = new Block(context).visitLabel(nullValue).append(elseValue);
        // reverse list because current if statement builder doesn't support if/else so we need to build the if statements bottom up
        for (TypedWhenClause whenClause : Lists.reverse(new ArrayList<>(whenClauses))) {
            FunctionBinding functionBinding = bootstrapFunctionBinder.bindOperator(
                    OperatorType.EQUAL,
                    getSessionByteCode,
                    ImmutableList.of(whenClause.operandBlock, getTempVariableNode),
                    types(whenClause.operand, node.getOperand()));
            ByteCodeNode equalsCall = visitFunctionBinding(context, functionBinding, whenClause.operand.toString());

            Block condition = new Block(context)
                    .append(equalsCall)
                    .putVariable("wasNull", false);
View Full Code Here

    }

    @Override
    protected ByteCodeNode visitNullIfExpression(NullIfExpression node, CompilerContext context)
    {
        ByteCodeNode first = process(node.getFirst(), context);
        Type firstType = expressionTypes.get(node.getFirst());
        ByteCodeNode second = process(node.getSecond(), context);

        LabelNode notMatch = new LabelNode("notMatch");

        // push first arg on the stack
        Block block = new Block(context)
                .comment(node.toString())
                .append(first)
                .append(ifWasNullPopAndGoto(context, notMatch, void.class));

        // if (equal(dupe(first), second)
        FunctionBinding functionBinding = bootstrapFunctionBinder.bindOperator(
                OperatorType.EQUAL,
                getSessionByteCode,
                ImmutableList.of(new Block(context).dup(firstType.getJavaType()), second),
                types(node.getFirst(), node.getSecond()));
        ByteCodeNode equalsCall = visitFunctionBinding(context, functionBinding, "equal");

        Block conditionBlock = new Block(context)
                .append(equalsCall)
                .append(ifWasNullClearPopAndGoto(context, notMatch, void.class, boolean.class));
View Full Code Here

            operands.add(process(expression, context));
        }

        Class<?> type = expressionTypes.get(node).getJavaType();

        ByteCodeNode nullValue = typedNull(context, type);
        // reverse list because current if statement builder doesn't support if/else so we need to build the if statements bottom up
        for (ByteCodeNode operand : Lists.reverse(operands)) {
            Block condition = new Block(context)
                    .append(operand)
                    .getVariable("wasNull");
View Full Code Here

        Expression valueListExpression = node.getValueList();
        if (!(valueListExpression instanceof InListExpression)) {
            throw new UnsupportedOperationException("Compilation of IN subquery is not supported yet");
        }

        ByteCodeNode value = process(node.getValue(), context);

        ImmutableList.Builder<ByteCodeNode> values = ImmutableList.builder();
        InListExpression valueList = (InListExpression) valueListExpression;
        for (Expression test : valueList.getValues()) {
            ByteCodeNode testNode = process(test, context);
            values.add(testNode);
        }

        Type type = expressionTypes.get(node.getValue());
        Class<?> javaType = type.getJavaType();

        FunctionBinding hashCodeFunction = bootstrapFunctionBinder.bindOperator(
                OperatorType.HASH_CODE,
                getSessionByteCode,
                ImmutableList.<ByteCodeNode>of(NOP),
                ImmutableList.of(type));

        ImmutableListMultimap.Builder<Integer, ByteCodeNode> hashBucketsBuilder = ImmutableListMultimap.builder();
        ImmutableList.Builder<ByteCodeNode> defaultBucket = ImmutableList.builder();
        ImmutableSet.Builder<Object> constantValuesBuilder = ImmutableSet.builder();
        for (ByteCodeNode testNode : values.build()) {
            if (testNode instanceof Constant) {
                Constant constant = (Constant) testNode;
                Object testValue = constant.getValue();
                constantValuesBuilder.add(testValue);

                if (javaType == boolean.class) {
                    // boolean constant is actually an integer type
                    testValue = ((Number) testValue).intValue() != 0;
                }

                int hashCode;
                try {
                    hashCode = (int) hashCodeFunction.getCallSite().dynamicInvoker().invoke(testValue);
                }
                catch (Throwable throwable) {
                    throw new IllegalArgumentException("Error processing IN statement: error calculating hash code for " + testValue, throwable);
                }

                hashBucketsBuilder.put(hashCode, testNode);
            }
            else {
                defaultBucket.add(testNode);
            }
        }
        ImmutableListMultimap<Integer, ByteCodeNode> hashBuckets = hashBucketsBuilder.build();
        ImmutableSet<Object> constantValues = constantValuesBuilder.build();

        LabelNode end = new LabelNode("end");
        LabelNode match = new LabelNode("match");
        LabelNode noMatch = new LabelNode("noMatch");

        LabelNode defaultLabel = new LabelNode("default");

        ByteCodeNode switchBlock;
        if (constantValues.size() < 1000) {
            Block switchCaseBlocks = new Block(context);
            LookupSwitchBuilder switchBuilder = lookupSwitchBuilder();
            for (Entry<Integer, Collection<ByteCodeNode>> bucket : hashBuckets.asMap().entrySet()) {
                LabelNode label = new LabelNode("inHash" + bucket.getKey());
View Full Code Here

                OperatorType.EQUAL,
                getSessionByteCode,
                ImmutableList.<ByteCodeNode>of(NOP, NOP),
                ImmutableList.of(type, type));

        ByteCodeNode elseNode = elseBlock;
        for (ByteCodeNode testNode : testValues) {
            LabelNode testLabel = new LabelNode("test");
            IfStatementBuilder test = ifStatementBuilder(context);

            Block condition = new Block(context)
View Full Code Here

            unboundArguments.add(TypedByteCodeNode.typedByteCodeNode(getSessionByteCode, Session.class));
            argIndex++;
        }

        for (TypedByteCodeNode argument : arguments) {
            ByteCodeNode node = argument.getNode();
            if (node instanceof Constant) {
                Object value = ((Constant) node).getValue();
                if (argument.getType() == boolean.class) {
                    checkArgument(value instanceof Integer, "boolean should be represented as an integer");
                    value = (((Integer) value) != 0);
View Full Code Here

        ByteCodeExpressionVisitor visitor = new ByteCodeExpressionVisitor(
                callSiteBinder,
                fieldReferenceCompiler(callSiteBinder, positionVariable, wasNullVariable),
                metadata.getFunctionRegistry());
        ByteCodeNode body = filter.accept(visitor, context);

        LabelNode end = new LabelNode("end");
        method
                .getBody()
                .comment("boolean wasNull = false;")
View Full Code Here

        LabelNode match = new LabelNode("match");
        LabelNode noMatch = new LabelNode("noMatch");

        LabelNode defaultLabel = new LabelNode("default");

        ByteCodeNode switchBlock;
        if (constantValues.size() < 1000) {
            Block switchCaseBlocks = new Block(context);
            LookupSwitchBuilder switchBuilder = lookupSwitchBuilder();
            for (Entry<Integer, Collection<TypedByteCodeNode>> bucket : hashBuckets.asMap().entrySet()) {
                LabelNode label = new LabelNode("inHash" + bucket.getKey());
View Full Code Here

TOP

Related Classes of com.facebook.presto.byteCode.ByteCodeNode

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.