Skip to content

Commit f42b1cc

Browse files
committed
[DOC] Add example creating a value with a user-defined type
Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
1 parent 8f8e0c2 commit f42b1cc

File tree

2 files changed

+21
-0
lines changed
  • docs.feldera.com/docs/sql
  • sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql

2 files changed

+21
-0
lines changed

docs.feldera.com/docs/sql/types.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ employee_typ(315, 'Francis', 'Logan', 'FLOGAN',
156156
address_typ('376 Mission', 'San Francisco', 'CA', '94222'))
157157
```
158158

159+
Here is an example query creating an object with the user-defined type
160+
`address_typ` defined above (the `CREATE TYPE` definition should be in
161+
the same program):
162+
163+
```sql
164+
CREATE TABLE T(street VARCHAR, city VARCHAR, year INT);
165+
CREATE VIEW V AS SELECT address_typ(T.street, city, 'CA', 94087) as address, T.year as year FROM T;
166+
```
167+
159168
Tables can have structure-valued columns, but these have to be fully
160169
qualified using both the table name and the column name in programs:
161170

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,18 @@ public void testCompilerToPng() throws IOException, SQLException {
611611
ImageIO.read(new File(png.getPath()));
612612
}
613613

614+
@Test
615+
public void testUDT() {
616+
this.getCCS("""
617+
CREATE TYPE address_typ AS (
618+
street VARCHAR(30),
619+
city VARCHAR(20),
620+
state CHAR(2),
621+
postal_code VARCHAR(6));
622+
CREATE TABLE T(street VARCHAR, city VARCHAR, year INT);
623+
CREATE VIEW V AS SELECT address_typ(T.street, city, 'CA', 94087) as address, T.year as year FROM T;""");
624+
}
625+
614626
@Test
615627
public void rawCalciteTest() throws SQLException {
616628
Connection connection = DriverManager.getConnection("jdbc:calcite:");

0 commit comments

Comments
 (0)