Skip to content

Commit f05734f

Browse files
committed
[SQL] We pull all constant expressions into statics, solving #2998
Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
1 parent 7555081 commit f05734f

1 file changed

Lines changed: 114 additions & 0 deletions

File tree

  • sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple

sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple/Regression2Tests.java

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.dbsp.util.NullPrintStream;
2323
import org.dbsp.util.Utilities;
2424
import org.junit.Assert;
25+
import org.junit.Ignore;
2526
import org.junit.Test;
2627

2728
import java.io.PrintStream;
@@ -628,4 +629,117 @@ public void testStdDevPop() {
628629
NULL
629630
(1 row)""");
630631
}
632+
633+
@Test
634+
public void issue1956() {
635+
var ccs = this.getCCS("""
636+
CREATE TABLE auctions (
637+
id INT NOT NULL PRIMARY KEY,
638+
seller INT,
639+
item TEXT
640+
);
641+
642+
CREATE TABLE bids (
643+
id INT NOT NULL PRIMARY KEY,
644+
buyer INT,
645+
auction_id INT,
646+
amount INT
647+
);
648+
649+
CREATE VIEW V AS SELECT id, (SELECT array_agg(buyer) FROM (
650+
SELECT buyer FROM bids WHERE auction_id = auctions.id
651+
ORDER BY buyer LIMIT 10
652+
)) FROM auctions;""");
653+
// Output validated using postgres
654+
ccs.step("""
655+
INSERT INTO auctions (id, seller, item) VALUES
656+
(1, 101, 'Vintage Camera'),
657+
(2, 102, 'Mountain Bike'),
658+
(3, 103, 'Gaming Laptop'),
659+
(4, 101, 'Antique Vase'),
660+
(5, 104, 'Smartphone');
661+
INSERT INTO bids (id, buyer, auction_id, amount) VALUES
662+
(1, 201, 1, 120),
663+
(2, 202, 1, 150),
664+
(3, 203, 1, 180),
665+
666+
(4, 204, 2, 300),
667+
(5, 205, 2, 350),
668+
669+
(6, 206, 3, 700),
670+
(7, 207, 3, 720),
671+
(8, 208, 3, 750),
672+
(9, 209, 3, 760),
673+
674+
(10, 210, 4, 90),
675+
(11, 211, 4, 110),
676+
677+
-- Auction 5 intentionally has no bids
678+
(12, 212, 2, 360); -- extra competing bid on auction 2""", """
679+
id | arr | weight
680+
----------------------------------------
681+
1 | { 201, 202, 203 } | 1
682+
2 | { 204, 205, 212 } | 1
683+
3 | { 206, 207, 208, 209 } | 1
684+
4 | { 210, 211 } | 1
685+
5 | NULL | 1""");
686+
}
687+
688+
@Test @Ignore("https://github.com/feldera/feldera/issues/2555")
689+
public void issue2555() {
690+
this.getCC("""
691+
create table spreadsheet (
692+
id int64 not null primary key,
693+
cell text not null,
694+
mentions int64 array\s
695+
) with ('materialized' = 'true');
696+
697+
create materialized view spreadsheet_view as
698+
select
699+
s.id,
700+
s.cell,
701+
array(
702+
select sp.cell
703+
from unnest(s.mentions) as mention_id
704+
join spreadsheet sp on sp.id = mention_id
705+
) as mentioned_cells
706+
from spreadsheet s;""");
707+
}
708+
709+
@Test
710+
public void issue2555a() {
711+
this.getCCS("""
712+
create table a(
713+
col1 text not null,
714+
col2 text not null,
715+
PRIMARY KEY (col1, col2)
716+
);
717+
718+
create table b(
719+
col1 text not null,
720+
col2 text not null,
721+
PRIMARY KEY (col1, col2)
722+
);
723+
724+
DECLARE RECURSIVE VIEW foo(
725+
out1 text not null,
726+
out2 text not null
727+
);
728+
729+
CREATE MATERIALIZED VIEW foo(out1, out2) as (
730+
SELECT a.col1, a.col2
731+
FROM a
732+
WHERE NOT EXISTS (
733+
SELECT true FROM b
734+
WHERE a.col1 = b.col1
735+
UNION
736+
SELECT true FROM b
737+
WHERE a.col2 = b.col2
738+
)
739+
UNION
740+
SELECT foo.out2, a.col1
741+
FROM a, foo
742+
WHERE foo.out1 = a.col2
743+
);""");
744+
}
631745
}

0 commit comments

Comments
 (0)