Skip to content

Commit 339b304

Browse files
committed
Add Tabular function showcase
1 parent 8120df9 commit 339b304

File tree

3 files changed

+312
-1
lines changed

3 files changed

+312
-1
lines changed
Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,304 @@
1+
###Relational
2+
Database demo::udtf::DemoDb
3+
(
4+
Schema Org
5+
(
6+
Table Firm
7+
(
8+
firmId INTEGER,
9+
legalname VARCHAR(200)
10+
)
11+
TabularFunction Person
12+
(
13+
firstname VARCHAR(200),
14+
lastname VARCHAR(200),
15+
age INTEGER,
16+
associatedFirmId INTEGER
17+
)
18+
TabularFunction Person2
19+
(
20+
firstname VARCHAR(200),
21+
lastname VARCHAR(200),
22+
age INTEGER,
23+
associatedFirmId INTEGER
24+
)
25+
TabularFunction ParentAndChildren
26+
(
27+
firstname VARCHAR(200),
28+
lastname VARCHAR(200),
29+
id INTEGER,
30+
age INTEGER,
31+
parentId INTEGER
32+
)
33+
)
34+
35+
Join firm_person(Org.Firm.firmId = Org.Person.associatedFirmId)
36+
Join firm_person2(Org.Firm.firmId = Org.Person2.associatedFirmId)
37+
Join relationship(Org.ParentAndChildren.parentId = {target}.id)
38+
39+
)
40+
41+
42+
###Pure
43+
Class demo::udtf::Org::Firm
44+
{
45+
firmId: Integer[1];
46+
legalname: String[1];
47+
}
48+
49+
Class demo::udtf::Org::Person
50+
{
51+
firstname: String[1];
52+
lastname: String[1];
53+
age: Integer[1];
54+
associatedFirmId: Integer[1];
55+
id: Integer[1];
56+
}
57+
58+
Association demo::udtf::Person_person
59+
{
60+
parent: demo::udtf::Org::Person[1];
61+
children: demo::udtf::Org::Person[1..*];
62+
}
63+
64+
Association demo::udtf::firm_person
65+
{
66+
assoacitedFirm: demo::udtf::Org::Firm[1];
67+
associatedPerson: demo::udtf::Org::Person[1..*];
68+
}
69+
70+
function demo::udtf::Org::FirmToPerson(): meta::pure::tds::TabularDataSet[1]
71+
{
72+
demo::udtf::Org::Firm.all()
73+
->project(
74+
[
75+
x|$x.firmId,
76+
x|$x.associatedPerson.age
77+
],
78+
[
79+
'Firm Id',
80+
'Associated Person/Age'
81+
]
82+
)->from(
83+
demo::udtf::DemoMapping,
84+
demo::runtimes::DemoRuntime
85+
)
86+
}
87+
88+
function demo::udtf::Org::FirmToPersonWithFilterOnPerson(): meta::pure::tds::TabularDataSet[1]
89+
{
90+
demo::udtf::Org::Firm.all()->filter(
91+
x|$x.associatedPerson->exists(
92+
x_1|$x_1.firstname == 'David'
93+
)
94+
)->project(
95+
[
96+
x|$x.firmId,
97+
x|$x.associatedPerson.age
98+
],
99+
[
100+
'Firm Id',
101+
'Associated Person/Age'
102+
]
103+
)->from(
104+
demo::udtf::DemoMapping,
105+
demo::runtimes::DemoRuntime
106+
)
107+
}
108+
109+
function demo::udtf::Org::FirmToPersonWithFilterOnPersonUsingUnion(): meta::pure::tds::TabularDataSet[1]
110+
{
111+
demo::udtf::Org::Firm.all()->filter(
112+
x|$x.associatedPerson->exists(
113+
x_1|$x_1.firstname == 'David'
114+
)
115+
)->project(
116+
[
117+
x|$x.firmId,
118+
x|$x.associatedPerson.age
119+
],
120+
[
121+
'Firm Id',
122+
'Associated Person/Age'
123+
]
124+
)->from(
125+
demo::udtf::DemoMappingUnion,
126+
demo::runtimes::DemoRuntime
127+
)
128+
}
129+
130+
131+
function demo::udtf::Org::FetchChildrenViaSelfJoin(): meta::pure::tds::TabularDataSet[1]
132+
{
133+
demo::udtf::Org::Person.all()->project(
134+
[
135+
x|$x.firstname,
136+
x|$x.id,
137+
x|$x.children.age,
138+
x|$x.children.id,
139+
x|$x.children.firstname
140+
],
141+
[
142+
'Firstname',
143+
'Id',
144+
'Children/Age',
145+
'Children/Id',
146+
'Children/Firstname'
147+
]
148+
)->from(
149+
demo::udtf::DemoMappingSelfJoin,
150+
demo::runtimes::DemoRuntime
151+
)
152+
}
153+
154+
155+
###Mapping
156+
Mapping demo::udtf::DemoMapping
157+
(
158+
*demo::udtf::Org::Firm[f]: Relational
159+
{
160+
~primaryKey
161+
(
162+
[demo::udtf::DemoDb]Org.Firm.firmId,
163+
[demo::udtf::DemoDb]Org.Firm.legalname
164+
)
165+
~mainTable [demo::udtf::DemoDb]Org.Firm
166+
firmId: [demo::udtf::DemoDb]Org.Firm.firmId,
167+
legalname: [demo::udtf::DemoDb]Org.Firm.legalname
168+
}
169+
*demo::udtf::Org::Person[p]: Relational
170+
{
171+
172+
~mainTable [demo::udtf::DemoDb]Org.Person
173+
firstname: [demo::udtf::DemoDb]Org.Person.firstname,
174+
lastname: [demo::udtf::DemoDb]Org.Person.lastname,
175+
age: [demo::udtf::DemoDb]Org.Person.age
176+
}
177+
178+
demo::udtf::firm_person: Relational
179+
{
180+
AssociationMapping
181+
(
182+
assoacitedFirm[p,f]: [demo::udtf::DemoDb]@firm_person,
183+
associatedPerson[f,p]: [demo::udtf::DemoDb]@firm_person
184+
)
185+
}
186+
)
187+
188+
###Mapping
189+
Mapping demo::udtf::DemoMappingUnion
190+
(
191+
*demo::udtf::Org::Person: Operation
192+
{
193+
meta::pure::router::operations::union_OperationSetImplementation_1__SetImplementation_MANY_(p1,p2)
194+
}
195+
*demo::udtf::Org::Firm[f]: Relational
196+
{
197+
~primaryKey
198+
(
199+
[demo::udtf::DemoDb]Org.Firm.firmId,
200+
[demo::udtf::DemoDb]Org.Firm.legalname
201+
)
202+
~mainTable [demo::udtf::DemoDb]Org.Firm
203+
firmId: [demo::udtf::DemoDb]Org.Firm.firmId,
204+
legalname: [demo::udtf::DemoDb]Org.Firm.legalname
205+
}
206+
demo::udtf::Org::Person[p1]: Relational
207+
{
208+
~mainTable [demo::udtf::DemoDb]Org.Person
209+
firstname: [demo::udtf::DemoDb]Org.Person.firstname,
210+
lastname: [demo::udtf::DemoDb]Org.Person.lastname,
211+
age: [demo::udtf::DemoDb]Org.Person.age
212+
}
213+
demo::udtf::Org::Person[p2]: Relational
214+
{
215+
~mainTable [demo::udtf::DemoDb]Org.Person2
216+
firstname: [demo::udtf::DemoDb]Org.Person2.firstname,
217+
lastname: [demo::udtf::DemoDb]Org.Person2.lastname,
218+
age: [demo::udtf::DemoDb]Org.Person2.age
219+
}
220+
221+
demo::udtf::firm_person: Relational
222+
{
223+
AssociationMapping
224+
(
225+
assoacitedFirm[p1,f]: [demo::udtf::DemoDb]@firm_person,
226+
assoacitedFirm[p2,f]: [demo::udtf::DemoDb]@firm_person2,
227+
associatedPerson[f,p1]: [demo::udtf::DemoDb]@firm_person,
228+
associatedPerson[f,p2]: [demo::udtf::DemoDb]@firm_person2
229+
)
230+
}
231+
)
232+
233+
###Mapping
234+
Mapping demo::udtf::DemoMappingSelfJoin
235+
(
236+
*demo::udtf::Org::Person[p1]: Relational
237+
{
238+
~primaryKey
239+
(
240+
[demo::udtf::DemoDb]Org.ParentAndChildren.firstname
241+
)
242+
~mainTable [demo::udtf::DemoDb]Org.ParentAndChildren
243+
firstname: [demo::udtf::DemoDb]Org.ParentAndChildren.firstname,
244+
lastname: [demo::udtf::DemoDb]Org.ParentAndChildren.lastname,
245+
id: [demo::udtf::DemoDb]Org.ParentAndChildren.id,
246+
age: [demo::udtf::DemoDb]Org.ParentAndChildren.age
247+
}
248+
249+
demo::udtf::Person_person: Relational
250+
{
251+
AssociationMapping
252+
(
253+
children[p1,p1]: [demo::udtf::DemoDb]@relationship,
254+
parent[p1,p1]: [demo::udtf::DemoDb]@relationship
255+
)
256+
}
257+
)
258+
259+
###Connection
260+
RelationalDatabaseConnection demo::udtf::DemoSnowflakeConnection
261+
{
262+
store: demo::udtf::DemoDb;
263+
type: Snowflake;
264+
specification: Snowflake
265+
{
266+
name: 'SUMMIT_MDM_DATA';
267+
account: 'sfcedeawseast1d01';
268+
warehouse: 'DEMO_WH';
269+
region: 'us-east-1';
270+
};
271+
auth: SnowflakePublic
272+
{
273+
publicUserName: 'isThis';
274+
privateKeyVaultReference: 'Hi';
275+
passPhraseVaultReference: 'What';
276+
};
277+
}
278+
279+
280+
###Runtime
281+
Runtime demo::runtimes::DemoRuntime
282+
{
283+
mappings:
284+
[
285+
demo::udtf::DemoMapping
286+
];
287+
connections:
288+
[
289+
demo::udtf::DemoDb:
290+
[
291+
connection_2: demo::udtf::DemoSnowflakeConnection
292+
]
293+
];
294+
}
295+
296+
###Snowflake
297+
SnowflakeApp demo::udtf::snowflakeApp::App1
298+
{
299+
applicationName : 'App1_revised';
300+
function : demo::udtf::Org::FirmToPersonWithFilterOnPersonUsingUnion():TabularDataSet[1];
301+
ownership : Deployment { identifier: '441143'};
302+
description : 'test App';
303+
activationConfiguration : demo::udtf::DemoSnowflakeConnection;
304+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Relational Database Specification with Tabular Functions
3+
description: Example of database specification with tabular Function.
4+
---
5+
6+
Tabular functions are database objects that effectively function as parameterized views.
7+
This showcase gives examples of tabular functions that do not accept any parameters.

showcases/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<maven.compiler.target>1.8</maven.compiler.target>
1717
<maven.surefire.thread.count>3</maven.surefire.thread.count>
1818
<showcase.projects.location>data</showcase.projects.location>
19-
<legend.engine.version>4.54.1</legend.engine.version>
19+
<legend.engine.version>4.68.0</legend.engine.version>
2020

2121
</properties>
2222

0 commit comments

Comments
 (0)