use of org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.builder.FunctionExpressionBuilder in project legend-engine by finos.
the class Handlers method register.
public void register(UserDefinedFunctionHandler handler) {
String functionName = handler.getFunctionName();
boolean functionRegisteredByName = isFunctionRegisteredByName(handler);
if (!functionRegisteredByName) {
map.put(functionName, new MultiHandlerFunctionExpressionBuilder(this.pureModel, handler));
} else {
Assert.assertFalse(isFunctionRegisteredBySignature(handler, functionRegisteredByName), () -> "Function '" + handler.getFunctionSignature() + "' is already registered");
FunctionExpressionBuilder builder = map.get(functionName);
if (builder.supportFunctionHandler(handler)) {
builder.addFunctionHandler(handler);
} else {
this.addFunctionHandler(handler, builder);
}
}
map.get(functionName).handlers().forEach(this::mayReplace);
}
use of org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.builder.FunctionExpressionBuilder in project legend-engine by finos.
the class CompileContext method resolveFunctionBuilder.
public FunctionExpressionBuilder resolveFunctionBuilder(String functionName, Set<String> metaPackages, Map<String, FunctionExpressionBuilder> functionHandlerMap, SourceInformation sourceInformation, ProcessingContext processingContext) {
// First do an optimistic check in the current handler to see if the function we are finding is available
// so we don't waste time going through all of the auto-imports
String extractedFunctionName = extractMetaFunctionName(functionName, metaPackages);
if (functionHandlerMap.containsKey(extractedFunctionName)) {
return functionHandlerMap.get(extractedFunctionName);
}
MutableMap<String, FunctionExpressionBuilder> results = searchImports(extractedFunctionName, functionHandlerMap::get);
switch(results.size()) {
case 0:
{
// Since we have tried to find basic function initially, this means the function builder is not found, we report error
String message = "Can't resolve the builder for function '" + functionName + "' - stack:" + processingContext.getStack();
LOGGER.error(new LogInfo(null, LoggingEventType.GRAPH_MISSING_FUNCTION, message).toString());
throw new EngineException(message, sourceInformation, EngineErrorType.COMPILATION);
}
case 1:
{
return results.valuesView().getAny();
}
default:
{
throw new EngineException(results.keysView().makeString("Can't resolve the builder for function '" + functionName + "' - multiple matches found [", ", ", "]"), sourceInformation, EngineErrorType.COMPILATION);
}
}
}
use of org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.builder.FunctionExpressionBuilder in project legend-engine by finos.
the class Handlers method register.
private void register(FunctionHandlerRegistrationInfo info) {
if (info.coordinates == null || info.coordinates.isEmpty()) {
register(info.functionHandler);
} else {
FunctionExpressionBuilder functionExpressionBuilder = Objects.requireNonNull(this.map.get(info.functionHandler.getFunctionName()), "Can't find expression builder for function '" + info.functionHandler.getFunctionName() + "'");
for (int i = 0; i < info.coordinates.size() - 1; ++i) {
functionExpressionBuilder = functionExpressionBuilder.getFunctionExpressionBuilderAtIndex(info.coordinates.get(i));
}
functionExpressionBuilder.insertFunctionHandlerAtIndex(info.coordinates.get(info.coordinates.size() - 1), info.functionHandler);
}
}
use of org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.builder.FunctionExpressionBuilder in project legend-engine by finos.
the class Handlers method register.
private void register(FunctionExpressionBuilderRegistrationInfo info) {
if (info.coordinates == null || info.coordinates.isEmpty()) {
register(info.functionExpressionBuilder);
} else {
FunctionExpressionBuilder functionExpressionBuilder = Objects.requireNonNull(this.map.get(info.functionExpressionBuilder.getFunctionName()), "Can't find expression builder for function '" + info.functionExpressionBuilder.getFunctionName() + "'");
for (int i = 0; i < info.coordinates.size() - 1; ++i) {
functionExpressionBuilder = functionExpressionBuilder.getFunctionExpressionBuilderAtIndex(info.coordinates.get(i));
}
functionExpressionBuilder.insertFunctionExpressionBuilderAtIndex(info.coordinates.get(info.coordinates.size() - 1), info.functionExpressionBuilder);
}
}
Aggregations