Hi,
I have a query similar to the following in Orient 2.0.12:
SELECT out()[group=:group]
FROM Person
I execute it from Java, with the following method over ODatabaseDocumentTx:
db.query(query, paramsMap);
It seems that parameters can't be used inside square brackets, as you can
see also in the attached UnitTest.
I think this is a bug, can you fix it in 2.0.13 release?
Otherwise can you help me obtaining the same results without this syntax?
Cheers,
Riccardo
--
---
You received this message because you are subscribed to the Google Groups
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
package it.celi.cbook.temp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hamcrest.Matchers;
import org.junit.Test;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.tinkerpop.blueprints.impls.orient.OrientGraphFactory;
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
import com.tinkerpop.blueprints.impls.orient.OrientVertex;
/**
* @author rayman
*/
public class OrientFilterParameterTest {
@Test
public void test() {
OrientGraphFactory gf = new OrientGraphFactory("memory:temp");
OrientGraphNoTx graph = gf.getNoTx();
graph.createVertexType("A");
graph.createVertexType("B");
graph.createVertexType("C");
OrientVertex a1 = graph.addVertex("class:A");
a1.setProperty("name", "a1");
assertEquals(1, graph.countVertices("A"));
OrientVertex b1 = graph.addVertex("class:B");
b1.setProperty("name", "b1");
assertEquals(1, graph.countVertices("B"));
OrientVertex c1 = graph.addVertex("class:C");
c1.setProperty("name", "c1");
OrientVertex c2 = graph.addVertex("class:C");
c2.setProperty("name", "c2");
assertEquals(2, graph.countVertices("C"));
graph.addEdge(null, b1, a1, "link");
graph.addEdge(null, c1, a1, "link");
graph.addEdge(null, c2, a1, "link");
// ONE //
List<ODocument> results = graph.getRawGraph().query(new OSQLSynchQuery<OrientVertex>("SELECT in('link') as inLink FROM A"));
assertThat(results.size(), Matchers.equalTo(1));
ODocument result = results.get(0);
assertThat(result.containsField("inLink"), Matchers.is(true));
List<Object> inLink = cast(result.field("inLink"));
assertThat(inLink.size(), Matchers.equalTo(3));
// TWO //
results = graph.getRawGraph().query(new OSQLSynchQuery<OrientVertex>("SELECT in('link')[name='b1'] as inLink FROM A"));
assertThat(results.size(), Matchers.equalTo(1));
result = results.get(0);
assertThat(result.containsField("inLink"), Matchers.is(true));
inLink = cast(result.field("inLink"));
assertThat(inLink.size(), Matchers.equalTo(1));
// THREE //
results = graph.getRawGraph().query(new OSQLSynchQuery<OrientVertex>("SELECT in('link')[name='x1'] as inLink FROM A"));
assertThat(results.size(), Matchers.equalTo(1));
result = results.get(0);
assertThat(result.containsField("inLink"), Matchers.is(true));
inLink = cast(result.field("inLink"));
for(Object link : inLink)
System.out.println(link);
assertThat(inLink.size(), Matchers.equalTo(0));
// FOUR //
Map<String, Object> params = new HashMap<>();
params.put("param", "b1");
results = graph.getRawGraph().query(new OSQLSynchQuery<OrientVertex>("SELECT in('link')[name = :param] as inLink FROM A"), params);
assertThat(results.size(), Matchers.equalTo(1));
result = results.get(0);
assertThat(result.containsField("inLink"), Matchers.is(true));
inLink = cast(result.field("inLink"));
for(Object link : inLink)
System.out.println(link);
assertThat(inLink.size(), Matchers.equalTo(1));
graph.shutdown();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private List<Object> cast(Object value) {
List<Object> list = new ArrayList<Object>();
if(value == null) {
return list;
} else if(value instanceof Collection) {
list.addAll((Collection) value);
} else {
list.add(value);
}
return list;
}
}