Skip to content

Commit

Permalink
Modify Variable to use genericType
Browse files Browse the repository at this point in the history
  • Loading branch information
pierredebelen committed Nov 3, 2024
1 parent 622e545 commit f4fb6a3
Show file tree
Hide file tree
Showing 26 changed files with 1,096 additions and 815 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.finos.legend.engine.plan.execution.result.ConstantResult;
import org.finos.legend.engine.plan.execution.result.Result;
import org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ParameterValidationContext;
import org.finos.legend.engine.protocol.pure.v1.model.type.PackageableType;
import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable;

import java.util.List;
Expand Down Expand Up @@ -64,7 +65,7 @@ private static void processStreamParameter(Variable param, List<ParameterValidat
}
catch (Exception e)
{
throw new IllegalArgumentException("Failed to process " + param._class.path + " parameter in plan for " + paramName + ", message: " + e.getMessage());
throw new IllegalArgumentException("Failed to process " + ((PackageableType) param.genericType.rawType).fullPath + " parameter in plan for " + paramName + ", message: " + e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.finos.legend.engine.plan.execution.result.ConstantResult;
import org.finos.legend.engine.plan.execution.result.Result;
import org.finos.legend.engine.plan.execution.result.date.EngineDate;
import org.finos.legend.engine.protocol.pure.v1.model.type.PackageableType;
import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable;

import java.math.BigDecimal;
Expand Down Expand Up @@ -58,7 +59,7 @@ public static Object normalizeParameterValue(Variable parameter, Object paramVal
{
return null;
}
switch (parameter._class.path)
switch (((PackageableType) parameter.genericType.rawType).fullPath)
{
case "StrictDate":
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.finos.legend.engine.plan.execution.result.Result;
import org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ParameterValidationContext;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity;
import org.finos.legend.engine.protocol.pure.v1.model.type.PackageableType;
import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable;

import java.util.List;
Expand All @@ -47,7 +48,7 @@ private static void validateNoMissingMandatoryParamaters(RichIterable<Variable>

if (!missingExternalParameters.isEmpty())
{
throw new IllegalArgumentException("Missing external parameter(s): " + missingExternalParameters.collect(a -> a.name + ":" + a._class.path + "[" + renderMultiplicity(a.multiplicity) + "]").makeString(","));
throw new IllegalArgumentException("Missing external parameter(s): " + missingExternalParameters.collect(a -> a.name + ":" + ((PackageableType) a.genericType.rawType).fullPath + "[" + renderMultiplicity(a.multiplicity) + "]").makeString(","));
}
}

Expand All @@ -72,7 +73,7 @@ private static void validateParameterValues(RichIterable<Variable> externalParam

public static ValidationResult validate(Variable var, List<ParameterValidationContext> parameterValidationContext, Object value)
{
FunctionParameterTypeValidator validator = FunctionParameterTypeValidator.externalParameterTypeValidator(var._class.path);
FunctionParameterTypeValidator validator = FunctionParameterTypeValidator.externalParameterTypeValidator(((PackageableType) var.genericType.rawType).fullPath);
if (validator == null)
{
ValidationResult result = null;
Expand All @@ -84,7 +85,7 @@ public static ValidationResult validate(Variable var, List<ParameterValidationCo
return result;
}
}
return result == null ? ValidationResult.errorValidationResult("Unknown external parameter type: " + var._class.path + ", valid external parameter types: " + FunctionParameterTypeValidator.getExternalParameterTypes().makeString("[", ", ", "]")) : ValidationResult.successValidationResult();
return result == null ? ValidationResult.errorValidationResult("Unknown external parameter type: " + ((PackageableType) var.genericType.rawType).fullPath + ", valid external parameter types: " + FunctionParameterTypeValidator.getExternalParameterTypes().makeString("[", ", ", "]")) : ValidationResult.successValidationResult();
}
if (value instanceof Stream)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.EnumValidationContext;
import org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ParameterValidationContextVisitor;
import org.finos.legend.engine.protocol.pure.v1.model.type.PackageableType;
import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable;

import java.util.List;
Expand All @@ -39,6 +40,6 @@ public ValidationResult visit(EnumValidationContext enumValidationContext)
{
throw new IllegalArgumentException("Collection of Enums (" + value + ") is not supported as service parameter");
}
return (validEnumValues.contains(value.toString())) ? ValidationResult.successValidationResult() : ValidationResult.errorValidationResult("Invalid enum value " + value + " for " + var._class.path + ", valid enum values: " + validEnumValues);
return (validEnumValues.contains(value.toString())) ? ValidationResult.successValidationResult() : ValidationResult.errorValidationResult("Invalid enum value " + value + " for " + ((PackageableType) var.genericType.rawType).fullPath + ", valid enum values: " + validEnumValues);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.finos.legend.engine.plan.execution.planHelper.PrimitiveValueSpecificationToObjectVisitor;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.ParameterValue;
import org.finos.legend.engine.protocol.pure.v1.model.type.PackageableType;
import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification;
import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable;
import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.datatype.CFloat;
Expand Down Expand Up @@ -62,7 +63,7 @@ public void testLambdaIsParameterized() throws IOException
expectedVariables.add(new Variable("GENERATEDL0L1", "Integer", Multiplicity.PURE_ONE));

String actualSpec = objectMapper.writeValueAsString(spec.getValueSpecification());
Assert.assertEquals("{\"_type\":\"lambda\",\"body\":[{\"_type\":\"func\",\"function\":\"take\",\"parameters\":[{\"_type\":\"func\",\"function\":\"project\",\"parameters\":[{\"_type\":\"func\",\"function\":\"filter\",\"parameters\":[{\"_type\":\"func\",\"function\":\"getAll\",\"parameters\":[{\"_type\":\"packageableElementPtr\",\"fullPath\":\"domain::Example\"}]},{\"_type\":\"lambda\",\"body\":[{\"_type\":\"func\",\"function\":\"and\",\"parameters\":[{\"_type\":\"func\",\"function\":\"equal\",\"parameters\":[{\"_type\":\"property\",\"parameters\":[{\"_type\":\"var\",\"name\":\"x\"}],\"property\":\"cases\"},{\"_type\":\"var\",\"class\":\"Float\",\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"name\":\"GENERATEDL0L0L0L1L0L0L1\"}]},{\"_type\":\"func\",\"function\":\"and\",\"parameters\":[{\"_type\":\"func\",\"function\":\"equal\",\"parameters\":[{\"_type\":\"property\",\"parameters\":[{\"_type\":\"var\",\"name\":\"x\"}],\"property\":\"caseType\"},{\"_type\":\"var\",\"class\":\"String\",\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"name\":\"GENERATEDL0L0L0L1L0L1L0L1\"}]},{\"_type\":\"func\",\"function\":\"and\",\"parameters\":[{\"_type\":\"func\",\"function\":\"equal\",\"parameters\":[{\"_type\":\"property\",\"parameters\":[{\"_type\":\"var\",\"name\":\"x\"}],\"property\":\"caseType\"},{\"_type\":\"packageableElementPtr\",\"fullPath\":\"test::pure::mapping::modelToModel::test::shared::dest::Person\"}]},{\"_type\":\"func\",\"function\":\"equal\",\"parameters\":[{\"_type\":\"property\",\"parameters\":[{\"_type\":\"var\",\"name\":\"x\"}],\"property\":\"date\"},{\"_type\":\"var\",\"class\":\"StrictDate\",\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"name\":\"GENERATEDL0L0L0L1L0L1L1L1L1\"}]}]}]}]}],\"parameters\":[{\"_type\":\"var\",\"name\":\"x\"}]}]},{\"_type\":\"collection\",\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"values\":[{\"_type\":\"lambda\",\"body\":[{\"_type\":\"property\",\"parameters\":[{\"_type\":\"var\",\"name\":\"x\"}],\"property\":\"cases\"}],\"parameters\":[{\"_type\":\"var\",\"name\":\"x\"}]}]},{\"_type\":\"collection\",\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"values\":[{\"_type\":\"string\",\"value\":\"Cases\"}]}]},{\"_type\":\"var\",\"class\":\"Integer\",\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"name\":\"GENERATEDL0L1\"}]}],\"parameters\":[]}", actualSpec);
Assert.assertEquals("{\"_type\":\"lambda\",\"body\":[{\"_type\":\"func\",\"function\":\"take\",\"parameters\":[{\"_type\":\"func\",\"function\":\"project\",\"parameters\":[{\"_type\":\"func\",\"function\":\"filter\",\"parameters\":[{\"_type\":\"func\",\"function\":\"getAll\",\"parameters\":[{\"_type\":\"packageableElementPtr\",\"fullPath\":\"domain::Example\"}]},{\"_type\":\"lambda\",\"body\":[{\"_type\":\"func\",\"function\":\"and\",\"parameters\":[{\"_type\":\"func\",\"function\":\"equal\",\"parameters\":[{\"_type\":\"property\",\"parameters\":[{\"_type\":\"var\",\"name\":\"x\"}],\"property\":\"cases\"},{\"_type\":\"var\",\"genericType\":{\"multiplicityArguments\":[],\"rawType\":{\"_type\":\"packageableType\",\"fullPath\":\"Float\"},\"typeArguments\":[],\"typeVariables\":[]},\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"name\":\"GENERATEDL0L0L0L1L0L0L1\"}]},{\"_type\":\"func\",\"function\":\"and\",\"parameters\":[{\"_type\":\"func\",\"function\":\"equal\",\"parameters\":[{\"_type\":\"property\",\"parameters\":[{\"_type\":\"var\",\"name\":\"x\"}],\"property\":\"caseType\"},{\"_type\":\"var\",\"genericType\":{\"multiplicityArguments\":[],\"rawType\":{\"_type\":\"packageableType\",\"fullPath\":\"String\"},\"typeArguments\":[],\"typeVariables\":[]},\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"name\":\"GENERATEDL0L0L0L1L0L1L0L1\"}]},{\"_type\":\"func\",\"function\":\"and\",\"parameters\":[{\"_type\":\"func\",\"function\":\"equal\",\"parameters\":[{\"_type\":\"property\",\"parameters\":[{\"_type\":\"var\",\"name\":\"x\"}],\"property\":\"caseType\"},{\"_type\":\"packageableElementPtr\",\"fullPath\":\"test::pure::mapping::modelToModel::test::shared::dest::Person\"}]},{\"_type\":\"func\",\"function\":\"equal\",\"parameters\":[{\"_type\":\"property\",\"parameters\":[{\"_type\":\"var\",\"name\":\"x\"}],\"property\":\"date\"},{\"_type\":\"var\",\"genericType\":{\"multiplicityArguments\":[],\"rawType\":{\"_type\":\"packageableType\",\"fullPath\":\"StrictDate\"},\"typeArguments\":[],\"typeVariables\":[]},\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"name\":\"GENERATEDL0L0L0L1L0L1L1L1L1\"}]}]}]}]}],\"parameters\":[{\"_type\":\"var\",\"name\":\"x\"}]}]},{\"_type\":\"collection\",\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"values\":[{\"_type\":\"lambda\",\"body\":[{\"_type\":\"property\",\"parameters\":[{\"_type\":\"var\",\"name\":\"x\"}],\"property\":\"cases\"}],\"parameters\":[{\"_type\":\"var\",\"name\":\"x\"}]}]},{\"_type\":\"collection\",\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"values\":[{\"_type\":\"string\",\"value\":\"Cases\"}]}]},{\"_type\":\"var\",\"genericType\":{\"multiplicityArguments\":[],\"rawType\":{\"_type\":\"packageableType\",\"fullPath\":\"Integer\"},\"typeArguments\":[],\"typeVariables\":[]},\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"name\":\"GENERATEDL0L1\"}]}],\"parameters\":[]}", actualSpec);

assert (IntStream.range(0, spec.getParameterValues().size()).allMatch(index -> parameterValueCompare(spec.getParameterValues().get(index), expectedParameters.get(index))));
assert (IntStream.range(0, spec.getVariables().size()).allMatch(index -> variableCompare(spec.getVariables().get(index), expectedVariables.get(index))));
Expand All @@ -86,7 +87,7 @@ public void testStringListIsNotParameterized() throws IOException
expectedVariables.add(new Variable("GENERATEDL0L1", "Integer", Multiplicity.PURE_ONE));

String actualSpec = objectMapper.writeValueAsString(spec.getValueSpecification());
Assert.assertEquals("{\"_type\":\"lambda\",\"body\":[{\"_type\":\"func\",\"function\":\"take\",\"parameters\":[{\"_type\":\"func\",\"function\":\"project\",\"parameters\":[{\"_type\":\"func\",\"function\":\"filter\",\"parameters\":[{\"_type\":\"func\",\"function\":\"getAll\",\"parameters\":[{\"_type\":\"packageableElementPtr\",\"fullPath\":\"domain::Example\"}]},{\"_type\":\"lambda\",\"body\":[{\"_type\":\"func\",\"function\":\"in\",\"parameters\":[{\"_type\":\"property\",\"parameters\":[{\"_type\":\"var\",\"name\":\"x\"}],\"property\":\"caseType\"},{\"_type\":\"collection\",\"multiplicity\":{\"lowerBound\":3,\"upperBound\":3},\"values\":[{\"_type\":\"string\",\"value\":\"Case 3\"},{\"_type\":\"string\",\"value\":\"Case 2\"},{\"_type\":\"string\",\"value\":\"Case 1\"}]}]}],\"parameters\":[{\"_type\":\"var\",\"name\":\"x\"}]}]},{\"_type\":\"collection\",\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"values\":[{\"_type\":\"lambda\",\"body\":[{\"_type\":\"property\",\"parameters\":[{\"_type\":\"var\",\"name\":\"x\"}],\"property\":\"cases\"}],\"parameters\":[{\"_type\":\"var\",\"name\":\"x\"}]}]},{\"_type\":\"collection\",\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"values\":[{\"_type\":\"string\",\"value\":\"Cases\"}]}]},{\"_type\":\"var\",\"class\":\"Integer\",\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"name\":\"GENERATEDL0L1\"}]}],\"parameters\":[]}", actualSpec);
Assert.assertEquals("{\"_type\":\"lambda\",\"body\":[{\"_type\":\"func\",\"function\":\"take\",\"parameters\":[{\"_type\":\"func\",\"function\":\"project\",\"parameters\":[{\"_type\":\"func\",\"function\":\"filter\",\"parameters\":[{\"_type\":\"func\",\"function\":\"getAll\",\"parameters\":[{\"_type\":\"packageableElementPtr\",\"fullPath\":\"domain::Example\"}]},{\"_type\":\"lambda\",\"body\":[{\"_type\":\"func\",\"function\":\"in\",\"parameters\":[{\"_type\":\"property\",\"parameters\":[{\"_type\":\"var\",\"name\":\"x\"}],\"property\":\"caseType\"},{\"_type\":\"collection\",\"multiplicity\":{\"lowerBound\":3,\"upperBound\":3},\"values\":[{\"_type\":\"string\",\"value\":\"Case 3\"},{\"_type\":\"string\",\"value\":\"Case 2\"},{\"_type\":\"string\",\"value\":\"Case 1\"}]}]}],\"parameters\":[{\"_type\":\"var\",\"name\":\"x\"}]}]},{\"_type\":\"collection\",\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"values\":[{\"_type\":\"lambda\",\"body\":[{\"_type\":\"property\",\"parameters\":[{\"_type\":\"var\",\"name\":\"x\"}],\"property\":\"cases\"}],\"parameters\":[{\"_type\":\"var\",\"name\":\"x\"}]}]},{\"_type\":\"collection\",\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"values\":[{\"_type\":\"string\",\"value\":\"Cases\"}]}]},{\"_type\":\"var\",\"genericType\":{\"multiplicityArguments\":[],\"rawType\":{\"_type\":\"packageableType\",\"fullPath\":\"Integer\"},\"typeArguments\":[],\"typeVariables\":[]},\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"name\":\"GENERATEDL0L1\"}]}],\"parameters\":[]}", actualSpec);

assert (IntStream.range(0, spec.getParameterValues().size()).allMatch(index -> parameterValueCompare(spec.getParameterValues().get(index), expectedParameters.get(index))));
assert (IntStream.range(0, spec.getVariables().size()).allMatch(index -> variableCompare(spec.getVariables().get(index), expectedVariables.get(index))));
Expand All @@ -102,7 +103,7 @@ private Boolean parameterValueCompare(ParameterValue a, ParameterValue b)

private Boolean variableCompare(Variable a, Variable b)
{
return a.name.equals(b.name) && a._class.path.equals(b._class.path) && a.multiplicity.equals(b.multiplicity);
return a.name.equals(b.name) && ((PackageableType) a.genericType.rawType).fullPath.equals(((PackageableType) a.genericType.rawType).fullPath) && a.multiplicity.equals(b.multiplicity);
}

private ParameterValue createParameterValue(String name, ValueSpecification value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.aggregationAware.AggregateSetImplementationContainer;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.aggregationAware.AggregationAwareClassMapping;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.mapping.PureInstanceClassMapping;
import org.finos.legend.engine.protocol.pure.v1.model.type.GenericType;
import org.finos.legend.engine.protocol.pure.v1.model.type.PackageableType;
import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable;
import org.finos.legend.pure.generated.Root_meta_external_store_model_PureInstanceSetImplementation_Impl;
import org.finos.legend.pure.generated.Root_meta_pure_mapping_MergeOperationSetImplementation_Impl;
Expand Down Expand Up @@ -119,7 +121,7 @@ public Pair<SetImplementation, RichIterable<EmbeddedSetImplementation>> visit(Pu
{
Variable param = new Variable();
param.name = "src";
param._class = new PackageableElementPointer(PackageableElementType.CLASS, classMapping.srcClass);
param.genericType = new GenericType(new PackageableType(classMapping.srcClass));
param.multiplicity = new Multiplicity(1, 1);
params = Lists.mutable.with(param);
}
Expand Down
Loading

0 comments on commit f4fb6a3

Please sign in to comment.