Skip to content

Commit

Permalink
feat(frontend): display UDF calls more concisely (#20127)
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Chien <[email protected]>
  • Loading branch information
stdrc authored Jan 13, 2025
1 parent b30c7e0 commit e1d3908
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/frontend/src/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use risingwave_expr::aggregate::PbAggKind;
use risingwave_expr::expr::build_from_prost;
use risingwave_pb::expr::expr_node::RexNode;
use risingwave_pb::expr::{ExprNode, ProjectSetSelectItem};
use user_defined_function::UserDefinedFunctionDisplay;

use crate::error::{ErrorCode, Result as RwResult};

Expand Down Expand Up @@ -1138,7 +1139,16 @@ impl std::fmt::Debug for ExprDisplay<'_> {
// TODO: WindowFunctionCallVerboseDisplay
write!(f, "{:?}", x)
}
ExprImpl::UserDefinedFunction(x) => write!(f, "{:?}", x),
ExprImpl::UserDefinedFunction(x) => {
write!(
f,
"{:?}",
UserDefinedFunctionDisplay {
func_call: x,
input_schema: self.input_schema
}
)
}
ExprImpl::Parameter(x) => write!(f, "{:?}", x),
ExprImpl::Now(x) => write!(f, "{:?}", x),
}
Expand Down
23 changes: 21 additions & 2 deletions src/frontend/src/expr/user_defined_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
use std::sync::Arc;

use itertools::Itertools;
use risingwave_common::catalog::FunctionId;
use risingwave_common::catalog::{FunctionId, Schema};
use risingwave_common::types::DataType;

use super::{Expr, ExprImpl};
use super::{Expr, ExprDisplay, ExprImpl};
use crate::catalog::function_catalog::{FunctionCatalog, FunctionKind};

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -102,3 +102,22 @@ impl Expr for UserDefinedFunction {
}
}
}

pub struct UserDefinedFunctionDisplay<'a> {
pub func_call: &'a UserDefinedFunction,
pub input_schema: &'a Schema,
}

impl std::fmt::Debug for UserDefinedFunctionDisplay<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let that = self.func_call;
let mut builder = f.debug_tuple(&that.catalog.name);
that.args.iter().for_each(|arg| {
builder.field(&ExprDisplay {
expr: arg,
input_schema: self.input_schema,
});
});
builder.finish()
}
}

0 comments on commit e1d3908

Please sign in to comment.