Skip to content

Commit

Permalink
Support assigning relation to variables
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelbey committed Jan 14, 2025
1 parent e6e7719 commit eac9191
Show file tree
Hide file tree
Showing 111 changed files with 759 additions and 699 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function <<access.private>> meta::external::format::shared::executionPlan::exter

^ExternalFormatExternalizeExecutionNode
(
resultType = ^ResultType(type=String),
resultType = ^ResultType(genericType=^GenericType(rawType = String)),
resultSizeRange = PureOne,
checked = $checked,
binding = $binding,
Expand All @@ -166,7 +166,7 @@ function <<access.private>> meta::external::format::shared::executionPlan::exter
let contentType = $fe.parametersValues->at(1)->byPassValueSpecificationWrapper()->cast(@InstanceValue).values->at(0)->cast(@String);
^ExternalFormatExternalizeTDSExecutionNode
(
resultType = ^ResultType(type=String),
resultType = ^ResultType(genericType=^GenericType(rawType = String)),
resultSizeRange = PureOne,
contentType = $contentType,
executionNodes = $children
Expand Down Expand Up @@ -200,7 +200,7 @@ function <<access.private>> meta::external::format::shared::executionPlan::inter

^ExternalFormatInternalizeExecutionNode
(
resultType = ^ClassResultType(type=$class),
resultType = ^ClassResultType(genericType=^GenericType(rawType = $class)),
config = $config,
resultSizeRange = ZeroMany,
binding = $binding,
Expand All @@ -223,20 +223,20 @@ function <<access.private>> meta::external::format::shared::executionPlan::gener

function <<access.private>> meta::external::format::shared::executionPlan::generateSourceNodeFromFunctionExpression(fe:FunctionExpression[1], state:ExternalFormatPlanGenerationState[1], extensions : Extension[*], debug:DebugContext[1]): ExecutionNode[1]
{
$fe.parametersValues->at(2)->match([ var:VariableExpression[1] | ^VariableResolutionExecutionNode(varName=$var.name->toOne(), resultType = ^DataTypeResultType(type = $var.genericType.rawType->toOne())),
$fe.parametersValues->at(2)->match([ var:VariableExpression[1] | ^VariableResolutionExecutionNode(varName=$var.name->toOne(), resultType = ^DataTypeResultType(genericType = $var.genericType)),
ins:InstanceValue[1] | assert($ins.values->size() == 1 && ($ins.values->toOne()->instanceOf(String) || $ins.values->toOne()->instanceOf(PlanVarPlaceHolder)) , | 'Expected single string value as parameter for internalize. Please contact dev team with this issue!');

if($ins.values->toOne()->instanceOf(String),
| let varName = 'internalizeVar$';
let allocationNode = ^AllocationExecutionNode(varName = $varName,
executionNodes = ^ConstantExecutionNode(values=$ins.values->cast(@String)->toOne(), resultType = ^DataTypeResultType(type = String)),
resultType = ^VoidResultType(type = meta::pure::router::store::routing::Void));
executionNodes = ^ConstantExecutionNode(values=$ins.values->cast(@String)->toOne(), resultType = ^DataTypeResultType(genericType = ^GenericType(rawType = String))),
resultType = ^VoidResultType(genericType = ^GenericType(rawType = meta::pure::router::store::routing::Void)));
let varResolutionNode = ^VariableResolutionExecutionNode(varName = $varName,
resultType = ^DataTypeResultType(type = String),
resultType = ^DataTypeResultType(genericType = ^GenericType(rawType = String)),
resultSizeRange = PureOne);

^SequenceExecutionNode(executionNodes = [$allocationNode, $varResolutionNode], resultType = ^DataTypeResultType(type = String), resultSizeRange = PureOne);,
| ^VariableResolutionExecutionNode(varName=$ins.values->toOne()->cast(@PlanVarPlaceHolder).name, resultType = ^DataTypeResultType(type = String)));,
^SequenceExecutionNode(executionNodes = [$allocationNode, $varResolutionNode], resultType = ^DataTypeResultType(genericType = ^GenericType(rawType = String)), resultSizeRange = PureOne);,
| ^VariableResolutionExecutionNode(varName=$ins.values->toOne()->cast(@PlanVarPlaceHolder).name, resultType = ^DataTypeResultType(genericType = ^GenericType(rawType = String))));,
c:ClusteredValueSpecification[1] | $c->plan($state.inScopeVars, $state.exeCtx, $extensions, $debug)
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ function meta::pure::functions::meta::resolve(v:VariableExpression[1], vars:Map<
|let res = $open.values;
$res->match([
{pv: meta::pure::executionPlan::PlanVarPlaceHolder[1] |
^InstanceValue(values=$pv, genericType=^GenericType(rawType=$pv.type), multiplicity=$pv.multiplicity->defaultIfEmpty(ZeroMany)->toOne())->evaluateAndDeactivate();
^InstanceValue(values=$pv, genericType = $pv.genericType, multiplicity=$pv.multiplicity->defaultIfEmpty(ZeroMany)->toOne())->evaluateAndDeactivate();
},
{a: Any[*] |
if($res->isEmpty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ Profile meta::pure::executionPlan::profiles::serverVersion

Class meta::pure::executionPlan::ResultType
{
type : Type[1];
genericType : GenericType[0..1];
genericType : GenericType[1];
}

Class meta::pure::executionPlan::ClassResultType extends ResultType
Expand Down Expand Up @@ -94,7 +93,7 @@ Class meta::pure::executionPlan::ExecutionNode
Class meta::pure::executionPlan::VariableInput
{
name : String[1];
type : Type[1];
genericType : GenericType[1];
multiplicity : Multiplicity[1];
}

Expand Down Expand Up @@ -195,7 +194,7 @@ Class meta::pure::executionPlan::EnumValidationContext extends ParameterValidati
Class meta::pure::executionPlan::FunctionParameter
{
name : String[1];
type : Type[1];
genericType : GenericType[1];
supportsStream : Boolean[0..1];
multiplicity: Multiplicity[0..1];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function meta::pure::executionPlan::processNode(node:ExecutionNode[1], mapping:M
[
s:SequenceExecutionNode[1] | let planParams = $s.executionNodes->filter(e|$e->instanceOf(AllocationExecutionNode))->cast(@AllocationExecutionNode)->map(node |let nodeRes = $node.executionNodes->toOne()->processNode($mapping, $runtime, $parametersValues, $extensions).values->toOne();
let varMultiplicity = if($nodeRes->size() == 1, | PureOne, | ZeroMany);
pair(^VariableExpression(name=$node.varName, genericType = ^GenericType(rawType=$node.resultType.type), multiplicity=$varMultiplicity), $nodeRes););
pair(^VariableExpression(name=$node.varName, genericType = $node.resultType.genericType, multiplicity=$varMultiplicity), $nodeRes););
$s.executionNodes->filter(e|!$e->instanceOf(FunctionParametersValidationNode) && !$e->instanceOf(AllocationExecutionNode))->map(e|$e->processNode($mapping, $runtime, $planParams->concatenate($parametersValues), $extensions))->toOne();,
f:FreeMarkerConditionalExecutionNode[1]| if($f.falseBlock->isNotEmpty(), |$f.falseBlock->toOne()->processNode($mapping, $runtime, $parametersValues, $extensions);, |^Result<Any|*>(values = [])),
c:ConstantExecutionNode[1]| ^Result<Any|*>(values = $c.values);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Class meta::pure::executionPlan::ExecutionOptionContext extends MultiExecutionCo

Class meta::pure::executionPlan::PlanVarPlaceHolder extends meta::pure::executionPlan::FunctionParameter
{
routedVs: ValueSpecification[0..1];
}

Class meta::pure::executionPlan::PlanSetPlaceHolder
Expand Down Expand Up @@ -161,9 +162,9 @@ function meta::pure::executionPlan::executionPlan(clusters:ClusteredValueSpecifi
| let allNodes = $clusters->fold({c,a|let x = $a.vars;
print(if($debugContext.debug,|'Generating plan for cluster: '+$c->meta::pure::router::printer::asString()+'\n',|''));
let node = $c->plan($x, $context, $extensions, ^$debugContext(space = $debugContext.space+' '));
let nVars = $node->match([a:AllocationExecutionNode[1]|let varValues = if($a.resultType.type == TabularDataSet,
|^PlanSetPlaceHolder(name=$a.varName,tdsColumns = $a.resultType->match([x:TDSResultType[1]|$x.tdsColumns, a:Any[1]|[]])),
|^PlanVarPlaceHolder(name=$a.varName,type = $a.resultType.type, multiplicity=$a.resultSizeRange));
let nVars = $node->match([a:AllocationExecutionNode[1]|let varValues = if($a.resultType->instanceOf(meta::pure::executionPlan::TDSResultType),
|^PlanSetPlaceHolder(name=$a.varName,tdsColumns = $a.resultType->cast(@TDSResultType).tdsColumns),
|^PlanVarPlaceHolder(name=$a.varName,genericType = $a.resultType.genericType, multiplicity=$a.resultSizeRange));
$x->put($a.varName, ^List<Any>(values=$varValues));,
a:Any[*]|$x]);
^$a(nodes+=$node, vars = $nVars);
Expand Down Expand Up @@ -212,12 +213,12 @@ function meta::pure::executionPlan::generatePlatformCode(plan:ExecutionPlan[1],

function <<access.private>> meta::pure::executionPlan::addFunctionParametersValidationNode(node:ExecutionNode[1], f:FunctionDefinition<Any>[1], planVarPlaceHolders:PlanVarPlaceHolder[*], routedFunction:FunctionDefinition<Any>[1]):ExecutionNode[1]
{
let collectionEnumParams = $planVarPlaceHolders->filter(p | $p.type->instanceOf(Enumeration) && $p.multiplicity == ZeroMany);
let collectionEnumParams = $planVarPlaceHolders->filter(p | $p.genericType.rawType->toOne()->instanceOf(Enumeration) && $p.multiplicity == ZeroMany);
assert($collectionEnumParams->size() == 0, |'Collection of Enums is not supported as service parameter ' + $collectionEnumParams->map(p | $p.name)->makeString('[',', ',']'));
let enumValidationContext = $planVarPlaceHolders->filter(p | $p.type->instanceOf(Enumeration))->map(e | ^meta::pure::executionPlan::EnumValidationContext(varName = $e.name, validEnumValues = $e.type->cast(@Enumeration<Any>)->enumValues()->map(e |$e->id())));
let enumValidationContext = $planVarPlaceHolders->filter(p | $p.genericType.rawType->toOne()->instanceOf(Enumeration))->map(e | ^meta::pure::executionPlan::EnumValidationContext(varName = $e.name, validEnumValues = $e.genericType.rawType->toOne()->cast(@Enumeration<Any>)->enumValues()->map(e |$e->id())));
let paramsSupportedForStreamInput = $routedFunction->findParamsSupportedForStreamInput();
if($planVarPlaceHolders->isNotEmpty(),| let functionParameters = $planVarPlaceHolders->map(p|^FunctionParameter(name=$p.name, supportsStream = $p.name->in($paramsSupportedForStreamInput), multiplicity=$p.multiplicity, type=$p.type));
let functionParametersValidationNode = ^FunctionParametersValidationNode(functionParameters = $functionParameters, resultType=^ResultType(type = Boolean), parameterValidationContext = $enumValidationContext);
if($planVarPlaceHolders->isNotEmpty(),| let functionParameters = $planVarPlaceHolders->map(p|^FunctionParameter(name=$p.name, supportsStream = $p.name->in($paramsSupportedForStreamInput), multiplicity=$p.multiplicity, genericType=$p.genericType));
let functionParametersValidationNode = ^FunctionParametersValidationNode(functionParameters = $functionParameters, resultType=^ResultType(genericType=^GenericType(rawType = Boolean)), parameterValidationContext = $enumValidationContext);
$node->match([s:SequenceExecutionNode[1]|^$s(executionNodes=$functionParametersValidationNode->concatenate($s.executionNodes)),
e:ExecutionNode[1]|^SequenceExecutionNode(executionNodes=[$functionParametersValidationNode, $e], resultType=$e.resultType, resultSizeRange=$e.resultSizeRange)]);
,| $node);
Expand Down Expand Up @@ -253,7 +254,7 @@ function <<access.private>> meta::pure::executionPlan::findParamsForStreamInput(

function meta::pure::executionPlan::stubFuncParameters(f:FunctionDefinition<Any>[1]):PlanVarPlaceHolder[*]
{
$f->functionType().parameters->evaluateAndDeactivate()->map(p|^PlanVarPlaceHolder(name=$p.name, type = $p.genericType.rawType->toOne(), multiplicity=$p.multiplicity));
$f->functionType().parameters->evaluateAndDeactivate()->map(p|^PlanVarPlaceHolder(name=$p.name, genericType = $p.genericType, multiplicity=$p.multiplicity));
}

function meta::pure::executionPlan::plan(cluster:ClusteredValueSpecification[1], inScopeVars:Map<String, List<Any>>[1], context:meta::pure::runtime::ExecutionContext[1], extensions:meta::pure::extension::Extension[*], debugContext:DebugContext[1]):ExecutionNode[1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function <<access.public>> meta::pure::executionPlan::toString::planNodeToString
c:ConstantExecutionNode[1]|'Constant\n'+$space+'('+header($c, $space, $extensions)+'\n'+$space+' values=['+$c.values->makeString(',')+']\n'+$space+')\n',
p:MultiResultSequenceExecutionNode[1]|'MultiResultSequence\n'+$space+'('+header($p, $space, $extensions)+$e->childrenToString($space+' ', $extensions)+'\n'+$space+')\n',
p:ErrorExecutionNode[1]|'Error\n'+$space+'('+header($p, $space, $extensions)+'\n'+$space+' message = '+ $p.message->replace('\n', '\\n')->replace('\r','\\r')+$e->childrenToString($space+' ', $extensions)+'\n'+$space+')\n',
e:FunctionParametersValidationNode[1] | 'FunctionParametersValidationNode\n'+ $space+ '(' + '\n'+ $space +' functionParameters = '+ $e.functionParameters->map(p|$p.name+':'+$p.type->elementToPath()+ '[' + printMultiplicity($p.multiplicity->toOne()) + ']')->makeString('[',', ',']')+'\n'+$space+')\n',
e:FunctionParametersValidationNode[1] | 'FunctionParametersValidationNode\n'+ $space+ '(' + '\n'+ $space +' functionParameters = '+ $e.functionParameters->map(p|$p.name+':'+$p.genericType.rawType->toOne()->elementToPath()+ '[' + printMultiplicity($p.multiplicity->toOne()) + ']')->makeString('[',', ',']')+'\n'+$space+')\n',
g:meta::pure::graphFetch::executionPlan::GlobalGraphFetchExecutionNode[1] | $g->meta::pure::graphFetch::executionPlan::globalGraphFetchExecutionNodeToString($space, $extensions),
g:meta::pure::mapping::modelToModel::graphFetch::executionPlan::StoreStreamReadingExecutionNode[1] | $g->meta::pure::mapping::modelToModel::graphFetch::executionPlan::storeStreamReadingExecutionNodeToString($space, $extensions),
i:meta::pure::mapping::modelToModel::graphFetch::executionPlan::InMemoryGraphFetchExecutionNode[1] | $i->meta::pure::mapping::modelToModel::graphFetch::executionPlan::inMemoryGraphFetchExecutionNodeToString($space, $extensions),
Expand Down Expand Up @@ -97,7 +97,7 @@ function meta::pure::executionPlan::toString::header(e:ExecutionNode[1], space:S
{
'\n'+ $space+' type = '+$e.resultType->typeToString($space, $extensions)+if($e.resultSizeRange->isEmpty(),|'',|'\n'
+ $space+' resultSizeRange = '+$e.resultSizeRange->toOne()->meta::pure::metamodel::serialization::grammar::printMultiplicity())
+ if($e.requiredVariableInputs->isEmpty(), |'', | '\n' + $space+' requires = '+$e.requiredVariableInputs->map(source | $source.name + '(' + $source.type->elementToPath() + '[' + $source.multiplicity->meta::pure::metamodel::serialization::grammar::printMultiplicity() +'])')->joinStrings('[',', ',']'));
+ if($e.requiredVariableInputs->isEmpty(), |'', | '\n' + $space+' requires = '+$e.requiredVariableInputs->map(source | $source.name + '(' + $source.genericType.rawType->toOne()->elementToPath() + '[' + $source.multiplicity->meta::pure::metamodel::serialization::grammar::printMultiplicity() +'])')->joinStrings('[',', ',']'));
}

function meta::pure::executionPlan::toString::childrenToString(e:ExecutionNode[*], space:String[1], extensions:meta::pure::extension::Extension[*]):String[1]
Expand All @@ -118,7 +118,7 @@ function <<access.private>> meta::pure::executionPlan::toString::typeToString(e:
partialClassResultType : PartialClassResultType[1]|'PartialClass[impls=['+$partialClassResultType.setImplementations->map(se|'('+$se.class->elementToPath()+' | '+$se.parent.name->toOne()+'.'+$se.id+')')->joinStrings(',')+'], propertiesWithParameters = ['+$partialClassResultType.propertiesWithParameters->map(x | if($x.property->instanceOf(Property), | $x.property.name->toOne(), | $x.parameters->map(x | $x->asString())->joinStrings($x.property.name->toOne() + '(', ', ', ')')))->sort()->joinStrings(', ')+']]',
classResultType : ClassResultType[1]|'Class[impls='+$classResultType.setImplementations->map(se|'('+$se.class->elementToPath()+' | '+$se.parent.name->toOne()+'.'+$se.id+')')->joinStrings(',')+']'+if($classResultType.genericType->isEmpty(), |'', |'\n'+$space+' as '+$classResultType.genericType->toOne()->printGenericType()),
voidResultType : VoidResultType[1]|'Void',
e:ResultType[1] | $e.type->elementToPath()
e:ResultType[1] | $e.genericType.rawType->toOne()->elementToPath()
])->toOneMany()
)
}
Expand Down
Loading

0 comments on commit eac9191

Please sign in to comment.