From 3d96464f44b8da8c6b2366fc1dfe9921b0d5a1ee Mon Sep 17 00:00:00 2001 From: "Anumala, Mrudula [Engineering]" Date: Thu, 31 Oct 2024 15:04:45 -0400 Subject: [PATCH] Fix property sequence on routing --- .../core/pure/mapping/mappingExtension.pure | 5 ++++ .../pure/router/routing/router_routing.pure | 2 +- .../pureToSQLQuery/pureToSQLQuery.pure | 5 +++- .../enumeration/testEnumerationMapping.pure | 23 +++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/mapping/mappingExtension.pure b/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/mapping/mappingExtension.pure index 41b8c656385..09c9cea630b 100644 --- a/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/mapping/mappingExtension.pure +++ b/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/mapping/mappingExtension.pure @@ -146,6 +146,11 @@ function meta::pure::mapping::allEnumerationMappings(m: Mapping[1]): Enumeration $m.enumerationMappings->concatenate($m.includes->map(i | $i.included->allEnumerationMappings())) } +function meta::pure::mapping::getEnumAndSourceValues(e:meta::pure::mapping::EnumerationMapping[1]):Pair>[*] +{ + $e.enumValueMappings->map(e|pair($e.enum->id(), list($e.sourceValues->map(s|$s->toString())))); +} + function meta::pure::mapping::allSuperSetImplementations(set :PropertyMappingsImplementation[1], m:Mapping[1]):PropertyMappingsImplementation[*] { if ($set.superSetImplementationId->isEmpty(), diff --git a/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/router/routing/router_routing.pure b/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/router/routing/router_routing.pure index d604fd61e1b..31f387c9fa8 100644 --- a/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/router/routing/router_routing.pure +++ b/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/router/routing/router_routing.pure @@ -646,7 +646,7 @@ function meta::pure::router::routing::resolveVar(va:VariableExpression[1], state let res = $state.propertyMap.v->filter(p|$p.first == $va.name); let fullRes = if (!$res->isEmpty(), |let routed = $res.second->evaluateAndDeactivate()->cast(@ExtendedRoutedValueSpecification)->at(0)->toOne(); - ^$state(value=^$routed(value = $va));, + ^$state(value=^$routed(value = $va, genericType = $va.genericType));, |^$state(value=$va) ); print(if($debug.debug,|$debug.space+'~>V) ('+$fullRes.routingStrategy.toString()+') '+$fullRes.value->evaluateAndDeactivate()->cast(@ValueSpecification)->toOne()->asString()+'\n',|'')); diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/legend-engine-xt-relationalStore-core-pure/src/main/resources/core_relational/relational/pureToSQLQuery/pureToSQLQuery.pure b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/legend-engine-xt-relationalStore-core-pure/src/main/resources/core_relational/relational/pureToSQLQuery/pureToSQLQuery.pure index 00ab6538418..ba5c85dd62c 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/legend-engine-xt-relationalStore-core-pure/src/main/resources/core_relational/relational/pureToSQLQuery/pureToSQLQuery.pure +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/legend-engine-xt-relationalStore-core-pure/src/main/resources/core_relational/relational/pureToSQLQuery/pureToSQLQuery.pure @@ -3500,8 +3500,11 @@ function <> meta::relational::functions::pureToSqlQuery::process let distinctTransformers = $propertyMappings->filter(m|$m->instanceOf(RelationalPropertyMapping))->cast(@RelationalPropertyMapping).transformer->distinct(); let semiStructuredMappings = $propertyMappings->filter(m|$m->instanceOf(RelationalPropertyMapping))->forAll(x|$x->instanceOf(SemiStructuredRelationalPropertyMapping)); + if ($distinctTransformers->size() > 1, + | assertFalse($distinctTransformers->cast(@EnumerationMapping)->map(e | $e->meta::pure::mapping::getEnumAndSourceValues()->list())->distinct()->size() > 1, 'Unable to determine a unique Enum property mapping for an if stmt (returning an Enum)');, + | []; + ); - assertFalse($distinctTransformers->size() > 1, 'Unable to determine a unique Enum property mapping for an if stmt (returning an Enum)'); if ($semiStructuredMappings, | print(if(!$context.debug, |'', |$context.space+' Ignoring distinct transformer check as all property mappings are semi structured property mappings\n'));, | assertFalse($distinctTransformers->isEmpty(), 'Unable to determine the Enum property mapping for an if stmt (returning an Enum)'); diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/legend-engine-xt-relationalStore-core-pure/src/main/resources/core_relational/relational/tests/mapping/enumeration/testEnumerationMapping.pure b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/legend-engine-xt-relationalStore-core-pure/src/main/resources/core_relational/relational/tests/mapping/enumeration/testEnumerationMapping.pure index f6a29a2bb1e..f35d055a836 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/legend-engine-xt-relationalStore-core-pure/src/main/resources/core_relational/relational/tests/mapping/enumeration/testEnumerationMapping.pure +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/legend-engine-xt-relationalStore-core-pure/src/main/resources/core_relational/relational/tests/mapping/enumeration/testEnumerationMapping.pure @@ -449,3 +449,26 @@ function <> meta::relational::tests::projection::enumeration::testTds let tds = $result.values->at(0); assertSize($tds.rows, 3); } + +function <> meta::relational::tests::projection::enumeration::testEnumValueReturnedInIfExpMatch():Boolean[1] +{ + let result = execute({|Employee.all()->project( + [ + x|$x.type, + x|if(true, + | $x.type, + | $x.type + ) + ], + [ + 'Type' , + 'Type If' + ] + ); + }, employeeTestMapping, enumTestRuntime(), meta::relational::extension::relationalExtensions() + ); + + assertSameElements($result.values.rows.getEnum('Type If'), $result.values.rows.getEnum('Type')); + let tds = $result.values->at(0); + assertSize($tds.rows, 3); +} \ No newline at end of file