diff --git a/sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/compiler/frontend/AggregateCompiler.java b/sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/compiler/frontend/AggregateCompiler.java index 0fdf600969b..d55c93c9f27 100644 --- a/sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/compiler/frontend/AggregateCompiler.java +++ b/sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/compiler/frontend/AggregateCompiler.java @@ -405,8 +405,8 @@ void processSingle(SqlSingleValueAggFunction function) { DBSPExpression increment = aggregatedValue; if (!increment.getType().mayBeNull) increment = increment.some(); - DBSPType semigroup = new DBSPTypeUser(CalciteObject.EMPTY, SEMIGROUP, "DefaultOptSemigroup", - false, accumulator.getType().setMayBeNull(false)); + DBSPType semigroup = new DBSPTypeUser(CalciteObject.EMPTY, SEMIGROUP, "UnimplementedSemigroup", + false, accumulator.getType()); this.setFoldingFunction(new DBSPAggregate.Implementation( node, zero, this.makeRowClosure(increment, accumulator), zero, semigroup, null)); } diff --git a/sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple/TimeTests.java b/sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple/TimeTests.java index 82fbe4d569f..b3bd703beb1 100644 --- a/sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple/TimeTests.java +++ b/sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple/TimeTests.java @@ -64,6 +64,31 @@ public Change createInput() { return new Change(new DBSPZSetLiteral(new DBSPTupleExpression(new DBSPTimestampLiteral(100)))); } + @Test + public void issue1843() { + String sql = """ + create table credit_card_transactions(transaction_time timestamp); + + create table my_timer(t timestamp);\s + + create view recent_transactions as + SELECT * FROM credit_card_transactions + WHERE transaction_time >= (SELECT t FROM my_timer) - INTERVAL 1 DAY;"""; + this.compileRustTestCase(sql); + } + + @Test + public void issue1844() { + String sql = """ + create table credit_card_transactions(transaction_time timestamp); + create table my_timer(id int primary key, t timestamp);\s + + create view recent_transactions as + SELECT * FROM credit_card_transactions + WHERE transaction_time >= (SELECT DATE_SUB(t, INTERVAL 1 DAY) FROM my_timer);"""; + this.compileRustTestCase(sql); + } + @Test public void testInterval() { this.testQuery("SELECT INTERVAL '20' YEAR", diff --git a/sql-to-dbsp-compiler/lib/sqllib/src/timestamp.rs b/sql-to-dbsp-compiler/lib/sqllib/src/timestamp.rs index 8c4084a4237..7bb5f37bbfe 100644 --- a/sql-to-dbsp-compiler/lib/sqllib/src/timestamp.rs +++ b/sql-to-dbsp-compiler/lib/sqllib/src/timestamp.rs @@ -275,6 +275,14 @@ polymorphic_return_function2!( Timestamp ); +pub fn minus_Date_ShortInterval_Date(left: Date, right: ShortInterval) -> Date { + let days = (right.milliseconds() / (86400 * 1000)) as i32; + let diff = left.days() - days; + Date::new(diff) +} + +polymorphic_return_function2!(minus, Date, Date, ShortInterval, ShortInterval, Date, Date); + pub fn minus_Timestamp_Timestamp_LongInterval(left: Timestamp, right: Timestamp) -> LongInterval { let ldate = left.to_dateTime(); let rdate = right.to_dateTime();