generated from finos/software-project-blueprint
-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move generation logic to Pure (#2519)
* Check string length before substring * Move generation to logic to pure * fix dependencies * fix dependencies * fix dependencies
- Loading branch information
1 parent
c4d7fcc
commit 564eeeb
Showing
6 changed files
with
264 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...gine-xt-snowflakeApp-pure/src/main/resources/core_snowflakeapp/generation/generation.pure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import meta::external::function::activator::snowflakeApp::generation::*; | ||
import meta::relational::mapping::*; | ||
import meta::pure::executionPlan::*; | ||
|
||
|
||
function meta::external::function::activator::snowflakeApp::generation::generateArtifact(s: meta::external::function::activator::snowflakeApp::SnowflakeApp[1]):Any[*] | ||
{ | ||
let extensions = meta::external::format::shared::externalFormatExtension()->concatenate(meta::relational::extension::relationalExtensions()); | ||
meta::external::function::activator::snowflakeApp::generation::generateArtifact($s, $extensions); | ||
} | ||
|
||
function meta::external::function::activator::snowflakeApp::generation::generateArtifact(s: meta::external::function::activator::snowflakeApp::SnowflakeApp[1], extensions:meta::pure::extension::Extension[*]):String[1] | ||
{ | ||
let plan = meta::pure::executionPlan::executionPlan($s.function->cast(@ConcreteFunctionDefinition<Any>),$extensions ); | ||
let resultStub = generateResultTypeStub($plan.rootExecutionNode.resultType->cast(@TDSResultType), $extensions); | ||
let generatedQuery = $plan.rootExecutionNode->allNodes($extensions)->filter(n|$n->instanceOf(SQLExecutionNode))->last()->cast(@SQLExecutionNode).sqlQuery->toOne('candidate query not found'); | ||
'CREATE OR REPLACE SECURE FUNCTION '+ $s.applicationName->toUpper()+ ' RETURNS TABLE ('+ $resultStub+ ') LANGUAGE SQL AS \''+ $generatedQuery +'\';'; | ||
|
||
} | ||
|
||
function meta::external::function::activator::snowflakeApp::generation::generateResultTypeStub(r: TDSResultType[1], extensions:meta::pure::extension::Extension[*]):String[1] | ||
{ | ||
let tdsTypeToRelationalTypeMap = TdsTypeToRelationalTypeMap(); | ||
$r.tdsColumns->map(c|'"'+ $c.name->toUpper() + '" '+ $tdsTypeToRelationalTypeMap->get($c.type->toOne('Column type missing for column: '+$c.name))->toOne('Relational type missing for type: '+ $c.type->toOne()->toString()))->joinStrings(','); | ||
} | ||
|
||
function meta::external::function::activator::snowflakeApp::generation::TdsTypeToRelationalTypeMap():Map<PrimitiveType, String>[1] | ||
{ | ||
[pair(String, 'VARCHAR(16777216)'), | ||
pair(Boolean, 'boolean'), | ||
pair(Integer, 'number'), | ||
pair(Float, 'number') | ||
]->newMap() | ||
} |
175 changes: 175 additions & 0 deletions
175
...ine-xt-snowflakeApp-pure/src/main/resources/core_snowflakeapp/showcase/showcaseModel.pure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
|
||
import meta::external::function::activator::snowflakeApp::tests::*; | ||
import meta::external::function::activator::snowflakeApp::tests::model::simple::*; | ||
import meta::pure::runtime::*; | ||
import meta::core::runtime::*; | ||
import meta::relational::runtime::*; | ||
import meta::external::store::relational::runtime::*; | ||
import meta::relational::metamodel::*; | ||
|
||
|
||
Class meta::external::function::activator::snowflakeApp::tests::model::simple::PersonX | ||
{ | ||
firstName : String[1]; | ||
lastName : String[1]; | ||
otherNames : String[*]; | ||
extraInformation : String[0..1]; | ||
manager : PersonX[0..1]; | ||
age : Integer[0..1]; | ||
nickName : String[0..1]; | ||
activeEmployment: Boolean[0..1]; | ||
name(){$this.firstName+' '+$this.lastName}:String[1]; | ||
|
||
} | ||
|
||
function meta::external::function::activator::snowflakeApp::tests::testRuntime(db:Database[1]):Runtime[1] | ||
{ | ||
testRuntime(testDatabaseConnection($db,[]->cast(@String))); | ||
} | ||
|
||
function meta::external::function::activator::snowflakeApp::tests::testRelationalConnection():ConnectionStore[1] | ||
{ | ||
^ConnectionStore( | ||
element = dbInc ,connection= | ||
^RelationalDatabaseConnection( | ||
type = DatabaseType.H2, | ||
datasourceSpecification = ^meta::pure::alloy::connections::alloy::specification::LocalH2DatasourceSpecification(testDataSetupCsv = ''), | ||
authenticationStrategy = ^meta::pure::alloy::connections::alloy::authentication::TestDatabaseAuthenticationStrategy() | ||
)) | ||
} | ||
|
||
function <<access.private>> meta::external::function::activator::snowflakeApp::tests::testRuntime(testConnection:ConnectionStore[1]):Runtime[1] | ||
{ | ||
^Runtime(connectionStores = $testConnection) | ||
} | ||
|
||
function <<access.private>> meta::external::function::activator::snowflakeApp::tests::testDatabaseConnection(db:Database[1], timeZone:String[0..1]):ConnectionStore[1] | ||
{ | ||
^ConnectionStore( | ||
element = $db, | ||
connection= | ||
^TestDatabaseConnection( | ||
type = DatabaseType.H2, | ||
timeZone = if($timeZone->isEmpty(), |'GMT', |$timeZone) | ||
)); | ||
} | ||
|
||
|
||
###Mapping | ||
|
||
import meta::external::function::activator::snowflakeApp::tests::model::simple::*; | ||
import meta::external::function::activator::snowflakeApp::tests::*; | ||
|
||
|
||
Mapping meta::external::function::activator::snowflakeApp::tests::simpleRelationalMapping | ||
( | ||
|
||
PersonX : Relational | ||
{ | ||
scope([dbInc]) | ||
( | ||
firstName : personTable.FIRSTNAME, | ||
age : personTable.AGE | ||
), | ||
scope([dbInc]default.personTable) | ||
( | ||
lastName : LASTNAME | ||
), | ||
manager : [dbInc]@Person_Manager | ||
} | ||
|
||
|
||
) | ||
|
||
|
||
|
||
Mapping meta::external::function::activator::snowflakeApp::tests::simpleRelationalMapping2 | ||
( | ||
|
||
PersonX : Relational | ||
{ | ||
scope([dbInc]) | ||
( | ||
firstName : concat(personTable.FIRSTNAME,'__X'), | ||
age : personTable.AGE | ||
), | ||
scope([dbInc]default.personTable) | ||
( | ||
lastName : concat(LASTNAME,'__X') | ||
), | ||
manager : [dbInc]@Person_Manager | ||
} | ||
|
||
|
||
) | ||
|
||
|
||
###Relational | ||
Database meta::external::function::activator::snowflakeApp::tests::dbInc | ||
( | ||
Table personTable (ID INT PRIMARY KEY, FIRSTNAME VARCHAR(200), LASTNAME VARCHAR(200), AGE INT, ADDRESSID INT, FIRMID INT, MANAGERID INT) | ||
Table validPersonTable (ID INT PRIMARY KEY, FIRSTNAME VARCHAR(200), LASTNAME VARCHAR(200), AGE INT, ADDRESSID INT, FIRMID INT, MANAGERID INT) | ||
Table PersonTableExtension (ID INT PRIMARY KEY, FIRSTNAME VARCHAR(200), LASTNAME VARCHAR(200), AGE INT, ADDRESSID INT, FIRMID INT, MANAGERID INT, birthDate DATE) | ||
Table differentPersonTable (ID INT PRIMARY KEY, FIRSTNAME VARCHAR(200), LASTNAME VARCHAR(200), AGE INT, ADDRESSID INT, FIRMID INT, MANAGERID INT) | ||
|
||
Table firmTable(ID INT PRIMARY KEY, LEGALNAME VARCHAR(200), ADDRESSID INT, CEOID INT) | ||
Table firmExtensionTable(firmId INT PRIMARY KEY, legalName VARCHAR(200), establishedDate DATE) | ||
Table otherFirmTable(ID INT PRIMARY KEY, LEGALNAME VARCHAR(200), ADDRESSID INT) | ||
|
||
Table addressTable(ID INT PRIMARY KEY, TYPE INT, NAME VARCHAR(200), STREET VARCHAR(100), COMMENTS VARCHAR(100)) | ||
Table locationTable(ID INT PRIMARY KEY, PERSONID INT, PLACE VARCHAR(200),date DATE) | ||
Table placeOfInterestTable(ID INT PRIMARY KEY,locationID INT PRIMARY KEY, NAME VARCHAR(200)) | ||
|
||
View PersonFirmView | ||
( | ||
PERSON_ID: personTable.ID PRIMARY KEY, | ||
lastName: personTable.LASTNAME, | ||
firm_name : @Firm_Person | firmTable.LEGALNAME | ||
) | ||
|
||
View FirstNameAddress | ||
( | ||
~distinct | ||
firstName: personTable.FIRSTNAME PRIMARY KEY, | ||
address : @Address_Person | addressTable.NAME PRIMARY KEY | ||
) | ||
|
||
View personViewWithGroupBy | ||
( | ||
~groupBy(personTable.ID) | ||
id: personTable.ID PRIMARY KEY, | ||
maxage: max(personTable.AGE) | ||
) | ||
|
||
View PersonViewWithDistinct | ||
( | ||
~distinct | ||
id: @PersonWithPersonView| personTable.ID PRIMARY KEY, | ||
firstName: @PersonWithPersonView| personTable.FIRSTNAME, | ||
lastName: @PersonWithPersonView|personTable.LASTNAME, | ||
firmId: @PersonWithPersonView|personTable.FIRMID | ||
) | ||
|
||
Schema productSchema | ||
( | ||
Table productTable(ID INT PRIMARY KEY, NAME VARCHAR(200)) | ||
) | ||
|
||
Filter FirmXFilter(firmTable.LEGALNAME = 'Firm X') | ||
Filter FirmBFilter(firmTable.LEGALNAME = 'Firm B') | ||
|
||
Join personViewWithFirmTable(firmTable.ID = PersonViewWithDistinct.firmId) | ||
Join PersonWithPersonView(personTable.ID = personViewWithGroupBy.id and personTable.AGE = personViewWithGroupBy.maxage) | ||
Join Address_Firm(addressTable.ID = firmTable.ADDRESSID) | ||
Join Address_Person(addressTable.ID = personTable.ADDRESSID) | ||
Join Firm_Ceo(firmTable.CEOID = personTable.ID) | ||
Join Firm_Person(firmTable.ID = personTable.FIRMID) | ||
Join Firm_Person1(firmTable.ID = personTable.FIRMID and firmTable.LEGALNAME = 'Firm X') | ||
Join Firm_Person2(firmTable.ID = personTable.FIRMID and personTable.FIRSTNAME = 'Peter') | ||
Join FirmExtension_PersonExtension(firmExtensionTable.firmId = PersonTableExtension.FIRMID) | ||
Join Person_Location(personTable.ID = locationTable.PERSONID) | ||
Join Person_Manager(personTable.MANAGERID = {target}.ID) | ||
Join location_PlaceOfInterest(locationTable.ID = placeOfInterestTable.locationID) | ||
Join Person_OtherFirm(personTable.FIRMID = otherFirmTable.ID) | ||
|
||
) |
31 changes: 31 additions & 0 deletions
31
...t-snowflakeApp-pure/src/main/resources/core_snowflakeapp/showcase/showcaseNativeApps.pure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import meta::external::function::activator::snowflakeApp::generation::*; | ||
import meta::external::store::relational::runtime::*; | ||
import meta::pure::mapping::*; | ||
import meta::external::function::activator::snowflakeApp::tests::model::simple::*; | ||
import meta::external::function::activator::snowflakeApp::tests::*; | ||
import meta::external::function::activator::snowflakeApp::*; | ||
|
||
function meta::external::function::activator::snowflakeApp::tests::defaultConfig():SnowflakeDeploymentConfiguration[1] | ||
{ | ||
^SnowflakeDeploymentConfiguration(target = testRelationalConnection().connection->cast(@RelationalDatabaseConnection) ); | ||
} | ||
|
||
function meta::external::function::activator::snowflakeApp::tests::simpleApp():Any[*] | ||
{ | ||
let app = ^SnowflakeApp | ||
( | ||
applicationName = 'App1', | ||
owner = 'owner1', | ||
description = 'bla bla', | ||
activationConfiguration = defaultConfig() , | ||
function = meta::external::function::activator::snowflakeApp::tests::simpleRelationalfunction__TabularDataSet_1_ | ||
); | ||
let generatedQuery = $app->generateArtifact(); | ||
//isMulti | ||
} | ||
|
||
function meta::external::function::activator::snowflakeApp::tests::simpleRelationalfunction():TabularDataSet[1] | ||
{ | ||
PersonX.all()->filter(p|$p.firstName == 'haha')->project([col(p|$p.firstName, 'firstName'), col(p|$p.lastName, 'lastName')]) | ||
->from(simpleRelationalMapping, testRuntime(dbInc)) | ||
} |