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
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,24 @@

import static org.dbsp.sqlCompiler.ir.type.DBSPTypeCode.*;

/**
* Implements a window aggregate with a RANGE
*/
/** Implements a window aggregate with a RANGE */
public class RangeAggregates extends WindowAggregates {
final int orderColumnIndex;
final RelFieldCollation collation;

protected RangeAggregates(CalciteToDBSPCompiler compiler, Window window, Window.Group group, int windowFieldIndex) {
super(compiler, window, group, windowFieldIndex);

CalciteObject object = CalciteObject.create(group.aggCalls.get(0).pos);
List<RelFieldCollation> orderKeys = this.group.orderKeys.getFieldCollations();
if (group.isRows)
throw new UnimplementedException("Window aggregates with ROWS", 457, object);
if (orderKeys.isEmpty())
throw new CompilationError("Missing ORDER BY in OVER", node);
throw new CompilationError("Missing ORDER BY in OVER", object);
if (orderKeys.size() > 1)
throw new UnimplementedException("ORDER BY in OVER requires exactly 1 column", 457, node);
throw new UnimplementedException("ORDER BY in OVER requires exactly 1 column", 457, object);
if (group.exclude != RexWindowExclusion.EXCLUDE_NO_OTHER)
throw new UnimplementedException("EXCLUDE BY in OVER", 457, node);
throw new UnimplementedException("EXCLUDE BY in OVER", 457, object);

this.collation = orderKeys.get(0);
this.orderColumnIndex = this.collation.getFieldIndex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@ WITH ranked_events AS (
String[] aggregates = new String[] {
"account_id", """
LAG(runtime_elapsed_msecs) OVER (
PARTITION BY account_id
ORDER BY event_timestamp
) AS daily_runtime_increment""", """
PARTITION BY account_id
ORDER BY event_timestamp
) AS daily_runtime_increment""", """
ROW_NUMBER() OVER (
PARTITION BY account_id
ORDER BY event_timestamp DESC
) AS event_rank"""
PARTITION BY account_id
ORDER BY event_timestamp DESC
) AS event_rank"""
};
String tail = """
FROM T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,8 +787,23 @@ amount DECIMAL(12, 2),
SUM(amount) OVER (
PARTITION BY customer_id
ORDER BY payment_time
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) AS running_amount
FROM payments""", "Not yet implemented: ROW_NUMBER only supported in a TopK pattern");
}

@Test
public void rowsTest() {
this.statementsFailingInCompilation("""
CREATE TABLE purchase (
ts TIMESTAMP NOT NULL,
amount BIGINT,
value BIGINT LATENESS 5
);

CREATE MATERIALIZED VIEW rolling_sum AS
SELECT ts,
SUM(value) OVER (ORDER BY ts ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS rolling_sum
FROM purchase;""", "Not yet implemented: Window aggregates with ROWS");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ CREATE TABLE feedback (
let _ = circuit.transaction().expect("could not run circuit");
let _ = circuit.transaction().expect("could not run circuit");
""");
if (BaseSQLTests.skipRust)
return;
this.measure(sql, main);
}
}
Loading