Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions crates/lance-graph/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,20 @@ pub enum ValueExpression {
Property(PropertyRef),
/// Literal value
Literal(PropertyValue),
/// Function call
Function {
/// Scalar function call (toLower, upper, etc.)
/// These are row-level functions that operate on individual values
ScalarFunction {
name: String,
args: Vec<ValueExpression>,
},
/// Aggregate function call (COUNT, SUM, AVG, MIN, MAX, COLLECT)
/// These functions operate across multiple rows and support DISTINCT
AggregateFunction {
name: String,
args: Vec<ValueExpression>,
/// Whether DISTINCT keyword was specified (e.g., COUNT(DISTINCT x))
distinct: bool,
},
/// Arithmetic operation
Arithmetic {
left: Box<ValueExpression>,
Expand Down Expand Up @@ -348,6 +357,27 @@ pub enum ValueExpression {
VectorLiteral(Vec<f32>),
}

/// Function type classification
#[derive(Debug, Clone, PartialEq)]
pub enum FunctionType {
/// Aggregate function (operates across multiple rows)
Aggregate,
/// Scalar function (operates on individual values)
Scalar,
/// Unknown function type
Unknown,
}

/// Classify a function by name
pub fn classify_function(name: &str) -> FunctionType {
match name.to_lowercase().as_str() {
"count" | "sum" | "avg" | "min" | "max" | "collect" => FunctionType::Aggregate,
"tolower" | "lower" | "toupper" | "upper" => FunctionType::Scalar,
// Vector functions are handled separately as special variants
_ => FunctionType::Unknown,
}
}

/// Arithmetic operators
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum ArithmeticOperator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ mod tests {
let project = LogicalOperator::Project {
input: Box::new(scan),
projections: vec![ProjectionItem {
expression: ValueExpression::Function {
expression: ValueExpression::AggregateFunction {
name: "count".to_string(),
args: vec![ValueExpression::Variable("*".to_string())],
distinct: false,
},
alias: Some("total".to_string()),
}],
Expand All @@ -114,9 +115,10 @@ mod tests {
let project = LogicalOperator::Project {
input: Box::new(scan),
projections: vec![ProjectionItem {
expression: ValueExpression::Function {
expression: ValueExpression::AggregateFunction {
name: "count".to_string(),
args: vec![ValueExpression::Variable("*".to_string())],
distinct: false,
},
alias: None,
}],
Expand Down
Loading
Loading