Returns a vector of (column_name, default_expr) pairs
(
&self,
columns: &Vec<SQLColumnDef>,
planner_context: &mut PlannerContext,
)
| 503 | |
| 504 | /// Returns a vector of (column_name, default_expr) pairs |
| 505 | pub(super) fn build_column_defaults( |
| 506 | &self, |
| 507 | columns: &Vec<SQLColumnDef>, |
| 508 | planner_context: &mut PlannerContext, |
| 509 | ) -> Result<Vec<(String, Expr)>> { |
| 510 | let mut column_defaults = vec![]; |
| 511 | // Default expressions are restricted, column references are not allowed |
| 512 | let empty_schema = DFSchema::empty(); |
| 513 | let error_desc = |e: DataFusionError| match e { |
| 514 | DataFusionError::SchemaError(ref err, _) |
| 515 | if matches!(**err, SchemaError::FieldNotFound { .. }) => |
| 516 | { |
| 517 | plan_datafusion_err!( |
| 518 | "Column reference is not allowed in the DEFAULT expression : {}", |
| 519 | e |
| 520 | ) |
| 521 | } |
| 522 | _ => e, |
| 523 | }; |
| 524 | |
| 525 | for column in columns { |
| 526 | if let Some(default_sql_expr) = |
| 527 | column.options.iter().find_map(|o| match &o.option { |
| 528 | ColumnOption::Default(expr) => Some(expr), |
| 529 | _ => None, |
| 530 | }) |
| 531 | { |
| 532 | let default_expr = self |
| 533 | .sql_to_expr(default_sql_expr.clone(), &empty_schema, planner_context) |
| 534 | .map_err(error_desc)?; |
| 535 | column_defaults.push(( |
| 536 | self.ident_normalizer.normalize(column.name.clone()), |
| 537 | default_expr, |
| 538 | )); |
| 539 | } |
| 540 | } |
| 541 | Ok(column_defaults) |
| 542 | } |
| 543 | |
| 544 | /// Apply the given TableAlias to the input plan |
| 545 | pub(crate) fn apply_table_alias( |