use of org.neo4j.driver.Record in project zeppelin by apache.
the class Neo4jCypherInterpreter method runQuery.
private InterpreterResult runQuery(String cypherQuery, InterpreterContext interpreterContext) {
if (StringUtils.isBlank(cypherQuery)) {
return new InterpreterResult(Code.SUCCESS);
}
try {
Iterator<Record> result = this.neo4jConnectionManager.execute(cypherQuery, interpreterContext).iterator();
Set<Node> nodes = new HashSet<>();
Set<Relationship> relationships = new HashSet<>();
List<String> columns = new ArrayList<>();
List<List<String>> lines = new ArrayList<List<String>>();
while (result.hasNext()) {
Record record = result.next();
List<Pair<String, Value>> fields = record.fields();
List<String> line = new ArrayList<>();
for (Pair<String, Value> field : fields) {
if (field.value().hasType(InternalTypeSystem.TYPE_SYSTEM.NODE())) {
nodes.add(field.value().asNode());
} else if (field.value().hasType(InternalTypeSystem.TYPE_SYSTEM.RELATIONSHIP())) {
relationships.add(field.value().asRelationship());
} else if (field.value().hasType(InternalTypeSystem.TYPE_SYSTEM.PATH())) {
nodes.addAll(Iterables.asList(field.value().asPath().nodes()));
relationships.addAll(Iterables.asList(field.value().asPath().relationships()));
} else {
setTabularResult(field.key(), field.value(), columns, line, InternalTypeSystem.TYPE_SYSTEM);
}
}
if (!line.isEmpty()) {
lines.add(line);
}
}
if (!nodes.isEmpty()) {
return renderGraph(nodes, relationships);
} else {
return renderTable(columns, lines);
}
} catch (Exception e) {
LOGGER.error("Exception while interpreting cypher query", e);
return new InterpreterResult(Code.ERROR, e.getMessage());
}
}
use of org.neo4j.driver.Record in project zeppelin by apache.
the class Neo4jCypherInterpreter method getLabels.
public Map<String, String> getLabels(boolean refresh) {
if (labels == null || refresh) {
Map<String, String> old = labels == null ? new LinkedHashMap<>() : new LinkedHashMap<>(labels);
labels = new LinkedHashMap<>();
Iterator<Record> result = this.neo4jConnectionManager.execute("CALL db.labels()").iterator();
Set<String> colors = new HashSet<>();
while (result.hasNext()) {
Record record = result.next();
String label = record.get("label").asString();
String color = old.get(label);
while (color == null || colors.contains(color)) {
color = Neo4jConversionUtils.getRandomLabelColor();
}
colors.add(color);
labels.put(label, color);
}
}
return labels;
}
use of org.neo4j.driver.Record in project zeppelin by apache.
the class Neo4jCypherInterpreter method getTypes.
private Set<String> getTypes(boolean refresh) {
if (types == null || refresh) {
types = new HashSet<>();
Iterator<Record> result = this.neo4jConnectionManager.execute("CALL db.relationshipTypes()").iterator();
while (result.hasNext()) {
Record record = result.next();
types.add(record.get("relationshipType").asString());
}
}
return types;
}
use of org.neo4j.driver.Record in project spring-boot by spring-projects.
the class Neo4jHealthIndicator method runHealthCheckQuery.
private void runHealthCheckQuery(Health.Builder builder) {
// all possible workloads
try (Session session = this.driver.session(DEFAULT_SESSION_CONFIG)) {
Result result = session.run(CYPHER);
Record record = result.single();
ResultSummary resultSummary = result.consume();
this.healthDetailsHandler.addHealthDetails(builder, new Neo4jHealthDetails(record, resultSummary));
}
}
use of org.neo4j.driver.Record in project neo4j by neo4j.
the class CypherShellTest method setParamShouldAddParamWithSpecialCharactersAndValue.
@Test
public void setParamShouldAddParamWithSpecialCharactersAndValue() throws ParameterException, CommandException {
Value value = mock(Value.class);
Record recordMock = mock(Record.class);
BoltResult boltResult = new ListBoltResult(asList(recordMock), mock(ResultSummary.class));
when(mockedBoltStateHandler.runCypher(anyString(), anyMap())).thenReturn(Optional.of(boltResult));
when(recordMock.get("bo`b")).thenReturn(value);
when(value.asObject()).thenReturn("99");
assertTrue(offlineTestShell.getParameterMap().allParameterValues().isEmpty());
Object result = offlineTestShell.getParameterMap().setParameter("`bo``b`", "99");
assertEquals(99L, result);
assertEquals(99L, offlineTestShell.getParameterMap().allParameterValues().get("bo`b"));
}
Aggregations