Skip to content

Commit

Permalink
Merge branch 'finos:master' into finos-master
Browse files Browse the repository at this point in the history
  • Loading branch information
MauricioUyaguari authored Nov 15, 2024
2 parents ac9392d + dac201d commit 1ce2646
Show file tree
Hide file tree
Showing 14 changed files with 168 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ function meta::pure::mapping::allEnumerationMappings(m: Mapping[1]): Enumeration
$m.enumerationMappings->concatenate($m.includes->map(i | $i.included->allEnumerationMappings()))
}

function meta::pure::mapping::valueTransformerEquality(a:ValueTransformer<Any>[0..1], b:ValueTransformer<Any>[0..1]):Boolean[1]
{
($a->isEmpty() && $b->isEmpty()) || ($a->isNotEmpty() && $b->isNotEmpty() && $a->type() == $b->type() && $a->match([
i:EnumerationMapping<Any>[1]| $i.enumeration == $b->cast(@EnumerationMapping<Any>).enumeration && enumValueMappingsEquality($i.enumValueMappings->zip($b->cast(@EnumerationMapping<Any>).enumValueMappings));,
v:ValueTransformer<Any>[1]| fail('UnSupported Operation: Only supports EnumerationMapping')
]))
}

function meta::pure::mapping::enumValueMappingsEquality(pairs:Pair<EnumValueMapping,EnumValueMapping>[*]):Boolean[1]
{
$pairs.first.enum == $pairs.second.enum && $pairs.first.sourceValues == $pairs.second.sourceValues
}

function meta::pure::mapping::allSuperSetImplementations(set :PropertyMappingsImplementation[1], m:Mapping[1]):PropertyMappingsImplementation[*]
{
if ($set.superSetImplementationId->isEmpty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',|''));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,28 @@ function <<test.Test>> meta::pure::functions::relation::tests::map::testSimpleMa
4
#->map(x|$x.val->toOne() + 1);
assertEquals([2,4,5], $res);
}

Primitive meta::pure::functions::relation::tests::map::SmallInt extends Integer
[
$this < 5
]

function <<test.Test>> meta::pure::functions::relation::tests::map::testSimpleWithCastMap():Boolean[1]
{
let res = #TDS
val
1
3
4
#->cast(@Relation<(val:meta::pure::functions::relation::tests::map::SmallInt)>)->map(x|$x.val->toOne() + 1);
assertEquals([2,4,5], $res);

let tds = #TDS
val
1
3
7
#;
assertError(|$tds->cast(@Relation<(val:meta::pure::functions::relation::tests::map::SmallInt)>)->map(x|$x.val->toOne() + 1), 'Constraint :[0] violated in the Class SmallInt');
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
import org.finos.legend.pure.m3.navigation.M3Paths;
import org.finos.legend.pure.m3.navigation.M3Properties;
import org.finos.legend.pure.m3.navigation.ProcessorSupport;
import org.finos.legend.pure.m3.navigation.generictype.GenericType;
import org.finos.legend.pure.m4.coreinstance.CoreInstance;
import org.finos.legend.pure.runtime.java.compiled.extension.CompiledExtension;
import org.finos.legend.pure.runtime.java.compiled.generation.ProcessorContext;
import org.finos.legend.pure.runtime.java.compiled.generation.processors.natives.Native;
import org.finos.legend.pure.runtime.java.compiled.generation.processors.natives.essentials.lang.cast.Cast;
import org.finos.legend.pure.runtime.java.compiled.generation.processors.support.Bridge;
import org.finos.legend.pure.runtime.java.compiled.generation.processors.support.function.PureFunction1;
import org.finos.legend.pure.runtime.java.compiled.generation.processors.type.TypeProcessor;
Expand Down Expand Up @@ -109,9 +111,18 @@ public Function3<CoreInstance, CoreInstance, ProcessorContext, String> getExtraF
ProcessorSupport processorSupport = processorContext.getSupport();
CoreInstance nativeFunction = Instance.getValueForMetaPropertyToOneResolved(functionExpression, M3Properties.func, processorSupport);
CoreInstance functionType = processorSupport.function_getFunctionType(nativeFunction);
String returnType = TypeProcessor.typeToJavaObjectSingle(Instance.getValueForMetaPropertyToOneResolved(functionType, M3Properties.returnType, processorSupport), true, processorSupport);
CoreInstance returnGenericType = Instance.getValueForMetaPropertyToOneResolved(functionType, M3Properties.returnType, processorSupport);
String returnType = TypeProcessor.typeToJavaObjectSingle(returnGenericType, true, processorSupport);

return "(" + returnType + ")((org.finos.legend.pure.runtime.java.extension.external.relation.compiled.natives.shared.RowContainer)" + processedOwnerInstance + ").apply(\"" + Instance.getValueForMetaPropertyToOneResolved(function, M3Properties.name, processorContext.getSupport()).getName() + "\")";
String getValue = "(" + returnType + ")((org.finos.legend.pure.runtime.java.extension.external.relation.compiled.natives.shared.RowContainer)" + processedOwnerInstance + ").apply(\"" + Instance.getValueForMetaPropertyToOneResolved(function, M3Properties.name, processorContext.getSupport()).getName() + "\")";
if (GenericType.testContainsExtendedPrimitiveTypes(returnGenericType, processorSupport))
{
return "(" + returnType + ")" + Cast.buildRunnableForExtendedPrimitiveType(getValue, returnGenericType, null, processorSupport) + ".value()";
}
else
{
return getValue;
}
}
return null;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
import org.eclipse.collections.api.stack.MutableStack;
import org.eclipse.collections.impl.tuple.Tuples;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.Function;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relation.Column;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType;
import org.finos.legend.pure.m3.navigation.Instance;
import org.finos.legend.pure.m3.navigation.M3Paths;
import org.finos.legend.pure.m3.navigation.ProcessorSupport;
import org.finos.legend.pure.m3.navigation.relation._Column;
import org.finos.legend.pure.m3.navigation.type.Type;
import org.finos.legend.pure.m4.coreinstance.CoreInstance;
import org.finos.legend.pure.runtime.java.extension.external.relation.interpreted.natives.AsOfJoin;
import org.finos.legend.pure.runtime.java.extension.external.relation.interpreted.natives.Columns;
Expand Down Expand Up @@ -58,6 +62,7 @@
import org.finos.legend.pure.runtime.java.interpreted.extension.BaseInterpretedExtension;
import org.finos.legend.pure.runtime.java.interpreted.extension.InterpretedExtension;
import org.finos.legend.pure.runtime.java.interpreted.natives.InstantiationContext;
import org.finos.legend.pure.runtime.java.interpreted.natives.essentials.lang.cast.Cast;
import org.finos.legend.pure.runtime.java.interpreted.profiler.Profiler;

import java.util.Stack;
Expand Down Expand Up @@ -104,7 +109,7 @@ public RelationExtensionInterpreted()
Tuples.pair("select_Relation_1__ColSpec_1__Relation_1_", Select::new),
Tuples.pair("select_Relation_1__ColSpecArray_1__Relation_1_", Select::new),
Tuples.pair("rowNumber_Relation_1__T_1__Integer_1_", RowNumber::new),
Tuples.pair("rank_Relation_1___Window_1__T_1__Integer_1_",Rank::new),
Tuples.pair("rank_Relation_1___Window_1__T_1__Integer_1_", Rank::new),
Tuples.pair("percentRank_Relation_1___Window_1__T_1__Float_1_", PercentRank::new),
Tuples.pair("denseRank_Relation_1___Window_1__T_1__Integer_1_", DenseRank::new),
Tuples.pair("ntile_Relation_1__T_1__Integer_1__Integer_1_", NTile::new),
Expand All @@ -125,6 +130,12 @@ public CoreInstance getExtraFunctionExecution(Function<?> function, ListIterable
{
if (Instance.instanceOf(function, M3Paths.Column, processorSupport))
{
CoreInstance value = ((TDSWithCursorCoreInstance) params.get(0).getValueForMetaPropertyToOne("values")).getValue(function._name());
GenericType colType = _Column.getColumnType((Column<?, ?>) function);
if (Type.isExtendedPrimitiveType(colType._rawType(), processorSupport))
{
Cast.evaluateConstraints(value, colType, interpreted, instantiationContext, functionExpressionCallStack, functionExpressionCallStack.isEmpty() ? null : functionExpressionCallStack.peek().getSourceInformation(), executionSupport, processorSupport);
}
return ((TDSWithCursorCoreInstance) params.get(0).getValueForMetaPropertyToOne("values")).getValue(function._name());
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,20 @@ function meta::analytics::mapping::modelCoverage::analyze(
let mapClassMappingsIds = $map->classMappings().id;
pair($map, list($classMappings->filter(cm | $cm.id->in($mapClassMappingsIds))));
));
let propertyFilter = {p:AbstractProperty<Any>[1] | true};
let entities = $classMappings->map(cm |
$cm->match([
o:OperationSetImplementation[1] |
let subTypeMappings = $o->resolveOperation($mapping)->concatenate($operations->filter(op | $op.class->superTypes()->contains($o.class)));
buildInheritanceEntities($o, $o, [], $subTypeMappings, '', $rootClassMappings, $allClasses, $allProperties, $inheritanceMap, $mappingToClassMappings, $o.root, true, $config);,
buildInheritanceEntities($o, $o, [], $subTypeMappings, '', $propertyFilter, $rootClassMappings, $allClasses, $allProperties, $inheritanceMap, $mappingToClassMappings, $o.root, true, $config);,
a:meta::pure::mapping::aggregationAware::AggregationAwareSetImplementation[1] |
buildEntity(
$a.mainSetImplementation.class, buildEntityName($a.mainSetImplementation), $a.mainSetImplementation, $a.mainSetImplementation->allPropertyMappings(), $rootClassMappings, $allClasses,
$a.mainSetImplementation.class, buildEntityName($a.mainSetImplementation), $a.mainSetImplementation, $a.mainSetImplementation->allPropertyMappings(), $propertyFilter, $rootClassMappings, $allClasses,
$allProperties, $inheritanceMap, $mappingToClassMappings, $a.root, $config
),
i:InstanceSetImplementation[1] |
buildEntity(
$i.class, buildEntityName($i), $i, $i->getPropertyMappings($classMappings), $rootClassMappings, $allClasses,
$i.class, buildEntityName($i), $i, $i->getPropertyMappings($classMappings), $propertyFilter, $rootClassMappings, $allClasses,
$allProperties, $inheritanceMap, $mappingToClassMappings, $i.root, $config
);,
an:Any[1] | []
Expand All @@ -150,7 +151,7 @@ function meta::analytics::mapping::modelCoverage::analyze(
let superTypes = $operations->filter(o | $o.class->superTypes()->contains($op.class));
let namePrefix = $i.entityPath->split('@')->at(0);
let uniqueTypes = $subTypes->concatenate($superTypes)->removeDuplicatesBy(t | $t.class);
buildInheritanceEntities($op, $op, [], $uniqueTypes, $namePrefix, $rootClassMappings, $allClasses, $allProperties, $inheritanceMap, $mappingToClassMappings, false, false, $config);
buildInheritanceEntities($op, $op, [], $uniqueTypes, $namePrefix, $propertyFilter, $rootClassMappings, $allClasses, $allProperties, $inheritanceMap, $mappingToClassMappings, false, false, $config);
)->removeDuplicatesBy(x | $x.path);
let mappedEntities = $entities->concatenate($inheritanceEntities);
if ($returnLightGraph == true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ function <<meta::pure::profiles::test.Test>> meta::analytics::mapping::modelCove
// embedded relational mapping
assertContains($mappedEntityForFirm.properties.name, 'employees');
assertContains($result.mappedEntities.path, $mappedEntityForFirm.properties->filter(p|$p.name == 'employees')->toOne()->cast(@EntityMappedProperty).entityPath);

let mappedEntityForLegalEntity = $result.mappedEntities->filter(mp|$mp.path == 'meta::analytics::mapping::modelCoverage::test::LegalEntity');
assert($mappedEntityForLegalEntity.properties->size() == 2);
}

function <<meta::pure::profiles::test.Test>> meta::analytics::mapping::modelCoverage::test::testSimpleRelationalInheritanceMappingCoverage():Boolean[1]
{
let result = meta::analytics::mapping::modelCoverage::test::generateModelCoverageAnalytics(meta::analytics::mapping::modelCoverage::test::sampleRelationalMapping);
let mappedEntityForLegalEntity = $result.mappedEntities->filter(mp|$mp.path == 'meta::analytics::mapping::modelCoverage::test::LegalEntity');
assert($mappedEntityForLegalEntity.properties->size() == 4);
assert($mappedEntityForLegalEntity.properties->size() == 2);
assertContains($mappedEntityForLegalEntity.properties->filter(p|$p->instanceOf(EntityMappedProperty))->cast(@EntityMappedProperty).entityPath, '@meta::analytics::mapping::modelCoverage::test::Firm');
assertContains($mappedEntityForLegalEntity.properties->filter(p|$p->instanceOf(EntityMappedProperty))->cast(@EntityMappedProperty).entityPath, 'meta_analytics_mapping_modelCoverage_test_Firm_employees');
assertContains($mappedEntityForLegalEntity.properties->filter(p|$p->instanceOf(EntityMappedProperty))->cast(@EntityMappedProperty).entityPath, 'meta::analytics::mapping::modelCoverage::test::Address');
}

function <<meta::pure::profiles::test.Test>> meta::analytics::mapping::modelCoverage::test::testSimpleRelationalUnionMappingCoverage():Boolean[1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import meta::analytics::class::modelCoverage::utility::*;
import meta::relational::metamodel::*;
import meta::relational::mapping::*;
import meta::analytics::mapping::modelCoverage::*;
import meta::pure::mapping::*;
Expand Down Expand Up @@ -241,6 +243,7 @@ function meta::analytics::mapping::modelCoverage::buildEntity(
target:String[1],
setImplementation:SetImplementation[1],
propertyMappings:PropertyMapping[*],
propertyFilter:Function<{AbstractProperty<Any>[1]->Boolean[1]}>[1],
rootClassMappings:SetImplementation[*],
classMap:Map<Class<Any>, ClassInfo>[1],
propertiesMap:Map<AbstractProperty<Any>, PropertyInfo>[1],
Expand All @@ -259,7 +262,7 @@ function meta::analytics::mapping::modelCoverage::buildEntity(
|| $pm->match([semi: meta::relational::mapping::SemiStructuredRelationalPropertyMapping[1] | false, rpm:InstanceSetImplementation[1] | true, a: PropertyMapping[1] | false])
// handle SemiStructuredRelationalPropertyMapping manually to take care of automapped properties
|| $pm.targetSetImplementationId->in($rootClassMappings.id))
);
)->filter(pm | $propertyFilter->eval($pm.property));

let properties = $supportedPropertyMappings->processPropertyMappings($rootClassMappings, $inheritanceMap, $propertiesMap, $config);

Expand All @@ -277,7 +280,8 @@ function meta::analytics::mapping::modelCoverage::buildEntity(
&& !$p->meta::pure::milestoning::isRangeMilestoningProperty()
&& ($rootClassMappings.class->contains($returnType)
|| $returnType == $class
|| $returnType->instanceOf(PrimitiveType));
|| $returnType->instanceOf(PrimitiveType))
&& $propertyFilter->eval($p);
)
->map(qp |
let qualifiedPropertyType = $qp.genericType.rawType->toOne();
Expand Down Expand Up @@ -373,6 +377,7 @@ function <<access.private>> meta::analytics::mapping::modelCoverage::buildInheri
seenInheritanceTypes: Class<Any>[*],
mappings:SetImplementation[*],
namePrefix: String[1],
originalPropertyFilter:Function<{AbstractProperty<Any>[1]->Boolean[1]}>[1],
rootClassMappings:SetImplementation[*],
classMap:Map<Class<Any>, ClassInfo>[1],
propertiesMap:Map<AbstractProperty<Any>, PropertyInfo>[1],
Expand Down Expand Up @@ -412,6 +417,14 @@ function <<access.private>> meta::analytics::mapping::modelCoverage::buildInheri
i:InstanceSetImplementation[1] | $i->allPropertyMappings()
]);

let propertyFilter = {a:AbstractProperty<Any>[1] |
let ownerClass = $a->ownerClass();
if ($mapping.class == $baseMapping.class,
| $ownerClass->in($mapping.class->superTypes()->concatenate($mapping.class)),
| $ownerClass == $mapping.class || $ownerClass->in($mapping.class->superTypes(false)->removeAll($seenInheritanceTypes)))
&& $originalPropertyFilter->eval($a);
};

let inheritanceTypes = $mapping->match([
o:OperationSetImplementation[1] | $seenInheritanceTypes->add($o.class),
i:InstanceSetImplementation[1] | $seenInheritanceTypes
Expand All @@ -420,12 +433,12 @@ function <<access.private>> meta::analytics::mapping::modelCoverage::buildInheri
let name = $namePrefix + if ($isBase, | $mapping->buildEntityName(),| $class->createInheritanceName());

let entities = buildEntity($class, $name, $mapping,
$mappedProperties, $rootClassMappings, $classMap, $propertiesMap, $inheritanceMap, $mappingClassMappings, $isRootEntity, $config);
$mappedProperties, $propertyFilter, $rootClassMappings, $classMap, $propertiesMap, $inheritanceMap, $mappingClassMappings, $isRootEntity, $config);

let rootEntity = $entities->at(0);
let currentMappings = $mappings->filter(m | $m.class->in($specs));
let inheritanceEntities = $currentMappings->map(cm |
$baseMapping->buildInheritanceEntitiesImpl($cm, $inheritanceTypes, $mappings, $namePrefix, $rootClassMappings, $classMap, $propertiesMap,
$baseMapping->buildInheritanceEntitiesImpl($cm, $inheritanceTypes, $mappings, $namePrefix, $originalPropertyFilter, $rootClassMappings, $classMap, $propertiesMap,
$inheritanceMap, $mappingClassMappings, false, false, $config);
);

Expand All @@ -446,6 +459,7 @@ function <<access.private>> meta::analytics::mapping::modelCoverage::buildInheri
seenInheritanceTypes: Class<Any>[*],
mappings:SetImplementation[*],
namePrefix: String[1],
originalPropertyFilter:Function<{AbstractProperty<Any>[1]->Boolean[1]}>[1],
rootClassMappings:SetImplementation[*],
classMap:Map<Class<Any>, ClassInfo>[1],
propertiesMap:Map<AbstractProperty<Any>, PropertyInfo>[1],
Expand All @@ -457,7 +471,7 @@ function <<access.private>> meta::analytics::mapping::modelCoverage::buildInheri
):MappedEntity[*]
{
let entities = buildInheritanceEntitiesImpl($baseMapping, $mapping, $seenInheritanceTypes, $mappings,
$namePrefix, $rootClassMappings, $classMap, $propertiesMap, $inheritanceMap, $mappingClassMappings, $isRootEntity, $isBase, $config);
$namePrefix, $originalPropertyFilter, $rootClassMappings, $classMap, $propertiesMap, $inheritanceMap, $mappingClassMappings, $isRootEntity, $isBase, $config);

$entities->map(e | ^$e(properties = $e.properties->removeDuplicatesBy(x | $x.name)));
}
Loading

0 comments on commit 1ce2646

Please sign in to comment.