Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.facebook.presto.sql.gen;
 
 
 import static com.facebook.presto.byteCode.instruction.Constant.loadBoolean;
 import static com.facebook.presto.byteCode.instruction.Constant.loadDouble;
 import static com.facebook.presto.byteCode.instruction.Constant.loadFloat;
 import static com.facebook.presto.byteCode.instruction.Constant.loadInt;
 import static com.facebook.presto.byteCode.instruction.Constant.loadLong;
 import static com.facebook.presto.byteCode.instruction.Constant.loadString;
 import static com.facebook.presto.sql.gen.ByteCodeUtils.loadConstant;
 import static com.facebook.presto.sql.relational.Signatures.CAST;
 import static com.facebook.presto.sql.relational.Signatures.COALESCE;
 import static com.facebook.presto.sql.relational.Signatures.IF;
 import static com.facebook.presto.sql.relational.Signatures.IN;
 import static com.facebook.presto.sql.relational.Signatures.IS_NULL;
 import static com.facebook.presto.sql.relational.Signatures.NULL_IF;
 import static com.facebook.presto.sql.relational.Signatures.SWITCH;
 
         implements RowExpressionVisitor<CompilerContextByteCodeNode>
 {
     private final CallSiteBinder callSiteBinder;
     private final FunctionRegistry registry;
 
     public ByteCodeExpressionVisitor(
             CallSiteBinder callSiteBinder,
             RowExpressionVisitor<CompilerContextByteCodeNodefieldReferenceCompiler,
             FunctionRegistry registry)
     {
         this. = callSiteBinder;
         this. = fieldReferenceCompiler;
         this. = registry;
     }
 
     @Override
     public ByteCodeNode visitCall(CallExpression callfinal CompilerContext context)
     {
         ByteCodeGenerator generator;
         // special-cased in function registry
         if (call.getSignature().getName().equals()) {
             generator = new CastCodeGenerator();
         }
         else {
             switch (call.getSignature().getName()) {
                 // lazy evaluation
                 case :
                     generator = new IfCodeGenerator();
                     break;
                 case :
                     generator = new NullIfCodeGenerator();
                     break;
                 case :
                     // (SWITCH <expr> (WHEN <expr> <expr>) (WHEN <expr> <expr>) <expr>)
                     generator = new SwitchCodeGenerator();
                     break;
                 // functions that take null as input
                 case :
                     generator = new IsNullCodeGenerator();
                     break;
                 case "IS_DISTINCT_FROM":
                     generator = new IsDistinctFromCodeGenerator();
                     break;
                 case :
                     generator = new CoalesceCodeGenerator();
                     break;
                 // functions that require varargs and/or complex types (e.g., lists)
                 case :
                     generator = new InCodeGenerator();
                     break;
                 // optimized implementations (shortcircuiting behavior)
                 case "AND":
                     generator = new AndCodeGenerator();
                     break;
                 case "OR":
                     generator = new OrCodeGenerator();
                     break;
                 default:
                    generator = new FunctionCallCodeGenerator();
            }
        }
        ByteCodeGeneratorContext generatorContext = new ByteCodeGeneratorContext(
                this,
                context,
                ,
                );
        return generator.generateExpression(call.getSignature(), generatorContextcall.getType(), call.getArguments());
    }
    @Override
    public ByteCodeNode visitConstant(ConstantExpression constantCompilerContext context)
    {
        Object value = constant.getValue();
        Class<?> javaType = constant.getType().getJavaType();
        Block block = new Block(context);
        if (value == null) {
            return block.comment("constant null")
                    .putVariable("wasNull"true)
                    .pushJavaDefault(javaType);
        }
        // use LDC for primitives (boolean, short, int, long, float, double)
        block.comment("constant " + constant.getType().getTypeSignature());
        if (javaType == boolean.class) {
            return block.append(loadBoolean((Booleanvalue));
        }
        if (javaType == byte.class || javaType == short.class || javaType == int.class) {
            return block.append(loadInt(((Numbervalue).intValue()));
        }
        if (javaType == long.class) {
            return block.append(loadLong((Longvalue));
        }
        if (javaType == float.class) {
            return block.append(loadFloat((Floatvalue));
        }
        if (javaType == double.class) {
            return block.append(loadDouble((Doublevalue));
        }
        if (javaType == String.class) {
            return block.append(loadString((Stringvalue));
        }
        if (javaType == void.class) {
            return block;
        }
        // bind constant object directly into the call-site using invoke dynamic
        Binding binding = .bind(valueconstant.getType().getJavaType());
        return new Block(context)
                .setDescription("constant " + constant.getType())
                .comment(constant.toString())
                .append(loadConstant(contextbinding));
    }
    @Override
    {
        return .visitInputReference(nodecontext);
    }
New to GrepCode? Check out our FAQ X