Skip to content

Commit 32885d5

Browse files
authored
Add Tabular function showcase (#846)
* Add Tabular function showcase * update import * fix tests
1 parent 8120df9 commit 32885d5

File tree

7 files changed

+324
-14
lines changed

7 files changed

+324
-14
lines changed

showcases/data/Essential/Functions/Date/Basic/code.pure

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ Mapping examples::stringToDate::StringToDateMapping
1818
targetValue: if(
1919
$src.sourceValue->isEmpty(),
2020
|[],
21-
|$src.sourceValue->toOne()->parseDate()->cast(
22-
@StrictDate
23-
)
21+
|$src.sourceValue->toOne()->parseDate()->cast(@StrictDate)
2422
)
2523
}
2624

@@ -48,4 +46,4 @@ Mapping examples::stringToDate::StringToDateMapping
4846
assert: '{"targetValue":"2022-02-17"}';
4947
)
5048
]
51-
)
49+
)

showcases/data/Model/Build a data model/code.pure

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ Mapping _03_modelToModelMapping::simpleModelToModelMapping
352352
*_01_basic::Product: Pure
353353
{
354354
~src _03_modelToModelMapping::S_Product
355-
~filter !($src.classification.type == 'type2')
355+
~filter $src.classification.type != 'type2'
356356
name: $src.name,
357357
synonyms[_01_basic_Synonym]: $src.synonym,
358358
classification[_01_basic_ProductClassification]: $src.classification
@@ -461,7 +461,7 @@ Mapping _03_modelToModelMapping::unionMapping
461461
_01_basic::Product[p1]: Pure
462462
{
463463
~src _03_modelToModelMapping::S_Product
464-
~filter !($src.classification.type == 'type2')
464+
~filter $src.classification.type != 'type2'
465465
name: $src.name,
466466
classification[_01_basic_ProductClassification]: $src.classification,
467467
synonyms[_01_basic_Synonym]: $src.synonym
Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
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+
12+
TabularFunction Person
13+
(
14+
firstname VARCHAR(200),
15+
lastname VARCHAR(200),
16+
age INTEGER,
17+
associatedFirmId INTEGER
18+
)
19+
TabularFunction Person2
20+
(
21+
firstname VARCHAR(200),
22+
lastname VARCHAR(200),
23+
age INTEGER,
24+
associatedFirmId INTEGER
25+
)
26+
TabularFunction ParentAndChildren
27+
(
28+
firstname VARCHAR(200),
29+
lastname VARCHAR(200),
30+
id INTEGER,
31+
age INTEGER,
32+
parentId INTEGER
33+
)
34+
)
35+
36+
Join firm_person(Org.Firm.firmId = Org.Person.associatedFirmId)
37+
Join firm_person2(Org.Firm.firmId = Org.Person2.associatedFirmId)
38+
Join relationship(Org.ParentAndChildren.parentId = {target}.id)
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()->project(
73+
[
74+
x|$x.firmId,
75+
x|$x.associatedPerson.age
76+
],
77+
[
78+
'Firm Id',
79+
'Associated Person/Age'
80+
]
81+
)->from(
82+
demo::udtf::DemoMapping,
83+
demo::runtimes::DemoRuntime
84+
)
85+
}
86+
87+
function demo::udtf::Org::FirmToPersonWithFilterOnPerson(): meta::pure::tds::TabularDataSet[1]
88+
{
89+
demo::udtf::Org::Firm.all()->filter(
90+
x|$x.associatedPerson->exists(
91+
x_1|$x_1.firstname == 'David'
92+
)
93+
)->project(
94+
[
95+
x|$x.firmId,
96+
x|$x.associatedPerson.age
97+
],
98+
[
99+
'Firm Id',
100+
'Associated Person/Age'
101+
]
102+
)->from(
103+
demo::udtf::DemoMapping,
104+
demo::runtimes::DemoRuntime
105+
)
106+
}
107+
108+
function demo::udtf::Org::FirmToPersonWithFilterOnPersonUsingUnion(): meta::pure::tds::TabularDataSet[1]
109+
{
110+
demo::udtf::Org::Firm.all()->filter(
111+
x|$x.associatedPerson->exists(
112+
x_1|$x_1.firstname == 'David'
113+
)
114+
)->project(
115+
[
116+
x|$x.firmId,
117+
x|$x.associatedPerson.age
118+
],
119+
[
120+
'Firm Id',
121+
'Associated Person/Age'
122+
]
123+
)->from(
124+
demo::udtf::DemoMappingUnion,
125+
demo::runtimes::DemoRuntime
126+
)
127+
}
128+
129+
function demo::udtf::Org::FetchChildrenViaSelfJoin(): meta::pure::tds::TabularDataSet[1]
130+
{
131+
demo::udtf::Org::Person.all()->project(
132+
[
133+
x|$x.firstname,
134+
x|$x.id,
135+
x|$x.children.age,
136+
x|$x.children.id,
137+
x|$x.children.firstname
138+
],
139+
[
140+
'Firstname',
141+
'Id',
142+
'Children/Age',
143+
'Children/Id',
144+
'Children/Firstname'
145+
]
146+
)->from(
147+
demo::udtf::DemoMappingSelfJoin,
148+
demo::runtimes::DemoRuntime
149+
)
150+
}
151+
152+
153+
###Mapping
154+
Mapping demo::udtf::DemoMapping
155+
(
156+
*demo::udtf::Org::Firm[f]: Relational
157+
{
158+
~primaryKey
159+
(
160+
[demo::udtf::DemoDb]Org.Firm.firmId,
161+
[demo::udtf::DemoDb]Org.Firm.legalname
162+
)
163+
~mainTable [demo::udtf::DemoDb]Org.Firm
164+
firmId: [demo::udtf::DemoDb]Org.Firm.firmId,
165+
legalname: [demo::udtf::DemoDb]Org.Firm.legalname
166+
}
167+
*demo::udtf::Org::Person[p]: Relational
168+
{
169+
~mainTable [demo::udtf::DemoDb]Org.Person
170+
firstname: [demo::udtf::DemoDb]Org.Person.firstname,
171+
lastname: [demo::udtf::DemoDb]Org.Person.lastname,
172+
age: [demo::udtf::DemoDb]Org.Person.age
173+
}
174+
175+
demo::udtf::firm_person: Relational
176+
{
177+
AssociationMapping
178+
(
179+
assoacitedFirm[p,f]: [demo::udtf::DemoDb]@firm_person,
180+
associatedPerson[f,p]: [demo::udtf::DemoDb]@firm_person
181+
)
182+
}
183+
)
184+
185+
186+
###Mapping
187+
Mapping demo::udtf::DemoMappingUnion
188+
(
189+
*demo::udtf::Org::Person: Operation
190+
{
191+
meta::pure::router::operations::union_OperationSetImplementation_1__SetImplementation_MANY_(p1,p2)
192+
}
193+
*demo::udtf::Org::Firm[f]: Relational
194+
{
195+
~primaryKey
196+
(
197+
[demo::udtf::DemoDb]Org.Firm.firmId,
198+
[demo::udtf::DemoDb]Org.Firm.legalname
199+
)
200+
~mainTable [demo::udtf::DemoDb]Org.Firm
201+
firmId: [demo::udtf::DemoDb]Org.Firm.firmId,
202+
legalname: [demo::udtf::DemoDb]Org.Firm.legalname
203+
}
204+
demo::udtf::Org::Person[p1]: Relational
205+
{
206+
~mainTable [demo::udtf::DemoDb]Org.Person
207+
firstname: [demo::udtf::DemoDb]Org.Person.firstname,
208+
lastname: [demo::udtf::DemoDb]Org.Person.lastname,
209+
age: [demo::udtf::DemoDb]Org.Person.age
210+
}
211+
demo::udtf::Org::Person[p2]: Relational
212+
{
213+
~mainTable [demo::udtf::DemoDb]Org.Person2
214+
firstname: [demo::udtf::DemoDb]Org.Person2.firstname,
215+
lastname: [demo::udtf::DemoDb]Org.Person2.lastname,
216+
age: [demo::udtf::DemoDb]Org.Person2.age
217+
}
218+
219+
demo::udtf::firm_person: Relational
220+
{
221+
AssociationMapping
222+
(
223+
assoacitedFirm[p1,f]: [demo::udtf::DemoDb]@firm_person,
224+
assoacitedFirm[p2,f]: [demo::udtf::DemoDb]@firm_person2,
225+
associatedPerson[f,p1]: [demo::udtf::DemoDb]@firm_person,
226+
associatedPerson[f,p2]: [demo::udtf::DemoDb]@firm_person2
227+
)
228+
}
229+
)
230+
231+
232+
###Mapping
233+
Mapping demo::udtf::DemoMappingSelfJoin
234+
(
235+
*demo::udtf::Org::Person[p1]: Relational
236+
{
237+
~primaryKey
238+
(
239+
[demo::udtf::DemoDb]Org.ParentAndChildren.firstname
240+
)
241+
~mainTable [demo::udtf::DemoDb]Org.ParentAndChildren
242+
firstname: [demo::udtf::DemoDb]Org.ParentAndChildren.firstname,
243+
lastname: [demo::udtf::DemoDb]Org.ParentAndChildren.lastname,
244+
id: [demo::udtf::DemoDb]Org.ParentAndChildren.id,
245+
age: [demo::udtf::DemoDb]Org.ParentAndChildren.age
246+
}
247+
248+
demo::udtf::Person_person: Relational
249+
{
250+
AssociationMapping
251+
(
252+
children[p1,p1]: [demo::udtf::DemoDb]@relationship,
253+
parent[p1,p1]: [demo::udtf::DemoDb]@relationship
254+
)
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+
297+
###Snowflake
298+
SnowflakeApp demo::udtf::snowflakeApp::App1
299+
{
300+
applicationName : 'App1_revised';
301+
function : demo::udtf::Org::FirmToPersonWithFilterOnPersonUsingUnion():TabularDataSet[1];
302+
ownership : Deployment { identifier: '441143'};
303+
description : 'test App';
304+
activationConfiguration : demo::udtf::DemoSnowflakeConnection;
305+
}
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/data/Store/Relational Store/Query/code.pure

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ function showcase::northwind::store::functions::NorthwindExtendd(): Any[*]
607607
function showcase::simple::functions::simpleFunctionSort(): Any[*]
608608
{
609609
#>{showcase::simple::store::TestDatabase.TEST0}#->filter(
610-
c|!($c.FIRSTNAME == 'Doe')
610+
c|$c.FIRSTNAME != 'Doe'
611611
)->from(
612612
showcase::simple::connection::TestRuntime
613613
)->sort(
@@ -620,8 +620,8 @@ function showcase::simple::functions::simpleFunctionSort(): Any[*]
620620
function showcase::simple::functions::simpleTableFunctionFilter(): Any[*]
621621
{
622622
#>{showcase::simple::store::TestDatabase.TEST0}#->filter(
623-
c|!($c.FIRSTNAME == 'Doe') &&
624-
!($c.LASTNAME == 'Doe')
623+
c|($c.FIRSTNAME != 'Doe') &&
624+
($c.LASTNAME != 'Doe')
625625
)->from(
626626
showcase::simple::connection::TestRuntime
627627
)->sort(
@@ -634,7 +634,7 @@ function showcase::simple::functions::simpleTableFunctionFilter(): Any[*]
634634
function showcase::simple::functions::simpleTableFunctionGroup(): Any[*]
635635
{
636636
#>{showcase::simple::store::TestDatabase.TEST0}#->filter(
637-
c|!($c.FIRSTNAME == 'Doe')
637+
c|$c.FIRSTNAME != 'Doe'
638638
)->from(
639639
showcase::simple::connection::TestRuntime
640640
)->groupBy(
@@ -650,8 +650,8 @@ function showcase::simple::functions::simpleTableFunctionGroup(): Any[*]
650650
function showcase::simple::functions::simpleTableFunctionSlice(): Any[*]
651651
{
652652
#>{showcase::simple::store::TestDatabase.TEST0}#->filter(
653-
c|!($c.FIRSTNAME == 'Doe') &&
654-
!($c.LASTNAME == 'Doe')
653+
c|($c.FIRSTNAME != 'Doe') &&
654+
($c.LASTNAME != 'Doe')
655655
)->from(
656656
showcase::simple::connection::TestRuntime
657657
)

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)