public static LogicalExpression getNumericExpression(String sign, String s, ExpressionPosition ep) { String numStr = (sign == null) ? s : sign+s; try { int a = Integer.parseInt(numStr); return new IntExpression(a, ep); } catch (Exception e) { } try { long l = Long.parseLong(numStr); return new LongExpression(l, ep); } catch (Exception e) { } try { double d = Double.parseDouble(numStr); return new DoubleExpression(d, ep); } catch (Exception e) { } throw new IllegalArgumentException(String.format("Unable to parse string %s as integer or floating point number.", numStr)); }
public static LogicalExpression getNumericExpression(String sign, String s, ExpressionPosition ep) { String numStr = (sign == null) ? s : sign+s; try { int a = Integer.parseInt(numStr); return new IntExpression(a, ep); } catch (Exception e) { } try { long l = Long.parseLong(numStr); return new LongExpression(l, ep); } catch (Exception e) { } try { double d = Double.parseDouble(numStr); return new DoubleExpression(d, ep); } catch (Exception e) { } throw new IllegalArgumentException(String.format("Unable to parse string %s as integer or floating point number.", numStr)); }
/** * Wraps the comparison function in an If-statement which compares the types first, evaluating the comaprison function only * if the types are equivialent * * @param comparisonFunction * @param args * @return */ private static LogicalExpression getTypeComparisonFunction(LogicalExpression comparisonFunction, HoldingContainer... args) { List<LogicalExpression> argExpressions = Lists.newArrayList(); List<MajorType> argTypes = Lists.newArrayList(); for(HoldingContainer c : args) { argTypes.add(c.getMajorType()); argExpressions.add(new HoldingContainerExpression(c)); } FunctionCall call = new FunctionCall("compareType", argExpressions, ExpressionPosition.UNKNOWN); List<LogicalExpression> newArgs = Lists.newArrayList(); newArgs.add(call); newArgs.add(new IntExpression(0, ExpressionPosition.UNKNOWN)); FunctionCall notEqual = new FunctionCall("not_equal", newArgs, ExpressionPosition.UNKNOWN); IfExpression.IfCondition ifCondition = new IfCondition(notEqual, call); IfExpression ifExpression = IfExpression.newBuilder().setIfCondition(ifCondition).setElse(comparisonFunction).build(); return ifExpression; }
castArgs.add(new ValueExpressions.IntExpression(toType.getPrecision(), null)); castArgs.add(new ValueExpressions.IntExpression(toType.getScale(), null)); } else if (!Types.isFixedWidthType(toType) && !Types.isUnion(toType)) {
newArgs.add(new ValueExpressions.IntExpression(type.getPrecision(), null)); newArgs.add(new ValueExpressions.IntExpression(type.getScale(), null)); } else if (!Types.isFixedWidthType(type)) { //VarLen type newArgs.add(new ValueExpressions.LongExpression(type.getPrecision(), null));
private void setupBuild64Hash(ClassGenerator<Hash64> cg, MappingSet incomingMapping, VectorAccessible batch, LogicalExpression[] keyExprs, TypedFieldId[] toHashKeyFieldIds) throws SchemaChangeException { cg.setMappingSet(incomingMapping); if (keyExprs == null || keyExprs.length == 0) { cg.getEvalBlock()._return(JExpr.lit(0)); } String seedValue = "seedValue"; String fieldId = "fieldId"; LogicalExpression seed = ValueExpressions.getParameterExpression(seedValue, Types.required(TypeProtos.MinorType.INT)); LogicalExpression fieldIdParamExpr = ValueExpressions.getParameterExpression(fieldId, Types.required(TypeProtos.MinorType.INT)); ClassGenerator.HoldingContainer fieldIdParamHolder = cg.addExpr(fieldIdParamExpr); int i = 0; for (LogicalExpression expr : keyExprs) { TypedFieldId targetTypeFieldId = toHashKeyFieldIds[i]; ValueExpressions.IntExpression targetBuildFieldIdExp = new ValueExpressions.IntExpression(targetTypeFieldId.getFieldIds()[0], ExpressionPosition.UNKNOWN); JFieldRef targetBuildSideFieldId = cg.addExpr(targetBuildFieldIdExp, ClassGenerator.BlkCreateMode.TRUE_IF_BOUND).getValue(); JBlock ifBlock = cg.getEvalBlock()._if(fieldIdParamHolder.getValue().eq(targetBuildSideFieldId))._then(); cg.nestEvalBlock(ifBlock); LogicalExpression hashExpression = HashPrelUtil.getHash64Expression(expr, seed, true); LogicalExpression materializedExpr = ExpressionTreeMaterializer.materializeAndCheckErrors(hashExpression, batch, context.getFunctionRegistry()); ClassGenerator.HoldingContainer hash = cg.addExpr(materializedExpr, ClassGenerator.BlkCreateMode.TRUE_IF_BOUND); ifBlock._return(hash.getValue()); cg.unNestEvalBlock(); i++; } cg.getEvalBlock()._return(JExpr.lit(0)); }
public static LogicalExpression getInt(int i){ return new IntExpression(i, ExpressionPosition.UNKNOWN); }
@Override public LogicalExpression visitIntConstant(IntExpression intExpr, Void value) throws RuntimeException { return new IntExpression(intExpr.getInt(), intExpr.getPosition()); }
public static LogicalExpression getInt(int i){ return new IntExpression(i, ExpressionPosition.UNKNOWN); }