Skip to content

Commit

Permalink
graphql dataspace
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishoya-gs committed Oct 23, 2023
1 parent 14e5dd1 commit cd9540a
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 26 deletions.
14 changes: 14 additions & 0 deletions legend-engine-xts-graphQL/legend-engine-xt-graphQL-query/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-language-pure-dsl-generation</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-data-space-pure-metamodel</artifactId>
</dependency>
<!-- ENGINE -->

<dependency>
Expand Down Expand Up @@ -304,6 +308,16 @@
<artifactId>legend-engine-xt-relationalStore-protocol</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-data-space-grammar</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-data-space-compiler</artifactId>
<scope>test</scope>
</dependency>
<!-- TEST -->
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class GraphQLProdCacheKey implements GraphQLCacheKey
private String runtimePath;
private String queryClassPath;
private String query;
private String dataspacePath;

public GraphQLProdCacheKey(String groupID, String artifactId, String versionId, String mappingPath, String runtimePath, String queryClassPath, String query)
{
Expand All @@ -37,6 +38,16 @@ public GraphQLProdCacheKey(String groupID, String artifactId, String versionId,
this.query = query;
}

public GraphQLProdCacheKey(String groupID, String artifactId, String versionId, String dataspacePath, String queryClassPath, String query)
{
this.groupID = groupID;
this.artifactId = artifactId;
this.versionId = versionId;
this.dataspacePath = dataspacePath;
this.queryClassPath = queryClassPath;
this.query = query;
}

@Override
public boolean equals(Object o)
{
Expand All @@ -49,12 +60,12 @@ public boolean equals(Object o)
return false;
}
GraphQLProdCacheKey that = (GraphQLProdCacheKey) o;
return Objects.equal(groupID, that.groupID) && Objects.equal(artifactId, that.artifactId) && Objects.equal(versionId, that.versionId) && Objects.equal(mappingPath, that.mappingPath) && Objects.equal(runtimePath, that.runtimePath) && Objects.equal(queryClassPath, that.queryClassPath) && Objects.equal(query, that.query);
return Objects.equal(groupID, that.groupID) && Objects.equal(artifactId, that.artifactId) && Objects.equal(versionId, that.versionId) && Objects.equal(mappingPath, that.mappingPath) && Objects.equal(runtimePath, that.runtimePath) && Objects.equal(queryClassPath, that.queryClassPath) && Objects.equal(query, that.query) && Objects.equal(dataspacePath, that.dataspacePath);
}

@Override
public int hashCode()
{
return Objects.hashCode(groupID, artifactId, versionId, mappingPath, runtimePath, queryClassPath, query);
return Objects.hashCode(groupID, artifactId, versionId, mappingPath, runtimePath, queryClassPath, query, dataspacePath);
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.finos.legend.engine.protocol.pure.v1.model.executionPlan.ExecutionPlan;
import org.finos.legend.engine.query.graphQL.api.execute.directives.IGraphQLDirectiveExtension;
import org.finos.legend.pure.generated.Root_meta_pure_extension_Extension;
import org.finos.legend.pure.generated.Root_meta_pure_runtime_Runtime;
import org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping;
import org.pac4j.core.profile.CommonProfile;

import java.util.Map;
Expand All @@ -40,7 +42,7 @@ public ImmutableList<String> getSupportedDirectives()
}

@Override
public ExecutionPlan planDirective(Document document, PureModel pureModel, String rootClassPath, String mappingPath, String runtimePath, RichIterable<? extends Root_meta_pure_extension_Extension> _extensions, Iterable<? extends PlanTransformer> transformers)
public ExecutionPlan planDirective(Document document, PureModel pureModel, org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class<?> _class, Mapping mapping, Root_meta_pure_runtime_Runtime runtime, RichIterable<? extends Root_meta_pure_extension_Extension> _extensions, Iterable<? extends PlanTransformer> transformers)
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.finos.legend.engine.protocol.graphQL.metamodel.Document;
import org.finos.legend.engine.protocol.pure.v1.model.executionPlan.ExecutionPlan;
import org.finos.legend.pure.generated.Root_meta_pure_extension_Extension;
import org.finos.legend.pure.generated.Root_meta_pure_runtime_Runtime;
import org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping;
import org.pac4j.core.profile.CommonProfile;

import java.util.Map;
Expand All @@ -36,9 +38,9 @@ public interface IGraphQLDirectiveExtension
ExecutionPlan planDirective(
Document document,
PureModel pureModel,
String rootClassPath,
String mappingPath,
String runtimePath,
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class<?> _class,
Mapping mapping,
Root_meta_pure_runtime_Runtime runtime,
RichIterable<? extends Root_meta_pure_extension_Extension> _extensions,
Iterable<? extends PlanTransformer> transformers);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.finos.legend.engine.plan.generation.extension.PlanGeneratorExtension;
import org.finos.legend.engine.protocol.Protocol;
import org.finos.legend.engine.protocol.pure.PureClientVersions;
import org.finos.legend.engine.protocol.pure.v1.model.context.AlloySDLC;
import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData;
import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextPointer;
import org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan;
Expand Down Expand Up @@ -94,6 +95,7 @@ public static void beforeClass() throws Exception
handlerCollection.setHandlers(new Handler[] {
buildPMCDMetadataHandler("/api/projects/Project1/workspaces/Workspace1/pureModelContextData", "/org/finos/legend/engine/query/graphQL/api/test/Project1_Workspace1.pure"),
buildJsonHandler("/api/projects/Project1/workspaces/Workspace1/revisions/HEAD/upstreamProjects", "[]"),
buildPMCDMetadataHandler("/projects/org.finos.legend.graphql/model.one/versions/1.0.0/pureModelContextData","/org/finos/legend/engine/query/graphQL/api/test/Project1_Workspace1.pure",new Protocol("pure", PureClientVersions.production),new PureModelContextPointer()),

buildPMCDMetadataHandler("/api/projects/Project1/workspaces/Workspace2/pureModelContextData", "/org/finos/legend/engine/query/graphQL/api/test/Project1_Workspace2.pure"),
buildJsonHandler("/api/projects/Project1/workspaces/Workspace2/revisions/HEAD/upstreamProjects", "[]"),
Expand Down Expand Up @@ -128,7 +130,8 @@ private GraphQLExecute getGraphQLExecute()

private GraphQLExecute getGraphQLExecuteWithCache(GraphQLPlanCache cache)
{
ModelManager modelManager = new ModelManager(DeploymentMode.TEST);
SDLCLoader sdlcLoader = new SDLCLoader(metaDataServerConfiguration, null);
ModelManager modelManager = new ModelManager(DeploymentMode.TEST, sdlcLoader);
PlanExecutor executor = PlanExecutor.newPlanExecutorWithAvailableStoreExecutors();
MutableList<PlanGeneratorExtension> generatorExtensions = Lists.mutable.withAll(ServiceLoader.load(PlanGeneratorExtension.class));
GraphQLExecute graphQLExecute = new GraphQLExecute(modelManager, executor, metaDataServerConfiguration, (pm) -> PureCoreExtensionLoader.extensions().flatCollect(g -> g.extraPureCoreExtensions(pm.getExecutionSupport())), generatorExtensions.flatCollect(PlanGeneratorExtension::getExtraPlanTransformers), cache);
Expand Down Expand Up @@ -165,6 +168,74 @@ public void testGraphQLExecuteDevAPI_Relational() throws Exception
Assert.assertEquals(expected, responseAsString(response));
}

@Test
public void testGraphQLExecuteProdAPI_Relational_With_Dataspace() throws Exception
{
GraphQLExecute graphQLExecute = getGraphQLExecute();
HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(mockRequest.getCookies()).thenReturn(new Cookie[0]);
Query query = new Query();
query.query = "query Query {\n" +
" allFirms {\n" +
" legalName,\n" +
" employees {\n" +
" firstName,\n" +
" lastName\n" +
" }\n" +
" }\n" +
" }";
Response response = graphQLExecute.executeProd(mockRequest, "org.finos.legend.graphql", "model.one", "1.0.0", "simple::dataspace", "simple::model::Query", query, null);

String expected = "{" +
"\"data\":{" +
"\"allFirms\":[" +
"{\"legalName\":\"Firm X\",\"employees\":[{\"firstName\":\"Peter\",\"lastName\":\"Smith\"},{\"firstName\":\"John\",\"lastName\":\"Johnson\"},{\"firstName\":\"John\",\"lastName\":\"Hill\"},{\"firstName\":\"Anthony\",\"lastName\":\"Allen\"}]}," +
"{\"legalName\":\"Firm A\",\"employees\":[{\"firstName\":\"Fabrice\",\"lastName\":\"Roberts\"}]}," +
"{\"legalName\":\"Firm B\",\"employees\":[{\"firstName\":\"Oliver\",\"lastName\":\"Hill\"},{\"firstName\":\"David\",\"lastName\":\"Harris\"}]}" +
"]" +
"}" +
"}";
Assert.assertEquals(expected, responseAsString(response));
}

@Test
public void testGraphQLExecuteProdAPI_Relational_With_Dataspace_With_Caching() throws Exception
{
GraphQLPlanCache cache = new GraphQLPlanCache(getExecutionCacheInstance());
GraphQLExecute graphQLExecute = getGraphQLExecuteWithCache(cache);
HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(mockRequest.getCookies()).thenReturn(new Cookie[0]);
Query query = new Query();
query.query = "query Query {\n" +
" allFirms {\n" +
" legalName,\n" +
" employees {\n" +
" firstName,\n" +
" lastName\n" +
" }\n" +
" }\n" +
" }";
Response response = graphQLExecute.executeProd(mockRequest, "org.finos.legend.graphql", "model.one", "1.0.0", "simple::dataspace", "simple::model::Query", query, null);

String expected = "{" +
"\"data\":{" +
"\"allFirms\":[" +
"{\"legalName\":\"Firm X\",\"employees\":[{\"firstName\":\"Peter\",\"lastName\":\"Smith\"},{\"firstName\":\"John\",\"lastName\":\"Johnson\"},{\"firstName\":\"John\",\"lastName\":\"Hill\"},{\"firstName\":\"Anthony\",\"lastName\":\"Allen\"}]}," +
"{\"legalName\":\"Firm A\",\"employees\":[{\"firstName\":\"Fabrice\",\"lastName\":\"Roberts\"}]}," +
"{\"legalName\":\"Firm B\",\"employees\":[{\"firstName\":\"Oliver\",\"lastName\":\"Hill\"},{\"firstName\":\"David\",\"lastName\":\"Harris\"}]}" +
"]" +
"}" +
"}";
Assert.assertEquals(expected, responseAsString(response));
Assert.assertEquals(0, cache.getCache().stats().hitCount(), 0);
Assert.assertEquals(1, cache.getCache().stats().missCount(), 0);

response = graphQLExecute.executeProd(mockRequest, "org.finos.legend.graphql", "model.one", "1.0.0", "simple::dataspace", "simple::model::Query", query, null);
Assert.assertEquals(expected, responseAsString(response));
Assert.assertEquals(1, cache.getCache().stats().hitCount(), 0);
Assert.assertEquals(1, cache.getCache().stats().missCount(), 0);
}

@Test
public void testGraphQLExecuteDevAPI_BiTemporalMilestoning_Root() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@ Database simple::store::DB
Join PERSON_ADDRESS(PERSON_TABLE.ID = ADDRESS_TABLE.PERSON_ID)
)

###DataSpace
DataSpace simple::dataspace
{
executionContexts:
[
{
name: 'dummyContext';
mapping: simple::mapping::Map;
defaultRuntime: simple::runtime::Runtime;
}
];
defaultExecutionContext: 'dummyContext';
}


###Mapping
import simple::model::*;
import simple::store::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,10 @@ public ImmutableList<String> getSupportedDirectives()
}

@Override
public ExecutionPlan planDirective(Document document, PureModel pureModel, String rootClassPath, String mappingPath, String runtimePath, RichIterable<? extends Root_meta_pure_extension_Extension> extensions, Iterable<? extends PlanTransformer> transformers)
public ExecutionPlan planDirective(Document document, PureModel pureModel, org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class<?> _class, Mapping mapping, Root_meta_core_runtime_Runtime runtime, RichIterable<? extends Root_meta_pure_extension_Extension> extensions, Iterable<? extends PlanTransformer> transformers)
{
try
{
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class<?> _class = pureModel.getClass(rootClassPath);
Mapping mapping = pureModel.getMapping(mappingPath);
Root_meta_core_runtime_Runtime runtime = pureModel.getRuntime(runtimePath);
org.finos.legend.pure.generated.Root_meta_external_query_graphQL_metamodel_sdl_Document queryDoc = GraphQLExecute.toPureModel(document, pureModel);
RichIterable<? extends Root_meta_external_query_graphQL_transformation_queryToPure_NamedExecutionPlan> purePlans = core_external_query_graphql_transformation_transformation_graphFetch.Root_meta_external_query_graphQL_transformation_queryToPure_getPlanForTotalCountDirective_Class_1__Mapping_1__Runtime_1__Document_1__Extension_MANY__NamedExecutionPlan_MANY_(_class, mapping, runtime, queryDoc, extensions, pureModel.getExecutionSupport());
List<SerializedNamedPlans> plans = purePlans.toList().stream().map(p ->
Expand Down

0 comments on commit cd9540a

Please sign in to comment.