Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
04c80f8
refactor(sql): use structural matching for aggregate/UDAF deduplication
forsaken628 Mar 24, 2026
fa8f708
feat(sql): add query-local UDF definition cache in BindContext
forsaken628 Mar 18, 2026
505a45f
refactor(sql): rewrite aggregate binder with intern/lookup pattern
forsaken628 Mar 24, 2026
d3727a5
fix(sql): make grouping() rewrite idempotent and add window aggregate…
forsaken628 Mar 19, 2026
b9050a5
test: migrate tests to integration framework with golden files
forsaken628 Mar 24, 2026
5b33901
fix(sql): reject aggregate functions in window partition/order spec
forsaken628 Mar 20, 2026
a5c455b
refactor(sql): add lookup_existing methods for pre-argument-replaceme…
forsaken628 Mar 20, 2026
802885d
refactor(sql): simplify project_set and qualify binder
forsaken628 Mar 20, 2026
b879728
test(sql): add comprehensive binder semantic tests
forsaken628 Mar 24, 2026
3b7056b
refactor(sql): simplify aggregate argument replacement logic
forsaken628 Mar 20, 2026
8edc264
fix(sql): fix window function type checking for nested aggregates
forsaken628 Mar 23, 2026
4c3b935
test: add UserApiProvider support to test framework
forsaken628 Mar 23, 2026
082b2cc
refactor(sql): update aggregate binding, qualify, and sort handling
forsaken628 Mar 23, 2026
507b9c8
refactor(sql): simplify qualify clause and improve grouping check
forsaken628 Mar 23, 2026
288e75a
feat(sql): add push_down_filter for ProjectSet and fix SRF ordering i…
forsaken628 Mar 24, 2026
1259f6f
fix
forsaken628 Mar 24, 2026
f4e00ba
fix
forsaken628 Mar 24, 2026
ecf76d3
init
forsaken628 Mar 24, 2026
a3e27b5
x
forsaken628 Mar 24, 2026
2ea5478
Merge remote-tracking branch 'up/main' into projection-bind
forsaken628 Apr 1, 2026
aabc196
fix
forsaken628 Apr 2, 2026
1809872
fix
forsaken628 Apr 2, 2026
d119cbb
Merge remote-tracking branch 'up/main' into projection-bind
forsaken628 Apr 2, 2026
2983534
fix
forsaken628 Apr 2, 2026
49600e9
refine
forsaken628 Apr 3, 2026
ec77883
fix
forsaken628 Apr 3, 2026
eb53805
refine
forsaken628 Apr 7, 2026
0705861
Merge branch 'main' into projection-bind
forsaken628 Apr 7, 2026
57ee744
fix
forsaken628 Apr 8, 2026
1fd2422
Merge remote-tracking branch 'up/main' into projection-bind
forsaken628 Apr 8, 2026
75bda64
fix
forsaken628 Apr 8, 2026
51e0b7b
refine
forsaken628 Apr 9, 2026
6f31ef1
x
forsaken628 Apr 17, 2026
ece4ed1
Merge remote-tracking branch 'up/main' into projection-bind
forsaken628 Apr 17, 2026
8e217b0
refine
forsaken628 Apr 17, 2026
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
19 changes: 5 additions & 14 deletions src/query/ast/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,7 @@ use nom::Parser;

use crate::ParseError;
use crate::Result;
use crate::ast::DatabaseRef;
use crate::ast::Expr;
use crate::ast::Identifier;
use crate::ast::Literal;
use crate::ast::ProcedureIdentity;
use crate::ast::Query;
use crate::ast::SelectTarget;
use crate::ast::SetExpr;
use crate::ast::Statement;
use crate::ast::StatementWithFormat;
use crate::ast::TableRef;
use crate::ast::*;
use crate::parser::Backtrace;
use crate::parser::common::IResult;
use crate::parser::common::comma_separated_list0;
Expand All @@ -48,9 +38,6 @@ use crate::parser::statement::statement;
use crate::parser::token::Token;
use crate::parser::token::TokenKind;
use crate::parser::token::Tokenizer;
use crate::visit::VisitControl;
use crate::visit::VisitorMut;
use crate::visit::WalkMut;

pub fn tokenize_sql(sql: &str) -> Result<Vec<Token<'_>>> {
Tokenizer::new(sql).collect::<Result<Vec<_>>>()
Expand Down Expand Up @@ -242,6 +229,10 @@ fn assert_reparse(sql: &str, stmt: StatementWithFormat) -> std::result::Result<(

#[cfg(debug_assertions)]
fn reset_ast(mut stmt: StatementWithFormat) -> StatementWithFormat {
use crate::visit::VisitControl;
use crate::visit::VisitorMut;
use crate::visit::WalkMut;

struct ResetAst;

impl ResetAst {
Expand Down
2 changes: 2 additions & 0 deletions src/query/ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ pub enum VisitControl<B = ()> {
Break(B),
}

pub type VisitResult = Result<VisitControl, !>;

/// Pre-order visitor hooks for immutable AST traversal.
///
/// Returning `Continue` lets the walker descend into children automatically.
Expand Down
41 changes: 34 additions & 7 deletions src/query/sql/src/planner/binder/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ use crate::plans::GroupingSets;
use crate::plans::ScalarExpr;
use crate::plans::ScalarItem;
use crate::plans::UDAFCall;
use crate::plans::Visitor;
use crate::plans::VisitorMut;
use crate::plans::Visitor as ScalarVisitor;
use crate::plans::VisitorMut as ScalarVisitorMut;
use crate::plans::walk_expr_mut;

/// Information for `GROUPING SETS`.
Expand Down Expand Up @@ -763,7 +763,7 @@ struct ExistingAggregateRewriter<'a> {
error_message: &'a str,
}

impl<'a> VisitorMut<'a> for ExistingAggregateRewriter<'a> {
impl<'a> ScalarVisitorMut<'a> for ExistingAggregateRewriter<'a> {
fn visit(&mut self, expr: &'a mut ScalarExpr) -> Result<()> {
match expr {
ScalarExpr::AggregateFunction(aggregate) => {
Expand Down Expand Up @@ -816,7 +816,7 @@ impl<'a> VisitorMut<'a> for ExistingAggregateRewriter<'a> {
}
}

impl<'a> VisitorMut<'a> for AggregateRewriter<'a> {
impl<'a> ScalarVisitorMut<'a> for AggregateRewriter<'a> {
fn visit(&mut self, expr: &'a mut ScalarExpr) -> Result<()> {
match expr {
ScalarExpr::AggregateFunction(aggregate) => {
Expand Down Expand Up @@ -906,8 +906,7 @@ impl Binder {
}
}

let original_context = bind_context.expr_context.clone();
bind_context.set_expr_context(ExprContext::GroupClaue);
let original_context = bind_context.replace_expr_context(ExprContext::GroupClaue);

let group_by = Self::expand_group(group_by.clone())?;
match &group_by {
Expand Down Expand Up @@ -935,7 +934,7 @@ impl Binder {
}
_ => unreachable!(),
}
bind_context.set_expr_context(original_context);
bind_context.expr_context = original_context;
Ok(())
}

Expand Down Expand Up @@ -1472,6 +1471,34 @@ impl Binder {
Ok((scalar.clone(), scalar.data_type()?))
}
}

pub(super) fn bind_and_rewrite_aggregate_expr(
&mut self,
bind_context: &mut BindContext,
aliases: &[(String, ScalarExpr)],
expr_context: ExprContext,
expr: &Expr,
) -> Result<ScalarExpr> {
let original_context = bind_context.replace_expr_context(expr_context);

let mut scalar_binder = ScalarBinder::new(
bind_context,
self.ctx.clone(),
&self.name_resolution_ctx,
self.metadata.clone(),
aliases,
);

let (mut result, _) = scalar_binder.bind(expr)?;
AggregateRewriter::rewrite_expr(
&mut bind_context.aggregate_info,
self.metadata.clone(),
&mut result,
)?;

bind_context.expr_context = original_context;
Ok(result)
}
}

fn build_replaced_aggregate_column(
Expand Down
Loading
Loading