Skip to content

Commit

Permalink
Add Tabular function showcase (#846)
Browse files Browse the repository at this point in the history
* Add Tabular function showcase

* update import

* fix tests
  • Loading branch information
Yasirmod17 authored Jan 27, 2025
1 parent 8120df9 commit 32885d5
Show file tree
Hide file tree
Showing 7 changed files with 324 additions and 14 deletions.
6 changes: 2 additions & 4 deletions showcases/data/Essential/Functions/Date/Basic/code.pure
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ Mapping examples::stringToDate::StringToDateMapping
targetValue: if(
$src.sourceValue->isEmpty(),
|[],
|$src.sourceValue->toOne()->parseDate()->cast(
@StrictDate
)
|$src.sourceValue->toOne()->parseDate()->cast(@StrictDate)
)
}

Expand Down Expand Up @@ -48,4 +46,4 @@ Mapping examples::stringToDate::StringToDateMapping
assert: '{"targetValue":"2022-02-17"}';
)
]
)
)
4 changes: 2 additions & 2 deletions showcases/data/Model/Build a data model/code.pure
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ Mapping _03_modelToModelMapping::simpleModelToModelMapping
*_01_basic::Product: Pure
{
~src _03_modelToModelMapping::S_Product
~filter !($src.classification.type == 'type2')
~filter $src.classification.type != 'type2'
name: $src.name,
synonyms[_01_basic_Synonym]: $src.synonym,
classification[_01_basic_ProductClassification]: $src.classification
Expand Down Expand Up @@ -461,7 +461,7 @@ Mapping _03_modelToModelMapping::unionMapping
_01_basic::Product[p1]: Pure
{
~src _03_modelToModelMapping::S_Product
~filter !($src.classification.type == 'type2')
~filter $src.classification.type != 'type2'
name: $src.name,
classification[_01_basic_ProductClassification]: $src.classification,
synonyms[_01_basic_Synonym]: $src.synonym
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,305 @@
###Relational
Database demo::udtf::DemoDb
(
Schema Org
(
Table Firm
(
firmId INTEGER,
legalname VARCHAR(200)
)

TabularFunction Person
(
firstname VARCHAR(200),
lastname VARCHAR(200),
age INTEGER,
associatedFirmId INTEGER
)
TabularFunction Person2
(
firstname VARCHAR(200),
lastname VARCHAR(200),
age INTEGER,
associatedFirmId INTEGER
)
TabularFunction ParentAndChildren
(
firstname VARCHAR(200),
lastname VARCHAR(200),
id INTEGER,
age INTEGER,
parentId INTEGER
)
)

Join firm_person(Org.Firm.firmId = Org.Person.associatedFirmId)
Join firm_person2(Org.Firm.firmId = Org.Person2.associatedFirmId)
Join relationship(Org.ParentAndChildren.parentId = {target}.id)
)


###Pure
Class demo::udtf::Org::Firm
{
firmId: Integer[1];
legalname: String[1];
}

Class demo::udtf::Org::Person
{
firstname: String[1];
lastname: String[1];
age: Integer[1];
associatedFirmId: Integer[1];
id: Integer[1];
}

Association demo::udtf::Person_person
{
parent: demo::udtf::Org::Person[1];
children: demo::udtf::Org::Person[1..*];
}

Association demo::udtf::firm_person
{
assoacitedFirm: demo::udtf::Org::Firm[1];
associatedPerson: demo::udtf::Org::Person[1..*];
}

function demo::udtf::Org::FirmToPerson(): meta::pure::tds::TabularDataSet[1]
{
demo::udtf::Org::Firm.all()->project(
[
x|$x.firmId,
x|$x.associatedPerson.age
],
[
'Firm Id',
'Associated Person/Age'
]
)->from(
demo::udtf::DemoMapping,
demo::runtimes::DemoRuntime
)
}

function demo::udtf::Org::FirmToPersonWithFilterOnPerson(): meta::pure::tds::TabularDataSet[1]
{
demo::udtf::Org::Firm.all()->filter(
x|$x.associatedPerson->exists(
x_1|$x_1.firstname == 'David'
)
)->project(
[
x|$x.firmId,
x|$x.associatedPerson.age
],
[
'Firm Id',
'Associated Person/Age'
]
)->from(
demo::udtf::DemoMapping,
demo::runtimes::DemoRuntime
)
}

function demo::udtf::Org::FirmToPersonWithFilterOnPersonUsingUnion(): meta::pure::tds::TabularDataSet[1]
{
demo::udtf::Org::Firm.all()->filter(
x|$x.associatedPerson->exists(
x_1|$x_1.firstname == 'David'
)
)->project(
[
x|$x.firmId,
x|$x.associatedPerson.age
],
[
'Firm Id',
'Associated Person/Age'
]
)->from(
demo::udtf::DemoMappingUnion,
demo::runtimes::DemoRuntime
)
}

function demo::udtf::Org::FetchChildrenViaSelfJoin(): meta::pure::tds::TabularDataSet[1]
{
demo::udtf::Org::Person.all()->project(
[
x|$x.firstname,
x|$x.id,
x|$x.children.age,
x|$x.children.id,
x|$x.children.firstname
],
[
'Firstname',
'Id',
'Children/Age',
'Children/Id',
'Children/Firstname'
]
)->from(
demo::udtf::DemoMappingSelfJoin,
demo::runtimes::DemoRuntime
)
}


###Mapping
Mapping demo::udtf::DemoMapping
(
*demo::udtf::Org::Firm[f]: Relational
{
~primaryKey
(
[demo::udtf::DemoDb]Org.Firm.firmId,
[demo::udtf::DemoDb]Org.Firm.legalname
)
~mainTable [demo::udtf::DemoDb]Org.Firm
firmId: [demo::udtf::DemoDb]Org.Firm.firmId,
legalname: [demo::udtf::DemoDb]Org.Firm.legalname
}
*demo::udtf::Org::Person[p]: Relational
{
~mainTable [demo::udtf::DemoDb]Org.Person
firstname: [demo::udtf::DemoDb]Org.Person.firstname,
lastname: [demo::udtf::DemoDb]Org.Person.lastname,
age: [demo::udtf::DemoDb]Org.Person.age
}

demo::udtf::firm_person: Relational
{
AssociationMapping
(
assoacitedFirm[p,f]: [demo::udtf::DemoDb]@firm_person,
associatedPerson[f,p]: [demo::udtf::DemoDb]@firm_person
)
}
)


###Mapping
Mapping demo::udtf::DemoMappingUnion
(
*demo::udtf::Org::Person: Operation
{
meta::pure::router::operations::union_OperationSetImplementation_1__SetImplementation_MANY_(p1,p2)
}
*demo::udtf::Org::Firm[f]: Relational
{
~primaryKey
(
[demo::udtf::DemoDb]Org.Firm.firmId,
[demo::udtf::DemoDb]Org.Firm.legalname
)
~mainTable [demo::udtf::DemoDb]Org.Firm
firmId: [demo::udtf::DemoDb]Org.Firm.firmId,
legalname: [demo::udtf::DemoDb]Org.Firm.legalname
}
demo::udtf::Org::Person[p1]: Relational
{
~mainTable [demo::udtf::DemoDb]Org.Person
firstname: [demo::udtf::DemoDb]Org.Person.firstname,
lastname: [demo::udtf::DemoDb]Org.Person.lastname,
age: [demo::udtf::DemoDb]Org.Person.age
}
demo::udtf::Org::Person[p2]: Relational
{
~mainTable [demo::udtf::DemoDb]Org.Person2
firstname: [demo::udtf::DemoDb]Org.Person2.firstname,
lastname: [demo::udtf::DemoDb]Org.Person2.lastname,
age: [demo::udtf::DemoDb]Org.Person2.age
}

demo::udtf::firm_person: Relational
{
AssociationMapping
(
assoacitedFirm[p1,f]: [demo::udtf::DemoDb]@firm_person,
assoacitedFirm[p2,f]: [demo::udtf::DemoDb]@firm_person2,
associatedPerson[f,p1]: [demo::udtf::DemoDb]@firm_person,
associatedPerson[f,p2]: [demo::udtf::DemoDb]@firm_person2
)
}
)


###Mapping
Mapping demo::udtf::DemoMappingSelfJoin
(
*demo::udtf::Org::Person[p1]: Relational
{
~primaryKey
(
[demo::udtf::DemoDb]Org.ParentAndChildren.firstname
)
~mainTable [demo::udtf::DemoDb]Org.ParentAndChildren
firstname: [demo::udtf::DemoDb]Org.ParentAndChildren.firstname,
lastname: [demo::udtf::DemoDb]Org.ParentAndChildren.lastname,
id: [demo::udtf::DemoDb]Org.ParentAndChildren.id,
age: [demo::udtf::DemoDb]Org.ParentAndChildren.age
}

demo::udtf::Person_person: Relational
{
AssociationMapping
(
children[p1,p1]: [demo::udtf::DemoDb]@relationship,
parent[p1,p1]: [demo::udtf::DemoDb]@relationship
)
}
)


###Connection
RelationalDatabaseConnection demo::udtf::DemoSnowflakeConnection
{
store: demo::udtf::DemoDb;
type: Snowflake;
specification: Snowflake
{
name: 'SUMMIT_MDM_DATA';
account: 'sfcedeawseast1d01';
warehouse: 'DEMO_WH';
region: 'us-east-1';
};
auth: SnowflakePublic
{
publicUserName: 'isThis';
privateKeyVaultReference: 'Hi';
passPhraseVaultReference: 'What';
};
}


###Runtime
Runtime demo::runtimes::DemoRuntime
{
mappings:
[
demo::udtf::DemoMapping
];
connections:
[
demo::udtf::DemoDb:
[
connection_2: demo::udtf::DemoSnowflakeConnection
]
];
}


###Snowflake
SnowflakeApp demo::udtf::snowflakeApp::App1
{
applicationName : 'App1_revised';
function : demo::udtf::Org::FirmToPersonWithFilterOnPersonUsingUnion():TabularDataSet[1];
ownership : Deployment { identifier: '441143'};
description : 'test App';
activationConfiguration : demo::udtf::DemoSnowflakeConnection;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Relational Database Specification with Tabular Functions
description: Example of database specification with tabular Function.
---

Tabular functions are database objects that effectively function as parameterized views.
This showcase gives examples of tabular functions that do not accept any parameters.
12 changes: 6 additions & 6 deletions showcases/data/Store/Relational Store/Query/code.pure
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ function showcase::northwind::store::functions::NorthwindExtendd(): Any[*]
function showcase::simple::functions::simpleFunctionSort(): Any[*]
{
#>{showcase::simple::store::TestDatabase.TEST0}#->filter(
c|!($c.FIRSTNAME == 'Doe')
c|$c.FIRSTNAME != 'Doe'
)->from(
showcase::simple::connection::TestRuntime
)->sort(
Expand All @@ -620,8 +620,8 @@ function showcase::simple::functions::simpleFunctionSort(): Any[*]
function showcase::simple::functions::simpleTableFunctionFilter(): Any[*]
{
#>{showcase::simple::store::TestDatabase.TEST0}#->filter(
c|!($c.FIRSTNAME == 'Doe') &&
!($c.LASTNAME == 'Doe')
c|($c.FIRSTNAME != 'Doe') &&
($c.LASTNAME != 'Doe')
)->from(
showcase::simple::connection::TestRuntime
)->sort(
Expand All @@ -634,7 +634,7 @@ function showcase::simple::functions::simpleTableFunctionFilter(): Any[*]
function showcase::simple::functions::simpleTableFunctionGroup(): Any[*]
{
#>{showcase::simple::store::TestDatabase.TEST0}#->filter(
c|!($c.FIRSTNAME == 'Doe')
c|$c.FIRSTNAME != 'Doe'
)->from(
showcase::simple::connection::TestRuntime
)->groupBy(
Expand All @@ -650,8 +650,8 @@ function showcase::simple::functions::simpleTableFunctionGroup(): Any[*]
function showcase::simple::functions::simpleTableFunctionSlice(): Any[*]
{
#>{showcase::simple::store::TestDatabase.TEST0}#->filter(
c|!($c.FIRSTNAME == 'Doe') &&
!($c.LASTNAME == 'Doe')
c|($c.FIRSTNAME != 'Doe') &&
($c.LASTNAME != 'Doe')
)->from(
showcase::simple::connection::TestRuntime
)
Expand Down
2 changes: 1 addition & 1 deletion showcases/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<maven.compiler.target>1.8</maven.compiler.target>
<maven.surefire.thread.count>3</maven.surefire.thread.count>
<showcase.projects.location>data</showcase.projects.location>
<legend.engine.version>4.54.1</legend.engine.version>
<legend.engine.version>4.68.0</legend.engine.version>

</properties>

Expand Down
Loading

0 comments on commit 32885d5

Please sign in to comment.