Skip to content

Commit

Permalink
Add from/with APIs that take in PackageableRuntime as a param (#3359)
Browse files Browse the repository at this point in the history
* Add from/with APIs that take in PackageableRuntime as a param

* Remove commented line of code
  • Loading branch information
jake-kim1 authored Jan 16, 2025
1 parent e55bc70 commit 5ebb940
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
import org.finos.legend.pure.generated.Root_meta_pure_metamodel_valuespecification_SimpleFunctionExpression_Impl;
import org.finos.legend.pure.generated.Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl;
import org.finos.legend.pure.generated.Root_meta_pure_runtime_ExecutionContext;
import org.finos.legend.pure.generated.Root_meta_pure_runtime_PackageableRuntime;
import org.finos.legend.pure.generated.Root_meta_pure_tds_AggregateValue_Impl;
import org.finos.legend.pure.generated.Root_meta_pure_tds_BasicColumnSpecification_Impl;
import org.finos.legend.pure.generated.Root_meta_pure_tds_SortInformation_Impl;
Expand Down Expand Up @@ -179,17 +178,6 @@ public ValueSpecification visit(PackageableElementPtr packageableElementPtr)
}
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement packageableElement = this.context.resolvePackageableElement(packageableElementPtr.fullPath, packageableElementPtr.sourceInformation);

if (packageableElement instanceof Root_meta_pure_runtime_PackageableRuntime)
{
Root_meta_core_runtime_Runtime resolvedRuntime = this.context.resolveRuntime(packageableElementPtr.fullPath);
GenericType runtimeGenericType = new Root_meta_pure_metamodel_type_generics_GenericType_Impl("", null, this.context.pureModel.getClass(M3Paths.GenericType))
._rawType(this.context.pureModel.getType("meta::core::runtime::Runtime"));
return new Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl("", SourceInformationHelper.toM3SourceInformation(packageableElementPtr.sourceInformation), this.context.pureModel.getClass(M3Paths.InstanceValue))
._genericType(runtimeGenericType)
._multiplicity(this.context.pureModel.getMultiplicity("one"))
._values(Lists.mutable.with(resolvedRuntime));
}

MutableList<InstanceValue> values = this.context.getCompilerExtensions().getExtraValueSpecificationBuilderForFuncExpr().collect(x -> x.value(packageableElement, this.context, this.processingContext), Lists.mutable.empty());
values.removeIf(Objects::isNull);
switch (values.size())
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,23 @@ function meta::pure::functions::meta::extractRuntimesFromFunctionDefinition(func

function meta::pure::functions::meta::extractRuntimesFromFunctionDefinition(func:FunctionDefinition<Any>[1], filterBeforeCast:Boolean[1]):Runtime[*]
{
let fromExprList = $func->findExpressionsForFunctionInFunctionDefinition([from_TabularDataSet_1__Mapping_1__Runtime_1__ExecutionContext_1__TabularDataSet_1_,
let fromExprList = $func->findExpressionsForFunctionInFunctionDefinition([from_T_m__PackageableRuntime_1__T_m_,
from_T_m__Mapping_1__PackageableRuntime_1__T_m_,
from_TabularDataSet_1__Mapping_1__PackageableRuntime_1__TabularDataSet_1_,
from_TabularDataSet_1__Mapping_1__PackageableRuntime_1__ExecutionContext_1__TabularDataSet_1_,
with_T_m__PackageableRuntime_1__T_m_,
with_T_m__Mapping_1__PackageableRuntime_1__T_m_,
with_T_m__Runtime_1__T_m_,
with_T_m__Mapping_1__Runtime_1__T_m_,
from_T_m__Runtime_1__T_m_,
from_T_m__Mapping_1__Runtime_1__T_m_,
from_TabularDataSet_1__Mapping_1__Runtime_1__TabularDataSet_1_,
from_T_m__Mapping_1__Runtime_1__T_m_]);
$fromExprList->evaluateAndDeactivate()->map(exp | $exp.parametersValues->at(2)->evaluateAndDeactivate()->filter(p | !$filterBeforeCast || $p->instanceOf(InstanceValue))->cast(@InstanceValue).values)->cast(@Runtime);
from_TabularDataSet_1__Mapping_1__Runtime_1__ExecutionContext_1__TabularDataSet_1_]);
$fromExprList->evaluateAndDeactivate()->map(exp | $exp.parametersValues->tail()->evaluateAndDeactivate()->filter(p | !$filterBeforeCast || $p->instanceOf(InstanceValue))->cast(@InstanceValue).values)
->map(v | $v->match([runtime:Runtime[1] | $runtime;,
packageableRuntime:meta::pure::runtime::PackageableRuntime[1] | $packageableRuntime.runtimeValue;,
any:Any[1] | [];
]));
}

function meta::pure::functions::meta::findPropertiesInValueSpecification(vs:ValueSpecification[1]):AbstractProperty<Any>[*]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,24 +289,34 @@ function <<access.private>> meta::pure::router::operations::getMappedLeafClasses
if($specs->isEmpty(), | $mappedClass, | $specs->map(s | $s->getMappedLeafClasses_recursive($mappedClass, $mapping, $state)));
}

function <<functionType.NotImplementedFunction>> meta::pure::mapping::from<T|m>(t:T[m], runtime:Runtime[1]):T[m]
function meta::pure::mapping::from<T|m>(t:T[m], packageableRuntime:meta::pure::runtime::PackageableRuntime[1]):T[m]
{
$t
$t->from($packageableRuntime.runtimeValue);
}

function <<functionType.NotImplementedFunction>> meta::pure::mapping::from<T|m>(t:T[m], m:meta::pure::mapping::Mapping[1], runtime:Runtime[1]):T[m]
function meta::pure::mapping::from<T|m>(t:T[m], m:meta::pure::mapping::Mapping[1], packageableRuntime:meta::pure::runtime::PackageableRuntime[1]):T[m]
{
$t
$t->from($m, $packageableRuntime.runtimeValue);
}

function <<functionType.NotImplementedFunction>> meta::pure::mapping::from(tds:TabularDataSet[1], mapping:Mapping[1], runtime:Runtime[1]):TabularDataSet[1]
function meta::pure::mapping::from(tds:TabularDataSet[1], mapping:Mapping[1], packageableRuntime:meta::pure::runtime::PackageableRuntime[1]):TabularDataSet[1]
{
$tds;
$tds->from($mapping, $packageableRuntime.runtimeValue);
}

function <<functionType.NotImplementedFunction>> meta::pure::mapping::from(tds:TabularDataSet[1], mapping:Mapping[1], runtime:Runtime[1], executionContext:meta::pure::runtime::ExecutionContext[1]):TabularDataSet[1]
function meta::pure::mapping::from(tds:TabularDataSet[1], mapping:Mapping[1], packageableRuntime:meta::pure::runtime::PackageableRuntime[1], executionContext:meta::pure::runtime::ExecutionContext[1]):TabularDataSet[1]
{
$tds;
$tds->from($mapping, $packageableRuntime.runtimeValue, $executionContext);
}

function meta::pure::mapping::with<T|m>(t:T[m], packageableRuntime:meta::pure::runtime::PackageableRuntime[1]):T[m]
{
$t->with($packageableRuntime.runtimeValue);
}

function meta::pure::mapping::with<T|m>(t:T[m], m:meta::pure::mapping::Mapping[1], packageableRuntime:meta::pure::runtime::PackageableRuntime[1]):T[m]
{
$t->with($m, $packageableRuntime.runtimeValue);
}

function meta::pure::mapping::with<T|m>(t:T[m], runtime:Runtime[1]):T[m]
Expand All @@ -319,6 +329,26 @@ function meta::pure::mapping::with<T|m>(t:T[m], m:meta::pure::mapping::Mapping[1
$t->from($m, $runtime);
}

function <<functionType.NotImplementedFunction>> meta::pure::mapping::from<T|m>(t:T[m], runtime:Runtime[1]):T[m]
{
$t
}

function <<functionType.NotImplementedFunction>> meta::pure::mapping::from<T|m>(t:T[m], m:meta::pure::mapping::Mapping[1], runtime:Runtime[1]):T[m]
{
$t
}

function <<functionType.NotImplementedFunction>> meta::pure::mapping::from(tds:TabularDataSet[1], mapping:Mapping[1], runtime:Runtime[1]):TabularDataSet[1]
{
$tds;
}

function <<functionType.NotImplementedFunction>> meta::pure::mapping::from(tds:TabularDataSet[1], mapping:Mapping[1], runtime:Runtime[1], executionContext:meta::pure::runtime::ExecutionContext[1]):TabularDataSet[1]
{
$tds;
}


###Mapping
Mapping meta::pure::mapping::MergedMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function meta::pure::router::clustering::specializedFunctionExpressionClustering
let childClustersResponse = $f.parametersValues->evaluateAndDeactivate()->map(v | $v->cluster($mapping, $openVariables, $exeCtx, $debug, $analyticsDecision, $extensions));
let params = $childClustersResponse.cluster->evaluateAndDeactivate();

let runtime = $f.parametersValues->at(3)->cast(@InstanceValue).values->cast(@Runtime)->toOne();
let runtime = $f.parametersValues->at(3)->cast(@InstanceValue).values->map(v | $v->match([runtime:Runtime[1] | $runtime, packageableRuntime:meta::pure::runtime::PackageableRuntime[1] | $packageableRuntime.runtimeValue]))->toOne();
let store = $runtime.connectionStores.element->cast(@meta::pure::store::Store)->toOne();
^ClusterResponse(
cluster = ^StoreMappingClusteredValueSpecification(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,15 @@ function meta::pure::router::store::routing::specializedFunctionExpressionRoute
{
[
pair(fe:FunctionExpression[1] | $fe.func->in([meta::pure::mapping::from_T_m__Runtime_1__T_m_,
meta::pure::mapping::with_T_m__Runtime_1__T_m_]),
meta::pure::mapping::from_T_m__PackageableRuntime_1__T_m_,
meta::pure::mapping::with_T_m__Runtime_1__T_m_,
meta::pure::mapping::with_T_m__PackageableRuntime_1__T_m_]),
{f:Function<Any>[1], fe:FunctionExpression[1], state:RoutingState[1], executionContext:meta::pure::runtime::ExecutionContext[1], vars:Map<VariableExpression, ValueSpecification>[1], inScopeVars:Map<String, List<Any>>[1], extensions:meta::pure::extension::Extension[*], debug:DebugContext[1] |
let resolvedParameters = $fe.parametersValues->tail()->map(p|$p->evaluateAndDeactivate()->match([v:VariableExpression[1] |let iv = meta::pure::functions::meta::resolve($v, $vars, $inScopeVars)->cast(@InstanceValue).values,
f:FunctionExpression[1] |let r = $f->meta::pure::router::preeval::preval($inScopeVars, $extensions, $debug);
$r->reactivate($inScopeVars);,
i:InstanceValue[1] |$i.values]));
let fromRuntime = $resolvedParameters->at(0)->cast(@Runtime);
let fromRuntime = $resolvedParameters->at(0)->match([runtime:Runtime[1] | $runtime;, packageableRuntime:PackageableRuntime[1] | $packageableRuntime.runtimeValue;]);
routeValueSpecification(
^$state(value = $fe.parametersValues->at(0),
routingStrategy = getRoutingStrategyFromRuntime($fromRuntime)),
Expand All @@ -397,9 +399,13 @@ function meta::pure::router::store::routing::specializedFunctionExpressionRoute
}
),
pair(fe:FunctionExpression[1] | $fe.func->in([meta::pure::mapping::from_TabularDataSet_1__Mapping_1__Runtime_1__TabularDataSet_1_,
meta::pure::mapping::from_TabularDataSet_1__Mapping_1__PackageableRuntime_1__TabularDataSet_1_,
meta::pure::mapping::from_TabularDataSet_1__Mapping_1__Runtime_1__ExecutionContext_1__TabularDataSet_1_,
meta::pure::mapping::from_TabularDataSet_1__Mapping_1__PackageableRuntime_1__ExecutionContext_1__TabularDataSet_1_,
meta::pure::mapping::from_T_m__Mapping_1__Runtime_1__T_m_,
meta::pure::mapping::with_T_m__Mapping_1__Runtime_1__T_m_]),
meta::pure::mapping::from_T_m__Mapping_1__PackageableRuntime_1__T_m_,
meta::pure::mapping::with_T_m__Mapping_1__Runtime_1__T_m_,
meta::pure::mapping::with_T_m__Mapping_1__PackageableRuntime_1__T_m_]),
{f:Function<Any>[1], fe:FunctionExpression[1], state:RoutingState[1], executionContext:meta::pure::runtime::ExecutionContext[1], vars:Map<VariableExpression, ValueSpecification>[1], inScopeVars:Map<String, List<Any>>[1], extensions:meta::pure::extension::Extension[*], debug:DebugContext[1] |
let resolvedParameters = $fe.parametersValues->tail()->map(p|$p->evaluateAndDeactivate()->match([v:VariableExpression[1] |let iv = meta::pure::functions::meta::resolve($v, $vars, $inScopeVars)->cast(@InstanceValue).values,
f:FunctionExpression[1] |let r = $f->meta::pure::router::preeval::preval($inScopeVars, $extensions, $debug);
Expand All @@ -409,6 +415,7 @@ function meta::pure::router::store::routing::specializedFunctionExpressionRoute
let fromRuntime = $resolvedParameters->at(1)
->match([
r:Runtime[1]| $r,
pr:PackageableRuntime[1] | $pr.runtimeValue;,
fe: FunctionExpression[1] | $fe->meta::pure::router::preeval::preval($inScopeVars, $extensions, $debug)->reactivate($inScopeVars)
])->toOne()->cast(@Runtime);
let fromExecutionContext = if($resolvedParameters->size() == 3, | $resolvedParameters->at(2)->cast(@meta::pure::runtime::ExecutionContext), | $executionContext);
Expand Down Expand Up @@ -461,7 +468,7 @@ function meta::pure::router::store::routing::specializedFunctionExpressionRoute
let prevalFunc = $fe->preval($inScopeVars, $extensions, $debug)->cast(@SimpleFunctionExpression);

let mapping = $prevalFunc.parametersValues->at(2)->cast(@InstanceValue).values->toOne()->cast(@Mapping);
let runtime = $prevalFunc.parametersValues->at(3)->cast(@InstanceValue).values->toOne()->cast(@Runtime);
let runtime = $prevalFunc.parametersValues->at(3)->cast(@InstanceValue).values->toOne()->match([runtime:Runtime[1] | $runtime, packageableRuntime:PackageableRuntime[1] | $packageableRuntime.runtimeValue]);

let currentRoutingStrategy = $state.routingStrategy;
let newRoutingStrategy = getRoutingStrategyFromMappingAndRuntime($currentRoutingStrategy, $mapping, $runtime, $extensions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,6 @@ function meta::external::dataquality::buildFromRuntimeExpression(f: FunctionExpr

function meta::external::dataquality::isFromFunctionPresent(func: FunctionDefinition<Any>[1]):Boolean[1]
{
let getExprList = $func->findExpressionsForFunctionInFunctionDefinition([meta::pure::mapping::from_T_m__Runtime_1__T_m_]);
let getExprList = $func->findExpressionsForFunctionInFunctionDefinition([meta::pure::mapping::from_T_m__Runtime_1__T_m_, meta::pure::mapping::from_T_m__PackageableRuntime_1__T_m_]);
!$getExprList->isEmpty();
}
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,28 @@ public void testServiceCompilationWithOnlyLambda()
" [\n" +
" ];\n" +
" }\n" +
"}\n", "COMPILATION error at [28:68-71]: Can't find a match for function 'from(class[*],Runtime[1],Mapping[1])'");
"}\n", "COMPILATION error at [28:68-71]: Can't find a match for function 'from(class[*],PackageableRuntime[1],Mapping[1])'");

test(resource + "###Service\n" +
"Service test::Service\n" +
"{\n" +
" pattern: 'url/myUrl/';\n" +
" owners: ['ownerName', 'ownerName2'];\n" +
" documentation: 'test';\n" +
" autoActivateUpdates: true;\n" +
" execution: Single\n" +
" {\n" +
// intentionally mess up the spacing here to test source information
" query: |test::class.all()->graphFetch(#{test::class{prop1}}#)->from(test::mapping, test::runtime);\n" +
" }\n" +
" test: Single\n" +
" {\n" +
" data: 'moreThanData';\n" +
" asserts:\n" +
" [\n" +
" ];\n" +
" }\n" +
"}\n");

// test the assert with toOne compiles
test(resource + "###Service\n" +
Expand Down

0 comments on commit 5ebb940

Please sign in to comment.