Skip to content

Commit

Permalink
add ontology support for primitive (properties) search types explicit…
Browse files Browse the repository at this point in the history
… declaration

add cursor pattern printing for AssignmentResults for all cursors available
Add runCypher with cursor type as parameter
  • Loading branch information
[email protected] committed Dec 31, 2019
1 parent de2c6d0 commit dd92835
Show file tree
Hide file tree
Showing 24 changed files with 594 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public CreateCursorRequest getCursorRequest() {
* @return
*/
static Class<? extends CreateCursorRequest> resolve(String cursorTypeName) {
Reflections reflections = new Reflections("com.yangdb.fuse");
Reflections reflections = new Reflections(CreateCursorRequest.class.getPackage().getName());
Set<Class<? extends CreateCursorRequest>> allClasses = reflections.getSubTypesOf(CreateCursorRequest.class);
Optional<Class<? extends CreateCursorRequest>> cursorType = allClasses.stream().filter(clazz -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public interface QueryDriver {

Optional<Object> run(String cypher, String ontology);

Optional<Object> run(String cypher, String ontology, int pageSize, String cursorType);

Optional<Object> getNextPageData(String queryId, Optional<String> cursorId,int pageSize, boolean deleteCurrentPage);

Optional<StoreResourceInfo> getInfo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@
import javaslang.control.Option;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;

import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.stream.Collectors;

import static com.yangdb.fuse.dispatcher.cursor.CursorFactory.request;
import static com.yangdb.fuse.dispatcher.cursor.CursorFactory.resolve;
import static com.yangdb.fuse.model.Utils.getOrCreateId;
import static com.yangdb.fuse.model.asgQuery.AsgCompositeQuery.hasInnerQuery;
import static com.yangdb.fuse.model.transport.CreateQueryRequestMetadata.QueryType.*;
import static com.yangdb.fuse.model.transport.CreateQueryRequestMetadata.QueryType.parameterized;
import static java.util.Collections.EMPTY_LIST;

/**
Expand Down Expand Up @@ -120,10 +118,10 @@ public Optional<Object> run(Query query, int pageSize, String cursorType) {
}

@Override
public Optional<Object> run(String cypher, String ontology) {
public Optional<Object> run(String cypher, String ontology, int pageSize, String cursorType) {
String id = UUID.randomUUID().toString();
try {
CreateJsonQueryRequest queryRequest = createJsonQueryRequest(cypher, ontology, id);
CreateJsonQueryRequest queryRequest = new CreateJsonQueryRequest(id, id, cypher, ontology, request(cursorType,new CreatePageRequest(pageSize)));
Optional<QueryResourceInfo> resourceInfo = create(queryRequest);
if (!resourceInfo.isPresent())
return Optional.empty();
Expand All @@ -132,14 +130,33 @@ public Optional<Object> run(String cypher, String ontology) {
return Optional.of(resourceInfo.get().getError());

return Optional.of(resourceInfo.get());
} catch (Throwable e) {
return Optional.of(new QueryResourceInfo().error(
new FuseError(Query.class.getSimpleName(), "failed building the cursor request " + cursorType)));

} finally {
//remove stateless query
// delete(id);
}
}

protected CreateJsonQueryRequest createJsonQueryRequest(String cypher, String ontology, String id) {
return new CreateJsonQueryRequest(id, id, cypher, ontology, new LogicalGraphCursorRequest(new CreatePageRequest()));
@Override
public Optional<Object> run(String cypher, String ontology) {
String id = UUID.randomUUID().toString();
try {
CreateJsonQueryRequest queryRequest = new CreateJsonQueryRequest(id, id, cypher, ontology, new LogicalGraphCursorRequest(new CreatePageRequest()));
Optional<QueryResourceInfo> resourceInfo = create(queryRequest);
if (!resourceInfo.isPresent())
return Optional.empty();

if (resourceInfo.get().getError() != null)
return Optional.of(resourceInfo.get().getError());

return Optional.of(resourceInfo.get());
} finally {
//remove stateless query
// delete(id);
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"structure": [
{
"type":"quantifier",
"typeOptionals": [
{ "op":"some"},
{ "op":"all"}
]
},
{
"type":"entity",
"typeOptionals": [
{ "op":"concrete"},
{ "op":"typed"},
{ "op":"untyped"}
]
},
{
"type":"relation",
"typeOptionals": [
{ "op":"typed"},
{ "op":"untyped"}
]
}
],
"primitives": ["string","int","date","text","float","array","geo_point","datetime"],
"operators": {
"empty": ["string","int","date","text","float","array","geo_point","datetime"],
"notEmpty": ["string","int","date","text","float","array","geo_point","datetime"],

"eq": ["string","int","date","text","float","array","geo_point","datetime"],
"ne": ["string","int","date","text","float","array","geo_point","datetime"],
"gt": ["string","int","date","text","float","datetime"],
"ge": ["string","int","date","text","float","datetime"],
"lt": ["string","int","date","text","float","datetime"],
"le": ["string","int","date","text","float","datetime"],

"contains": ["string","text"],
"like": ["string","text"],
"likeAny": ["string","text"],

"inSet": ["string","int","date","text","float","array","geo_point","datetime"],
"notInSet": ["string","int","date","text","float","array","geo_point","datetime"],

"inRange": ["datetime","int","float","date"],
"notInRange": ["datetime","int","float","date"]
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,5 @@ protected CreateQueryRequest createQueryRequest(Query query, String id) {

//endregion
private QueryTransformer<String, Query> transformer;

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public ContentResponse<Object> run(Query query, int pageSize, String cursorType)
return controller.run(query,pageSize,cursorType);
}

@Override
public ContentResponse<Object> run(String cypher, String ontology, int pageSize, String cursorType) {
return controller.run(cypher, ontology, pageSize, cursorType);
}

@Override
public ContentResponse<ValidationResult> validate(Query query) {
return controller.validate(query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public Optional<Object> run(String cypher, String ontology) {
return Optional.empty();
}

@Override
public Optional<Object> run(String cypher, String ontology, int pageSize, String cursorType) {
return Optional.empty();
}

@Override
public Optional<GraphTraversal> traversal(com.yangdb.fuse.model.query.Query query) {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"structure": [
{
"type":"quantifier",
"typeOptionals": [
{ "op":"some"},
{ "op":"all"}
]
},
{
"type":"entity",
"typeOptionals": [
{ "op":"concrete"},
{ "op":"typed"},
{ "op":"untyped"}
]
},
{
"type":"relation",
"typeOptionals": [
{ "op":"typed"},
{ "op":"untyped"}
]
}
],
"primitives": ["string","int","date","text","float","array","geo_point","datetime"],
"operators": {
"empty": ["string","int","date","text","float","array","geo_point","datetime"],
"notEmpty": ["string","int","date","text","float","array","geo_point","datetime"],

"eq": ["string","int","date","text","float","array","geo_point","datetime"],
"ne": ["string","int","date","text","float","array","geo_point","datetime"],
"gt": ["string","int","date","text","float","datetime"],
"ge": ["string","int","date","text","float","datetime"],
"lt": ["string","int","date","text","float","datetime"],
"le": ["string","int","date","text","float","datetime"],

"contains": ["string","text"],
"like": ["string","text"],
"likeAny": ["string","text"],

"inSet": ["string","int","date","text","float","array","geo_point","datetime"],
"notInSet": ["string","int","date","text","float","array","geo_point","datetime"],

"inRange": ["datetime","int","float","date"],
"notInRange": ["datetime","int","float","date"]
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.yangdb.fuse.model.execution.plan.entity.EntityOp;
import com.yangdb.fuse.model.execution.plan.relation.RelationOp;
import com.yangdb.fuse.model.ontology.Ontology;
import com.yangdb.fuse.model.query.Query;
import com.yangdb.fuse.model.query.Rel;
import com.yangdb.fuse.model.query.entity.EEntityBase;
import com.yangdb.fuse.model.results.*;
Expand Down Expand Up @@ -152,9 +153,6 @@ public QueryResultBase getNextResults(int numResults) {
}

Assignment.Builder builder = Assignment.Builder.instance();



for(Map.Entry<String, Map<Vertex, Set<String>>> idVertexEtagsEntry : idVertexEtagsMap.entrySet()) {
Vertex mergedVertex = mergeVertices(Stream.ofAll(idVertexEtagsEntry.getValue().keySet()).toJavaList());
if(this.idsScore.containsKey(mergedVertex.id())) {
Expand All @@ -178,7 +176,10 @@ public QueryResultBase getNextResults(int numResults) {


Assignment assignment = compose(builder);
return AssignmentsQueryResult.Builder.instance().withAssignment(assignment).build();
final Query pattern = getContext().getQueryResource().getQuery();
return AssignmentsQueryResult.Builder.instance()
.withPattern(pattern)
.withAssignment(assignment).build();
}

protected Assignment compose(Assignment.Builder builder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public ContentResponse<Object> run(String cypher, String ontology) {
return controller.run(cypher,ontology);
}

@Override
public ContentResponse<Object> run(String cypher, String ontology, int pageSize, String cursorType) {
return controller.run(cypher,ontology,pageSize,cursorType);
}

@Override
public ContentResponse<QueryResourceInfo> createAndFetch(CreateQueryRequest request) {
return controller.createAndFetch(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import com.yangdb.fuse.model.transport.CreateQueryRequestMetadata;
import com.yangdb.fuse.model.validation.ValidationResult;

import java.util.Optional;

import static com.yangdb.fuse.model.transport.CreateQueryRequestMetadata.QueryType.concrete;

/**
Expand Down Expand Up @@ -99,5 +101,6 @@ protected AsgQuery rewrite(AsgQuery asgQuery) {
private PlanSearcher<Plan, PlanDetailedCost, AsgQuery> planSearcher;



//endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.yangdb.fuse.dispatcher.cursor.Cursor;
import com.yangdb.fuse.dispatcher.cursor.CursorFactory;
import com.yangdb.fuse.executor.cursor.TraversalCursorContext;
import com.yangdb.fuse.model.query.Query;
import com.yangdb.fuse.model.results.Assignment;
import com.yangdb.fuse.model.results.AssignmentsQueryResult;
import com.yangdb.fuse.model.results.Entity;
Expand All @@ -33,6 +34,8 @@

import java.util.*;

import static com.yangdb.fuse.model.results.AssignmentsQueryResult.Builder.instance;

/**
* Created by roman.margolis on 11/03/2018.
*/
Expand Down Expand Up @@ -71,6 +74,9 @@ public GraphHierarchyTraversalCursor(Cursor<TraversalCursorContext> cursor, Iter
//region Cursor Implementation
@Override
public AssignmentsQueryResult getNextResults(int numResults) {
final Query pattern = getContext().getQueryResource().getQuery();
this.fullGraph.setPattern(pattern);

AssignmentsQueryResult newResult = (AssignmentsQueryResult) this.cursor.getNextResults(numResults);
while(newResult.getAssignments().size() > 0) {
consolidateFullGraph(newResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.yangdb.fuse.dispatcher.cursor.CursorFactory;
import com.yangdb.fuse.executor.cursor.TraversalCursorContext;
import com.yangdb.fuse.model.asgQuery.AsgQuery;
import com.yangdb.fuse.model.query.Query;
import com.yangdb.fuse.model.query.properties.CalculatedEProp;
import com.yangdb.fuse.model.query.properties.projection.CalculatedFieldProjection;
import com.yangdb.fuse.model.results.*;
Expand Down Expand Up @@ -69,6 +70,9 @@ public GraphTraversalCursor(Cursor<TraversalCursorContext> cursor) {
//region Cursor Implementation
@Override
public AssignmentsQueryResult getNextResults(int numResults) {
final Query pattern = getContext().getQueryResource().getQuery();
this.fullGraph.setPattern(pattern);

AssignmentsQueryResult newResult = (AssignmentsQueryResult) this.cursor.getNextResults(numResults);
consolidateFullGraph(newResult);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.yangdb.fuse.model.execution.plan.entity.EntityOp;
import com.yangdb.fuse.model.execution.plan.relation.RelationOp;
import com.yangdb.fuse.model.ontology.Ontology;
import com.yangdb.fuse.model.query.Query;
import com.yangdb.fuse.model.query.Rel;
import com.yangdb.fuse.model.query.entity.EEntityBase;
import com.yangdb.fuse.model.results.*;
Expand Down Expand Up @@ -151,7 +152,10 @@ public QueryResultBase getNextResults(int numResults) {
relTuple._3()));
}

return AssignmentsQueryResult.Builder.instance().withAssignment(builder.build()).build();
final Query pattern = getContext().getQueryResource().getQuery();
return AssignmentsQueryResult.Builder.instance()
.withPattern(pattern)
.withAssignment(builder.build()).build();
}
//endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ protected AssignmentsQueryResult toQuery(int numResults) {
return builder.build();
}


protected Assignment toAssignment(Path path) {
Assignment.Builder builder = Assignment.Builder.instance();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public Ontology() {

primitiveTypes.add(new PrimitiveType("int", Long.class));
primitiveTypes.add(new PrimitiveType("string", String.class));
primitiveTypes.add(new PrimitiveType("text", String.class));
primitiveTypes.add(new PrimitiveType("float", Double.class));
primitiveTypes.add(new PrimitiveType("date", Date.class));
primitiveTypes.add(new PrimitiveType("datetime", Date.class));
Expand Down
Loading

0 comments on commit dd92835

Please sign in to comment.