forked from finos/legend-engine
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
346 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...e-code-compiled-core/src/main/resources/core/pure/executionPlan/executionPlanFeature.pure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright 2023 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::executionPlan::*; | ||
import meta::pure::runtime::*; | ||
import meta::pure::router::routing::*; | ||
import meta::pure::extension::*; | ||
import meta::pure::executionPlan::featureFlag::*; | ||
|
||
|
||
Enum meta::pure::executionPlan::features::Feature | ||
{ | ||
PUSH_DOWN_ENUM_TRANSFORM | ||
} | ||
|
||
function meta::pure::executionPlan::featureFlag::withFeatureFlags<T>(object:T[*],e:Enum[*]):T[*] | ||
{ | ||
$object; | ||
} | ||
|
||
Class meta::pure::executionPlan::featureFlag::FeatureFlagOption extends meta::pure::executionPlan::ExecutionOption | ||
{ | ||
flags:Enum[*]; | ||
} | ||
|
||
|
||
function meta::pure::executionPlan::featureFlag::contextHasFlag(context:ExecutionContext[1],flag:Enum[1]) : Boolean[1] | ||
{ | ||
$context ->getContexts()->filter(c|$c->instanceOf(ExecutionOptionContext))->cast(@ExecutionOptionContext)->map(c| $c.executionOptions->filter(f| $f->instanceOf(FeatureFlagOption))->cast(@FeatureFlagOption).flags)->contains($flag); | ||
} | ||
|
||
function meta::pure::executionPlan::featureFlag::addFlagToContext(context:ExecutionContext[1],flag:Enum[*]) : ExecutionContext[1] | ||
{ | ||
let flagOption =^FeatureFlagOption(flags = $flag); | ||
if($context->instanceOf(ExecutionOptionContext), | ||
|let optionContext = $context->cast(@ExecutionOptionContext); | ||
^$optionContext(executionOptions += $flagOption);, | ||
| let option = ^ExecutionOptionContext(executionOptions=$flagOption); | ||
$context->meta::pure::executionPlan::mergeContext($option); | ||
); | ||
} | ||
|
||
|
||
function meta::pure::executionPlan::featureFlag::wrapFnWithFeatureFlag<T>(function:Function<T>[1],flags:Enum[*]) : Function<T>[1] | ||
{ | ||
$function; | ||
} | ||
|
||
|
||
|
||
|
||
function meta::pure::executionPlan::featureFlag::ExecutionPlanFeatureFlagExtension() : Extension[1] | ||
{ | ||
let shared = ^Extension( | ||
type = 'featureFlag', | ||
availableFeatures = ^FeatureExtension | ||
( | ||
id = 'featureFlag', | ||
routeFunctionExpressions = [ | ||
pair( | ||
fe:FunctionExpression[1] | $fe.func == meta::pure::executionPlan::featureFlag::withFeatureFlags_T_MANY__Enum_MANY__T_MANY_, | ||
{f:Function<Any>[1], fe:FunctionExpression[1], state:RoutingState[1], executionContext:ExecutionContext[1], vars:Map<VariableExpression, ValueSpecification>[1], inScopeVars:Map<String, List<Any>>[1], extensions:meta::pure::extension::Extension[*], debug:DebugContext[1] | | ||
|
||
let flags = $fe.parametersValues->at(1)->match([ s: SimpleFunctionExpression[1] | $s->at(0)->cast(@SimpleFunctionExpression)->reactivate()->cast(@Enum);, | ||
i :InstanceValue[*] | $i.values->map(v|$v->cast(@SimpleFunctionExpression)->reactivate()->cast(@Enum));, | ||
a :Any[*] | fail('Found unsupported feature flag Specification, Parameters are not supported for feature flags'); @Enum; | ||
]); | ||
|
||
|
||
let updatedContext =meta::pure::executionPlan::featureFlag::addFlagToContext($executionContext,$flags); | ||
routeFunctionExpressionFunctionDefinition($f, $fe, ^$state(executionContext=$updatedContext), $updatedContext, $vars, $inScopeVars, $extensions, $debug); | ||
} | ||
)] | ||
) | ||
|
||
|
||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...ed-core/src/main/resources/core/pure/executionPlan/test/testExecutionPlanFeatureFlag.pure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import meta::pure::router::platform::metamodel::*; | ||
import meta::pure::executionPlan::*; | ||
import meta::pure::graphFetch::execution::*; | ||
import meta::pure::functions::tests::model::*; | ||
import meta::pure::router::platform::metamodel::clustering::*; | ||
import meta::pure::executionPlan::featureFlag::*; | ||
|
||
Enum meta::pure::executionPlan::tests::ExampleFlag | ||
{ | ||
myFlag | ||
|
||
} | ||
Enum meta::pure::executionPlan::tests::ExampleFlag2 | ||
{ | ||
AnotherFlag | ||
|
||
} | ||
|
||
|
||
Class meta::pure::executionPlan::tests::featureFlag::Person | ||
{ | ||
|
||
} | ||
|
||
function <<test.Test>> meta::pure::executionPlan::tests::featureFlag::testTwoFeatureFlags() : Boolean[1] | ||
{ | ||
let gft = #{Person{firstName}}#; | ||
let fn = {|meta::pure::executionPlan::tests::featureFlag::Person.all()->graphFetch($gft)->withFeatureFlags([meta::pure::executionPlan::tests::ExampleFlag.myFlag ,meta::pure::executionPlan::tests::ExampleFlag2.AnotherFlag ])}; | ||
let result = meta::pure::router::routeFunction($fn,meta::pure::executionPlan::featureFlag::ExecutionPlanFeatureFlagExtension()); | ||
let context =$result.expressionSequence->evaluateAndDeactivate()->cast(@PlatformClusteredValueSpecification).val->cast(@PlatformRoutedValueSpecification).executionContext->toOne(); | ||
|
||
assert( $context ->contextHasFlag(meta::pure::executionPlan::tests::ExampleFlag.myFlag)); | ||
assert( $context ->contextHasFlag(meta::pure::executionPlan::tests::ExampleFlag2.AnotherFlag)); | ||
} | ||
|
||
function <<test.Test>> meta::pure::executionPlan::tests::featureFlag::testTwoFlagFunctions() : Boolean[1] | ||
{ | ||
let gft = #{Person{firstName}}#; | ||
let fn = {|meta::pure::executionPlan::tests::featureFlag::Person.all()->withFeatureFlags([meta::pure::executionPlan::tests::ExampleFlag.myFlag ])->graphFetch($gft)->serialize($gft)->withFeatureFlags([meta::pure::executionPlan::tests::ExampleFlag2.AnotherFlag ])}; | ||
let result = meta::pure::router::routeFunction($fn ,meta::pure::executionPlan::featureFlag::ExecutionPlanFeatureFlagExtension()); | ||
let context =$result.expressionSequence->evaluateAndDeactivate()->cast(@PlatformClusteredValueSpecification).val->cast(@PlatformRoutedValueSpecification).executionContext->toOne(); | ||
assert( $context ->contextHasFlag(meta::pure::executionPlan::tests::ExampleFlag.myFlag)); | ||
assert( $context ->contextHasFlag(meta::pure::executionPlan::tests::ExampleFlag2.AnotherFlag)); | ||
|
||
} | ||
|
||
function <<test.Test>> meta::pure::executionPlan::tests::featureFlag::testContextHasFlag() : Boolean[1] | ||
{ | ||
let context1= ^ExecutionOptionContext(executionOptions=^FeatureFlagOption(flags=meta::pure::executionPlan::tests::ExampleFlag.myFlag)); | ||
assert( $context1 ->contextHasFlag(meta::pure::executionPlan::tests::ExampleFlag.myFlag)); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.