use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Filter in project legend-pure by finos.
the class AssociationProcessor method getPropertyNameForLeftSideOfQualifiedPropertyFilter.
private static String getPropertyNameForLeftSideOfQualifiedPropertyFilter(Association association, QualifiedProperty qualifiedProperty, ValueSpecification instance, Context context, ProcessorSupport processorSupport) {
String functionName = instance instanceof FunctionExpression ? ((FunctionExpression) instance)._functionName() : null;
String propertyNameForLeftSideOfQualifiedPropertyFilter;
if ("filter".equals(functionName)) {
ValueSpecification leftSideOfFilter = ((FunctionExpression) instance)._parametersValues().toList().getFirst();
CoreInstance propertyName = leftSideOfFilter instanceof FunctionExpression ? ((FunctionExpression) leftSideOfFilter)._propertyName()._valuesCoreInstance().toList().getFirst() : null;
ValueSpecification variableExpression = leftSideOfFilter instanceof FunctionExpression ? ((FunctionExpression) leftSideOfFilter)._parametersValues().toList().getFirst() : null;
String variableExpressionName = variableExpression instanceof VariableExpression ? ((VariableExpression) variableExpression)._name() : null;
if (!"this".equals(variableExpressionName)) {
throw new PureCompilationException(instance.getSourceInformation(), validQualifiedPropertyInAssociationMsg() + qualifiedPropertyCompileErrorMsgPrefix(association, qualifiedProperty) + " left side of filter should refer to '$this' not '" + variableExpressionName + "'");
}
propertyNameForLeftSideOfQualifiedPropertyFilter = Objects.requireNonNull(propertyName).getName();
} else {
ValueSpecification firstParamValue = instance instanceof FunctionExpression ? ((FunctionExpression) instance)._parametersValues().toList().getFirst() : null;
if (firstParamValue != null) {
propertyNameForLeftSideOfQualifiedPropertyFilter = getPropertyNameForLeftSideOfQualifiedPropertyFilter(association, qualifiedProperty, firstParamValue, context, processorSupport);
} else {
throw new PureCompilationException(qualifiedProperty.getSourceInformation(), validQualifiedPropertyInAssociationMsg() + qualifiedPropertyCompileErrorMsgPrefix(association, qualifiedProperty) + " does not use the 'filter' function");
}
}
return propertyNameForLeftSideOfQualifiedPropertyFilter;
}
use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Filter in project legend-pure by finos.
the class AbstractTestIncrementalCompilation method test3.
@Test
public void test3() {
FastList<String> processed = FastList.newList();
FastList<String> notProcessed = FastList.newList();
processed.add("start__Any_MANY_");
notProcessed.add("myFunc__Any_MANY_");
RuntimeVerifier.verifyOperationIsStable(new RuntimeTestScriptBuilder().createInMemorySource("sourceId1.pure", "Enum my::Gender\n" + "{\n" + " MALE, FEMALE\n" + "}\n" + "\n" + "Class my::Person\n" + "{\n" + " firstName : String[0..1];\n" + " lastName : String[0..1];\n" + " gender : my::Gender[0..1];\n" + "}").createInMemorySource("sourceId2.pure", "function myFunc():Any[*]\n" + "{\n" + " let set = \n" + " [\n" + " ^my::Person(firstName = 'Marie', lastName='Random', gender = my::Gender.FEMALE),\n" + " ^my::Person(firstName = 'John', lastName='Doe', gender = my::Gender.MALE)\n" + " ];\n" + " $set->filter(p|$p.gender == my::Gender.FEMALE).lastName;\n" + "}").createInMemorySource("sourceId3.pure", "function start():Any[*]\n" + "{\n" + " assert( myFunc() == 'Random', |'');\n" + "}").executeFunction("start():Any[*]"), new RuntimeTestScriptBuilder().updateSource("sourceId1.pure", "Enum my::Gender\n" + "{\n" + " FEMALE\n" + "}\n" + "\n" + "Class my::Person\n" + "{\n" + " firstName : String[0..1];\n" + " lastName : String[0];\n" + " gender : my::Gender[0..1];\n" + "}\n").compileWithExpectedCompileFailureAndAssertions("Multiplicity Error: [1] is not compatible with [0]", "sourceId2.pure", 5, 48, FastList.newListWith("start__Any_MANY_", "myFunc__Any_MANY_"), FastList.<String>newList(), FastList.newListWith("my::Person, my::Gender")).updateSource("sourceId1.pure", "Enum my::Gender\n" + "{\n" + " MALE, FEMALE\n" + "}\n" + "\n" + "Class my::Person\n" + "{\n" + " firstName : String[0..1];\n" + " lastName : String[0..1];\n" + " gender : my::Gender[0..1];\n" + "}").executeFunction("start():Any[*]"), this.runtime, this.functionExecution, this.getAdditionalVerifiers());
}
use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Filter in project legend-pure by finos.
the class TestPureRuntimeGraph method testPureRuntimeChangeEnumeration.
@Test
public void testPureRuntimeChangeEnumeration() {
String source = "Class EntityWithLocations\n" + "{\n" + " locations : Location[*];\n" + " locationsByType(types:GeographicEntityType[*])\n" + " {\n" + " $this.locations->filter(l | $types->exists(type | is($l.type, $type)))\n" + " }:Location[*];\n" + "}\n" + "Class Location\n" + "{\n" + " type : GeographicEntityType[1];\n" + "}\n";
String enumSource = "Enum GeographicEntityType\n" + "{\n" + " CITY,\n" + " COUNTRY\n" + "}";
String enumSource2 = "Enum GeographicEntityType\n" + "{\n" + " CITY,\n" + " COUNTRY,\n" + " REGION\n" + "}";
RuntimeVerifier.verifyOperationIsStable(new RuntimeTestScriptBuilder().createInMemorySource("source1.pure", source).createInMemorySource("source2.pure", enumSource).createInMemorySource("userId.pure", "function test():Boolean[1]{print(#{EntityWithLocations{locationsByType(GeographicEntityType.CITY)}}#,0);true;}").compile(), new RuntimeTestScriptBuilder().updateSource("source2.pure", enumSource2).compile().updateSource("source2.pure", enumSource).compile(), this.runtime, this.functionExecution, Lists.fixedSize.<FunctionExecutionStateVerifier>of());
}
use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Filter in project legend-pure by finos.
the class TestPureRuntimeGraph method testPureRuntimeAddEnumVar.
@Test
public void testPureRuntimeAddEnumVar() {
String source = "Class EntityWithLocations\n" + "{\n" + " locations : Location[*];\n" + " locationsByType(types:GeographicEntityType[*])\n" + " {\n" + " $this.locations->filter(l | $types->exists(type | is($l.type, $type)))\n" + " }:Location[*];\n" + "}\n" + "Class Location\n" + "{\n" + " type : GeographicEntityType[1];\n" + "}\n";
String enumSource = "Enum GeographicEntityType\n" + "{\n" + " CITY,\n" + " COUNTRY\n" + "}";
RuntimeVerifier.verifyOperationIsStable(new RuntimeTestScriptBuilder().createInMemorySource("source1.pure", source).createInMemorySource("source2.pure", enumSource).createInMemorySource("userId.pure", "function test():Boolean[1]{print(#{EntityWithLocations{locationsByType(GeographicEntityType.CITY)}}#,0);true;}").compile(), new RuntimeTestScriptBuilder().updateSource("userId.pure", "function test():Boolean[1]{let x = GeographicEntityType.CITY; print(#{EntityWithLocations{locationsByType($x)}}#,0);true;}").compile().updateSource("userId.pure", "function test():Boolean[1]{print(#{EntityWithLocations{locationsByType(GeographicEntityType.CITY)}}#,0);true;}").compile(), this.runtime, this.functionExecution, Lists.fixedSize.<FunctionExecutionStateVerifier>of());
}
use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Filter in project legend-pure by finos.
the class TestPureRuntimeGraph method testPureRuntimeChangeEnum.
@Test
public void testPureRuntimeChangeEnum() {
String source = "Class EntityWithLocations\n" + "{\n" + " locations : Location[*];\n" + " locationsByType(types:GeographicEntityType[*])\n" + " {\n" + " $this.locations->filter(l | $types->exists(type | is($l.type, $type)))\n" + " }:Location[*];\n" + "}\n" + "Class Location\n" + "{\n" + " type : GeographicEntityType[1];\n" + "}\n";
String enumSource = "Enum GeographicEntityType\n" + "{\n" + " CITY,\n" + " COUNTRY\n" + "}";
RuntimeVerifier.verifyOperationIsStable(new RuntimeTestScriptBuilder().createInMemorySource("source1.pure", source).createInMemorySource("source2.pure", enumSource).createInMemorySource("userId.pure", "function test():Boolean[1]{print(#{EntityWithLocations{locationsByType(GeographicEntityType.CITY)}}#,0);true;}").compile(), new RuntimeTestScriptBuilder().updateSource("userId.pure", "function test():Boolean[1]{print(#{EntityWithLocations{locationsByType(GeographicEntityType.COUNTRY)}}#,0);true;}").compile().updateSource("userId.pure", "function test():Boolean[1]{print(#{EntityWithLocations{locationsByType(GeographicEntityType.CITY)}}#,0);true;}").compile(), this.runtime, this.functionExecution, Lists.fixedSize.<FunctionExecutionStateVerifier>of());
}
Aggregations