generated from finos/software-project-blueprint
-
Notifications
You must be signed in to change notification settings - Fork 237
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
Support functions with complex parameters #3356
Open
hbalasu2
wants to merge
7
commits into
finos:master
Choose a base branch
from
goldmansachs:review-functionsWithComplexParameters
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8ad47cc
Fix Routing for Complex Object Function Parameters
hbalasu2 a5efda2
Fix Functions with complex parameter routing
hbalasu2 cf4c2d7
Fix Functions with complex parameter routing
hbalasu2 2661ccb
Fix dependencies
hbalasu2 d9680f2
Fix dependencies and Add tests for collection - generation and - exec…
hbalasu2 59998b9
Test Fixes for Functions with Complex parameters
hbalasu2 2d3ebf3
Test Fixes for Functions with Complex parameters
hbalasu2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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 |
---|---|---|
|
@@ -14,13 +14,20 @@ | |
|
||
package org.finos.legend.engine.plan.execution.validation; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.eclipse.collections.api.RichIterable; | ||
import org.finos.legend.engine.plan.execution.nodes.helpers.platform.ExecutionPlanJavaCompilerExtension; | ||
import org.finos.legend.engine.plan.execution.nodes.helpers.platform.ExecutionPlanJavaCompilerExtensionLoader; | ||
import org.finos.legend.engine.plan.execution.nodes.state.ExecutionState; | ||
import org.finos.legend.engine.plan.execution.result.ConstantResult; | ||
import org.finos.legend.engine.plan.execution.result.Result; | ||
import org.finos.legend.engine.plan.execution.result.date.EngineDate; | ||
import org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ParameterValidationContext; | ||
import org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ProtocolObjectValidationContext; | ||
import org.finos.legend.engine.protocol.pure.v1.model.type.PackageableType; | ||
import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable; | ||
import org.finos.legend.engine.shared.core.ObjectMapperFactory; | ||
|
||
import java.math.BigDecimal; | ||
import java.time.Instant; | ||
|
@@ -29,22 +36,30 @@ | |
import java.time.ZonedDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.function.Function; | ||
|
||
class FunctionParametersNormalizer | ||
{ | ||
static void normalizeParameters(RichIterable<Variable> functionParameters, ExecutionState executionState) | ||
static void normalizeParameters(RichIterable<Variable> functionParameters,List<ParameterValidationContext> parameterValidationContexts, ExecutionState executionState) | ||
{ | ||
functionParameters.forEach(p -> normalizeParameter(p, executionState)); | ||
if (parameterValidationContexts == null) | ||
{ | ||
functionParameters.forEach(p -> normalizeParameter(p, null, executionState)); | ||
} | ||
else | ||
{ | ||
functionParameters.forEach(p -> normalizeParameter(p, parameterValidationContexts.stream().filter(x -> x.varName.equals(p.name)).findAny().orElse(null), executionState)); | ||
} | ||
} | ||
|
||
private static void normalizeParameter(Variable parameter, ExecutionState executionState) | ||
private static void normalizeParameter(Variable parameter, ParameterValidationContext parameterValidationContext, ExecutionState executionState) | ||
{ | ||
Result paramResult = executionState.getResult(parameter.name); | ||
if (paramResult instanceof ConstantResult) | ||
{ | ||
Object paramValue = ((ConstantResult) paramResult).getValue(); | ||
Object normalized = normalizeParameterValue(parameter, paramValue); | ||
Object normalized = normalizeParameterValue(parameter, parameterValidationContext, paramValue); | ||
if (normalized != paramValue) | ||
{ | ||
ConstantResult updatedDateTime = new ConstantResult(normalized); | ||
|
@@ -53,7 +68,7 @@ private static void normalizeParameter(Variable parameter, ExecutionState execut | |
} | ||
} | ||
|
||
public static Object normalizeParameterValue(Variable parameter, Object paramValue) | ||
public static Object normalizeParameterValue(Variable parameter, ParameterValidationContext parameterValidationContext, Object paramValue) | ||
{ | ||
if (paramValue == null) | ||
{ | ||
|
@@ -91,11 +106,47 @@ public static Object normalizeParameterValue(Variable parameter, Object paramVal | |
} | ||
default: | ||
{ | ||
if (parameterValidationContext instanceof ProtocolObjectValidationContext) | ||
{ | ||
return normalizeParameterValue(paramValue, x -> normalizeProtocolObjectParameterValue((ProtocolObjectValidationContext) parameterValidationContext, x)); | ||
} | ||
return paramValue; | ||
} | ||
} | ||
} | ||
|
||
private static Object normalizeProtocolObjectParameterValue(ProtocolObjectValidationContext parameterValidationContext, Object paramValue) | ||
{ | ||
String protocolObjectClassName = parameterValidationContext.protocolClassName; | ||
try | ||
{ | ||
Class<?> protocolObjectClass = ExecutionPlanJavaCompilerExtensionLoader.extensions().stream() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Class.forName(protocolObjectClassName) |
||
.map(ExecutionPlanJavaCompilerExtension::dependencies) | ||
.map(map -> map.get(protocolObjectClassName)) | ||
.filter(Objects::nonNull) | ||
.findAny() | ||
.orElseThrow(() -> new IllegalArgumentException("Function Parameter class not found in package dependencies for class:." + protocolObjectClassName)); | ||
|
||
if (protocolObjectClass.isInstance(paramValue)) | ||
{ | ||
return paramValue; | ||
} | ||
else if (paramValue instanceof String) | ||
{ | ||
ObjectMapper objectMapper = ObjectMapperFactory.getNewStandardObjectMapperWithPureProtocolExtensionSupports(); | ||
return objectMapper.readValue((String) paramValue, protocolObjectClass); | ||
} | ||
else | ||
{ | ||
throw new IllegalArgumentException("Function Parameter should be of type JSON String or " + protocolObjectClass.getName()); | ||
} | ||
} | ||
catch (JsonProcessingException e) | ||
{ | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private static Object normalizeParameterValue(Object value, Function<Object, ?> normalizer) | ||
{ | ||
if (value == null) | ||
|
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
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
26 changes: 26 additions & 0 deletions
26
...nd/engine/protocol/pure/v1/model/executionPlan/nodes/ProtocolObjectValidationContext.java
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,26 @@ | ||
// Copyright 2025 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. | ||
|
||
package org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes; | ||
|
||
public class ProtocolObjectValidationContext extends ParameterValidationContext | ||
{ | ||
public String protocolClassName; | ||
|
||
@Override | ||
public <T> T accept(ParameterValidationContextVisitor<T> validationContextVisitor) | ||
{ | ||
return validationContextVisitor.visit(this); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -192,6 +192,11 @@ Class meta::pure::executionPlan::EnumValidationContext extends ParameterValidati | |
validEnumValues: String[*]; | ||
} | ||
|
||
Class meta::pure::executionPlan::ProtocolObjectValidationContext extends ParameterValidationContext | ||
{ | ||
protocolClassName: String[1]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. parameterClass: Class[1]; |
||
} | ||
|
||
Class meta::pure::executionPlan::FunctionParameter | ||
{ | ||
name : String[1]; | ||
|
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed