Skip to content

Commit

Permalink
from Dataspace support (finos#2821)
Browse files Browse the repository at this point in the history
* from Dataspace support

* Add missing files

* add dependencies
  • Loading branch information
Yasirmod17 authored May 3, 2024
1 parent 463f303 commit 5edd0dc
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@
<artifactId>legend-engine-pure-functions-legendCompiler-pure</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-data-space-pure-metamodel</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
Expand All @@ -112,6 +117,11 @@
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-data-space-pure-metamodel</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.finos.legend.pure</groupId>
<artifactId>legend-pure-m2-dsl-mapping-grammar</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package org.finos.legend.engine.language.pure.compiler.toPureGraph;

import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.Function2;
import org.eclipse.collections.api.block.function.Function3;
import org.eclipse.collections.api.factory.Lists;
Expand All @@ -23,12 +24,16 @@
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.api.set.MutableSet;
import org.eclipse.collections.impl.list.mutable.FastList;
import org.eclipse.collections.impl.utility.Iterate;
import org.eclipse.collections.impl.utility.ListIterate;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.data.EmbeddedDataFirstPassBuilder;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.data.core.EmbeddedDataCompilerHelper;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.extension.CompilerExtension;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.extension.Processor;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.FunctionExpressionBuilderRegistrationInfo;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.FunctionHandlerDispatchBuilderInfo;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.Handlers;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.IncludedMappingHandler;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.StoreProviderCompilerHelper;
import org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType;
Expand Down Expand Up @@ -60,11 +65,16 @@
import org.finos.legend.pure.generated.Root_meta_pure_metamodel_dataSpace_DataSpaceSupportInfo;
import org.finos.legend.pure.generated.Root_meta_pure_metamodel_dataSpace_DataSpace_Impl;
import org.finos.legend.pure.generated.Root_meta_pure_metamodel_extension_TaggedValue_Impl;
import org.finos.legend.pure.generated.Root_meta_pure_metamodel_type_generics_GenericType_Impl;
import org.finos.legend.pure.generated.Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl;
import org.finos.legend.pure.generated.Root_meta_pure_runtime_PackageableRuntime;
import org.finos.legend.pure.generated.Root_meta_pure_metamodel_dataSpace_DataSpacePackageableElementExecutable_Impl;
import org.finos.legend.pure.generated.Root_meta_pure_metamodel_dataSpace_DataSpaceTemplateExecutable_Impl;
import org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification;
import org.finos.legend.pure.m3.coreinstance.meta.pure.store.Store;

import java.util.Collections;
Expand Down Expand Up @@ -267,6 +277,24 @@ public Map<String, IncludedMappingHandler> getExtraIncludedMappingHandlers()
);
}


@Override
public List<Function3<org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement, CompileContext, ProcessingContext, InstanceValue>> getExtraValueSpecificationBuilderForFuncExpr()
{
return org.eclipse.collections.impl.factory.Lists.mutable.with((packageableElement, context, processingContext) ->
{
if (packageableElement instanceof Root_meta_pure_metamodel_dataSpace_DataSpace)
{
GenericType dSGenericType = new Root_meta_pure_metamodel_type_generics_GenericType_Impl("", null, context.pureModel.getClass("meta::pure::metamodel::type::generics::GenericType"))._rawType(context.pureModel.getType("meta::pure::metamodel::dataSpace::DataSpace"));
return new Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl("", null, context.pureModel.getClass("meta::pure::metamodel::valuespecification::InstanceValue"))
._genericType(dSGenericType)
._multiplicity(context.pureModel.getMultiplicity("one"))
._values(processingContext.peek().equals("Applying new") ? FastList.newList() : FastList.newListWith(packageableElement));
}
return null;
});
}

@Override
public Map<PackageableElementType, Function2<StoreProviderPointer, CompileContext, Store>> getExtraStoreProviderHandlers()
{
Expand Down Expand Up @@ -340,4 +368,31 @@ private static List<EmbeddedData> getDataFromDataReferencePMCD(DataElementRefere
.collect(d -> Iterate.detect(d.executionContexts, e -> e.name.equals(d.defaultExecutionContext)).testData)
.collect(d -> EmbeddedDataCompilerHelper.getEmbeddedDataFromDataElement(d, pureModelContextData));
}

@Override
public List<Function<Handlers, List<FunctionHandlerDispatchBuilderInfo>>> getExtraFunctionHandlerDispatchBuilderInfoCollectors()
{
return Collections.singletonList((handlers) ->
org.eclipse.collections.api.factory.Lists.mutable.with(
new FunctionHandlerDispatchBuilderInfo("meta::pure::mapping::from_T_m__DataSpaceExecutionContext_1__T_m_", (List<ValueSpecification> ps) -> ps.size() == 2 && handlers.isOne(ps.get(1)._multiplicity()) && ("Nil".equals(ps.get(1)._genericType()._rawType()._name()) || "DataSpaceExecutionContext".equals(ps.get(1)._genericType()._rawType()._name()))),
new FunctionHandlerDispatchBuilderInfo("meta::pure::metamodel::dataSpace::get_DataSpace_1__String_1__DataSpaceExecutionContext_1_", (List<ValueSpecification> ps) -> ps.size() == 2 && handlers.isOne(ps.get(0)._multiplicity()) && ("Nil".equals(ps.get(0)._genericType()._rawType()._name()) || "DataSpace".equals(ps.get(0)._genericType()._rawType()._name())) && handlers.isOne(ps.get(1)._multiplicity()) && ("Nil".equals(ps.get(1)._genericType()._rawType()._name()) || "String".equals(ps.get(1)._genericType()._rawType()._name())))

));
}

@Override
public List<Function<Handlers, List<FunctionExpressionBuilderRegistrationInfo>>> getExtraFunctionExpressionBuilderRegistrationInfoCollectors()
{
return Collections.singletonList((handlers) ->
org.eclipse.collections.api.factory.Lists.mutable.with(
new FunctionExpressionBuilderRegistrationInfo(org.eclipse.collections.impl.factory.Lists.mutable.with(0),
handlers.m(handlers.h("meta::pure::mapping::from_T_m__DataSpaceExecutionContext_1__T_m_", false, ps -> handlers.res(ps.get(0)._genericType(), ps.get(0)._multiplicity()), ps -> ps.size() == 2 && handlers.typeOne(ps.get(1), "DataSpaceExecutionContext")))
),
// getter for execution parameters from execution environment
new FunctionExpressionBuilderRegistrationInfo(null,
handlers.m(handlers.m(handlers.h("meta::pure::metamodel::dataSpace::get_DataSpace_1__String_1__DataSpaceExecutionContext_1_", false, ps -> handlers.res("meta::pure::metamodel::dataSpace::DataSpaceExecutionContext", "one"), ps -> ps.size() == 2))))

));
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "core_data_space_metamodel",
"pattern": "(meta::pure::metamodel::dataSpace)(::.*)?",
"pattern": "(meta::pure::metamodel::dataSpace|meta::pure::mapping)(::.*)?",
"dependencies": [
"platform",
"platform_dsl_mapping",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2022 Goldman Sachs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import meta::pure::metamodel::dataSpace::*;

function meta::pure::metamodel::dataSpace::get(ds: DataSpace[1], key:String[1]):DataSpaceExecutionContext[1]
{
let context = $ds.executionContexts->cast(@DataSpaceExecutionContext)->filter(x| $x.name == $key->toOne());
assert($context->isNotEmpty(),| 'The key value provided is not present in the dataspace contexts');
$context->at(0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2022 Goldman Sachs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

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

function <<functionType.NotImplementedFunction>> meta::pure::mapping::from<T|m>(t:T[m], dataSpace: meta::pure::metamodel::dataSpace::DataSpaceExecutionContext[1]):T[m]
{
$t
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static ExecutionPlan generatePlan(PureModel pureModel, Root_meta_external
{
Map<String, SingleExecutionPlan> plans = Maps.mutable.empty();
String execKey = core_hostedservice_generation_generation.Root_meta_external_function_activator_hostedService_generation_getEnvironmentkey_HostedService_1__String_1_(activator, pureModel.getExecutionSupport());
core_hostedservice_generation_generation.Root_meta_external_function_activator_hostedService_generation_rebuildServiceUsingSingleExecutionParams_HostedService_1__Pair_MANY_(activator, pureModel.getExecutionSupport()).forEach(p ->
core_hostedservice_generation_generation.Root_meta_external_function_activator_hostedService_generation_rebuildServiceUsingFlattenedParams_HostedService_1__Pair_MANY_(activator, pureModel.getExecutionSupport()).forEach(p ->
{
ExecutionPlan plan = PlanGenerator.generateExecutionPlan((ConcreteFunctionDefinition) p._second()._function(), null, null, null, pureModel,
clientVersion, PlanPlatform.JAVA, null, routerExtensions.apply(pureModel), transformers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ function meta::external::function::activator::hostedService::generation::getEnvi
function meta::external::function::activator::hostedService::generation::getExecutionParam(func: PackageableFunction<Any>[1]):PackageableElement[*]
{
let valueSpecification = $func->cast(@ConcreteFunctionDefinition<Any>).expressionSequence->cast(@SimpleFunctionExpression)->evaluateAndDeactivate().parametersValues
->filter(x| $x.genericType.rawType->toOne()->in([ExecutionEnvironmentInstance, SingleExecutionParameters, DataSpace]));
->filter(x| $x.genericType.rawType->toOne()->in([ExecutionEnvironmentInstance, SingleExecutionParameters, DataSpace, DataSpaceExecutionContext]));
//today we'll get a function cos we're in the pure IDE. from syudio we should be getting a packageable element so the need for the inner match will be eliminated
if($valueSpecification->isNotEmpty(),
|$valueSpecification->match([
s:SimpleFunctionExpression[1]|if($s.func == get_ExecutionEnvironmentInstance_1__String_1__SingleExecutionParameters_1_ ,
|$s->evaluateAndDeactivate().parametersValues->filter(x| $x.genericType.rawType->toOne()==ExecutionEnvironmentInstance)->map(pv|
s:SimpleFunctionExpression[1]|if($s.func->in([get_ExecutionEnvironmentInstance_1__String_1__SingleExecutionParameters_1_, get_DataSpace_1__String_1__DataSpaceExecutionContext_1_ ]),
|$s->evaluateAndDeactivate().parametersValues->filter(x| $x.genericType.rawType->toOne()->in([ExecutionEnvironmentInstance, DataSpace]))->map(pv|
$pv->match([
s:SimpleFunctionExpression[1]| $s->reactivate()->toOne();,
i:InstanceValue[1]| $i.values->toOne();,
Expand All @@ -190,7 +190,7 @@ function meta::external::function::activator::hostedService::generation::getExec
|[])->cast(@PackageableElement);
}

function meta::external::function::activator::hostedService::generation::rebuildServiceUsingSingleExecutionParams(h:HostedService[1] ):Pair<String,HostedService>[*]
function meta::external::function::activator::hostedService::generation::rebuildServiceUsingFlattenedParams(h:HostedService[1] ):Pair<String,HostedService>[*]
{
let execParam = getExecutionParam($h.function);
$execParam->match([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function meta::external::function::activator::hostedService::tests::simpleServic
//validate
$service->meta::external::function::activator::hostedService::validator::validateService();
//printlnPlan
$service->rebuildServiceUsingSingleExecutionParams().second->map(s|$s->meta::external::function::activator::hostedService::generation::printPlan());
$service->rebuildServiceUsingFlattenedParams().second->map(s|$s->meta::external::function::activator::hostedService::generation::printPlan());

}

Expand All @@ -136,7 +136,7 @@ function meta::external::function::activator::hostedService::tests::simpleServic
{
let service = ^HostedService
(
pattern = '/service',
pattern = '/service/{env}',
ownership = ^UserList(users = ['debelp', 'harted']),
documentation = 'bla bla',
autoActivateUpdates = true,
Expand All @@ -148,7 +148,7 @@ function meta::external::function::activator::hostedService::tests::simpleServic
//validate
$service->meta::external::function::activator::hostedService::validator::validateService();
//printlnPlan
$service->rebuildServiceUsingSingleExecutionParams().second->map(s|$s->meta::external::function::activator::hostedService::generation::printPlan());
$service->rebuildServiceUsingFlattenedParams().second->map(s|$s->meta::external::function::activator::hostedService::generation::printPlan());

}

Expand All @@ -174,7 +174,7 @@ function meta::external::function::activator::hostedService::tests::simpleServic
//validate
$service->meta::external::function::activator::hostedService::validator::validateService();
//printlnPlan
$service->rebuildServiceUsingSingleExecutionParams().second->map(s|$s->meta::external::function::activator::hostedService::generation::printPlan());
$service->rebuildServiceUsingFlattenedParams().second->map(s|$s->meta::external::function::activator::hostedService::generation::printPlan());

}

Expand All @@ -195,7 +195,7 @@ $service-> meta::external::function::activator::hostedService::generation::isMul
//validate
$service->meta::external::function::activator::hostedService::validator::validateService();
//printlnPlan
$service->rebuildServiceUsingSingleExecutionParams().second->map(s|$s->meta::external::function::activator::hostedService::generation::printPlan());
$service->rebuildServiceUsingFlattenedParams().second->map(s|$s->meta::external::function::activator::hostedService::generation::printPlan());

}

Expand Down Expand Up @@ -230,26 +230,27 @@ function meta::external::function::activator::hostedService::tests::simpleServic
{
let service = ^HostedService
(
pattern = '/service',
pattern = '/service/{key}',
ownership = ^UserList(users = ['debelp', 'harted']),
contentType = 'application/json',
documentation = 'bla bla',
autoActivateUpdates = true,
function= meta::external::function::activator::hostedService::tests::simplegraphFetchfunctionWithDataSpace__PersonX_MANY_
function= meta::external::function::activator::hostedService::tests::simplegraphFetchfunctionWithDataSpace_String_1__PersonX_MANY_
);
//isMulti
print('isMultiExecService:');
$service-> meta::external::function::activator::hostedService::generation::isMultiEenvironmentService()->println();
//validate
$service->meta::external::function::activator::hostedService::validator::validateService();
//printlnPlan
$service->rebuildServiceUsingSingleExecutionParams().second->map(s|$s->meta::external::function::activator::hostedService::generation::printPlan());
$service->rebuildServiceUsingFlattenedParams().second->map(s|$s->meta::external::function::activator::hostedService::generation::printPlan());

}

function meta::external::function::activator::hostedService::tests::simplegraphFetchfunctionWithDataSpace():PersonX[*]
function meta::external::function::activator::hostedService::tests::simplegraphFetchfunctionWithDataSpace(key:String[1]):PersonX[*]
{
PersonX.all()->graphFetch(#{ PersonX {firstName} } #)->from(meta::external::function::activator::hostedService::tests::TestDataSpaces());
PersonX.all()->graphFetch(#{ PersonX {firstName} } #)
->from(meta::external::function::activator::hostedService::tests::TestDataSpaces()->meta::pure::metamodel::dataSpace::get($key));
}

function meta::external::function::activator::hostedService::tests::TestDataSpaces(): meta::pure::metamodel::dataSpace::DataSpace[1]
Expand Down
Loading

0 comments on commit 5edd0dc

Please sign in to comment.