Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Routing of MultiExpressions involving platform function #2718

Merged
merged 4 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ 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())),
ins:InstanceValue[1] | assert($ins.values->size() == 1 && ($ins.values->toOne()->instanceOf(String) || $ins.values->toOne()->instanceOf(RoutedVariablePlaceHolder)), | 'Expected single string value as parameter for internalize. Please contact dev team with this issue!');
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$';
Expand All @@ -218,7 +218,7 @@ function <<access.private>> meta::external::format::shared::executionPlan::gener
resultSizeRange = PureOne);

^SequenceExecutionNode(executionNodes = [$allocationNode, $varResolutionNode], resultType = ^DataTypeResultType(type = String), resultSizeRange = PureOne);,
| ^VariableResolutionExecutionNode(varName=$ins.values->toOne()->cast(@RoutedVariablePlaceHolder).name, resultType = ^DataTypeResultType(type = String)));,
| ^VariableResolutionExecutionNode(varName=$ins.values->toOne()->cast(@PlanVarPlaceHolder).name, resultType = ^DataTypeResultType(type = 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 @@ -83,6 +83,7 @@ function meta::pure::router::platform::routing::enrichPlatformRoutedValueSpecifi
]));
^$i(values = $updatedValues);,
v:VariableExpression[1] | $v,
f: FunctionRoutedValueSpecification[1]| $f,
e:ExtendedRoutedValueSpecification[1] | $e->enrichExpressionWithStrategyBasedEnrichment($exeCtx, $extensions, $debug)
]
);
Expand Down Expand Up @@ -147,6 +148,7 @@ function meta::pure::router::platform::clustering::cluster(v:ValueSpecification[
$res;
);,
v:VariableExpression[1] | $v,
f: FunctionRoutedValueSpecification[1]| $f,
e:ExtendedRoutedValueSpecification[1] | $e->clusterFunctionExpressions($openVariables, $exeCtx, $extensions, $debug),
c:ClusteredValueSpecification[1] | $c
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function meta::pure::router::printer::asString(f:ValueSpecification[1], pref:Pre
b:KeyExpression[1]|'^KeyExpression(key = ' + $b.key->asString($pref) + ', value = '+ $b.expression->asString($pref) + ')',
a:BasicColumnSpecification<Any>[1]| '^BasicColumnSpecification<' + $a->genericType().typeArguments.rawType.name->makeString() + '>(name = \'' + $a.name + '\', func = ' + $a.func->asString($pref) + ')';,
r:RoutedVariablePlaceHolder[1]|'$'+$r.name,
p:meta::pure::executionPlan::PlanVarPlaceHolder[1]|'$'+$p.name,
a:Class<Any>[1]|if (efq($pref),|$a->elementToPath(),|$a->genericType().rawType.name->toOne()+' '+$a->toString()),
a:Any[1]|$a->genericType().rawType.name->toOne()+' '+$a->toString();
]))->joinStrings(', ')+if($i.values->size() < 2,|'',|']');,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ function meta::pure::router::routeFunction(f:FunctionDefinition<Any>[1], exeCtx:
{|
let unRoutedFunction = ^$l(expressionSequence = $vs, openVariables=$a.second->keys());
let routedFunction = routeFunction($unRoutedFunction, getPlatformRoutingStrategy(), $exeCtx, $a.second, $extensions, $debug);
let vars = $a.second->put($varName->toOne(), ^List<RoutedVariablePlaceHolder>(values=^RoutedVariablePlaceHolder(name=$varName->toOne())));
let deactivatedEs = $routedFunction.expressionSequence->evaluateAndDeactivate();
let vars = $a.second->put($varName->toOne(), ^List<meta::pure::executionPlan::PlanVarPlaceHolder>(values=^meta::pure::executionPlan::PlanVarPlaceHolder(type = $deactivatedEs->last().genericType.rawType->toOne(),
name=$varName->toOne(), multiplicity = $deactivatedEs->last()->toOne().multiplicity,
supportsStream = $deactivatedEs->last()->toOne().multiplicity->isToMany())));

^$a
(
first = ^$routedFunction(expressionSequence = $a.first.expressionSequence->concatenate($routedFunction.expressionSequence)->evaluateAndDeactivate()->toOneMany())->cast(@FunctionDefinition<Any>),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function meta::pure::mapping::modelToModel::executionPlan::platformBinding::lege
},
{
model: ModelConnection[1] |
let varName = $model.instances->values()->at(0)->get(0)->cast(@RoutedVariablePlaceHolder).name;
let varName = $model.instances->values()->at(0)->get(0)->match([p:PlanVarPlaceHolder[1]| $p.name, r:RoutedVariablePlaceHolder[1]| $r.name]);
let typeArg = $storeStreamReadingContext->j_invoke('streamType', $conventions->className($pureClass)->j_field('class', javaClassType()), javaReflectType());
$conventions->meta::pure::mapping::modelToModel::executionPlan::platformBinding::legendJava::graphFetch::storeStreamReading::objectStream::streamReaderClass($path)
->j_new($storeStreamReadingContext->j_invoke('getResult', [j_string($varName), $typeArg], javaStream($conventions->className($pureClass))))->j_return();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2529,3 +2529,101 @@ function <<test.Test>> meta::pure::executionPlan::tests::datetime::testPlanWithL
' )\n' +
')\n', $result->planToString($extensions));
}

function <<test.Test>> meta::pure::executionPlan::tests::testMultiExpressionWithPlatformAndFromFunction():Boolean[1]
{
let f = {names:String[*]|
let upperNames = $names->map(n|$n->toUpper());
meta::relational::tests::model::simple::Person.all()->filter(e|$e.firm.legalName->in($upperNames))->meta::pure::mapping::from(simpleRelationalMapping, meta::external::store::relational::tests::testRuntime());
};

let plan = executionPlan($f, meta::relational::extension::relationalExtensions());
assertEquals (
'Sequence\n'+
'(\n'+
' type = Class[impls=(meta::relational::tests::model::simple::Person | simpleRelationalMappingInc.meta_relational_tests_model_simple_Person)]\n'+
' resultSizeRange = *\n'+
' (\n'+
' FunctionParametersValidationNode\n'+
' (\n'+
' functionParameters = [names:String[*]]\n'+
' )\n'+
' Allocation\n'+
' (\n'+
' type = String\n'+
' resultSizeRange = *\n'+
' name = upperNames\n'+
' value = \n'+
' (\n'+
' PureExp\n'+
' (\n'+
' type = String\n'+
' resultSizeRange = *\n'+
' requires = [names(String[*])]\n'+
' expression = $names -> map([Routed Func:n:String[1] | $n -> toUpper();])\n'+
' )\n'+
' )\n'+
' )\n'+
' RelationalBlockExecutionNode\n'+
' (\n'+
' type = Class[impls=(meta::relational::tests::model::simple::Person | simpleRelationalMappingInc.meta_relational_tests_model_simple_Person)]\n'+
' resultSizeRange = *\n'+
' (\n'+
' Allocation\n'+
' (\n'+
' type = String\n'+
' name = inFilterClause_upperNames\n'+
' value = \n'+
' (\n'+
' FreeMarkerConditionalExecutionNode\n'+
' (\n'+
' type = String\n'+
' condition = ${(instanceOf(upperNames, "Stream") || instanceOf(upperNames, "StreamingResult") || ((collectionSize(upperNames![])?number) > 50))?c}\n'+
' trueBlock = \n'+
' (\n'+
' Sequence\n'+
' (\n'+
' type = String\n'+
' (\n'+
' CreateAndPopulateTempTable\n'+
' (\n'+
' type = Void\n'+
' inputVarNames = [upperNames]\n'+
' tempTableName = tempTableForIn_upperNames\n'+
' tempTableColumns = [(ColumnForStoringInCollection, VARCHAR(200) )]\n'+
' connection = TestDatabaseConnection(type = "H2")\n'+
' )\n'+
' Constant\n'+
' (\n'+
' type = String\n'+
' values=[select "temptableforin_uppernames_0".ColumnForStoringInCollection as ColumnForStoringInCollection from tempTableForIn_upperNames as "temptableforin_uppernames_0"]\n'+
' )\n'+
' )\n'+
' )\n'+
' )\n'+
' falseBlock = \n'+
' (\n'+
' Constant\n'+
' (\n'+
' type = String\n'+
' values=[${renderCollection(upperNames![] "," "\'" "\'" {"\'" : "\'\'" } "null")}]\n'+
' )\n'+
' )\n'+
' )\n'+
' )\n'+
' )\n'+
' Relational\n'+
' (\n'+
' type = Class[impls=(meta::relational::tests::model::simple::Person | simpleRelationalMappingInc.meta_relational_tests_model_simple_Person)]\n'+
' resultSizeRange = *\n'+
' resultColumns = [("pk_0", INT), ("firstName", VARCHAR(200)), ("age", INT), ("lastName", VARCHAR(200))]\n'+
' sql = select "root".ID as "pk_0", "root".FIRSTNAME as "firstName", "root".AGE as "age", "root".LASTNAME as "lastName" from personTable as "root" left outer join firmTable as "firmtable_0" on ("firmtable_0".ID = "root".FIRMID) where "firmtable_0".LEGALNAME in (${inFilterClause_upperNames})\n'+
' connection = TestDatabaseConnection(type = "H2")\n'+
' )\n'+
' ) \n'+
' )\n'+
' )\n'+
')\n' , $plan->planToString( meta::relational::extension::relationalExtensions()));

}

Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,20 @@ function <<test.Test>> meta::relational::tests::query::routing::multipleexpressi
assertEquals(' | {Platform> [strategy_wrapper /let firstFirmLegalName = {Platform> {Platform> [1 meta_relational_tests_model_simple_Firm/{meta::relational::tests::db> [1 meta_relational_tests_model_simple_Firm/[1 meta_relational_tests_model_simple_Firm/Class Firm].all()]} -> at(0)]}.legalName}]};\n {Platform> [strategy_wrapper /let otherLegalName = [$firstFirmLegalName, \'Test\'] -> plus()]};', $routingResult->map(f|$f->meta::pure::router::printer::asString())->joinStrings(''));
}


function <<test.Test>> meta::relational::tests::query::routing::multipleexpressions::testPlatformExpressionDependencyOnAFromExpression2():Boolean[1]
{
let f = {names:String[*]|
let upperNames = $names->map(n|$n->toUpper());
meta::relational::tests::model::simple::Person.all()->filter(e|$e.firm.legalName->in($upperNames))->meta::pure::mapping::from(simpleRelationalMapping, meta::external::store::relational::tests::testRuntime());
};

let routingResult = routeFunction($f, ^meta::pure::runtime::ExecutionContext(), meta::relational::extension::relationalExtensions(), noDebug());
assertEquals(1, $routingResult->size());
assertEquals('names:String[*] | {Platform> [strategy_wrapper /let upperNames = $names -> map([Routed Func:n:String[1] | $n -> toUpper();])]};\n {meta::relational::tests::db> [1 meta_relational_tests_model_simple_Person/[1 meta_relational_tests_model_simple_Person/[1 meta_relational_tests_model_simple_Person/Class Person].all()] -> filter([Routed Func:e:meta::relational::tests::model::simple::Person[1] | [2 meta_relational_tests_model_simple_Firm/[2 @firm(meta_relational_tests_model_simple_Person->meta_relational_tests_model_simple_Firm)@ meta_relational_tests_model_simple_Firm/[1 meta_relational_tests_model_simple_Person/$e].firm] -> map([2 meta_relational_tests_model_simple_Firm/[Routed Func:v_automap:meta::relational::tests::model::simple::Firm[1] | [2 @legalName(meta_relational_tests_model_simple_Firm->)@ meta_relational_tests_model_simple_Firm/[2 meta_relational_tests_model_simple_Firm/$v_automap].legalName];]])] -> in($upperNames);])]};', $routingResult->map(f|$f->meta::pure::router::printer::asString())->joinStrings(''));
}


function meta::relational::tests::query::routing::doSomething(a:Integer[1]):String[1]
{
let b = 10;
Expand Down
Loading