use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class OSQLPredicate method extractConditions.
protected Object extractConditions(final OSQLFilterCondition iParentCondition) {
final int oldPosition = parserGetCurrentPosition();
parserNextWord(true, " )=><,\r\n", true);
final String word = parserGetLastWord();
boolean inBraces = word.length() > 0 && word.charAt(0) == OStringSerializerHelper.EMBEDDED_BEGIN;
if (word.length() > 0 && (word.equalsIgnoreCase("SELECT") || word.equalsIgnoreCase("TRAVERSE"))) {
// SUB QUERY
final StringBuilder embedded = new StringBuilder(256);
OStringSerializerHelper.getEmbedded(parserText, oldPosition - 1, -1, embedded);
parserSetCurrentPosition(oldPosition + embedded.length() + 1);
return new OSQLSynchQuery<Object>(embedded.toString());
}
parserSetCurrentPosition(oldPosition);
OSQLFilterCondition currentCondition = extractCondition();
// CHECK IF THERE IS ANOTHER CONDITION ON RIGHT
while (parserSkipWhiteSpaces()) {
if (!parserIsEnded() && parserGetCurrentChar() == ')')
return currentCondition;
final OQueryOperator nextOperator = extractConditionOperator();
if (nextOperator == null)
return currentCondition;
if (nextOperator.precedence > currentCondition.getOperator().precedence) {
// SWAP ITEMS
final OSQLFilterCondition subCondition = new OSQLFilterCondition(currentCondition.right, nextOperator);
currentCondition.right = subCondition;
subCondition.right = extractConditionItem(false, 1);
} else {
final OSQLFilterCondition parentCondition = new OSQLFilterCondition(currentCondition, nextOperator);
parentCondition.right = extractConditions(parentCondition);
currentCondition = parentCondition;
}
}
currentCondition.inBraces = inBraces;
// END OF TEXT
return currentCondition;
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class SQLUpdateEdgeTest method testUpdateEdgeOfTypeE.
@Test
public void testUpdateEdgeOfTypeE() {
//issue #6378
ODocument v1 = database.command(new OCommandSQL("create vertex")).execute();
ODocument v2 = database.command(new OCommandSQL("create vertex")).execute();
ODocument v3 = database.command(new OCommandSQL("create vertex")).execute();
Iterable<OrientEdge> edges = database.command(new OCommandSQL("create edge E from " + v1.getIdentity() + " to " + v2.getIdentity())).execute();
OrientEdge edge = edges.iterator().next();
database.command(new OCommandSQL("UPDATE EDGE " + edge.getIdentity() + " SET in = " + v3.getIdentity())).execute();
Iterable<ODocument> result = database.command(new OSQLSynchQuery<ODocument>("select expand(out()) from " + v1.getIdentity())).execute();
Assert.assertEquals(result.iterator().next().getIdentity(), v3.getIdentity());
result = database.command(new OSQLSynchQuery<ODocument>("select expand(in()) from " + v3.getIdentity())).execute();
Assert.assertEquals(result.iterator().next().getIdentity(), v1.getIdentity());
result = database.command(new OSQLSynchQuery<ODocument>("select expand(in()) from " + v2.getIdentity())).execute();
Assert.assertFalse(result.iterator().hasNext());
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class SQLUpdateEdgeTest method testUpdateEdge.
@Test
public void testUpdateEdge() {
database.command(new OCommandSQL("create class V1 extends V")).execute();
database.command(new OCommandSQL("create class E1 extends E")).execute();
database.getMetadata().getSchema().reload();
// VERTEXES
ODocument v1 = database.command(new OCommandSQL("create vertex")).execute();
Assert.assertEquals(v1.getClassName(), OrientVertexType.CLASS_NAME);
ODocument v2 = database.command(new OCommandSQL("create vertex V1")).execute();
Assert.assertEquals(v2.getClassName(), "V1");
ODocument v3 = database.command(new OCommandSQL("create vertex set vid = 'v3', brand = 'fiat'")).execute();
Assert.assertEquals(v3.getClassName(), OrientVertexType.CLASS_NAME);
Assert.assertEquals(v3.field("brand"), "fiat");
ODocument v4 = database.command(new OCommandSQL("create vertex V1 set vid = 'v4', brand = 'fiat',name = 'wow'")).execute();
Assert.assertEquals(v4.getClassName(), "V1");
Assert.assertEquals(v4.field("brand"), "fiat");
Assert.assertEquals(v4.field("name"), "wow");
List<OrientEdge> edges = database.command(new OCommandSQL("create edge E1 from " + v1.getIdentity() + " to " + v2.getIdentity())).execute();
Assert.assertEquals(edges.size(), 1);
OrientEdge edge = edges.get(0);
Assert.assertEquals(edge.getLabel(), "E1");
database.command(new OCommandSQL("update edge E1 set out = " + v3.getIdentity() + ", in = " + v4.getIdentity() + " where @rid = " + edge.getIdentity())).execute();
List<ODocument> result = database.query(new OSQLSynchQuery("select expand(out('E1')) from " + v3.getIdentity()));
Assert.assertEquals(edges.size(), 1);
ODocument vertex4 = result.get(0);
Assert.assertEquals(vertex4.field("vid"), "v4");
result = database.query(new OSQLSynchQuery("select expand(in('E1')) from " + v4.getIdentity()));
Assert.assertEquals(result.size(), 1);
ODocument vertex3 = result.get(0);
Assert.assertEquals(vertex3.field("vid"), "v3");
result = database.query(new OSQLSynchQuery("select expand(out('E1')) from " + v1.getIdentity()));
Assert.assertEquals(result.size(), 0);
result = database.query(new OSQLSynchQuery("select expand(in('E1')) from " + v2.getIdentity()));
Assert.assertEquals(result.size(), 0);
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class TestGraphUnwindOut method testUwindLightweightEdges.
@Test
public void testUwindLightweightEdges() {
OrientGraph graph = new OrientGraph("memory:" + TestGraphUnwindOut.class.getSimpleName());
graph.setUseLightweightEdges(true);
try {
OrientVertexType type = graph.createVertexType("edgetest");
graph.createEdgeType("edgetestedge");
type.createEdgeProperty(Direction.IN, "edgetestedge");
type.createEdgeProperty(Direction.OUT, "edgetestedge");
OrientVertex test = graph.addVertex("class:edgetest");
test.setProperty("ida", "parentckt1");
test.save();
OrientVertex test1 = graph.addVertex("class:edgetest");
test1.setProperty("ida", "childckt2");
test1.save();
OrientVertex test2 = graph.addVertex("class:edgetest");
test2.setProperty("ida", "childckt3");
test2.save();
OrientVertex test3 = graph.addVertex("class:edgetest");
test3.setProperty("ida", "childckt4");
test3.save();
graph.commit();
graph.command(new OCommandSQL("create edge edgetestedge from (select from edgetest where ida='parentckt1') to (select from edgetest where ida like 'childckt%')")).execute();
graph.commit();
Iterable<OrientElement> res = graph.command(new OSQLSynchQuery("select out_edgetestedge[0] from v where out_edgetestedge.size() > 0 unwind out_edgetestedge ")).execute();
for (OrientElement oDocument : res) {
assertNotNull(oDocument.getRecord().field("out_edgetestedge"));
ODocument doc = oDocument.getRecord().field("out_edgetestedge");
assertEquals(doc.getClassName(), "edgetest");
}
} finally {
graph.drop();
}
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class OMatchStatementExecutionTest method testMatched1.
@Test
public void testMatched1() {
//issue #6931
db.command(new OCommandSQL("CREATE CLASS testMatched1_Foo EXTENDS V")).execute();
db.command(new OCommandSQL("CREATE CLASS testMatched1_Bar EXTENDS V")).execute();
db.command(new OCommandSQL("CREATE CLASS testMatched1_Baz EXTENDS V")).execute();
db.command(new OCommandSQL("CREATE CLASS testMatched1_Far EXTENDS V")).execute();
db.command(new OCommandSQL("CREATE CLASS testMatched1_Foo_Bar EXTENDS E")).execute();
db.command(new OCommandSQL("CREATE CLASS testMatched1_Bar_Baz EXTENDS E")).execute();
db.command(new OCommandSQL("CREATE CLASS testMatched1_Foo_Far EXTENDS E")).execute();
db.command(new OCommandSQL("CREATE VERTEX testMatched1_Foo SET name = 'foo'")).execute();
db.command(new OCommandSQL("CREATE VERTEX testMatched1_Bar SET name = 'bar'")).execute();
db.command(new OCommandSQL("CREATE VERTEX testMatched1_Baz SET name = 'baz'")).execute();
db.command(new OCommandSQL("CREATE VERTEX testMatched1_Far SET name = 'far'")).execute();
db.command(new OCommandSQL("CREATE EDGE testMatched1_Foo_Bar FROM (SELECT FROM testMatched1_Foo) TO (SELECT FROM testMatched1_Bar)")).execute();
db.command(new OCommandSQL("CREATE EDGE testMatched1_Bar_Baz FROM (SELECT FROM testMatched1_Bar) TO (SELECT FROM testMatched1_Baz)")).execute();
db.command(new OCommandSQL("CREATE EDGE testMatched1_Foo_Far FROM (SELECT FROM testMatched1_Foo) TO (SELECT FROM testMatched1_Far)")).execute();
List result = db.query(new OSQLSynchQuery("MATCH \n" + "{class: testMatched1_Foo, as: foo}.out('testMatched1_Foo_Bar') {as: bar}, \n" + "{class: testMatched1_Bar,as: bar}.out('testMatched1_Bar_Baz') {as: baz}, \n" + "{class: testMatched1_Foo,as: foo}.out('testMatched1_Foo_Far') {where: ($matched.baz IS null),as: far}\n" + "RETURN $matches"));
assertTrue(result.isEmpty());
result = db.query(new OSQLSynchQuery("MATCH \n" + "{class: testMatched1_Foo, as: foo}.out('testMatched1_Foo_Bar') {as: bar}, \n" + "{class: testMatched1_Bar,as: bar}.out('testMatched1_Bar_Baz') {as: baz}, \n" + "{class: testMatched1_Foo,as: foo}.out('testMatched1_Foo_Far') {where: ($matched.baz IS not null),as: far}\n" + "RETURN $matches"));
assertEquals(1, result.size());
result = db.query(new OSQLSynchQuery("MATCH \n" + "{class: testMatched1_Foo, as: foo}.out('testMatched1_Foo_Bar') {as: bar}, \n" + "{class: testMatched1_Bar,as: bar}.out('testMatched1_Bar_Baz') {as: baz}, \n" + "{class: testMatched1_Foo,as: foo}.out('testMatched1_Foo_Far') {where: (name != '$matched.baz'),as: far}\n" + "RETURN $matches"));
assertEquals(1, result.size());
//test that "$matched" in a string does not affect the optimization and execution planning
result = db.query(new OSQLSynchQuery("MATCH \n" + "{class: testMatched1_Foo, as: foo, where: (name != '$matched.baz')}.out('testMatched1_Foo_Bar') {as: bar, where: (name != '$matched.foo')}, \n" + "{class: testMatched1_Bar,as: bar}.out('testMatched1_Bar_Baz') {as: baz, where: (name != '$matched.far')}, \n" + "{class: testMatched1_Foo,as: foo}.out('testMatched1_Foo_Far') {where: (name != '$matched.baz'),as: far}\n" + "RETURN $matches"));
assertEquals(1, result.size());
//test that cyclic $matched conditions throw an execution exception (not supported in current executor, it will be in 3.0 probably)
try {
result = db.query(new OSQLSynchQuery("MATCH \n" + "{class: testMatched1_Foo, as: foo, where: (name != $matched.baz.name)}.out('testMatched1_Foo_Bar') {as: bar, where: (name != $matched.foo.name)}, \n" + "{class: testMatched1_Bar,as: bar}.out('testMatched1_Bar_Baz') {as: baz, where: (name != $matched.far.name)}, \n" + "{class: testMatched1_Foo,as: foo}.out('testMatched1_Foo_Far') {where: (name != $matched.baz.name),as: far}\n" + "RETURN $matches"));
fail();
} catch (OCommandExecutionException x) {
}
}
Aggregations