From 94da376852ab6fac6581ed6f63bc1d9af421698e Mon Sep 17 00:00:00 2001 From: gs-gunjan <72594207+gs-gunjan@users.noreply.github.com> Date: Mon, 27 May 2024 14:48:07 +0530 Subject: [PATCH] fixing report lineage for lambdas with only groupBys (#2865) --- .../core/pure/lineage/scanProject.pure | 19 +++++++++++++++++++ .../tests/scanProjectTests.pure | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/lineage/scanProject.pure b/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/lineage/scanProject.pure index 30b30e5abc8..774c0ba08ec 100644 --- a/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/lineage/scanProject.pure +++ b/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/lineage/scanProject.pure @@ -59,6 +59,16 @@ function <> meta::pure::lineage::scanProject::scanProjectRecursi ] ); + ), + pair('meta::pure::tds::groupBy_K_MANY__Function_MANY__AggregateValue_MANY__String_MANY__TabularDataSet_1_', + | let funcs = $fe.parametersValues->at(1)->match([s:InstanceValue[1]|$s.values, a:Any[*]|^Unknown()]); + let aggregateFuncs = $fe.parametersValues->at(2)->scanAggregateValue(); + let allFuncs = $funcs->concatenate($aggregateFuncs); + let names = $fe.parametersValues->at(3)->match([s:InstanceValue[1]|$s.values,a:Any[*]|^Unknown()]); + ^Project(projectfuncEntryPoint = $fe, + columns = zip($names->match([s:String[*]|$s, a:Unknown[*]|range(1, $allFuncs->size(),1)->map(z|'unknown_'+$z->toString())]), + $allFuncs->match([s:FunctionDefinition[*]|$s, a:Unknown[*]|[]])) + ); ) ]; let funcFullPath = $fe.func->toOne()->elementToPath(); @@ -87,3 +97,12 @@ function <> meta::pure::lineage::scanProject::scanProjectRecursi ] ); } + +function <> meta::pure::lineage::scanProject::scanAggregateValue(val:Any[*]):FunctionDefinition[*] +{ + $val->match([ + s:InstanceValue[*]|$s.values->scanAggregateValue(), + se: FunctionExpression[*]| $se->map(x| $x.parametersValues->at(0))->scanAggregateValue(), + f: FunctionDefinition[*]|$f, + a:Any[*]|[]]); +} 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/scanProjectTests.pure b/legend-engine-xts-analytics/legend-engine-xts-analytics-lineage/legend-engine-xt-analytics-lineage-pure/src/main/resources/core_analytics_lineage/tests/scanProjectTests.pure index d3cea2e99fa..22b8f08de2f 100644 --- a/legend-engine-xts-analytics/legend-engine-xts-analytics-lineage/legend-engine-xt-analytics-lineage-pure/src/main/resources/core_analytics_lineage/tests/scanProjectTests.pure +++ b/legend-engine-xts-analytics/legend-engine-xts-analytics-lineage/legend-engine-xt-analytics-lineage-pure/src/main/resources/core_analytics_lineage/tests/scanProjectTests.pure @@ -28,6 +28,17 @@ function <> meta::pure::lineage::scanProject::test::executeWithP ]), simpleRelationalMapping, meta::external::store::relational::tests::testRuntime(), meta::relational::extension::relationalExtensions()); } +function <> meta::pure::lineage::scanProject::test::executeWithGroupBy():Any[1] +{ + execute(|Trade.all()->groupBy([x|$x.date->adjust(0, DurationUnit.DAYS)], + [ + agg(x | $x.quantity, y | $y->sum()), + agg(x | $x.id, y | $y->count()) + ], + ['tradeDate', 'quantity', 'count'] + ), simpleRelationalMapping, meta::external::store::relational::tests::testRuntime(), meta::relational::extension::relationalExtensions()); +} + function <> meta::pure::lineage::scanProject::test::executeWithProjectUsingCol():Any[1] { execute(|Firm.all()->project([ @@ -94,3 +105,10 @@ function <> meta::pure::lineage::scanProject::t let p = $x.funcEntryPoint->toOne()->evaluateAndDeactivate()->meta::pure::lineage::scanProject::scanProject(); assertEquals(['a', 'b', 'c'], $p.columns.first); } + +function <> meta::pure::lineage::scanProject::test::testFindGroupBy():Boolean[1] +{ + let x = meta::pure::lineage::scanProject::test::executeWithGroupBy__Any_1_->scanExecutes(); + let p = $x.funcEntryPoint->toOne()->evaluateAndDeactivate()->meta::pure::lineage::scanProject::scanProject(); + assertEquals(['tradeDate', 'quantity', 'count'], $p.columns.first); +}