Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Route using map rather than fold to prevent state from parameters aff…
Browse files Browse the repository at this point in the history
…ecting the outer state
rafaelbey committed Dec 18, 2024
1 parent d467d9a commit 6dee758
Showing 7 changed files with 104 additions and 101 deletions.
Original file line number Diff line number Diff line change
@@ -14,6 +14,9 @@

package org.finos.legend.engine.plan.dependencies.domain.date;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.eclipse.collections.api.tuple.Pair;
import org.eclipse.collections.impl.block.factory.Comparators;
import org.eclipse.collections.impl.tuple.Tuples;
@@ -40,6 +43,7 @@
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;

@JsonSerialize(using = ToStringSerializer.class)
public class PureDate implements org.finos.legend.pure.m4.coreinstance.primitive.date.PureDate, Serializable
{
private static final long serialVersionUID = 8608696099577042248L;
@@ -1632,6 +1636,7 @@ else if ((second instanceof Float) || (second instanceof Double) || (second inst
* @param string string
* @return Pure date
*/
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public static PureDate parsePureDate(String string)
{
return parsePureDate(string, 0, string.length());
Original file line number Diff line number Diff line change
@@ -29,20 +29,11 @@

public class SetImplTransformers
{
public static final Function<Object, Object> TEMPORARY_DATATYPE_TRANSFORMER = (Function<Object, Object>) o ->
public static final Function<Object, Object> TEMPORARY_DATATYPE_TRANSFORMER = o ->
{
if (o instanceof Timestamp)
{
return DateFunctions.fromSQLTimestamp((Timestamp) o);
}
if (o instanceof java.sql.Date)
{
return StrictDate.fromSQLDate((java.sql.Date) o);
}
if (o instanceof Date)
{
PureDate pureDate = PureDate.fromDate((Date) o);
return pureDate.toString();
return PureDate.fromDate((Date) o);
}
return o;
};
Original file line number Diff line number Diff line change
@@ -94,7 +94,7 @@ function meta::pure::router::clustering::areClustersCompatible(cluster1:Clustere
function meta::pure::router::clustering::isFunctionSupportedByCluster(cluster:ClusteredValueSpecification[1], f:FunctionExpression[1]):Boolean[1]
{
$cluster->match([
sc:StoreMappingClusteredValueSpecification[1] |
sc:StoreClusteredValueSpecification[1] |
$sc.s.supports->toOne()->eval($f->evaluateAndDeactivate()),
ef:ExternalFormatClusteredValueSpecification[1] |
$f->meta::pure::router::externalFormat::clustering::externalFormatSupportsFunction(),

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -338,6 +338,26 @@ function <<access.private>> meta::pure::router::store::routing::wrapValueSpecifi
function meta::pure::router::store::routing::specializedFunctionExpressionRouterProcessorForStore(extensions:meta::pure::extension::Extension[*]):Pair<Function<{FunctionExpression[1]->Boolean[1]}>, Function<{Function<Any>[1], FunctionExpression[1], RoutingState[1], meta::pure::runtime::ExecutionContext[1], Map<VariableExpression, ValueSpecification>[1], Map<String, List<Any>>[1], meta::pure::extension::Extension[*], DebugContext[1]->RoutingState[1]}>>[*]
{
[
pair(fe:FunctionExpression[1] | $fe.func == letFunction_String_1__T_m__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 assigmentRouted = routeValueSpecification(
^$state(value = $fe.parametersValues->at(1)),
$executionContext,
$vars,
$inScopeVars,
$extensions,
$debug
);

let wrappedValueSpec = $assigmentRouted.value->evaluateAndDeactivate()->match([
evs: ExtendedRoutedValueSpecification[1] | $evs,
vs: ValueSpecification[1] | $assigmentRouted.routingStrategy.wrapValueSpec($vs, 'from wrapper', $executionContext, $extensions, $debug)
]);
let processedLet = ^$fe(parametersValues = $fe.parametersValues->at(0)->concatenate($wrappedValueSpec));
^$state(value = $processedLet, routingStrategy = meta::pure::router::platform::routing::getPlatformRoutingStrategy());
}
),
pair(fe:FunctionExpression[1] | $fe.func->in([meta::pure::mapping::from_T_m__Runtime_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,
Original file line number Diff line number Diff line change
@@ -194,7 +194,7 @@ function meta::pure::metamodel::serialization::grammar::printFunctionExpression(
|$main
);
$val->elementToPath() + '.all()';),
pair(|$name == 'letFunction',|'let '+$functionExpression.parametersValues->at(0)->cast(@InstanceValue).values->toOne()->toString()+ ' = ' +$functionExpression.parametersValues->at(0)->printValueSpecification($space)),
pair(|$name == 'letFunction',|'let '+$functionExpression.parametersValues->at(0)->cast(@InstanceValue).values->toOne()->toString()+ ' = ' +$functionExpression.parametersValues->at(1)->printValueSpecification($space)),
pair(|$name == 'colSpec', |'~'+$functionExpression.parametersValues->at(0)->cast(@InstanceValue).values->at(0)->toString()->printColName()),
pair(|$name == 'funcColSpec' || $name == 'funcColSpec2', | '~'+printColSpec($functionExpression, $configuration, $space)),
pair(|$name == 'aggColSpec' || $name == 'aggColSpec2', | '~'+printColSpec($functionExpression, $configuration, $space)),
Original file line number Diff line number Diff line change
@@ -452,38 +452,41 @@ function meta::relational::tests::pct::process::reprocess(a:Any[1], state:Proces
{
$a->match(
[
z:FunctionExpression[1]| if($z.func == new_Class_1__String_1__KeyExpression_MANY__T_1_,
| meta::relational::tests::pct::process::reprocessNew($z->reactivate()->evaluateAndDeactivate(), $z.genericType.rawType->toOne()->cast(@Class<Any>), $state);,
| if (!$z.func->in(
[
meta::pure::functions::relation::funcColSpecArray_FuncColSpec_MANY__P_1__FuncColSpecArray_1_,
meta::pure::functions::relation::funcColSpecArray2_FuncColSpec_MANY__P_1__FuncColSpecArray_1_,
meta::pure::functions::relation::funcColSpec_Function_1__String_1__T_1__FuncColSpec_1_,
meta::pure::functions::relation::funcColSpec2_Function_1__String_1__T_1__FuncColSpec_1_,
meta::pure::functions::relation::aggColSpecArray_AggColSpec_MANY__P_1__AggColSpecArray_1_,
meta::pure::functions::relation::aggColSpecArray2_AggColSpec_MANY__P_1__AggColSpecArray_1_,
meta::pure::functions::relation::aggColSpec_Function_1__Function_1__String_1__T_1__AggColSpec_1_,
meta::pure::functions::relation::aggColSpec2_Function_1__Function_1__String_1__T_1__AggColSpec_1_
]),
| let repro = $z.parametersValues->evaluateAndDeactivate()->map(x|$x->reprocess($state));
^$state
(
current = ^$z(parametersValues = if ($z->cast(@FunctionExpression).func == write_Relation_1__RelationElementAccessor_1__Integer_1_,
| let reproCurrent = $repro.current->cast(@ValueSpecification);
let tds = $reproCurrent->at(1)->cast(@FunctionExpression).parametersValues->at(0);
$reproCurrent->at(0)->concatenate($tds);,
| $repro.current->cast(@ValueSpecification))
)->evaluateAndDeactivate(),
mapping = $repro.mapping->first(),
replaced = $repro.replaced,
csvs = $repro.csvs
);,
| ^$state
(
current = $z
)
)
);,
z:FunctionExpression[1]|
let ifElseIf = [
pair(
|$z.func == new_Class_1__String_1__KeyExpression_MANY__T_1_,
|meta::relational::tests::pct::process::reprocessNew($z->reactivate()->evaluateAndDeactivate(), $z.genericType.rawType->toOne()->cast(@Class<Any>), $state)
),
pair(
|!$z.func->in(
[
meta::pure::functions::relation::funcColSpecArray_FuncColSpec_MANY__P_1__FuncColSpecArray_1_,
meta::pure::functions::relation::funcColSpecArray2_FuncColSpec_MANY__P_1__FuncColSpecArray_1_,
meta::pure::functions::relation::funcColSpec_Function_1__String_1__T_1__FuncColSpec_1_,
meta::pure::functions::relation::funcColSpec2_Function_1__String_1__T_1__FuncColSpec_1_,
meta::pure::functions::relation::aggColSpecArray_AggColSpec_MANY__P_1__AggColSpecArray_1_,
meta::pure::functions::relation::aggColSpecArray2_AggColSpec_MANY__P_1__AggColSpecArray_1_,
meta::pure::functions::relation::aggColSpec_Function_1__Function_1__String_1__T_1__AggColSpec_1_,
meta::pure::functions::relation::aggColSpec2_Function_1__Function_1__String_1__T_1__AggColSpec_1_
]
),
|let repro = $z.parametersValues->evaluateAndDeactivate()->map(x|$x->reprocess($state));
^$state
(
current = ^$z(parametersValues = if ($z->cast(@FunctionExpression).func == write_Relation_1__RelationElementAccessor_1__Integer_1_,
| let reproCurrent = $repro.current->cast(@ValueSpecification);
let tds = $reproCurrent->at(1)->cast(@FunctionExpression).parametersValues->at(0);
$reproCurrent->at(0)->concatenate($tds);,
| $repro.current->cast(@ValueSpecification))
)->evaluateAndDeactivate(),
mapping = $repro.mapping->first(),
replaced = $repro.replaced,
csvs = $repro.csvs
);
)
];
if($ifElseIf, |^$state(current = $z));,
ix:InstanceValue[1]|
let i = $ix->evaluateAndDeactivate();
let type = $i.genericType.rawType->toOne();

0 comments on commit 6dee758

Please sign in to comment.