MCPcopy Create free account
hub / github.com/apache/datafusion / coerce_exprs_for_schema

Function coerce_exprs_for_schema

datafusion/expr/src/expr_rewriter/mod.rs:246–281  ·  view source on GitHub ↗
(
    exprs: Vec<Expr>,
    src_schema: &DFSchema,
    dst_schema: &DFSchema,
)

Source from the content-addressed store, hash-verified

244}
245
246fn coerce_exprs_for_schema(
247 exprs: Vec<Expr>,
248 src_schema: &DFSchema,
249 dst_schema: &DFSchema,
250) -> Result<Vec<Expr>> {
251 exprs
252 .into_iter()
253 .enumerate()
254 .map(|(idx, expr)| {
255 let new_type = dst_schema.field(idx).data_type();
256 if new_type != &expr.get_type(src_schema)? {
257 match expr {
258 Expr::Alias(Alias { expr, name, .. }) => {
259 Ok(expr.cast_to(new_type, src_schema)?.alias(name))
260 }
261 #[expect(deprecated)]
262 Expr::Wildcard { .. } => Ok(expr),
263 _ => {
264 match expr {
265 // maintain the original name when casting a column, to avoid the
266 // tablename being added to it when not explicitly set by the query
267 // (see: https://github.com/apache/datafusion/issues/18818)
268 Expr::Column(ref column) => {
269 let name = column.name().to_owned();
270 Ok(expr.cast_to(new_type, src_schema)?.alias(name))
271 }
272 _ => Ok(expr.cast_to(new_type, src_schema)?),
273 }
274 }
275 }
276 } else {
277 Ok(expr)
278 }
279 })
280 .collect::<Result<_>>()
281}
282
283/// Recursively un-alias an expressions
284#[inline]

Callers 1

Calls 8

mapMethod · 0.45
into_iterMethod · 0.45
data_typeMethod · 0.45
fieldMethod · 0.45
get_typeMethod · 0.45
aliasMethod · 0.45
cast_toMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…