Package com.facebook.presto.sql.relational

Examples of com.facebook.presto.sql.relational.RowExpression


        implements ByteCodeGenerator
{
    @Override
    public ByteCodeNode generateExpression(Signature signature, ByteCodeGeneratorContext generatorContext, Type returnType, List<RowExpression> arguments)
    {
        RowExpression argument = arguments.get(0);

        CompilerContext context = generatorContext.getContext();
        if (argument.getType().equals(UnknownType.UNKNOWN)) {
            return new Block(context).putVariable("wasNull", true).pushJavaDefault(returnType.getJavaType());
        }

        FunctionBinding binding = generatorContext
                .getBootstrapBinder()
                .bindCastOperator(generatorContext.generateGetSession(), generatorContext.generate(argument), argument.getType(), returnType);

        return generateFunctionCall(signature, context, binding, "cast");
    }
View Full Code Here


    @Override
    public ByteCodeNode generateExpression(Signature signature, ByteCodeGeneratorContext generatorContext, Type returnType, List<RowExpression> arguments)
    {
        CompilerContext context = generatorContext.getContext();

        RowExpression first = arguments.get(0);
        RowExpression second = arguments.get(1);

        LabelNode notMatch = new LabelNode("notMatch");

        // push first arg on the stack
        Block block = new Block(context)
                .comment("check if first arg is null")
                .append(generatorContext.generate(first))
                .append(ByteCodeUtils.ifWasNullPopAndGoto(context, notMatch, void.class));

        Type firstType = first.getType();
        Type secondType = second.getType();

        // this is a hack! We shouldn't be determining type coercions at this point, but there's no way
        // around it in the current expression AST
        Type commonType = FunctionRegistry.getCommonSuperType(firstType, secondType).get();
View Full Code Here

    {
        Preconditions.checkArgument(arguments.size() == 2);

        CompilerContext context = generator.getContext();

        RowExpression left = arguments.get(0);
        RowExpression right = arguments.get(1);

        Type leftType = left.getType();
        Type rightType = right.getType();

        FunctionBinding functionBinding = generator.getBootstrapBinder().bindOperator(
                OperatorType.EQUAL,
                generator.generateGetSession(),
                ImmutableList.<ByteCodeNode>of(NOP, NOP),
View Full Code Here

            TimeZoneKey timeZoneKey,
            CompilerContext context,
            Block getSessionByteCode)
    {
        if (useNewByteCodeGenerator) {
            RowExpression translated = SqlToRowExpressionTranslator.translate(expression, types, metadata, timeZoneKey);
            NewByteCodeExpressionVisitor visitor = new NewByteCodeExpressionVisitor(bootstrap.getFunctionBinder(), getSessionByteCode, sourceIsCursor);
            return translated.accept(visitor, context);
        }
        else {
            ByteCodeExpressionVisitor visitor = new ByteCodeExpressionVisitor(metadata, bootstrap.getFunctionBinder(), types, getSessionByteCode, sourceIsCursor, timeZoneKey);
            return visitor.process(expression, context);
        }
View Full Code Here

         */

        CompilerContext context = generatorContext.getContext();

        // process value, else, and all when clauses
        RowExpression value = arguments.get(0);
        ByteCodeNode valueBytecode = generatorContext.generate(value);
        ByteCodeNode elseValue;

        List<RowExpression> whenClauses;
        RowExpression last = arguments.get(arguments.size() - 1);
        if (last instanceof CallExpression && ((CallExpression) last).getSignature().getName().equals("WHEN")) {
            whenClauses = arguments.subList(1, arguments.size());
            elseValue = new Block(context)
                    .putVariable("wasNull", true)
                    .pushJavaDefault(returnType.getJavaType());
        }
        else {
            whenClauses = arguments.subList(1, arguments.size() - 1);
            elseValue = generatorContext.generate(last);
        }

        // determine the type of the value and result
        Class<?> valueType = value.getType().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(valueBytecode)
                .append(ByteCodeUtils.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 (RowExpression clause : Lists.reverse(whenClauses)) {
            Preconditions.checkArgument(clause instanceof CallExpression && ((CallExpression) clause).getSignature().getName().equals("WHEN"));

            RowExpression operand = ((CallExpression) clause).getArguments().get(0);
            RowExpression result = ((CallExpression) clause).getArguments().get(1);

            // call equals(value, operand)
            FunctionBinding functionBinding = generatorContext.getBootstrapBinder().bindOperator(
                    OperatorType.EQUAL,
                    generatorContext.generateGetSession(),
View Full Code Here

        implements ByteCodeGenerator
{
    @Override
    public ByteCodeNode generateExpression(Signature signature, ByteCodeGeneratorContext generatorContext, Type returnType, List<RowExpression> arguments)
    {
        RowExpression argument = arguments.get(0);

        CompilerContext context = generatorContext.getContext();
        if (argument.getType().equals(UnknownType.UNKNOWN)) {
            return new Block(context).putVariable("wasNull", true).pushJavaDefault(returnType.getJavaType());
        }

        FunctionInfo function = generatorContext
                .getRegistry()
                .getCoercion(argument.getType(), returnType);

        return generatorContext.generateCall(function, ImmutableList.of(generatorContext.generate(argument)));
    }
View Full Code Here

    {
        Preconditions.checkArgument(arguments.size() == 2);

        CompilerContext context = generatorContext.getContext();

        RowExpression left = arguments.get(0);
        RowExpression right = arguments.get(1);

        Type leftType = left.getType();
        Type rightType = right.getType();

        FunctionInfo operator = generatorContext
                .getRegistry()
                .resolveOperator(OperatorType.EQUAL, ImmutableList.of(leftType, rightType));
View Full Code Here

    @Override
    public ByteCodeNode generateExpression(Signature signature, ByteCodeGeneratorContext generatorContext, Type returnType, List<RowExpression> arguments)
    {
        CompilerContext context = generatorContext.getContext();

        RowExpression first = arguments.get(0);
        RowExpression second = arguments.get(1);

        LabelNode notMatch = new LabelNode("notMatch");

        // push first arg on the stack
        Block block = new Block(context)
                .comment("check if first arg is null")
                .append(generatorContext.generate(first))
                .append(ByteCodeUtils.ifWasNullPopAndGoto(context, notMatch, void.class));

        Type firstType = first.getType();
        Type secondType = second.getType();

        // this is a hack! We shouldn't be determining type coercions at this point, but there's no way
        // around it in the current expression AST
        Type commonType = FunctionRegistry.getCommonSuperType(firstType, secondType).get();
View Full Code Here

    {
        Preconditions.checkArgument(arguments.size() == 2);

        CompilerContext context = generatorContext.getContext();

        RowExpression left = arguments.get(0);
        RowExpression right = arguments.get(1);

        Type leftType = left.getType();
        Type rightType = right.getType();

        FunctionInfo operator = generatorContext
                .getRegistry()
                .resolveOperator(OperatorType.EQUAL, ImmutableList.of(leftType, rightType));
View Full Code Here

        implements ByteCodeGenerator
{
    @Override
    public ByteCodeNode generateExpression(Signature signature, ByteCodeGeneratorContext generatorContext, Type returnType, List<RowExpression> arguments)
    {
        RowExpression argument = arguments.get(0);

        CompilerContext context = generatorContext.getContext();
        if (argument.getType().equals(UnknownType.UNKNOWN)) {
            return new Block(context)
                    .putVariable("wasNull", true)
                    .pushJavaDefault(returnType.getJavaType());
        }

        FunctionInfo function = generatorContext
                .getRegistry()
                .getCoercion(argument.getType(), returnType);

        return generatorContext.generateCall(function, ImmutableList.of(generatorContext.generate(argument)));
    }
View Full Code Here

TOP

Related Classes of com.facebook.presto.sql.relational.RowExpression

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.