Search in sources :

Example 1 with FunctionExpressionBuilder

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);
}
Also used : CompositeFunctionExpressionBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.builder.CompositeFunctionExpressionBuilder) RequiredInferenceSimilarSignatureFunctionExpressionBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.builder.RequiredInferenceSimilarSignatureFunctionExpressionBuilder) MultiHandlerFunctionExpressionBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.builder.MultiHandlerFunctionExpressionBuilder) FunctionExpressionBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.builder.FunctionExpressionBuilder) MultiHandlerFunctionExpressionBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.builder.MultiHandlerFunctionExpressionBuilder)

Example 2 with FunctionExpressionBuilder

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);
            }
    }
}
Also used : LogInfo(org.finos.legend.engine.shared.core.operational.logs.LogInfo) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) FunctionExpressionBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.builder.FunctionExpressionBuilder)

Example 3 with FunctionExpressionBuilder

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);
    }
}
Also used : CompositeFunctionExpressionBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.builder.CompositeFunctionExpressionBuilder) RequiredInferenceSimilarSignatureFunctionExpressionBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.builder.RequiredInferenceSimilarSignatureFunctionExpressionBuilder) MultiHandlerFunctionExpressionBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.builder.MultiHandlerFunctionExpressionBuilder) FunctionExpressionBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.builder.FunctionExpressionBuilder)

Example 4 with FunctionExpressionBuilder

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);
    }
}
Also used : CompositeFunctionExpressionBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.builder.CompositeFunctionExpressionBuilder) RequiredInferenceSimilarSignatureFunctionExpressionBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.builder.RequiredInferenceSimilarSignatureFunctionExpressionBuilder) MultiHandlerFunctionExpressionBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.builder.MultiHandlerFunctionExpressionBuilder) FunctionExpressionBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.builder.FunctionExpressionBuilder)

Aggregations

FunctionExpressionBuilder (org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.builder.FunctionExpressionBuilder)4 CompositeFunctionExpressionBuilder (org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.builder.CompositeFunctionExpressionBuilder)3 MultiHandlerFunctionExpressionBuilder (org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.builder.MultiHandlerFunctionExpressionBuilder)3 RequiredInferenceSimilarSignatureFunctionExpressionBuilder (org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.builder.RequiredInferenceSimilarSignatureFunctionExpressionBuilder)3 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)1 LogInfo (org.finos.legend.engine.shared.core.operational.logs.LogInfo)1