diff --git a/docs.feldera.com/docs/sql/grammar.md b/docs.feldera.com/docs/sql/grammar.md index dc41e94fe1f..b8af03c8899 100644 --- a/docs.feldera.com/docs/sql/grammar.md +++ b/docs.feldera.com/docs/sql/grammar.md @@ -399,8 +399,14 @@ orderItem ``` projectItem : expression [ [ AS ] columnAlias ] - | ROW(*) [ [ AS ] columnAlias ] - | tableAlias . * + | ROW(rowStarItem [, projectItem ]* [ [ AS columnAlias ] ] + | tableAlias . '*' + +rowStarItem + : '*' + | tableAlias . '*' + | '*' { EXCLUDE | EXCEPT } '(' column [, column ]* ')' + | tableAlias . '*' { EXCLUDE | EXCEPT } '(' column [, column ]* ')' ``` The following forms of `SELECT` are supported: @@ -409,6 +415,8 @@ The following forms of `SELECT` are supported: - `SELECT * EXCLUDE a, b FROM T`: select all columns of table `T` except the ones named `a` and `b` - `SELECT * EXCEPT a, b FROM T`: `EXCEPT` is a synonym for `EXCLUDE`; this statement is equivalent to the previous statement - `SELECT * REPLACE (a+b AS a) FROM T`: Select all columns of table `T` and replace column `a` with the expression `a+b` +- `SELECT ROW(T.*) FROM T`: Create a `ROW`-typed column with all columns of table `T` +- `SELECT ROW(T.* EXCLUDE(a, b)) FROM T: Create a `ROW`-typed column with all columns of table `T` except columns `a` and `b` - `SELECT` supports [lateral column aliasing](identifiers.md#lateral-column-aliasing), where an identifier defined in a `SELECT` statement can be immediately used in the same statement or in the associated `GROUP BY` and `HAVING` statements. diff --git a/sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/CompilerMain.java b/sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/CompilerMain.java index 6a639e15be1..8f67060514c 100644 --- a/sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/CompilerMain.java +++ b/sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/CompilerMain.java @@ -220,9 +220,13 @@ CompilerMessages run() { } } - String dotFormat = (this.options.ioOptions.emitJpeg ? "jpg" - : this.options.ioOptions.emitPng ? "png" - : null); + String dotFormat = null; + if (this.options.ioOptions.emitJpeg) + dotFormat = "jpg"; + else if (this.options.ioOptions.emitPng) + dotFormat = "png"; + else if (this.options.ioOptions.emitSvg) + dotFormat = "svg"; if (dotFormat != null) { if (this.options.ioOptions.outputFile.isEmpty()) { compiler.reportError(SourcePositionRange.INVALID, "Invalid output", diff --git a/sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/compiler/CompilerOptions.java b/sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/compiler/CompilerOptions.java index c2554d5afa5..55cbe5246e8 100644 --- a/sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/compiler/CompilerOptions.java +++ b/sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/compiler/CompilerOptions.java @@ -174,6 +174,8 @@ public static class IO implements IDiff, IValidate { public boolean emitJpeg = false; @Parameter(names = {"--png", "-png"}, description = "Emit a png image of the circuit instead of Rust") public boolean emitPng = false; + @Parameter(names = {"--svg", "-svg"}, description = "Emit an svg image of the circuit instead of Rust") + public boolean emitSvg = false; @Parameter(names="--jit", description = "Emit a JSON representation suitable for an interpreter") public boolean interpreterJson = false; @Nullable @Parameter(names = "--plan", description = "Emit the Calcite plan of the program in the specified JSON file") @@ -242,9 +244,16 @@ public boolean multiCrates() { @Override public boolean validate(IErrorReporter reporter) { - if (this.emitJpeg && this.emitPng) { + int count = 0; + if (this.emitJpeg) + count++; + if (this.emitSvg) + count++; + if (this.emitPng) + count++; + if (count > 1) { reporter.reportError(SourcePositionRange.INVALID, "Invalid options", - "Options -png and -jpg cannot be used at the same time"); + "Options -png/-jpg/-svg cannot be used at the same time"); return false; } return true; @@ -258,6 +267,7 @@ public String toString() { ",\n\tcrates=" + this.crates + ",\n\temitHandles=" + this.emitHandles + ",\n\temitJpeg=" + this.emitJpeg + + ",\n\temitSvg=" + this.emitSvg + ",\n\tinterpreterJson=" + this.interpreterJson + ",\n\temitJsonErrors=" + this.emitJsonErrors + ",\n\temitJsonSchema=" + Utilities.singleQuote(this.emitJsonSchema) + diff --git a/sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/MetadataTests.java b/sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/MetadataTests.java index 99ea1f7d3dc..86be95485b3 100644 --- a/sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/MetadataTests.java +++ b/sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/MetadataTests.java @@ -1272,6 +1272,9 @@ Use handles (true) or Catalog (false) in the emitted Rust code --streaming Compiling a streaming program, where only inserts are allowed Default: false + --svg, -svg + Emit an svg image of the circuit instead of Rust + Default: false --trimInputs Do not ingest unused fields of input tables Default: false diff --git a/sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple/Regression2Tests.java b/sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple/Regression2Tests.java index 7910ae6545c..95b5e778020 100644 --- a/sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple/Regression2Tests.java +++ b/sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple/Regression2Tests.java @@ -1776,6 +1776,6 @@ public void testCompareTz() { "Operation < between TIMESTAMP and TIMESTAMP WITH TIME ZONE not supported"); this.statementsFailingInCompilation( "CREATE VIEW V AS SELECT TIMESTAMP '2020-01-01 10:00:00' - TIMESTAMP WITH TIME ZONE '2020-01-01 10:00:00 UTC'", - "Cannot apply '-' to arguments of type ' - '"); + "Cannot apply '-' to arguments of type ' - '"); } } diff --git a/sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple/Regression3Tests.java b/sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple/Regression3Tests.java index be0585f056e..20c27e04fee 100644 --- a/sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple/Regression3Tests.java +++ b/sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple/Regression3Tests.java @@ -7,6 +7,7 @@ import org.dbsp.sqlCompiler.compiler.sql.tools.SqlIoTest; import org.dbsp.sqlCompiler.compiler.visitors.outer.CircuitVisitor; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; public class Regression3Tests extends SqlIoTest { @@ -30,6 +31,44 @@ public void issue6400() { ^^^"""); } + @Test + public void issue6342() { + this.getCC(""" + CREATE TABLE dept_nested ( + employees ROW( + detail ROW( + skills ROW( + desc VARCHAR + ) ARRAY + ) + ) ARRAY + ); + create view v as select * from dept_nested order by employees[1].detail.skills[2+3].desc"""); + + this.getCC(""" + CREATE TABLE T ( + id INT, + col ROW(field1 VARCHAR, field2 INT) + ); + + CREATE VIEW V AS + SELECT id FROM T t ORDER BY (t.col).field2;"""); + } + + @Test + public void issue5398() { + var ccs = this.getCCS(""" + CREATE TABLE T(x INT, y INT, z INT); + CREATE TABLE S(a INT, b INT); + CREATE LOCAL VIEW V AS SELECT ROW(T.* EXCLUDE(x), ROW(S.* EXCLUDE(a))) AS R FROM T, S; + CREATE VIEW W AS SELECT R[1], R[2], R[3][1] FROM V;"""); + ccs.stepWeightOne(""" + INSERT INTO T VALUES(0, 1, 2); INSERT INTO S VALUES(3, 4);""", """ + y | z | b + ----------- + 1 | 2 | 4"""); + } + @Test public void issue5806() { // Temporal filters and joins can be swapped by Calcite optimizer diff --git a/sql-to-dbsp-compiler/calcite_version.env b/sql-to-dbsp-compiler/calcite_version.env index 9cfc91909d8..2666bc1ab3a 100644 --- a/sql-to-dbsp-compiler/calcite_version.env +++ b/sql-to-dbsp-compiler/calcite_version.env @@ -3,5 +3,5 @@ CALCITE_REPO="https://github.com/apache/calcite.git" #CALCITE_REPO="https://github.com/mihaibudiu/calcite" CALCITE_BRANCH="main" CALCITE_CURRENT="1.42.0" -CALCITE_NEXT_COMMIT="fda2874d73250c373f1e74b445547f1c0b0debd8" +CALCITE_NEXT_COMMIT="1a3173d52a41683acca60fb09a31ad6ee25e587e" CALCITE_NEXT="1.43.0" diff --git a/sql-to-dbsp-compiler/using.md b/sql-to-dbsp-compiler/using.md index 3c7e21f3681..eff8552be32 100644 --- a/sql-to-dbsp-compiler/using.md +++ b/sql-to-dbsp-compiler/using.md @@ -109,6 +109,9 @@ Usage: sql-to-dbsp [options] Input file to compile --streaming Compiling a streaming program, where only inserts are allowed Default: false + --svg, -svg + Emit an svg image of the circuit instead of Rust + Default: false --trimInputs Do not ingest unused fields of input tables Default: false