Skip to content
This repository has been archived by the owner on Apr 4, 2021. It is now read-only.

Commit

Permalink
Handle Union in cypher queries and in TeX serialization. Addresses #9
Browse files Browse the repository at this point in the history
TODO: make distinction between UNION and UNION ALL
  • Loading branch information
jmarton committed Sep 14, 2016
1 parent 2715628 commit 6aafc6a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import relalg.ExpandOperator
import relalg.GetVerticesOperator
import relalg.JoinOperator
import relalg.RelalgFactory
import relalg.UnionOperator
import relalg.VertexLabel
import relalg.VertexVariable

Expand All @@ -34,6 +35,7 @@ class RelalgBaseCypherListener extends RelalgBaseUnsupportedCypherListener {
for (retVal = i.next; i.hasNext;) {
val nextAE = switch (betaOperatorType) {
case typeof(JoinOperator): createJoinOperator
case typeof(UnionOperator): createUnionOperator
default: throw new IllegalArgumentException(
"Got unexpected BetaOperator type to build left-deep-tree")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import ingraph.antlr.CypherParser.RelTypeNameContext
import ingraph.antlr.CypherParser.RelationshipDetailContext
import ingraph.antlr.CypherParser.RelationshipPatternContext
import ingraph.antlr.CypherParser.RelationshipTypesContext
import ingraph.antlr.CypherParser.RelationshipsPatternContext
import ingraph.antlr.CypherParser.ReturnBodyContext
import ingraph.antlr.CypherParser.ReturnContext
import ingraph.antlr.CypherParser.ReturnItemContext
import ingraph.antlr.CypherParser.RightArrowHeadContext
import ingraph.antlr.CypherParser.SingleQueryContext
import ingraph.antlr.CypherParser.SymbolicNameContext
import ingraph.antlr.CypherParser.UnionContext
import ingraph.antlr.CypherParser.VariableContext
import ingraph.antlr.CypherParser.WhereContext
import ingraph.cypher2relalg.factories.EdgeLabelFactory
Expand All @@ -44,6 +44,7 @@ import relalg.EdgeVariable
import relalg.ExpandOperator
import relalg.GetVerticesOperator
import relalg.JoinOperator
import relalg.UnionOperator
import relalg.Variable
import relalg.VertexVariable

Expand All @@ -69,13 +70,10 @@ class RelalgCypherListener extends RelalgBaseCypherListener {
}

override exitQuery(QueryContext ctx) {
val i = query_SingleQueryList.iterator
if (i.hasNext) { // FIXME: union of multiple singleQuery's
val rootExpression = createProductionOperator
rootExpression.input = i.next
val rootExpression = createProductionOperator
rootExpression.input = buildLeftDeepTree(typeof(UnionOperator), query_SingleQueryList?.iterator)

container.rootExpression = rootExpression
}
container.rootExpression = rootExpression
}

var List<Variable> return_VariableList = null
Expand Down Expand Up @@ -143,6 +141,10 @@ class RelalgCypherListener extends RelalgBaseCypherListener {
}
}

override enterUnion(UnionContext ctx) {
//FIXME: make distinction of UNION/UNION ALL
}

/*
* List of relalg subtrees for each MATCH clause.
*
Expand All @@ -152,6 +154,12 @@ class RelalgCypherListener extends RelalgBaseCypherListener {

override enterSingleQuery(SingleQueryContext ctx) {
singleQuery_MatchList = new ArrayList<AlgebraExpression>

// allow for a new return_VariableList for this singleQuery
// for duplicate return clause in a single singleQuery, Exception will be raised in enterReturn
if (!return_InsideReturn) {
return_VariableList=null;
}
}

override exitSingleQuery(SingleQueryContext ctx) {
Expand Down
5 changes: 5 additions & 0 deletions ingraph-relalg2tex/src/ingraph/relalg2tex/TexSerializer.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import relalg.JoinOperator
import relalg.ProductionOperator
import relalg.ProjectionOperator
import relalg.SelectionOperator
import relalg.UnionOperator
import relalg.Variable

abstract class TexSerializer {
Expand Down Expand Up @@ -119,6 +120,10 @@ abstract class TexSerializer {
'''antijoin'''
}

def dispatch betaOperator(UnionOperator operator) {
'''union'''
}

def directionToTex(Direction direction) {
switch direction {
case BOTH: {
Expand Down

0 comments on commit 6aafc6a

Please sign in to comment.