@Override public EvalNode visitCastExpr(Context ctx, Stack<Expr> stack, CastExpr expr) throws TajoException { EvalNode child = super.visitCastExpr(ctx, stack, expr); // if it is a casting operation for a constant value, it will be pre-computed and casted to a constant value. if (child.getType() == EvalType.CONST) { ConstEval constEval = (ConstEval) child; // some cast operation may require earlier evaluation with timezone. return new ConstEval( DatumFactory.cast(constEval.getValue(), LogicalPlanner.convertDataType(expr.getTarget()), ctx.timeZone)); } else { return new CastEval(ctx.queryContext, child, LogicalPlanner.convertDataType(expr.getTarget())); } }
@Override protected EvalNode visitConst(Object o, ConstEval evalNode, Stack<EvalNode> stack) { exprs.push(convertDatumToExpr(evalNode.getValueType().kind(), evalNode.getValue())); return super.visitConst(o, evalNode, stack); }
public static void emitConstEval(TajoGeneratorAdapter adapter, MethodVisitor mv, ConstEval evalNode) { mv.visitLdcInsn(evalNode.toJson()); adapter.invokeStatic(EvalCodeGenerator.class, "createConstEval", ConstEval.class, new Class[] {String.class}); }
public static ConstEval newConst(Datum datum) { return new ConstEval(datum); }
@Override protected EvalNode visitConst(Context context, ConstEval constant, Stack<EvalNode> stack) { context.sb.append(convertDatumToSQLLiteral(constant.getValue())).append(" "); return constant; }
@Override public EvalNode visitConst(EvalCodeGenContext context, ConstEval constEval, Stack<EvalNode> stack) { if (constEval.getValueType().getType() == TajoDataTypes.Type.INTERVAL) { if (!context.symbols.containsKey(constEval)) { String fieldName = constEval.getValueType().getType().name() + "_" + context.seqId++; context.symbols.put(constEval, fieldName); context.classWriter.visitField(Opcodes.ACC_PRIVATE, fieldName, "L" + TajoGeneratorAdapter.getInternalName(IntervalDatum.class) + ";", null, null); } } return constEval; }
public static ConstEval newConst(Datum datum) { return new ConstEval(datum); }
public PatternMatchPredicateEval(EvalType evalType, boolean not, EvalNode predicand, ConstEval pattern, boolean caseInsensitive) { super(evalType, predicand, pattern); this.not = not; this.pattern = pattern.getValue().asChars(); this.caseInsensitive = caseInsensitive; }
@Override public EvalNode visitConst(EvalCodeGenContext context, ConstEval constEval, Stack<EvalNode> stack) { if (constEval.getValueType().kind() == TajoDataTypes.Type.INTERVAL) { if (!context.symbols.containsKey(constEval)) { String fieldName = constEval.getValueType().kind().name() + "_" + context.seqId++; context.symbols.put(constEval, fieldName); context.classWriter.visitField(Opcodes.ACC_PRIVATE, fieldName, "L" + TajoGeneratorAdapter.getInternalName(IntervalDatum.class) + ";", null, null); } } return constEval; }
@Override public EvalNode visitNullLiteral(Context ctx, Stack<Expr> stack, NullLiteral expr) throws TajoException { return new ConstEval(NullDatum.get()); }
@Override public EvalNode visitCastExpr(Context ctx, Stack<Expr> stack, CastExpr expr) throws TajoException { EvalNode child = super.visitCastExpr(ctx, stack, expr); // if it is a casting operation for a constant value, it will be pre-computed and casted to a constant value. if (child.getType() == EvalType.CONST) { ConstEval constEval = (ConstEval) child; // some cast operation may require earlier evaluation with timezone. return new ConstEval( DatumFactory.cast(constEval.getValue(), LogicalPlanner.convertDataType(expr.getTarget()).getDataType(), ctx.timeZone)); } else { return new CastEval(ctx.queryContext, child, LogicalPlanner.convertDataType(expr.getTarget()).getDataType()); } }
public PatternMatchPredicateEval(EvalType evalType, boolean not, EvalNode predicand, ConstEval pattern, boolean caseInsensitive) { super(evalType, predicand, pattern); this.not = not; this.pattern = pattern.getValue().asChars(); this.caseInsensitive = caseInsensitive; }
@Override public EvalNode visitConst(EvalCodeGenContext context, ConstEval constEval, Stack<EvalNode> stack) { switch (constEval.getValueType().kind()) { case NULL_TYPE: context.push(constEval.getValue().asInt4()); break; case INT4: case DATE: context.push(constEval.getValue().asInt4()); break; case INT8: case TIMESTAMP: case TIME: context.push(constEval.getValue().asInt8()); break; case FLOAT4: context.push(constEval.getValue().asFloat4()); break; case FLOAT8: context.push(constEval.getValue().asFloat8()); break; case CHAR: case TEXT: context.push(constEval.getValue().asChars()); break; case INTERVAL: break;
public static void emitConstEval(TajoGeneratorAdapter adapter, MethodVisitor mv, ConstEval evalNode) { mv.visitLdcInsn(evalNode.toJson()); adapter.invokeStatic(EvalCodeGenerator.class, "createConstEval", ConstEval.class, new Class[] {String.class}); }
@Override public EvalNode visitNullLiteral(Context ctx, Stack<Expr> stack, NullLiteral expr) throws TajoException { return new ConstEval(NullDatum.get()); }
private EvalNode visitPatternMatchPredicate(Context ctx, Stack<Expr> stack, PatternMatchPredicate expr) throws TajoException { EvalNode field = visit(ctx, stack, expr.getPredicand()); ConstEval pattern = (ConstEval) visit(ctx, stack, expr.getPattern()); // A pattern is a const value in pattern matching predicates. // In a binary expression, the result is always null if a const value in left or right side is null. if (pattern.getValue() instanceof NullDatum) { return new ConstEval(NullDatum.get()); } else { if (expr.getType() == OpType.LikePredicate) { return new LikePredicateEval(expr.isNot(), field, pattern, expr.isCaseInsensitive()); } else if (expr.getType() == OpType.SimilarToPredicate) { return new SimilarToPredicateEval(expr.isNot(), field, pattern); } else { return new RegexPredicateEval(expr.isNot(), field, pattern, expr.isCaseInsensitive()); } } }
@Override protected EvalNode visitConst(Context context, ConstEval constant, Stack<EvalNode> stack) { context.sb.append(convertDatumToSQLLiteral(constant.getValue())).append(" "); return constant; }
@Override public EvalNode visitConst(EvalCodeGenContext context, ConstEval constEval, Stack<EvalNode> stack) { switch (constEval.getValueType().getType()) { case NULL_TYPE: context.push(constEval.getValue().asInt4()); break; case INT4: case DATE: context.push(constEval.getValue().asInt4()); break; case INT8: case TIMESTAMP: case TIME: context.push(constEval.getValue().asInt8()); break; case FLOAT4: context.push(constEval.getValue().asFloat4()); break; case FLOAT8: context.push(constEval.getValue().asFloat8()); break; case CHAR: case TEXT: context.push(constEval.getValue().asChars()); break; case INTERVAL: break;
@Override public EvalNode visitLiteral(Context ctx, Stack<Expr> stack, LiteralValue expr) throws TajoException { switch (expr.getValueType()) { case Boolean: return new ConstEval(DatumFactory.createBool(Boolean.parseBoolean(expr.getValue()))); case String: return new ConstEval(DatumFactory.createText(expr.getValue())); case Unsigned_Integer: return new ConstEval(DatumFactory.createInt4(expr.getValue())); case Unsigned_Large_Integer: return new ConstEval(DatumFactory.createInt8(expr.getValue())); case Unsigned_Float: return new ConstEval(DatumFactory.createFloat8(expr.getValue())); default: throw new RuntimeException("Unsupported type: " + expr.getValueType()); } }
private EvalNode visitPatternMatchPredicate(Context ctx, Stack<Expr> stack, PatternMatchPredicate expr) throws TajoException { EvalNode field = visit(ctx, stack, expr.getPredicand()); ConstEval pattern = (ConstEval) visit(ctx, stack, expr.getPattern()); // A pattern is a const value in pattern matching predicates. // In a binary expression, the result is always null if a const value in left or right side is null. if (pattern.getValue() instanceof NullDatum) { return new ConstEval(NullDatum.get()); } else { if (expr.getType() == OpType.LikePredicate) { return new LikePredicateEval(expr.isNot(), field, pattern, expr.isCaseInsensitive()); } else if (expr.getType() == OpType.SimilarToPredicate) { return new SimilarToPredicateEval(expr.isNot(), field, pattern); } else { return new RegexPredicateEval(expr.isNot(), field, pattern, expr.isCaseInsensitive()); } } }