Skip to content

Commit

Permalink
little changes to MATCH syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
luigidellaquila committed May 27, 2015
1 parent c31ef20 commit 6d23016
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 14 deletions.
2 changes: 1 addition & 1 deletion core/src/main/grammar/OrientSQL.jjt
Expand Up @@ -2795,7 +2795,7 @@ OMatchFilterItem MatchFilterItem():
)
|
(
<AS> <COLON> jjtThis.alias = Expression()
<AS> <COLON> jjtThis.alias = Identifier()
)
|
(
Expand Down
Expand Up @@ -84,7 +84,7 @@ public interface OCommandExecutor {

/**
* Returns the security operation type use to check about security.
*
* @see com.orientechnologies.orient.core.metadata.security.ORole PERMISSION_*
* @return
*/
public int getSecurityOperationType();
Expand Down
Expand Up @@ -5,7 +5,7 @@
public class OMatchFilterItem extends SimpleNode {
protected OExpression className;
protected OExpression classNames;
protected OExpression alias;
protected OIdentifier alias;
protected OWhereClause filter;
protected OArrayRangeSelector depth;
protected OInteger minDepth;
Expand Down
Expand Up @@ -2,13 +2,23 @@
/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=false,VISITOR=true,TRACK_TOKENS=true,NODE_PREFIX=O,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
package com.orientechnologies.orient.core.sql.parser;

import com.orientechnologies.common.listener.OProgressListener;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.command.OCommandExecutor;
import com.orientechnologies.orient.core.command.OCommandRequest;
import com.orientechnologies.orient.core.metadata.security.ORole;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class OMatchStatement extends OStatement {
public class OMatchStatement extends OStatement implements OCommandExecutor {
protected List<OMatchExpression> matchExpressions = new ArrayList<OMatchExpression>();
protected List<OIdentifier> returnItems = new ArrayList<OIdentifier>();

private OCommandContext context;

public OMatchStatement(int id) {
super(id);
}
Expand All @@ -21,5 +31,66 @@ public OMatchStatement(OrientSql p, int id) {
public Object jjtAccept(OrientSqlVisitor visitor, Object data) {
return visitor.visit(this, data);
}

@Override
public <RET extends OCommandExecutor> RET parse(OCommandRequest iRequest) {
return null;
}

@Override
public Object execute(Map<Object, Object> iArgs) {
return null;
}

@Override
public <RET extends OCommandExecutor> RET setProgressListener(OProgressListener progressListener) {
return null;
}

@Override
public <RET extends OCommandExecutor> RET setLimit(int iLimit) {
return null;
}

@Override
public String getFetchPlan() {
return null;
}

@Override
public Map<Object, Object> getParameters() {
return null;
}

@Override
public OCommandContext getContext() {
return null;
}

@Override
public void setContext(OCommandContext context) {

this.context = context;
}

@Override
public boolean isIdempotent() {
return true;
}

@Override
public Set<String> getInvolvedClusters() {
return null;// TODO
}

@Override
public int getSecurityOperationType() {
return ORole.PERMISSION_READ;
}

@Override
public boolean involveSchema() {
return false;
}
}
/* JavaCC - OriginalChecksum=6ff0afbe9d31f08b72159fcf24070c9f (do not edit this line) */
Expand Up @@ -7996,7 +7996,7 @@ final public OMatchFilterItem MatchFilterItem() throws ParseException {
case AS:
jj_consume_token(AS);
jj_consume_token(COLON);
jjtn000.alias = Expression();
jjtn000.alias = Identifier();
break;
case MINDEPTH:
jj_consume_token(MINDEPTH);
Expand Down
Expand Up @@ -42,40 +42,40 @@ public void testWrongFilterKey() {

@Test
public void testBasicMatch() {
checkRightSyntax("MATCH {class: 'V', as: 'foo'} RETURN foo");
checkRightSyntax("MATCH {class: 'V', as: foo} RETURN foo");
}

@Test
public void testNoReturn() {
checkWrongSyntax("MATCH {class: 'V', as: 'foo'}");
checkWrongSyntax("MATCH {class: 'V', as: foo}");
}

@Test
public void testSingleMethod() {
checkRightSyntax("MATCH {class: 'V', as: 'foo'}.out() RETURN foo");
checkRightSyntax("MATCH {class: 'V', as: foo}.out() RETURN foo");
}

@Test
public void testSingleMethodAndFilter() {
checkRightSyntax("MATCH {class: 'V', as: 'foo'}.out(){class: 'V', as: 'bar'} RETURN foo");
checkRightSyntax("MATCH {class: 'V', as: foo}.out(){class: 'V', as: bar} RETURN foo");
}

@Test
public void testLongPath() {
checkRightSyntax("MATCH {class: 'V', as: 'foo'}.out().in('foo').both('bar').out(){as: 'bar'} RETURN foo");
checkRightSyntax("MATCH {class: 'V', as: foo}.out().in('foo').both('bar').out(){as: bar} RETURN foo");
}

@Test
public void testLongPath2() {
checkRightSyntax("MATCH {class: 'V', as: 'foo'}.out().in('foo'){}.both('bar'){CLASS: 'bar'}.out(){as: 'bar'} RETURN foo");
checkRightSyntax("MATCH {class: 'V', as: foo}.out().in('foo'){}.both('bar'){CLASS: 'bar'}.out(){as: bar} RETURN foo");
}

@Test
public void testFilterTypes() {
StringBuilder query = new StringBuilder();
query.append("MATCH {");
query.append(" class: 'v', ");
query.append(" as: 'foo', ");
query.append(" as: foo, ");
query.append(" where: (name = 'foo' and surname = 'bar' or aaa in [1,2,3]), ");
query.append(" minDepth: 0, ");
query.append(" maxDepth: 10 ");
Expand All @@ -89,7 +89,7 @@ public void testFilterTypes2() {
StringBuilder query = new StringBuilder();
query.append("MATCH {");
query.append(" classes: ['V', 'E'], ");
query.append(" as: 'foo', ");
query.append(" as: foo, ");
query.append(" where: (name = 'foo' and surname = 'bar' or aaa in [1,2,3]), ");
query.append(" minDepth: 0, ");
query.append(" maxDepth: 10 ");
Expand All @@ -98,7 +98,6 @@ public void testFilterTypes2() {
checkRightSyntax(query.toString());
}


@Test
public void testMultiPath() {
StringBuilder query = new StringBuilder();
Expand All @@ -108,6 +107,12 @@ public void testMultiPath() {
checkRightSyntax(query.toString());
}

@Test
public void testMultipleMatches() {
String query = "" + "MATCH {class: 'V', as: foo}.out(){class: 'V', as: bar}, "
+ "{class: 'V', as: foo}.out(){class: 'V', as: bar}," + " {class: 'V', as: foo}.out(){class: 'V', as: bar} RETURN foo";
checkRightSyntax(query);
}

private void printTree(String s) {
OrientSql osql = getParserFor(s);
Expand Down

0 comments on commit 6d23016

Please sign in to comment.