MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / rewrite_expr

Method rewrite_expr

src/sql/src/plan/transform_ast.rs:449–476  ·  view source on GitHub ↗
(&mut self, expr: &Expr<Aug>)

Source from the content-addressed store, hash-verified

447 }
448
449 fn rewrite_expr(&mut self, expr: &Expr<Aug>) -> Option<(Ident, Expr<Aug>)> {
450 match expr {
451 Expr::Function(function) => self.rewrite_function(function),
452 // Rewrites special keywords that SQL considers to be function calls
453 // to actual function calls. For example, `SELECT current_timestamp`
454 // is rewritten to `SELECT current_timestamp()`.
455 Expr::Identifier(ident) if ident.len() == 1 => {
456 let ident = normalize::ident(ident[0].clone());
457 let fn_ident = match ident.as_str() {
458 "current_role" => Some("current_user"),
459 "current_schema" | "current_timestamp" | "current_user" | "session_user"
460 | "current_catalog" => Some(ident.as_str()),
461 _ => None,
462 };
463 match fn_ident {
464 None => None,
465 Some(fn_ident) => {
466 let expr = Expr::call_nullary(
467 self.scx
468 .dangerous_resolve_name(vec![PG_CATALOG_SCHEMA, fn_ident]),
469 );
470 Some((Ident::new_unchecked(ident), expr))
471 }
472 }
473 }
474 _ => None,
475 }
476 }
477}
478
479impl<'ast> VisitMut<'ast, Aug> for FuncRewriter<'_> {

Callers 2

visit_select_item_mutMethod · 0.80
visit_expr_mutMethod · 0.80

Calls 6

identFunction · 0.85
rewrite_functionMethod · 0.80
lenMethod · 0.45
cloneMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected