From 1a7ab77ae87f71eb77b2a7cf67987e22df6b2cdf Mon Sep 17 00:00:00 2001 From: "Sherjan, Haroon" Date: Thu, 26 Oct 2023 09:29:27 -0700 Subject: [PATCH] Instantiate dummy database if user passes string as element --- .../toPureGraph/HelperRuntimeBuilder.java | 22 +++++-------------- .../runner/mapping/MappingTestRunner.java | 4 ++-- .../mapping/extension/MappingTestRunner.java | 5 ++--- ...erRelationalDatabaseConnectionBuilder.java | 2 +- 4 files changed, 10 insertions(+), 23 deletions(-) diff --git a/legend-engine-core/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperRuntimeBuilder.java b/legend-engine-core/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperRuntimeBuilder.java index 792570cc0af..c10e4d4d7b9 100644 --- a/legend-engine-core/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperRuntimeBuilder.java +++ b/legend-engine-core/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperRuntimeBuilder.java @@ -126,7 +126,7 @@ public static void buildEngineRuntime(EngineRuntime engineRuntime, Root_meta_cor Root_meta_core_runtime_ConnectionStore connectionStore = new Root_meta_core_runtime_ConnectionStore_Impl("") ._connection(connection) - ._element(getElement(storePointer.path, storePointer.sourceInformation, context)); + ._element(getStore(storePointer.path, storePointer.sourceInformation, context)); pureRuntime._connectionStoresAdd(connectionStore); }); }); @@ -155,7 +155,7 @@ public static void buildEngineRuntime(EngineRuntime engineRuntime, Root_meta_cor connection.accept(new ConnectionSecondPassBuilder(context, pureConnection)); final Root_meta_core_runtime_ConnectionStore connectionStore = new Root_meta_core_runtime_ConnectionStore_Impl("", null, context.pureModel.getClass("meta::core::runtime::ConnectionStore")) ._connection(pureConnection) - ._element(getElement(storeConnections.store.path, storeConnections.store.sourceInformation, context)); + ._element(getStore(storeConnections.store.path, storeConnections.store.sourceInformation, context)); pureRuntime._connectionStoresAdd(connectionStore); }); @@ -222,7 +222,7 @@ public static Root_meta_core_runtime_Runtime buildPureRuntime(Runtime runtime, C connection.accept(new ConnectionSecondPassBuilder(context, pureConnection)); final Root_meta_core_runtime_ConnectionStore connectionStore = new Root_meta_core_runtime_ConnectionStore_Impl("", null, context.pureModel.getClass("meta::core::runtime::ConnectionStore")) ._connection(pureConnection) - ._element(getElement(connection.element, connection.sourceInformation, context)); + ._element(getStore(connection.element, connection.sourceInformation, context)); pureRuntime._connectionStoresAdd(connectionStore); }); return pureRuntime; @@ -238,23 +238,11 @@ else if (runtime instanceof RuntimePointer) throw new UnsupportedOperationException(); } - public static Object getElement(String element, SourceInformation sourceInformation, CompileContext context) + public static Object getStore(String element, SourceInformation sourceInformation, CompileContext context) { return element.equals("ModelStore") ? new Root_meta_external_store_model_ModelStore_Impl("", null, context.pureModel.getClass("meta::external::store::model::ModelStore")) - : resolveElementSafe(element, sourceInformation, context); - } - - private static Object resolveElementSafe(String element, SourceInformation sourceInformation, CompileContext context) - { - try - { - return context.resolveStore(element, sourceInformation); - } - catch (EngineException e) - { - return element; - } + : context.resolveStore(element, sourceInformation); } /** diff --git a/legend-engine-core/legend-engine-core-test/legend-engine-test-runner-mapping/src/main/java/org/finos/legend/engine/test/runner/mapping/MappingTestRunner.java b/legend-engine-core/legend-engine-core-test/legend-engine-test-runner-mapping/src/main/java/org/finos/legend/engine/test/runner/mapping/MappingTestRunner.java index 81fb2474bcc..e402ce14b76 100644 --- a/legend-engine-core/legend-engine-core-test/legend-engine-test-runner-mapping/src/main/java/org/finos/legend/engine/test/runner/mapping/MappingTestRunner.java +++ b/legend-engine-core/legend-engine-core-test/legend-engine-test-runner-mapping/src/main/java/org/finos/legend/engine/test/runner/mapping/MappingTestRunner.java @@ -60,7 +60,7 @@ import java.util.*; import java.util.function.Consumer; -import static org.finos.legend.engine.language.pure.compiler.toPureGraph.HelperRuntimeBuilder.getElement; +import static org.finos.legend.engine.language.pure.compiler.toPureGraph.HelperRuntimeBuilder.getStore; @Deprecated public class MappingTestRunner @@ -102,7 +102,7 @@ public void setupTestData() CompileContext context = this.pureModel.getContext(); Root_meta_core_runtime_ConnectionStore connectionStore = new Root_meta_core_runtime_ConnectionStore_Impl("") ._connection(conn.accept(connectionVisitor)) - ._element(getElement(conn.element, conn.elementSourceInformation, context)); + ._element(getStore(conn.element, conn.elementSourceInformation, context)); this.runtime._connectionStoresAdd(connectionStore); }); } diff --git a/legend-engine-core/legend-engine-core-test/legend-engine-test-runner-mapping/src/main/java/org/finos/legend/engine/testable/mapping/extension/MappingTestRunner.java b/legend-engine-core/legend-engine-core-test/legend-engine-test-runner-mapping/src/main/java/org/finos/legend/engine/testable/mapping/extension/MappingTestRunner.java index 52e11c1d323..89c8d97ed58 100644 --- a/legend-engine-core/legend-engine-core-test/legend-engine-test-runner-mapping/src/main/java/org/finos/legend/engine/testable/mapping/extension/MappingTestRunner.java +++ b/legend-engine-core/legend-engine-core-test/legend-engine-test-runner-mapping/src/main/java/org/finos/legend/engine/testable/mapping/extension/MappingTestRunner.java @@ -19,7 +19,6 @@ import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.impl.tuple.Tuples; import org.eclipse.collections.impl.utility.ListIterate; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.CompileContext; import org.finos.legend.engine.language.pure.compiler.toPureGraph.ConnectionFirstPassBuilder; import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; import org.finos.legend.engine.plan.execution.PlanExecutor; @@ -57,7 +56,7 @@ import java.util.stream.Collectors; import static org.finos.legend.engine.language.pure.compiler.toPureGraph.HelperModelBuilder.getElementFullPath; -import static org.finos.legend.engine.language.pure.compiler.toPureGraph.HelperRuntimeBuilder.getElement; +import static org.finos.legend.engine.language.pure.compiler.toPureGraph.HelperRuntimeBuilder.getStore; public class MappingTestRunner implements TestRunner { @@ -142,7 +141,7 @@ private TestResult executeMappingTest(MappingTest mappingTest, MappingTestRunne Connection conn = connection.getOne(); Root_meta_core_runtime_ConnectionStore connectionStore = new Root_meta_core_runtime_ConnectionStore_Impl("") ._connection(conn.accept(context.getConnectionVisitor())) - ._element(getElement(conn.element, conn.elementSourceInformation, context.getPureModel().getContext())); + ._element(getStore(conn.element, conn.elementSourceInformation, context.getPureModel().getContext())); runtime._connectionStoresAdd(connectionStore); }); handleGenerationOfPlan(connections.stream().map(Pair::getOne).collect(Collectors.toList()), runtime, context); diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperRelationalDatabaseConnectionBuilder.java b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperRelationalDatabaseConnectionBuilder.java index c1476ad4b91..059003133ec 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperRelationalDatabaseConnectionBuilder.java +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperRelationalDatabaseConnectionBuilder.java @@ -51,7 +51,7 @@ public static void addDatabaseConnectionProperties(Root_meta_external_store_rela } catch (RuntimeException e) { - new Root_meta_relational_metamodel_Database_Impl(element)._name(element); + context.pureModel.storesIndex.putIfAbsent(element, new Root_meta_relational_metamodel_Database_Impl(element)._name(element)); } }