Skip to content

Commit

Permalink
Store PackageableElements in setNameAndPackage to streamline the stor…
Browse files Browse the repository at this point in the history
…ing process (#3084)
  • Loading branch information
jake-kim1 authored Sep 11, 2024
1 parent 83bfe94 commit 5f04a49
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.opentracing.util.GlobalTracer;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.util.Arrays;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
Expand Down Expand Up @@ -280,7 +279,7 @@ public PureModel(PureModelContextData pureModelContextData, CompilerExtensions e
MutableList<org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement> sectionIndices = classToElements.removeAll(SectionIndex.class);
sectionIndices.forEach(sectionIndex -> ((SectionIndex) sectionIndex).sections.forEach(section -> section.elements.forEach(elementPath -> this.sectionsIndex.putIfAbsent(elementPath, section))));
this.maybeParallel(Stream.concat(sectionIndices.stream(), classToElements.removeAll(Profile.class).stream()))
.forEach(handleEngineExceptions(this::processElementFirstPass));
.forEach(handleEngineExceptions(this::processFirstPass));

MutableMap<java.lang.Class<? extends org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement>, Collection<java.lang.Class<? extends org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement>>> dependencyGraph = Maps.mutable.empty();
dependencyGraph.put(Class.class, Lists.fixedSize.with(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Measure.class));
Expand All @@ -297,7 +296,7 @@ public PureModel(PureModelContextData pureModelContextData, CompilerExtensions e
MutableSet<MutableSet<java.lang.Class<? extends org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement>>> disjointDependencyGraphs = dependencyManagement.getDisjointDependencyGraphs();
this.maybeParallel(disjointDependencyGraphs.stream()).forEach(disjointDependencyGraph ->
{
processPass("firstPass", classToElements, dependentToDependencies, handleEngineExceptions(this::processElementFirstPass), disjointDependencyGraph);
processPass("firstPass", classToElements, dependentToDependencies, handleEngineExceptions(this::processFirstPass), disjointDependencyGraph);
processPass("secondPass", classToElements, dependentToDependencies, handleEngineExceptions(this::processSecondPass), disjointDependencyGraph);
processPass("thirdPass", classToElements, dependentToDependencies, handleEngineExceptions(this::processThirdPass), disjointDependencyGraph);
processPass("fourthPass", classToElements, dependentToDependencies, handleEngineExceptions(this::processFourthPass), disjointDependencyGraph);
Expand Down Expand Up @@ -586,17 +585,6 @@ else if (cause instanceof RuntimeException)
}
}

private void processElementFirstPass(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement element)
{
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement packageableElement = processFirstPass(element);
String elementName = element.name;
if (element instanceof Function)
{
elementName = HelperModelBuilder.getSignature((Function) element);
}
this.packageableElementsIndex.put(buildPackageString(element._package, elementName), packageableElement);
}

private org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement processFirstPass(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement element)
{
return visitWithErrorHandling(element, new PackageableElementFirstPassBuilder(getContext(element)));
Expand Down Expand Up @@ -1632,6 +1620,7 @@ protected <T extends org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.P
pureElement.setSourceInformation(SourceInformationHelper.toM3SourceInformation(sourceInformation));
pack._childrenAdd(pureElement);
}
this.packageableElementsIndex.put(buildPackageString(packagePath, name), pureElement);
return pureElement;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@
package org.finos.legend.engine.language.pure.compiler.test;

import org.eclipse.collections.api.tuple.Pair;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.HelperRuntimeBuilder;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel;
import org.finos.legend.engine.language.pure.grammar.from.PureGrammarParser;
import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation;
import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.PackageableConnection;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime;
import org.finos.legend.pure.generated.Root_meta_external_store_relational_runtime_RelationalDatabaseConnection;
import org.finos.legend.pure.generated.Root_meta_pure_alloy_connections_alloy_authentication_UserNamePasswordAuthenticationStrategy_Impl;
import org.junit.Assert;
import org.junit.Test;

import java.util.stream.Collectors;

import static org.finos.legend.engine.language.pure.compiler.test.TestCompilationFromGrammar.TestCompilationFromGrammarTestSuite.test;
import static org.junit.Assert.assertEquals;

Expand Down Expand Up @@ -84,6 +90,35 @@ public void testSqlServerConnectionPropertiesPropagatedToCompiledGraph()
"}\n");
}

@Test
public void testConnectionWithNoStore()
{
Pair<PureModelContextData, PureModel> test = test("");
PureModelContextData result = PureGrammarParser.newInstance().parseModel(
"###Connection\n" +
"RelationalDatabaseConnection simple::StaticConnection\n" +
"{\n" +
" store: asasmodel::relational::tests::dbInc;\n" +
" type: MemSQL;\n" +
" specification: Static\n" +
" {\n" +
" name: 'name';\n" +
" host: 'host';\n" +
" port: 1234;\n" +
" };\n" +
" auth: UserNamePassword\n" +
" {\n" +
" baseVaultReference: 'value';\n" +
" userNameVaultReference: 'value';\n" +
" passwordVaultReference: 'value';\n" +
" };\n" +
"}\n");

LegacyRuntime runtime = new LegacyRuntime();
runtime.connections = result.getElementsOfType(PackageableConnection.class).stream().map(x -> x.connectionValue).collect(Collectors.toList());
HelperRuntimeBuilder.buildPureRuntime(runtime, test.getTwo().getContext());
}

@Test
public void testH2ConnectionPropertiesPropagatedToCompiledGraph()
{
Expand All @@ -109,5 +144,4 @@ public void testH2ConnectionPropertiesPropagatedToCompiledGraph()

Assert.assertTrue(quoteIdentifiers);
}

}

0 comments on commit 5f04a49

Please sign in to comment.