Skip to content

DuckDB parser uses wrong default window frame when ORDER BY is absent #16549

@mbasmanova

Description

@mbasmanova

Bug description

Summary

The DuckDB parser bundled in Velox (v0.8.1) always defaults the window frame end bound to CURRENT ROW, regardless of whether ORDER BY is present. The SQL standard specifies different defaults:

  • With ORDER BY: RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
  • Without ORDER BY: RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING

Reproduction

auto windowExpr = parse::DuckSqlExpressionsParser().parseWindowExpr(
    "rank() OVER (PARTITION BY a)");
// windowExpr.frame.endType is kCurrentRow
// Expected: kUnboundedFollowing (per SQL standard, no ORDER BY)

The existing DuckDB parser test in velox/duckdb/conversion/tests/DuckParserTest.cpp confirms this behavior:

EXPECT_EQ(
    "row_number() AS a OVER (  RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)",
    parseWindow("row_number() over () as a"));

Impact

Any code using DuckSqlExpressionsParser::parseWindowExpr() to parse window expressions without ORDER BY gets the wrong default frame. The Axiom query optimizer works around this in its test PlanMatcher, but the fix belongs in the parser.

Suggested Fix

Upgrade to a newer DuckDB version.

CC: @majetideepak @aditi-pandit @kgpai @amitkdutta @natashasehgal @czentgr

System information

n/a

Relevant logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageNewly created issue that needs attention.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions