use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class CoalesceCodeGenerator method generateExpression.
@Override
public BytecodeNode generateExpression(BytecodeGeneratorContext generatorContext, Type returnType, List<RowExpression> arguments, Optional<Variable> outputBlockVariable) {
Variable wasNull = generatorContext.wasNull();
LabelNode endLabel = new LabelNode("end");
BytecodeBlock block = new BytecodeBlock();
// Generate all but the last one.
for (RowExpression expression : arguments.subList(0, arguments.size() - 1)) {
block.append(generatorContext.generate(expression, Optional.empty()));
// Check if null
IfStatement ifStatement = new IfStatement().condition(wasNull);
ifStatement.ifTrue().pop(returnType.getJavaType()).append(wasNull.set(constantFalse()));
ifStatement.ifFalse().gotoLabel(endLabel);
block.append(ifStatement);
}
// Just return the last one here if control reaches here.
block.append(generatorContext.generate(arguments.get(arguments.size() - 1), Optional.empty()));
block.visitLabel(endLabel);
outputBlockVariable.ifPresent(output -> block.append(generateWrite(generatorContext, returnType, output)));
return block;
}
use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class TestVerifyNoOriginalExpression method validateSpatialJoinWithFilter.
private void validateSpatialJoinWithFilter(RowExpression filter) {
ImmutableList<VariableReferenceExpression> outputVariables = ImmutableList.of(VARIABLE_REFERENCE_EXPRESSION);
Optional<VariableReferenceExpression> leftPartitionVariable = Optional.of(VARIABLE_REFERENCE_EXPRESSION);
Optional<VariableReferenceExpression> rightPartitionVariable = Optional.of(VARIABLE_REFERENCE_EXPRESSION);
Optional<String> kdbTree = Optional.of("");
ImmutableMap<VariableReferenceExpression, RowExpression> map = ImmutableMap.of(VARIABLE_REFERENCE_EXPRESSION, VARIABLE_REFERENCE_EXPRESSION);
ProjectNode projectNode = builder.project(new Assignments(map), valuesNode);
SpatialJoinNode spatialJoinNode = new SpatialJoinNode(Optional.empty(), new PlanNodeId("1"), SpatialJoinNode.Type.INNER, projectNode, projectNode, outputVariables, filter, leftPartitionVariable, rightPartitionVariable, kdbTree);
testValidation(spatialJoinNode);
}
use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class TestVerifyNoOriginalExpression method testValidateSpatialJoin.
@Test
public void testValidateSpatialJoin() {
RowExpression filter = comparisonCallExpression;
validateSpatialJoinWithFilter(filter);
}
use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class TestVerifyNoOriginalExpression method testValidateFailedCompound.
@Test(expectedExceptions = IllegalArgumentException.class)
public void testValidateFailedCompound() {
Expression predicate = COMPARISON_EXPRESSION;
RowExpression rowExpression = castToRowExpression(predicate);
FilterNode filterNode = builder.filter(rowExpression, valuesNode);
ImmutableMap<VariableReferenceExpression, RowExpression> map = ImmutableMap.of(VARIABLE_REFERENCE_EXPRESSION, castToRowExpression(new SymbolReference("count")));
ProjectNode projectNode = builder.project(new Assignments(map), filterNode);
testValidation(projectNode);
}
use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class TestVerifyNoOriginalExpression method testValidateForApplyFailed.
@Test(expectedExceptions = IllegalArgumentException.class)
public void testValidateForApplyFailed() {
ImmutableMap<VariableReferenceExpression, RowExpression> map = ImmutableMap.of(VARIABLE_REFERENCE_EXPRESSION, castToRowExpression(new SymbolReference("count")));
Assignments assignments = new Assignments(map);
ImmutableList<VariableReferenceExpression> variableReferenceExpressions = ImmutableList.of(VARIABLE_REFERENCE_EXPRESSION);
ApplyNode applyNode = builder.apply(assignments, variableReferenceExpressions, valuesNode, valuesNode);
testValidation(applyNode);
}
Aggregations