(cid: rq::CId, ctx: &mut Context)
| 632 | } |
| 633 | |
| 634 | pub(super) fn translate_cid(cid: rq::CId, ctx: &mut Context) -> Result<ExprOrSource> { |
| 635 | if ctx.query.pre_projection { |
| 636 | log::debug!("translating {cid:?} pre projection"); |
| 637 | let decl = ctx.anchor.column_decls.get(&cid).expect("bad RQ ids"); |
| 638 | |
| 639 | Ok(match decl { |
| 640 | ColumnDecl::Compute(compute) => { |
| 641 | let window = compute.window.clone(); |
| 642 | let span = compute.expr.span; |
| 643 | |
| 644 | let prev_wf = ctx.query.window_function; |
| 645 | ctx.query.window_function = window.is_some(); |
| 646 | let expr = translate_expr(compute.expr.clone(), ctx)?; |
| 647 | ctx.query.window_function = prev_wf; |
| 648 | |
| 649 | if let Some(window) = window { |
| 650 | translate_windowed(expr, window, ctx, span)? |
| 651 | } else { |
| 652 | expr |
| 653 | } |
| 654 | } |
| 655 | ColumnDecl::RelationColumn(riid, _, col) => { |
| 656 | let column = match col.clone() { |
| 657 | rq::RelationColumn::Wildcard => translate_star(ctx, None)?, |
| 658 | rq::RelationColumn::Single(name) => name.unwrap(), |
| 659 | }; |
| 660 | let t = &ctx.anchor.relation_instances[riid]; |
| 661 | |
| 662 | let table_ident = t.table_ref.name.clone().map(Ident::from_name); |
| 663 | let ident = translate_ident(table_ident, Some(column), ctx); |
| 664 | sql_ast::Expr::CompoundIdentifier(ident).into() |
| 665 | } |
| 666 | }) |
| 667 | } else { |
| 668 | // translate into ident |
| 669 | let column_decl = &&ctx.anchor.column_decls[&cid]; |
| 670 | |
| 671 | let table_name = if let ColumnDecl::RelationColumn(riid, _, _) = column_decl { |
| 672 | let t = &ctx.anchor.relation_instances[riid]; |
| 673 | Some(t.table_ref.name.clone().unwrap()) |
| 674 | } else { |
| 675 | None |
| 676 | }; |
| 677 | |
| 678 | let column = match &column_decl { |
| 679 | ColumnDecl::RelationColumn(_, _, rq::RelationColumn::Wildcard) => { |
| 680 | translate_star(ctx, None)? |
| 681 | } |
| 682 | |
| 683 | _ => { |
| 684 | let name = ctx.anchor.column_names.get(&cid).cloned(); |
| 685 | name.expect("name of this column has not been to be set before generating SQL") |
| 686 | } |
| 687 | }; |
| 688 | |
| 689 | let ident = translate_ident(table_name.map(Ident::from_name), Some(column), ctx); |
| 690 | |
| 691 | log::debug!("translating {cid:?} post projection: {ident:?}"); |
no test coverage detected