Skip to content

Commit bb533cf

Browse files
committed
test: add CREATE AGGREGATE round-trip tests
Three tests covering: basic old-style aggregate (SFUNC/STYPE/FINALFUNC/INITCOND), CREATE OR REPLACE with PARALLEL = SAFE, and moving-aggregate options (MSFUNC/MINVFUNC/MSTYPE/MFINALFUNC_EXTRA/MFINALFUNC_MODIFY). All use pg().verified_stmt() to assert parse-then-display round-trips identically.
1 parent 9af8b16 commit bb533cf

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

tests/sqlparser_postgres.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9221,3 +9221,63 @@ fn parse_lock_table() {
92219221
}
92229222
}
92239223
}
9224+
9225+
#[test]
9226+
fn parse_create_aggregate_basic() {
9227+
let sql = "CREATE AGGREGATE myavg (NUMERIC) (SFUNC = numeric_avg_accum, STYPE = internal, FINALFUNC = numeric_avg, INITCOND = '0')";
9228+
let stmt = pg().verified_stmt(sql);
9229+
match stmt {
9230+
Statement::CreateAggregate(agg) => {
9231+
assert!(!agg.or_replace);
9232+
assert_eq!(agg.name.to_string(), "myavg");
9233+
assert_eq!(agg.args.len(), 1);
9234+
assert_eq!(agg.args[0].to_string(), "NUMERIC");
9235+
assert_eq!(agg.options.len(), 4);
9236+
assert_eq!(
9237+
agg.options[0].to_string(),
9238+
"SFUNC = numeric_avg_accum"
9239+
);
9240+
assert_eq!(agg.options[1].to_string(), "STYPE = internal");
9241+
assert_eq!(agg.options[2].to_string(), "FINALFUNC = numeric_avg");
9242+
assert_eq!(agg.options[3].to_string(), "INITCOND = '0'");
9243+
}
9244+
_ => panic!("Expected CreateAggregate, got: {stmt:?}"),
9245+
}
9246+
}
9247+
9248+
#[test]
9249+
fn parse_create_aggregate_or_replace_with_parallel() {
9250+
let sql = "CREATE OR REPLACE AGGREGATE sum2 (INT4, INT4) (SFUNC = int4pl, STYPE = INT4, PARALLEL = SAFE)";
9251+
let stmt = pg().verified_stmt(sql);
9252+
match stmt {
9253+
Statement::CreateAggregate(agg) => {
9254+
assert!(agg.or_replace);
9255+
assert_eq!(agg.name.to_string(), "sum2");
9256+
assert_eq!(agg.args.len(), 2);
9257+
assert_eq!(agg.options.len(), 3);
9258+
assert_eq!(agg.options[2].to_string(), "PARALLEL = SAFE");
9259+
}
9260+
_ => panic!("Expected CreateAggregate, got: {stmt:?}"),
9261+
}
9262+
}
9263+
9264+
#[test]
9265+
fn parse_create_aggregate_with_moving_aggregate_options() {
9266+
let sql = "CREATE AGGREGATE moving_sum (FLOAT8) (SFUNC = float8pl, STYPE = FLOAT8, MSFUNC = float8pl, MINVFUNC = float8mi, MSTYPE = FLOAT8, MFINALFUNC_EXTRA, MFINALFUNC_MODIFY = READ_ONLY)";
9267+
let stmt = pg().verified_stmt(sql);
9268+
match stmt {
9269+
Statement::CreateAggregate(agg) => {
9270+
assert!(!agg.or_replace);
9271+
assert_eq!(agg.name.to_string(), "moving_sum");
9272+
assert_eq!(agg.args.len(), 1);
9273+
assert_eq!(agg.options.len(), 7);
9274+
assert_eq!(agg.options[4].to_string(), "MSTYPE = FLOAT8");
9275+
assert_eq!(agg.options[5].to_string(), "MFINALFUNC_EXTRA");
9276+
assert_eq!(
9277+
agg.options[6].to_string(),
9278+
"MFINALFUNC_MODIFY = READ_ONLY"
9279+
);
9280+
}
9281+
_ => panic!("Expected CreateAggregate, got: {stmt:?}"),
9282+
}
9283+
}

0 commit comments

Comments
 (0)