MCPcopy Index your code
hub / github.com/apache/datafusion / cast_to_sql

Method cast_to_sql

datafusion/sql/src/unparser/expr.rs:1243–1269  ·  view source on GitHub ↗

Explicit type cast on ast::Expr::Value is not needed by underlying engine for certain types For example: CAST(Utf8("binary_value") AS Binary) and CAST(Utf8("dictionary_value") AS Dictionary)

(&self, expr: &Expr, field: &FieldRef)

Source from the content-addressed store, hash-verified

1241 // Explicit type cast on ast::Expr::Value is not needed by underlying engine for certain types
1242 // For example: CAST(Utf8("binary_value") AS Binary) and CAST(Utf8("dictionary_value") AS Dictionary)
1243 fn cast_to_sql(&self, expr: &Expr, field: &FieldRef) -> Result<ast::Expr> {
1244 let inner_expr = self.expr_to_sql_inner(expr)?;
1245 let data_type = field.data_type();
1246 match inner_expr {
1247 ast::Expr::Value(_) => match data_type {
1248 DataType::Dictionary(_, _) | DataType::Binary | DataType::BinaryView
1249 if field.metadata().is_empty() =>
1250 {
1251 Ok(inner_expr)
1252 }
1253 _ => Ok(ast::Expr::Cast {
1254 kind: ast::CastKind::Cast,
1255 expr: Box::new(inner_expr),
1256 data_type: self.arrow_dtype_to_ast_dtype(field)?,
1257 array: false,
1258 format: None,
1259 }),
1260 },
1261 _ => Ok(ast::Expr::Cast {
1262 kind: ast::CastKind::Cast,
1263 expr: Box::new(inner_expr),
1264 data_type: self.arrow_dtype_to_ast_dtype(field)?,
1265 array: false,
1266 format: None,
1267 }),
1268 }
1269 }
1270
1271 /// DataFusion ScalarValues sometimes require a ast::Expr to construct.
1272 /// For example ScalarValue::Date32(d) corresponds to the ast::Expr CAST('datestr' as DATE)

Callers 1

expr_to_sql_innerMethod · 0.80

Calls 6

newFunction · 0.85
expr_to_sql_innerMethod · 0.80
data_typeMethod · 0.45
is_emptyMethod · 0.45
metadataMethod · 0.45

Tested by

no test coverage detected