@Override protected EvalNode visitBinaryEval(Context context, Stack<EvalNode> stack, BinaryEval binaryEval) { stack.push(binaryEval); visit(context, binaryEval.getLeftExpr(), stack); context.sb.append(convertBinOperatorToSQLRepr(binaryEval.getType())).append(" "); visit(context, binaryEval.getRightExpr(), stack); stack.pop(); return binaryEval; }
public static BinaryEval create(EvalType type, EvalNode e1, EvalNode e2) { return new BinaryEval(type, e1, e2); } }
@Override public EvalNode visitBinaryEval(LogicalPlanner.PlanContext context, Stack<EvalNode> stack, BinaryEval binaryEval) { stack.push(binaryEval); EvalNode lhs = visit(context, binaryEval.getLeftExpr(), stack); EvalNode rhs = visit(context, binaryEval.getRightExpr(), stack); stack.pop(); if (!binaryEval.getLeftExpr().equals(lhs)) { binaryEval.setLeftExpr(lhs); } if (!binaryEval.getRightExpr().equals(rhs)) { binaryEval.setRightExpr(rhs); } if (lhs.getType() == EvalType.CONST && rhs.getType() == EvalType.CONST) { binaryEval.bind(null, null); return new ConstEval(binaryEval.eval(null)); } return binaryEval; }
private RESULT visitDefaultBinaryEval(CONTEXT context, BinaryEval binaryEval, Stack<EvalNode> stack) { stack.push(binaryEval); RESULT result = visit(context, binaryEval.getLeftExpr(), stack); visit(context, binaryEval.getRightExpr(), stack); stack.pop(); return result; }
private EvalNode rewrite(BinaryEval evalNode) { EvalType outerType = evalNode.getType(); // type of the outer operation. ex) AND if ((evalNode.getLeftExpr().getType() == EvalType.AND || evalNode.getLeftExpr().getType() == EvalType.OR) && evalNode.getLeftExpr().getType() == evalNode.getRightExpr().getType()) { EvalNode leftChild = evalNode.getLeftExpr(); EvalNode rightChild = evalNode.getRightExpr(); finalQual = new BinaryEval(innerType, commonQual, new BinaryEval(outerType, leftChild, rightChild)); } else if (evalNode.getLeftExpr().equals(evalNode.getRightExpr())) { finalQual = evalNode.getLeftExpr();
public EvalNode visitArithmeticEval(EvalCodeGenContext context, BinaryEval evalNode, Stack<EvalNode> stack) { stack.push(evalNode); visit(context, evalNode.getLeftExpr(), stack); // < left_child, push nullflag int LHS_NULLFLAG = context.istore(); int LHS = context.store(evalNode.getLeftExpr().getValueType()); visit(context, evalNode.getRightExpr(), stack); // < left_child, right_child, nullflag int RHS_NULLFLAG = context.istore(); int RHS = context.store(evalNode.getRightExpr().getValueType()); stack.pop(); Label ifNull = new Label(); Label afterEnd = new Label(); context.emitNullityCheck(ifNull, LHS_NULLFLAG, RHS_NULLFLAG); context.load(evalNode.getLeftExpr().getValueType(), LHS); context.load(evalNode.getRightExpr().getValueType(), RHS); int opCode = TajoGeneratorAdapter.getOpCode(evalNode.getType(), evalNode.getValueType()); context.methodvisitor.visitInsn(opCode); context.pushNullFlag(true); emitGotoLabel(context, afterEnd); emitLabel(context, ifNull); context.pushDummyValue(evalNode.getValueType()); context.pushNullFlag(false); emitLabel(context, afterEnd); return evalNode; }
if (isSingleVar(binaryEval.getLeftExpr())) { return expr; EvalNode left = binaryEval.getLeftExpr(); EvalNode lTerm = null; EvalNode rTerm = null; if (EvalTreeUtil.containColumnRef(((BinaryEval)left).getLeftExpr(), target)) { PartialBinaryExpr tmpTerm = splitRightTerm((BinaryEval) left); tmpTerm.type = inverseOperator(tmpTerm.type); tmpTerm.setLeftExpr(((BinaryEval)expr).getRightExpr()); lTerm = ((BinaryEval)left).getLeftExpr(); rTerm = new BinaryEval(tmpTerm); } else { tmpTerm.setLeftExpr(((BinaryEval)expr).getRightExpr()); lTerm = ((BinaryEval)left).getRightExpr(); rTerm = new BinaryEval(tmpTerm); return _transpose(new BinaryEval(expr.getType(), lTerm, rTerm), target); } else { return _expr;
public EvalNode visitStringConcat(EvalCodeGenContext context, BinaryEval evalNode, Stack<EvalNode> stack) throws CompilationError { stack.push(evalNode); visit(context, evalNode.getLeftExpr(), stack); // < lhs, l_null final int LHS_NULLFLAG = context.istore(); // < lhs final int LHS = context.store(evalNode.getLeftExpr().getValueType()); visit(context, evalNode.getRightExpr(), stack); // < rhs, r_nullflag int RHS_NULLFLAG = context.istore(); int RHS = context.store(evalNode.getRightExpr().getValueType()); // < stack.pop(); Label ifNull = new Label(); Label afterEnd = new Label(); context.emitNullityCheck(ifNull, LHS_NULLFLAG, RHS_NULLFLAG); context.load(evalNode.getLeftExpr().getValueType(), LHS); // < lhs context.load(evalNode.getRightExpr().getValueType(), RHS); // < lhs, rhs context.invokeVirtual(String.class, "concat", String.class, new Class[] {String.class}); context.pushNullFlag(true); context.methodvisitor.visitJumpInsn(Opcodes.GOTO, afterEnd); context.methodvisitor.visitLabel(ifNull); context.pushDummyValue(evalNode.getValueType()); context.pushNullFlag(false); context.methodvisitor.visitLabel(afterEnd); return evalNode; }
/** * It checks both expressions in a comparison operator are compatible to each other. */ private static void verifyComparisonOperator(VerificationState state, BinaryEval expr) { if (!isCompatibleType(expr.getLeftExpr().getValueType(), expr.getRightExpr().getValueType())) { state.addVerification(new UndefinedOperatorException(expr.toString())); } }
/** * Split the left term and transform it into the right deep expression. * * @param binary - notice the left term of this expr will be eliminated * after done. * @return the separated expression changed into the right deep expression. * For example, the expr 'x * y' is transformed into '* x'. * */ public static PartialBinaryExpr splitLeftTerm(BinaryEval binary) { if (!(EvalType.isArithmeticOperator(binary.getType()))) { throw new AlgebraicException("Invalid algebraic operation: " + binary); } if (binary.getLeftExpr() instanceof BinaryEval) { return splitLeftTerm((BinaryEval) binary.getLeftExpr()); } PartialBinaryExpr splitted = new PartialBinaryExpr(binary.getType(), null, binary.getLeftExpr()); binary.setLeftExpr(null); return splitted; }
/** * Split the left term and transform it into the right deep expression. * * @param binary - to be splited * @return the separated expression changed into the right deep expression. * For example, the expr 'x * y' is transformed into '* y'. * * @throws CloneNotSupportedException */ public static PartialBinaryExpr splitRightTerm(BinaryEval binary) { if (!(EvalType.isArithmeticOperator(binary.getType()))) { throw new AlgebraicException("Invalid algebraic operation: " + binary); } if (binary.getRightExpr() instanceof BinaryEval) { return splitRightTerm((BinaryEval) binary.getRightExpr()); } PartialBinaryExpr splitted = new PartialBinaryExpr(binary.getType(), null, binary.getRightExpr()); binary.setRightExpr(null); return splitted; }
@Test public void testOrTest() { MockTrueEval trueExpr = new MockTrueEval(); MockFalseExpr falseExpr = new MockFalseExpr(); BinaryEval orExpr = new BinaryEval(EvalType.OR, trueExpr, trueExpr); orExpr.bind(null, null); assertTrue(orExpr.eval(null).asBool()); orExpr = new BinaryEval(EvalType.OR, falseExpr, trueExpr); orExpr.bind(null, null); assertTrue(orExpr.eval(null).asBool()); orExpr = new BinaryEval(EvalType.OR, trueExpr, falseExpr); orExpr.bind(null, null); assertTrue(orExpr.eval(null).asBool()); orExpr = new BinaryEval(EvalType.OR, falseExpr, falseExpr); orExpr.bind(null, null); assertFalse(orExpr.eval(null).asBool()); }
@Test public final void testGetReturnType() { ConstEval e1; ConstEval e2; // PLUS e1 = new ConstEval(DatumFactory.createInt4(9)); e2 = new ConstEval(DatumFactory.createInt4(34)); BinaryEval expr = new BinaryEval(EvalType.PLUS, e1, e2); assertEquals(Type.Int4, expr.getValueType()); expr = new BinaryEval(EvalType.LTH, e1, e2); assertTrue(expr.bind(null, null).eval(null).asBool()); assertEquals(Type.Bool, expr.getValueType()); e1 = new ConstEval(DatumFactory.createFloat8(9.3)); e2 = new ConstEval(DatumFactory.createFloat8(34.2)); expr = new BinaryEval(EvalType.PLUS, e1, e2); assertEquals(Type.Float8, expr.getValueType()); }
private static void checkDivisionByZero(VerificationState state, BinaryEval evalNode) { if (evalNode.getRightExpr().getType() == EvalType.CONST) { ConstEval constEval = evalNode.getRightExpr(); if (constEval.getValue().asFloat8() == 0) { state.addVerification(new TajoException(Errors.ResultCode.DIVISION_BY_ZERO, evalNode.toString())); } } }
BinaryEval joinQual = new BinaryEval(EvalType.EQUAL , new FieldEval(new Column("default.n.n_name", Type.TEXT)) , new ConstEval(new TextDatum("MOROCCO")) if (!entry.getValue()) { Preconditions.checkArgument(false, "SelectionQual not found. -> required JoinQual:" + entry.getKey().toJson());
expr = new BinaryEval(EvalType.LTH, e1, e2); assertTrue(expr.bind(null, null).eval(null).asBool()); expr = new BinaryEval(EvalType.LEQ, e1, e2); assertTrue(expr.bind(null, null).eval(null).asBool()); expr = new BinaryEval(EvalType.LTH, e2, e1); assertFalse(expr.bind(null, null).eval(null).asBool()); expr = new BinaryEval(EvalType.LEQ, e2, e1); assertFalse(expr.bind(null, null).eval(null).asBool()); expr = new BinaryEval(EvalType.GTH, e2, e1); assertTrue(expr.bind(null, null).eval(null).asBool()); expr = new BinaryEval(EvalType.GEQ, e2, e1); assertTrue(expr.bind(null, null).eval(null).asBool()); expr = new BinaryEval(EvalType.GTH, e1, e2); assertFalse(expr.bind(null, null).eval(null).asBool()); expr = new BinaryEval(EvalType.GEQ, e1, e2); assertFalse(expr.bind(null, null).eval(null).asBool()); BinaryEval plus = new BinaryEval(EvalType.PLUS, e1, e2); expr = new BinaryEval(EvalType.LTH, e1, plus); assertTrue(expr.bind(null, null).eval(null).asBool()); expr = new BinaryEval(EvalType.LEQ, e1, plus); assertTrue(expr.bind(null, null).eval(null).asBool()); expr = new BinaryEval(EvalType.LTH, plus, e1); assertFalse(expr.bind(null, null).eval(null).asBool()); expr = new BinaryEval(EvalType.LEQ, plus, e1); assertFalse(expr.bind(null, null).eval(null).asBool()); expr = new BinaryEval(EvalType.GTH, plus, e1);
@Test public final void testEquals() throws CloneNotSupportedException { ConstEval e1; ConstEval e2; // PLUS e1 = new ConstEval(DatumFactory.createInt4(34)); e2 = new ConstEval(DatumFactory.createInt4(34)); assertEquals(e1, e2); BinaryEval plus1 = new BinaryEval(EvalType.PLUS, e1, e2); BinaryEval plus2 = new BinaryEval(EvalType.PLUS, e2, e1); assertEquals(plus1, plus2); ConstEval e3 = new ConstEval(DatumFactory.createInt4(29)); BinaryEval plus3 = new BinaryEval(EvalType.PLUS, e1, e3); assertFalse(plus1.equals(plus3)); // LTH ConstEval e4 = new ConstEval(DatumFactory.createInt4(9)); ConstEval e5 = new ConstEval(DatumFactory.createInt4(34)); BinaryEval compExpr1 = new BinaryEval(EvalType.LTH, e4, e5); assertCloneEqual(compExpr1); ConstEval e6 = new ConstEval(DatumFactory.createInt4(9)); ConstEval e7 = new ConstEval(DatumFactory.createInt4(34)); BinaryEval compExpr2 = new BinaryEval(EvalType.LTH, e6, e7); assertCloneEqual(compExpr2); assertTrue(compExpr1.equals(compExpr2)); }
public EvalNode visitBinaryEval(EvalCodeGenContext context, Stack<EvalNode> stack, BinaryEval binaryEval) { super.visitBinaryEval(context, stack, binaryEval); if (EvalType.isStringPatternMatchOperator(binaryEval.getType())) { if (!context.symbols.containsKey(binaryEval)) { String fieldName = binaryEval.getType().name() + "_" + context.seqId++; context.symbols.put(binaryEval, fieldName); Class clazz = EvalCodeGenerator.getStringPatternEvalClass(binaryEval.getType()); context.classWriter.visitField(Opcodes.ACC_PRIVATE, fieldName, "L" + TajoGeneratorAdapter.getInternalName(clazz) + ";", null, null); } } else if (binaryEval.getType() == EvalType.IN) { if (!context.symbols.containsKey(binaryEval)) { String fieldName = binaryEval.getType().name() + "_" + context.seqId++; context.symbols.put(binaryEval, fieldName); context.classWriter.visitField(Opcodes.ACC_PRIVATE, fieldName, "L" + TajoGeneratorAdapter.getInternalName(InEval.class) + ";", null, null); } } return binaryEval; }
@Override public boolean equals(Object obj) { if (obj instanceof PartialBinaryExpr) { return super.equals(obj); } return false; }
@Override public EvalNode bind(EvalContext evalContext, Schema schema) { super.bind(evalContext, schema); compile(pattern); return this; }