From 66095a3099d03940abd288981d15333e3c0b3316 Mon Sep 17 00:00:00 2001 From: afine-gs Date: Thu, 31 Oct 2024 09:05:24 -0400 Subject: [PATCH] add testWrapper Example --- .../tests/testWrapper.pure | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 legend-engine-xts-analytics/legend-engine-xts-analytics-lineage/legend-engine-xt-analytics-lineage-pure/src/main/resources/core_analytics_lineage/tests/testWrapper.pure diff --git a/legend-engine-xts-analytics/legend-engine-xts-analytics-lineage/legend-engine-xt-analytics-lineage-pure/src/main/resources/core_analytics_lineage/tests/testWrapper.pure b/legend-engine-xts-analytics/legend-engine-xts-analytics-lineage/legend-engine-xt-analytics-lineage-pure/src/main/resources/core_analytics_lineage/tests/testWrapper.pure new file mode 100644 index 00000000000..2a58588341a --- /dev/null +++ b/legend-engine-xts-analytics/legend-engine-xts-analytics-lineage/legend-engine-xt-analytics-lineage-pure/src/main/resources/core_analytics_lineage/tests/testWrapper.pure @@ -0,0 +1,89 @@ +// Copyright 2024 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +###Pure +import meta::pure::lineage::*; +import meta::analytics::lineage::*; +import meta::relational::tests::model::simple::*; +import meta::relational::tests::mapping::association::embedded::*; +function meta::pure::lineage::test::testPersonToOrganisationsExample():Boolean[1] +{ + meta::relational::tests::mapping::association::embedded::setUp(); + let result = testWrapper(|Person.all()->project([p|$p.lastName,p|$p.firm.legalName, p|$p.firm.organizations.name], ['name', 'firm', 'team']), associationMapping, meta::external::store::relational::tests::testRuntime(), meta::relational::extension::relationalExtensions()); + let lineage = $result->meta::pure::lineage::test::getLineage(); + assertLineage(['Lambda', 'db_myDB', 'tb_myDBdefaultORGANIZATIONS', 'tb_myDBdefaultPERSON_FIRM_DENORM'], ['Lambda', 'meta::relational::tests::model::simple::Firm', 'meta::relational::tests::model::simple::Organization', 'meta::relational::tests::model::simple::Person', 'pack_meta::relational::tests::model::simple'],'[firm: [PERSON_FIRM_DENORM.FIRM_LEGALNAME ], name: [PERSON_FIRM_DENORM.PERSON_LASTNAME ], team: [ORGANIZATIONS.FIRM_ID , ORGANIZATIONS.NAME , PERSON_FIRM_DENORM.FIRM_ID ]]',$lineage); + let tds= $result->getTabularDatasetResult().values->at(0); + assertEquals(5, $tds.rows->size()); + assertSameElements(['Smith Firm X Team 1', 'Smith Firm X Team 2', 'Johnson Firm X Team 1', 'Johnson Firm X Team 2', 'Roberts Firm A Team 3'], $tds.rows->map(r|$r.getString('name')+' '+$r.getString('firm')->toString()+ ' ' +$r.getString('team'))); +} + + + +###Pure +import meta::analytics::lineage::*; +import meta::core::runtime::*; +import meta::pure::mapping::*; +import meta::pure::lineage::test::*; +function meta::pure::lineage::test::getLineage(result:Map[1]):FunctionAnalytics[1] +{ +$result->get('lineage')->cast(@LineageResult).result->toOne(); + +} + +function meta::pure::lineage::getTabularDatasetResult(result:Map[1]):meta::pure::mapping::Result[1] +{ +$result->get('executeResult')->cast(@ExecuteResult).result->toOne(); + +} + +function meta::pure::lineage::testWrapper(f:FunctionDefinition<{->T[y]}>[1], m:Mapping[1], runtime:Runtime[1], extensions:meta::pure::extension::Extension[*]):Map[1] +{ + + newMap([meta::pure::lineage::test::executeWrapper($f,$m,$runtime,$extensions), + meta::pure::lineage::test::lineageWrapper($f,$m,$runtime,$extensions) + ] + ); + +} + + +function meta::pure::lineage::test::executeWrapper(f:FunctionDefinition<{->T[y]}>[1], m:Mapping[1], runtime:Runtime[1], extensions:meta::pure::extension::Extension[*]):Pair[1] +{ + +pair('executeResult',^ExecuteResult(result=meta::pure::router::execute($f,$m,$runtime,$extensions))); + +} + +function meta::pure::lineage::test::lineageWrapper(f:FunctionDefinition<{->T[y]}>[1], m:Mapping[1], runtime:Runtime[1], extensions:meta::pure::extension::Extension[*]):Pair[1] +{ + +pair('lineage',^LineageResult(result=computeLineage($f,$m,$runtime,$extensions))); + +} + + +Class meta::pure::lineage::test::Result +{ + +} + +Class meta::pure::lineage::test::ExecuteResult extends meta::pure::lineage::test::Result +{ + result:meta::pure::mapping::Result[1]; + +} +Class meta::pure::lineage::test::LineageResult extends meta::pure::lineage::test::Result +{ + result:FunctionAnalytics[1]; +} \ No newline at end of file