public static LogicalExpression createCast(MajorType type, ExpressionPosition ep, LogicalExpression expr){ return new CastExpression(expr, type, ep); }
@Override public Void visitCastExpression(CastExpression e, StringBuilder sb) throws RuntimeException { MajorType mt = e.getMajorType(); e.getInput().accept(this, sb); sb.append(" ) as "); sb.append(mt.getMinorType().name());
LogicalExpression input = e.getInput().accept(this, functionLookupContext); MajorType newMajor = e.getMajorType(); // Output type if (castEqual(e.getPosition(), input.getMajorType(), newMajor)) { return input; // don't do pointless cast. return new CastExpression(input, e.getMajorType(), e.getPosition()); } else if (newMinor == MinorType.NULL) { return new TypedNullConstant(e.getMajorType().toBuilder().setMode(DataMode.OPTIONAL).build()); } else { MajorType type = e.getMajorType(); FunctionCall fc = new FunctionCall(castFuncWithType, newArgs, e.getPosition()); return fc.accept(this, functionLookupContext);
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof CastExpression)) { return false; } CastExpression other = (CastExpression) obj; return this.input.equals(other.input) && (this.getMajorType().hasMinorType() == other.getMajorType().hasMinorType()); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof CastExpression)) { return false; } CastExpression other = (CastExpression) obj; return this.input.equals(other.input) && (this.getMajorType().hasMinorType() == other.getMajorType().hasMinorType()); }
@Override public Boolean visitCastExpression(CastExpression e, ErrorCollector errors) { return e.getInput().accept(this, errors); }
boolean castIsCompatible(CastExpression castExpr, Collection<LogicalExpression> indexFields) { for (LogicalExpression indexExpr : indexFields) { if (indexExpr.getClass() != castExpr.getClass()) { continue; } CastExpression indexCastExpr = (CastExpression)indexExpr; // we compare input using equals because we know we are comparing SchemaPath, // if we extend to support other expression, make sure the equals of that expression // is implemented properly, otherwise it will fall to identity comparison if (!castExpr.getInput().equals(indexCastExpr.getInput()) ) { continue; } if (castExpr.getMajorType().getMinorType() != indexCastExpr.getMajorType().getMinorType()) { continue; } return true; } return false; }
@Override public Boolean visitCastExpression(CastExpression e, LogicalExpression value) throws RuntimeException { if (!(value instanceof CastExpression)) { return false; } if (!e.getMajorType().equals(value.getMajorType())) { return false; } return checkChildren(e, value); }
public static LogicalExpression createCast(MajorType type, ExpressionPosition ep, LogicalExpression expr){ return new CastExpression(expr, type, ep); }
@Override public Boolean visitCastExpression(CastExpression e, ErrorCollector value) throws RuntimeException { return e.getInput().accept(this, value); }
@Override public RexNode visitCastExpression(CastExpression e, Void value) throws RuntimeException { RexNode convertedInput = e.getInput().accept(this, null); String typeStr = e.getMajorType().getMinorType().toString(); if (SqlTypeName.get(typeStr) == null) { logger.debug("SqlTypeName could not find {}", typeStr); } SqlTypeName typeName = TypeInferenceUtils.getCalciteTypeFromDrillType(e.getMajorType().getMinorType()); RelDataType targetType = TypeInferenceUtils.createCalciteTypeWithNullability( inputRel.getCluster().getTypeFactory(), typeName, true); return builder.makeCast(targetType, convertedInput); }
if (castExprInFilter.getMajorType().getMinorType() == TypeProtos.MinorType.VARCHAR && (castExprInFilter.getMajorType().getPrecision() > relatedPaths.get(idxFound).getMajorType().getPrecision())) { continue;
@Override public Void visitCastExpression(CastExpression e, ErrorCollector value) throws RuntimeException { return e.getInput().accept(this, value); }
if (indexed instanceof CastExpression) { final CastExpression indexedCast = (CastExpression) indexed; if (expr.getInput().equals(indexedCast.getInput()) && expr.getMajorType().getMinorType().equals(indexedCast.getMajorType().getMinorType()) && expr.getMajorType().getPrecision() < indexedCast.getMajorType().getPrecision()) { toRewriteEqualCastMap.put(entry.getKey(), entry.getValue());
private void init() { int count = 0; for (LogicalExpression indexedExpr : indexDesc.getIndexColumns()) { if (!(indexedExpr instanceof SchemaPath)) { hasFunctionalField = true; SchemaPath functionalFieldPath = SchemaPath.getSimplePath("$"+count); newPathsForIndexedFunction.add(functionalFieldPath); // now we handle only cast expression if (indexedExpr instanceof CastExpression) { // We handle only CAST directly on SchemaPath for now. SchemaPath pathBeingCasted = (SchemaPath)((CastExpression) indexedExpr).getInput(); addTargetPathForOriginalPath(pathBeingCasted, functionalFieldPath); addPathInExpr(indexedExpr, pathBeingCasted); exprToConvert.put(indexedExpr, functionalFieldPath); allPathsInFunction.add(pathBeingCasted); } count++; } } }
@Override public Void visitCastExpression(CastExpression e, StringBuilder sb) throws RuntimeException { MajorType mt = e.getMajorType(); e.getInput().accept(this, sb); sb.append(" ) as "); sb.append(mt.getMinorType().name());
@Override public Boolean visitCastExpression(CastExpression e, IdentityHashMap<LogicalExpression, Object> value) throws RuntimeException { return e.getInput().accept(this, value); }
@Override public Boolean visitCastExpression(CastExpression e, ErrorCollector errors) { return e.getInput().accept(this, errors); }