@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; }
@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 EvalNode visitBinaryEval(EvalCodeGenContext context, Stack<EvalNode> stack, BinaryEval binaryEval) { if (EvalType.isLogicalOperator(binaryEval.getType())) { return visitAndOrEval(context, binaryEval, stack); } else if (EvalType.isArithmeticOperator(binaryEval.getType())) { return visitArithmeticEval(context, binaryEval, stack); } else if (EvalType.isComparisonOperator(binaryEval.getType())) { return visitComparisonEval(context, binaryEval, stack); } else if (binaryEval.getType() == EvalType.CONCATENATE) { return visitStringConcat(context, binaryEval, stack); } else if (binaryEval.getType() == EvalType.LIKE || binaryEval.getType() == EvalType.SIMILAR_TO || binaryEval.getType() == EvalType.REGEX) { return visitStringPatternMatch(context, binaryEval, stack); } else if (binaryEval.getType() == EvalType.IN) { return visitInPredicate(context, binaryEval, stack); } else { stack.push(binaryEval); visit(context, binaryEval.getLeftExpr(), stack); visit(context, binaryEval.getRightExpr(), stack); stack.pop(); return binaryEval; } }
public EvalNode visitBinaryEval(EvalCodeGenContext context, Stack<EvalNode> stack, BinaryEval binaryEval) { if (EvalType.isLogicalOperator(binaryEval.getType())) { return visitAndOrEval(context, binaryEval, stack); } else if (EvalType.isArithmeticOperator(binaryEval.getType())) { return visitArithmeticEval(context, binaryEval, stack); } else if (EvalType.isComparisonOperator(binaryEval.getType())) { return visitComparisonEval(context, binaryEval, stack); } else if (binaryEval.getType() == EvalType.CONCATENATE) { return visitStringConcat(context, binaryEval, stack); } else if (binaryEval.getType() == EvalType.LIKE || binaryEval.getType() == EvalType.SIMILAR_TO || binaryEval.getType() == EvalType.REGEX) { return visitStringPatternMatch(context, binaryEval, stack); } else if (binaryEval.getType() == EvalType.IN) { return visitInPredicate(context, binaryEval, stack); } else { stack.push(binaryEval); visit(context, binaryEval.getLeftExpr(), stack); visit(context, binaryEval.getRightExpr(), stack); stack.pop(); return binaryEval; } }
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; }
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; }
/** * 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; }
/** * 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 - 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; }
public EvalNode visitAndOrEval(EvalCodeGenContext context, BinaryEval evalNode, Stack<EvalNode> stack) { stack.push(evalNode); visit(context, evalNode.getLeftExpr(), stack); context.pop(); int LHS = context.istore(); visit(context, evalNode.getRightExpr(), stack); context.pop(); int RHS = context.istore(); stack.pop(); if (evalNode.getType() == EvalType.AND) { context.methodvisitor.visitFieldInsn(Opcodes.GETSTATIC, org.apache.tajo.org.objectweb.asm.Type.getInternalName(EvalCodeGenerator.class), "AND_LOGIC", "[[B"); } else if (evalNode.getType() == EvalType.OR) { context.methodvisitor.visitFieldInsn(Opcodes.GETSTATIC, org.apache.tajo.org.objectweb.asm.Type.getInternalName(EvalCodeGenerator.class), "OR_LOGIC", "[[B"); } else { throw new CompilationError("visitAndOrEval() cannot generate the code at " + evalNode); } context.load(evalNode.getLeftExpr().getValueType(), LHS); context.methodvisitor.visitInsn(Opcodes.AALOAD); context.load(evalNode.getRightExpr().getValueType(), RHS); context.methodvisitor.visitInsn(Opcodes.BALOAD); // get three valued logic number from the AND/OR_LOGIC array context.methodvisitor.visitInsn(Opcodes.DUP); // three valued logic number x 2, three valued logic number can be null flag. return evalNode; }
public EvalNode visitAndOrEval(EvalCodeGenContext context, BinaryEval evalNode, Stack<EvalNode> stack) { stack.push(evalNode); visit(context, evalNode.getLeftExpr(), stack); context.pop(); int LHS = context.istore(); visit(context, evalNode.getRightExpr(), stack); context.pop(); int RHS = context.istore(); stack.pop(); if (evalNode.getType() == EvalType.AND) { context.methodvisitor.visitFieldInsn(Opcodes.GETSTATIC, org.apache.tajo.org.objectweb.asm.Type.getInternalName(EvalCodeGenerator.class), "AND_LOGIC", "[[B"); } else if (evalNode.getType() == EvalType.OR) { context.methodvisitor.visitFieldInsn(Opcodes.GETSTATIC, org.apache.tajo.org.objectweb.asm.Type.getInternalName(EvalCodeGenerator.class), "OR_LOGIC", "[[B"); } else { throw new CompilationError("visitAndOrEval() cannot generate the code at " + evalNode); } context.load(evalNode.getLeftExpr().getValueType(), LHS); context.methodvisitor.visitInsn(Opcodes.AALOAD); context.load(evalNode.getRightExpr().getValueType(), RHS); context.methodvisitor.visitInsn(Opcodes.BALOAD); // get three valued logic number from the AND/OR_LOGIC array context.methodvisitor.visitInsn(Opcodes.DUP); // three valued logic number x 2, three valued logic number can be null flag. return evalNode; }
EvalNode left = eval.getLeftExpr(); EvalNode right = eval.getRightExpr(); EvalType type = eval.getType();
EvalNode left = eval.getLeftExpr(); EvalNode right = eval.getRightExpr(); EvalType type = eval.getType();
@Test public final void testGetContainExprs() throws CloneNotSupportedException, TajoException { Expr expr = analyzer.parse(QUERIES[1]); LogicalPlan plan = planner.createPlan(defaultContext, expr, true); List<Target> targets = plan.getRootBlock().getRawTargets(); Column col1 = new Column("default.people.score", TajoDataTypes.Type.INT4); Collection<EvalNode> exprs = EvalTreeUtil.getContainExpr(targets.get(0).getEvalTree(), col1); BinaryEval node = (BinaryEval) exprs.iterator().next(); assertEquals(EvalType.LTH, node.getType()); assertEquals(EvalType.PLUS, node.getLeftExpr().getType()); assertEquals(new ConstEval(DatumFactory.createInt4(4)), node.getRightExpr()); Column col2 = new Column("default.people.age", TajoDataTypes.Type.INT4); exprs = EvalTreeUtil.getContainExpr(targets.get(1).getEvalTree(), col2); node = (BinaryEval) exprs.iterator().next(); assertEquals(EvalType.GTH, node.getType()); assertEquals("default.people.age", node.getLeftExpr().getName()); assertEquals(new ConstEval(DatumFactory.createInt4(5)), node.getRightExpr()); }
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; }
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; }
@Test public final void testTranspose() throws TajoException { Column col1 = new Column("default.people.score", TajoDataTypes.Type.INT4); EvalNode node = getRootSelection(QUERIES[3]); // we expect that score < 3 BinaryEval transposed = (BinaryEval) AlgebraicUtil.transpose(node, col1); assertEquals(EvalType.GTH, transposed.getType()); FieldEval field = transposed.getLeftExpr(); assertEquals(col1, field.getColumnRef()); assertEquals(1, transposed.getRightExpr().bind(null, null).eval(null).asInt4()); node = getRootSelection(QUERIES[4]); // we expect that score < 3 transposed = (BinaryEval) AlgebraicUtil.transpose(node, col1); assertEquals(EvalType.LTH, transposed.getType()); field = transposed.getLeftExpr(); assertEquals(col1, field.getColumnRef()); assertEquals(2, transposed.getRightExpr().bind(null, null).eval(null).asInt4()); }
@Test public final void testGetCNF() throws TajoException { // "select score from people where score < 10 and 4 < score " EvalNode node = getRootSelection(QUERIES[5]); EvalNode [] cnf = AlgebraicUtil.toConjunctiveNormalFormArray(node); Column col1 = new Column("default.people.score", TajoDataTypes.Type.INT4); assertEquals(2, cnf.length); BinaryEval first = (BinaryEval) cnf[0]; BinaryEval second = (BinaryEval) cnf[1]; FieldEval field = first.getLeftExpr(); assertEquals(col1, field.getColumnRef()); assertEquals(EvalType.LTH, first.getType()); assertEquals(10, first.getRightExpr().bind(null, null).eval(null).asInt4()); field = second.getRightExpr(); assertEquals(col1, field.getColumnRef()); assertEquals(EvalType.LTH, second.getType()); assertEquals(4, second.getLeftExpr().bind(null, null).eval(null).asInt4()); }
context.ifCmp(evalNode.getLeftExpr().getValueType(), evalNode.getType(), ifNotMatched);