use of org.finos.legend.engine.plan.execution.PlanExecutor in project legend-engine by finos.
the class TestStreamInput method testExecutionPlanWithStreamInput.
@Test
public void testExecutionPlanWithStreamInput() {
String plan = "{\"serializer\":{\"name\":\"pure\",\"version\":\"vX_X_X\"},\"templateFunctions\":[\"<#function renderCollection collection separator><#return collection?join(separator)><\\/#function>\",\"<#function collectionSize collection> <#return collection?size> <\\/#function>\"],\"rootExecutionNode\":{\"_type\":\"relationalBlock\",\"resultType\":{\"tdsColumns\":[{\"name\":\"name\",\"type\":\"String\",\"relationalType\":\"VARCHAR(1000)\"}],\"_type\":\"tds\"},\"executionNodes\":[{\"functionParameters\":[{\"name\":\"id\",\"supportsStream\":false,\"multiplicity\":{\"lowerBound\":0},\"class\":\"String\",\"_type\":\"var\"},{\"name\":\"name\",\"supportsStream\":true,\"multiplicity\":{\"lowerBound\":0},\"class\":\"String\",\"_type\":\"var\"}],\"_type\":\"function-parameters-validation\",\"resultType\":{\"dataType\":\"Boolean\",\"_type\":\"dataType\"}},{\"varName\":\"inFilterClause_name\",\"_type\":\"allocation\",\"resultType\":{\"dataType\":\"String\",\"_type\":\"dataType\"},\"executionNodes\":[{\"freeMarkerBooleanExpression\":\"${(instanceOf(name, \\\"Stream\\\") || ((collectionSize(name)) > 50))?c}\",\"trueBlock\":{\"_type\":\"sequence\",\"resultType\":{\"dataType\":\"String\",\"_type\":\"dataType\"},\"executionNodes\":[{\"inputVarNames\":[\"name\"],\"tempTableName\":\"tempTableForIn_name\",\"tempTableColumnMetaData\":[{\"column\":{\"label\":\"ColumnForStoringInCollection\",\"dataType\":\"VARCHAR(200)\"}}],\"connection\": {\"_type\": \"RelationalDatabaseConnection\",\"type\": \"H2\",\"authenticationStrategy\" : {\"_type\" : \"test\"},\"datasourceSpecification\" : {\"_type\" : \"h2Local\"}},\"_type\":\"createAndPopulateTempTable\",\"resultType\":{\"_type\":\"void\"},\"implementation\":{\"executionClassFullName\":\"com.alloy.plan.root.n2.n1.trueBlock.n1.CreateAndPopulateTempTable\",\"_type\":\"java\"}},{\"values\":{\"values\":[\"select \\\"temptableforin_name_0\\\".ColumnForStoringInCollection as ColumnForStoringInCollection from tempTableForIn_name as \\\"temptableforin_name_0\\\"\"],\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"_type\":\"string\"},\"_type\":\"constant\",\"resultType\":{\"dataType\":\"String\",\"_type\":\"dataType\"}}]},\"falseBlock\":{\"values\":{\"values\":[\"'${renderCollection(name \\\"','\\\")}'\"],\"multiplicity\":{\"lowerBound\":1,\"upperBound\":1},\"_type\":\"string\"},\"_type\":\"constant\",\"resultType\":{\"dataType\":\"String\",\"_type\":\"dataType\"}},\"_type\":\"freeMarkerConditionalExecutionNode\",\"resultType\":{\"dataType\":\"String\",\"_type\":\"dataType\"}}]},{\"_type\":\"relationalTdsInstantiation\",\"resultType\":{\"tdsColumns\":[{\"name\":\"name\",\"type\":\"String\",\"relationalType\":\"VARCHAR(1000)\"}],\"_type\":\"tds\"},\"executionNodes\":[{\"sqlQuery\":\"select \\\"root\\\".name as \\\"name\\\" from employeeTable as \\\"root\\\" where (\\\"root\\\".name in (${inFilterClause_name}) or (${collectionSize(id)}) = 0)\",\"resultColumns\":[{\"label\":\"\\\"name\\\"\",\"dataType\":\"VARCHAR(1000)\"}],\"connection\": {\"_type\": \"RelationalDatabaseConnection\",\"type\": \"H2\",\"authenticationStrategy\" : {\"_type\" : \"test\"},\"datasourceSpecification\" : {\"_type\" : \"h2Local\"}},\"_type\":\"sql\",\"resultType\":{\"dataType\":\"meta::pure::metamodel::type::Any\",\"_type\":\"dataType\"}}]}]},\"authDependent\":false,\"globalImplementationSupport\":{\"classes\":[{\"package\":\"com.alloy.plan.root.n2.n1.trueBlock.n1\",\"name\":\"CreateAndPopulateTempTable\",\"source\":\"package com.alloy.plan.root.n2.n1.trueBlock.n1;\\n\\nimport org.finos.legend.engine.plan.dependencies.store.relational.IRelationalCreateAndPopulateTempTableExecutionNodeSpecifics;\\nimport org.finos.legend.engine.plan.dependencies.util.Library;\\nimport java.util.Arrays;\\nimport java.util.List;\\nimport java.util.Optional;\\nimport java.util.stream.Collector;\\nimport java.util.stream.Collectors;\\nimport java.util.stream.Stream;\\n\\npublic class CreateAndPopulateTempTable implements IRelationalCreateAndPopulateTempTableExecutionNodeSpecifics {\\n\\n public String getGetterNameForProperty(String p) {\\n return p == null ? null : Arrays.asList(\\\"get\\\", Library.toOne(Optional.ofNullable(p).map(Stream::of).orElseGet(Stream::empty).map(Library::toUpperFirstCharacter).collect(Collectors.toList()))).stream().collect(Collectors.joining(\\\"\\\"));\\n }\\n}\\n\"}],\"_type\":\"java\"}}";
PlanExecutor planExecutor = buildRelationalPlanExecutor();
Map<String, ?> allInputsAsList = Maps.mutable.with("name", Lists.mutable.with("Alice", "Bob", "Curtis"), "id", Lists.mutable.with("A", "B", "C"));
RelationalResult resultWithLists = (RelationalResult) planExecutor.execute(plan, allInputsAsList);
Assert.assertEquals("{\"builder\": {\"_type\":\"tdsBuilder\",\"columns\":[{\"name\":\"name\",\"type\":\"String\",\"relationalType\":\"VARCHAR(1000)\"}]}, \"activities\": [{\"_type\":\"relational\",\"sql\":\"select \\\"root\\\".name as \\\"name\\\" from employeeTable as \\\"root\\\" where (\\\"root\\\".name in ('Alice','Bob','Curtis') or (3) = 0)\"}], \"result\" : {\"columns\" : [\"name\"], \"rows\" : [{\"values\": [\"Alice\"]},{\"values\": [\"Bob\"]},{\"values\": [\"Curtis\"]}]}}", resultWithLists.flush(new RelationalResultToJsonDefaultSerializer(resultWithLists)));
Map<String, ?> allInputsAsStream = Maps.mutable.with("name", Lists.mutable.with("Alice", "Bob", "Curtis").stream(), "id", Lists.mutable.with("A", "B", "C").stream());
RelationalResult resultWithStreams = (RelationalResult) planExecutor.execute(plan, allInputsAsStream);
Assert.assertEquals("{\"builder\": {\"_type\":\"tdsBuilder\",\"columns\":[{\"name\":\"name\",\"type\":\"String\",\"relationalType\":\"VARCHAR(1000)\"}]}, \"activities\": [{\"_type\":\"relational\",\"sql\":\"select \\\"root\\\".name as \\\"name\\\" from employeeTable as \\\"root\\\" where (\\\"root\\\".name in (select \\\"temptableforin_name_0\\\".ColumnForStoringInCollection as ColumnForStoringInCollection from tempTableForIn_name as \\\"temptableforin_name_0\\\") or (3) = 0)\"}], \"result\" : {\"columns\" : [\"name\"], \"rows\" : [{\"values\": [\"Alice\"]},{\"values\": [\"Bob\"]},{\"values\": [\"Curtis\"]}]}}", resultWithStreams.flush(new RelationalResultToJsonDefaultSerializer(resultWithStreams)));
Map<String, ?> inputsAsListAndStream1 = Maps.mutable.with("name", Lists.mutable.with("Alice", "Bob", "Curtis").stream(), "id", Lists.mutable.with("A", "B", "C"));
RelationalResult resultWithListAndStream1 = (RelationalResult) planExecutor.execute(plan, inputsAsListAndStream1);
Assert.assertEquals("{\"builder\": {\"_type\":\"tdsBuilder\",\"columns\":[{\"name\":\"name\",\"type\":\"String\",\"relationalType\":\"VARCHAR(1000)\"}]}, \"activities\": [{\"_type\":\"relational\",\"sql\":\"select \\\"root\\\".name as \\\"name\\\" from employeeTable as \\\"root\\\" where (\\\"root\\\".name in (select \\\"temptableforin_name_0\\\".ColumnForStoringInCollection as ColumnForStoringInCollection from tempTableForIn_name as \\\"temptableforin_name_0\\\") or (3) = 0)\"}], \"result\" : {\"columns\" : [\"name\"], \"rows\" : [{\"values\": [\"Alice\"]},{\"values\": [\"Bob\"]},{\"values\": [\"Curtis\"]}]}}", resultWithListAndStream1.flush(new RelationalResultToJsonDefaultSerializer(resultWithListAndStream1)));
Map<String, ?> inputsAsListAndStream2 = Maps.mutable.with("name", Lists.mutable.with("Alice", "Bob", "Curtis"), "id", Lists.mutable.with("A", "B", "C").stream());
RelationalResult resultWithListAndStream2 = (RelationalResult) planExecutor.execute(plan, inputsAsListAndStream2);
Assert.assertEquals("{\"builder\": {\"_type\":\"tdsBuilder\",\"columns\":[{\"name\":\"name\",\"type\":\"String\",\"relationalType\":\"VARCHAR(1000)\"}]}, \"activities\": [{\"_type\":\"relational\",\"sql\":\"select \\\"root\\\".name as \\\"name\\\" from employeeTable as \\\"root\\\" where (\\\"root\\\".name in ('Alice','Bob','Curtis') or (3) = 0)\"}], \"result\" : {\"columns\" : [\"name\"], \"rows\" : [{\"values\": [\"Alice\"]},{\"values\": [\"Bob\"]},{\"values\": [\"Curtis\"]}]}}", resultWithListAndStream2.flush(new RelationalResultToJsonDefaultSerializer(resultWithListAndStream2)));
}
use of org.finos.legend.engine.plan.execution.PlanExecutor in project legend-engine by finos.
the class TestM2MGrammarCompileAndExecute method runTest.
private Response runTest(ExecuteInput input) {
ModelManager modelManager = new ModelManager(DeploymentMode.TEST);
PlanExecutor executor = PlanExecutor.newPlanExecutor(InMemory.build());
HttpServletRequest request = (HttpServletRequest) Proxy.newProxyInstance(getClass().getClassLoader(), new java.lang.Class<?>[] { HttpServletRequest.class }, new ReflectiveInvocationHandler(new Request()));
// Should use: core_pure_extensions_extension.Root_meta_pure_router_extension_defaultExtensions__RouterExtension_MANY_(modelManager.)
Response result = new Execute(modelManager, executor, (PureModel pureModel) -> Lists.mutable.empty(), LegendPlanTransformers.transformers).execute(request, input, SerializationFormat.defaultFormat, null, null);
Assert.assertEquals(200, result.getStatus());
return result;
}
use of org.finos.legend.engine.plan.execution.PlanExecutor in project legend-engine by finos.
the class Server method run.
@Override
public void run(ServerConfiguration serverConfiguration, Environment environment) {
loadVaults(serverConfiguration.vaults);
this.environment = environment;
DeploymentStateAndVersions.DEPLOYMENT_MODE = serverConfiguration.deployment.mode;
SDLCLoader sdlcLoader = new SDLCLoader(serverConfiguration.metadataserver, null);
ModelManager modelManager = new ModelManager(serverConfiguration.deployment.mode, sdlcLoader);
ChainFixingFilterHandler.apply(environment.getApplicationContext(), serverConfiguration.filterPriorities);
RelationalStoreExecutor relationalStoreExecutor = (RelationalStoreExecutor) Relational.build(serverConfiguration.relationalexecution);
PlanExecutor planExecutor = PlanExecutor.newPlanExecutor(relationalStoreExecutor, ServiceStore.build(), InMemory.build());
// Session Management
SessionTracker sessionTracker = new SessionTracker();
environment.servlets().setSessionHandler(new SessionHandler());
environment.servlets().addServletListeners(sessionTracker);
environment.jersey().register(new SessionInfo(sessionTracker));
// API & Swagger
environment.jersey().setUrlPattern("/api/*");
ServerShared.registerSwagger(environment, serverConfiguration.swagger);
// Server
environment.jersey().register(new Info(serverConfiguration.deployment, serverConfiguration.opentracing));
environment.jersey().register(new CurrentUser());
environment.jersey().register(new Memory());
environment.jersey().register(new RelationalExecutorInformation());
// Grammar
environment.jersey().register(new GrammarToJson());
environment.jersey().register(new JsonToGrammar());
environment.jersey().register(new RelationalOperationElementGrammarToJson());
environment.jersey().register(new RelationalOperationElementJsonToGrammar());
environment.jersey().register(new TransformGrammarToJson());
environment.jersey().register(new TransformJsonToGrammar());
environment.jersey().register(new TransformRelationalOperationElementGrammarToJson());
environment.jersey().register(new TransformRelationalOperationElementJsonToGrammar());
// Relational
environment.jersey().register(new SchemaExplorationApi(modelManager, relationalStoreExecutor));
// Compilation
environment.jersey().register((DynamicFeature) (resourceInfo, context) -> context.register(new InflateInterceptor()));
environment.jersey().register(new Compile(modelManager));
// Generation and Import
MutableList<GenerationExtension> genExtensions = Iterate.addAllTo(ServiceLoader.load(GenerationExtension.class), Lists.mutable.empty());
environment.jersey().register(new CodeGenerators(modelManager, genExtensions.select(p -> p.getMode() == GenerationMode.Code).collect(GenerationExtension::getGenerationDescription).select(Objects::nonNull)));
environment.jersey().register(new CodeImports(modelManager, genExtensions.select(p -> p.getMode() == GenerationMode.Code).collect(GenerationExtension::getImportDescription).select(Objects::nonNull)));
environment.jersey().register(new SchemaGenerators(modelManager, genExtensions.select(p -> p.getMode() == GenerationMode.Schema).collect(GenerationExtension::getGenerationDescription).select(Objects::nonNull)));
environment.jersey().register(new SchemaImports(modelManager, genExtensions.select(p -> p.getMode() == GenerationMode.Schema).collect(GenerationExtension::getImportDescription).select(Objects::nonNull)));
genExtensions.forEach(p -> environment.jersey().register(p.getService(modelManager)));
// Execution
MutableList<PlanGeneratorExtension> generatorExtensions = Lists.mutable.withAll(ServiceLoader.load(PlanGeneratorExtension.class));
Function<PureModel, RichIterable<? extends Root_meta_pure_router_extension_RouterExtension>> routerExtensions = (PureModel pureModel) -> generatorExtensions.flatCollect(e -> e.getExtraRouterExtensions(pureModel));
environment.jersey().register(new Execute(modelManager, planExecutor, routerExtensions, generatorExtensions.flatCollect(PlanGeneratorExtension::getExtraPlanTransformers)));
environment.jersey().register(new ExecutePlanStrategic(planExecutor));
environment.jersey().register(new ExecutePlanLegacy(planExecutor));
// GraphQL
environment.jersey().register(new GraphQLGrammar());
environment.jersey().register(new GraphQLExecute(modelManager, planExecutor, serverConfiguration.metadataserver, generatorExtensions.flatCollect(PlanGeneratorExtension::getExtraPlanTransformers)));
environment.jersey().register(new GraphQLDebug(modelManager, serverConfiguration.metadataserver));
// Service
environment.jersey().register(new ServiceModelingApi(modelManager, serverConfiguration.deployment.mode));
// Query
environment.jersey().register(new ApplicationQuery(ApplicationQueryConfiguration.getMongoClient()));
// Global
environment.jersey().register(new JsonInformationExceptionMapper());
environment.jersey().register(new CatchAllExceptionMapper());
// External Format
environment.jersey().register(new ExternalFormats(modelManager));
enableCors(environment);
}
use of org.finos.legend.engine.plan.execution.PlanExecutor in project legend-engine by finos.
the class TestPlanExecutor method testPlanExecutorConstructionWithNoConfig.
@Test
public void testPlanExecutorConstructionWithNoConfig() {
// assert that we construct a plan executor with all known store executors even when no configuration is supplied
PlanExecutor planExecutor = PlanExecutor.newPlanExecutorWithConfigurations();
ImmutableList<StoreExecutor> extraExecutors = planExecutor.getExtraExecutors();
StoreExecutor relationalExecutor = extraExecutors.detect(storeExecutor -> storeExecutor instanceof FakeRelationalStoreExecutorBuilder.Executor);
assertNotNull("failed to locate relational executor", relationalExecutor);
StoreExecutor serviceStoreExecutor = extraExecutors.detect(storeExecutor -> storeExecutor instanceof FakeServiceStoreExecutorBuilder.Executor);
assertNotNull("failed to locate service store executor", serviceStoreExecutor);
StoreExecutor inmemoryExecutor = extraExecutors.detect(storeExecutor -> storeExecutor instanceof InMemoryStoreExecutor);
assertNotNull("failed to locate inmemory executor", inmemoryExecutor);
}
use of org.finos.legend.engine.plan.execution.PlanExecutor in project legend-engine by finos.
the class TestPlanExecutor method testPlanExecutorConstructionWithConfig.
@Test
public void testPlanExecutorConstructionWithConfig() {
// assert that we construct a plan executor with the proper configs
PlanExecutor planExecutor = PlanExecutor.newPlanExecutorWithConfigurations(new FakeRelationalStoreExecutorBuilder.Configuration(), new FakeServiceStoreExecutorBuilder.Configuration());
ImmutableList<StoreExecutor> extraExecutors = planExecutor.getExtraExecutors();
StoreExecutor relationalExecutor = extraExecutors.detect(storeExecutor -> storeExecutor instanceof FakeRelationalStoreExecutorBuilder.Executor);
assertNotNull("failed to locate relational executor", relationalExecutor);
StoreExecutorConfiguration relationalConfiguration = ((FakeRelationalStoreExecutorBuilder.Executor) relationalExecutor).getConfiguration();
assertNotNull("builder not invoked with config", relationalConfiguration);
StoreExecutor serviceStoreExecutor = extraExecutors.detect(storeExecutor -> storeExecutor instanceof FakeServiceStoreExecutorBuilder.Executor);
assertNotNull("failed to locate service store executor", serviceStoreExecutor);
StoreExecutorConfiguration serviceStoreConfiguration = ((FakeServiceStoreExecutorBuilder.Executor) serviceStoreExecutor).getConfiguration();
assertNotNull("builder not invoked with config", serviceStoreConfiguration);
StoreExecutor inmemoryExecutor = extraExecutors.detect(storeExecutor -> storeExecutor instanceof InMemoryStoreExecutor);
assertNotNull("failed to locate inmemory executor", inmemoryExecutor);
}
Aggregations