@Override public BytecodeNode visitInputReference(InputReferenceExpression node, Scope scope) { int field = node.getField(); Type type = node.getType(); BytecodeExpression block = blockResolver.apply(scope, field); BytecodeExpression position = positionResolver.apply(scope, field); return generateInputReference(callSiteBinder, scope, type, block, position); }
@Override public RowExpression visitInputReference(InputReferenceExpression reference, Void context) { int parameter = getParameterForField(reference); return field(parameter, reference.getType()); }
@Override public BytecodeNode visitInputReference(InputReferenceExpression node, Context context) { BytecodeNode inputReferenceBytecode = fieldReferenceCompiler.visitInputReference(node, context.getScope()); if (!context.getOutputBlockVariable().isPresent()) { return inputReferenceBytecode; } return new BytecodeBlock() .append(inputReferenceBytecode) .append(generateWrite( callSiteBinder, context.getScope(), context.getScope().getVariable("wasNull"), node.getType(), context.getOutputBlockVariable().get())); }
@Override public BytecodeNode visitInputReference(InputReferenceExpression node, Scope scope) { int field = node.getField(); Type type = node.getType(); Variable wasNullVariable = scope.getVariable("wasNull"); Class<?> javaType = type.getJavaType(); if (!javaType.isPrimitive() && javaType != Slice.class) { javaType = Object.class; } IfStatement ifStatement = new IfStatement(); ifStatement.condition() .setDescription(format("cursor.get%s(%d)", type, field)) .getVariable(cursorVariable) .push(field) .invokeInterface(RecordCursor.class, "isNull", boolean.class, int.class); ifStatement.ifTrue() .putVariable(wasNullVariable, true) .pushJavaDefault(javaType); ifStatement.ifFalse() .getVariable(cursorVariable) .push(field) .invokeInterface(RecordCursor.class, "get" + Primitives.wrap(javaType).getSimpleName(), javaType, int.class); return ifStatement; }
private Supplier<PageProjection> compileProjectionInternal(RowExpression projection, Optional<String> classNameSuffix) { requireNonNull(projection, "projection is null"); if (projection instanceof InputReferenceExpression) { InputReferenceExpression input = (InputReferenceExpression) projection; InputPageProjection projectionFunction = new InputPageProjection(input.getField(), input.getType()); return () -> projectionFunction; } if (projection instanceof ConstantExpression) { ConstantExpression constant = (ConstantExpression) projection; ConstantPageProjection projectionFunction = new ConstantPageProjection(constant.getValue(), constant.getType()); return () -> projectionFunction; } PageFieldsToInputParametersRewriter.Result result = rewritePageFieldsToInputParameters(projection); CallSiteBinder callSiteBinder = new CallSiteBinder(); // generate Work ClassDefinition pageProjectionWorkDefinition = definePageProjectWorkClass(result.getRewrittenExpression(), callSiteBinder, classNameSuffix); Class<? extends Work> pageProjectionWorkClass; try { pageProjectionWorkClass = defineClass(pageProjectionWorkDefinition, Work.class, callSiteBinder.getBindings(), getClass().getClassLoader()); } catch (Exception e) { throw new PrestoException(COMPILER_ERROR, e); } return () -> new GeneratedPageProjection( result.getRewrittenExpression(), determinismEvaluator.isDeterministic(result.getRewrittenExpression()), result.getInputChannels(), constructorMethodHandle(pageProjectionWorkClass, BlockBuilder.class, ConnectorSession.class, Page.class, SelectedPositions.class)); }
@Override public BytecodeNode visitInputReference(InputReferenceExpression node, Scope scope) { int field = node.getField(); Type type = node.getType(); Class<?> javaType = type.getJavaType(); if (!javaType.isPrimitive() && javaType != Slice.class) { javaType = Object.class; } IfStatement ifStatement = new IfStatement(); ifStatement.condition() .setDescription(format("cursor.get%s(%d)", type, field)) .getVariable(cursorVariable) .push(field) .invokeInterface(RecordCursor.class, "isNull", boolean.class, int.class); ifStatement.ifTrue() .putVariable(wasNullVariable, true) .pushJavaDefault(javaType); ifStatement.ifFalse() .getVariable(cursorVariable) .push(field) .invokeInterface(RecordCursor.class, "get" + Primitives.wrap(javaType).getSimpleName(), javaType, int.class); return ifStatement; }
@Override public BytecodeNode visitInputReference(InputReferenceExpression node, Scope scope) { int field = node.getField(); Type type = node.getType(); Variable block = scope.getVariable("block_" + field); Class<?> javaType = type.getJavaType(); if (!javaType.isPrimitive() && javaType != Slice.class) { javaType = Object.class; } IfStatement ifStatement = new IfStatement(); ifStatement.condition() .setDescription(format("block_%d.get%s()", field, type)) .append(block) .getVariable(positionVariable) .invokeInterface(Block.class, "isNull", boolean.class, int.class); ifStatement.ifTrue() .putVariable(wasNullVariable, true) .pushJavaDefault(javaType); String methodName = "get" + Primitives.wrap(javaType).getSimpleName(); ifStatement.ifFalse() .append(loadConstant(callSiteBinder.bind(type, Type.class))) .append(block) .getVariable(positionVariable) .invokeInterface(Type.class, methodName, javaType, Block.class, int.class); return ifStatement; }