datafusion icon indicating copy to clipboard operation
datafusion copied to clipboard

Unparser: numeric values in window frame definition are converted into string literals

Open sgrebnov opened this issue 1 year ago • 0 comments

Describe the bug

As pointed here: https://github.com/apache/datafusion/pull/12946/files#r1803027063

window frame definition SUM(id) OVER (PARTITION BY first_name ROWS BETWEEN 5 PRECEDING AND 2 FOLLOWING) is incorrectly unparsed as SUM(id) OVER (PARTITION BY first_name ROWS BETWEEN '5' PRECEDING AND '2' FOLLOWING)

long literals 5 and 2 are converted to string literals '5' and '2'

To Reproduce

The following test can be used

#[test]
fn test_aggregation_to_sql() {
    sql_round_trip(
        GenericDialect {},
        r#"SELECT id, first_name,
        SUM(id) OVER (PARTITION BY first_name ROWS BETWEEN 5 PRECEDING AND 2 FOLLOWING) AS moving_sum
        FROM person
        GROUP BY id, first_name;"#,
        r#"SELECT person.id, person.first_name, SUM(person.id) OVER (PARTITION BY person.first_name ROWS BETWEEN 5 PRECEDING AND 2 FOLLOWING) AS moving_sum FROM person GROUP BY person.id, person.first_name"#,
    );
}

Expected behavior

window frame definition is unparsed correctly

Additional context

https://github.com/apache/datafusion/pull/12946/files#r1803027063

sgrebnov avatar Oct 17 '24 07:10 sgrebnov