use of org.neo4j.driver.Record in project beam by apache.
the class Neo4jIOIT method testWriteUnwind.
@Test
public void testWriteUnwind() throws Exception {
PCollection<String> stringsCollections = writeUnwindPipeline.apply(Create.of(Arrays.asList("one", "two", "three")));
// Every row is represented by a Map<String, Object> in the parameters map.
// We accumulate the rows and 'unwind' those to Neo4j for performance reasons.
//
SerializableFunction<String, Map<String, Object>> parametersMapper = name -> Collections.singletonMap("name", name);
Neo4jIO.WriteUnwind<String> read = Neo4jIO.<String>writeUnwind().withDriverConfiguration(Neo4jTestUtil.getDriverConfiguration(containerHostname, containerPort)).withSessionConfig(SessionConfig.forDatabase(Neo4jTestUtil.NEO4J_DATABASE)).withBatchSize(5000).withUnwindMapName("rows").withCypher("UNWIND $rows AS row MERGE(n:Num { name : row.name })").withParametersFunction(parametersMapper).withCypherLogging();
stringsCollections.apply(read);
// Now run this pipeline
//
PipelineResult pipelineResult = writeUnwindPipeline.run();
Assert.assertEquals(PipelineResult.State.DONE, pipelineResult.getState());
//
try (Driver driver = Neo4jTestUtil.getDriver(containerHostname, containerPort)) {
try (Session session = Neo4jTestUtil.getSession(driver, true)) {
List<String> names = session.readTransaction(tx -> {
List<String> list = new ArrayList<>();
Result result = tx.run("MATCH(n:Num) RETURN n.name");
while (result.hasNext()) {
Record record = result.next();
list.add(record.get(0).asString());
}
return list;
});
assertThat(names, containsInAnyOrder("one", "two", "three"));
}
}
}
use of org.neo4j.driver.Record in project beam by apache.
the class Neo4jIOIT method testParameterizedRead.
@Test
public void testParameterizedRead() throws Exception {
PCollection<String> stringsCollections = parameterizedReadPipeline.apply(Create.of(Arrays.asList("one", "two", "three")));
final Schema outputSchema = Schema.of(Schema.Field.of("One", Schema.FieldType.INT32), Schema.Field.of("Str", Schema.FieldType.STRING));
SerializableFunction<String, Map<String, Object>> parametersFunction = string -> Collections.singletonMap("par1", string);
Neo4jIO.RowMapper<Row> rowMapper = record -> {
int one = record.get(0).asInt();
String string = record.get(1).asString();
return Row.withSchema(outputSchema).attachValues(one, string);
};
Neo4jIO.ReadAll<String, Row> read = Neo4jIO.<String, Row>readAll().withCypher("RETURN 1, $par1").withDriverConfiguration(Neo4jTestUtil.getDriverConfiguration(containerHostname, containerPort)).withSessionConfig(SessionConfig.forDatabase(Neo4jTestUtil.NEO4J_DATABASE)).withRowMapper(rowMapper).withParametersFunction(parametersFunction).withCoder(SerializableCoder.of(Row.class)).withCypherLogging();
PCollection<Row> outputRows = stringsCollections.apply(read);
PCollection<String> outputLines = outputRows.apply(ParDo.of(new ParameterizedReadRowToLineFn()));
PAssert.that(outputLines).containsInAnyOrder("1,one", "1,two", "1,three");
// Now run this pipeline
//
PipelineResult pipelineResult = parameterizedReadPipeline.run();
Assert.assertEquals(PipelineResult.State.DONE, pipelineResult.getState());
}
use of org.neo4j.driver.Record in project jmeter by apache.
the class BoltSampler method response.
private String response(Result result) {
StringBuilder response = new StringBuilder();
List<Record> records;
if (isRecordQueryResults()) {
// get records already as consume() will exhaust the stream
records = result.list();
} else {
records = Collections.emptyList();
}
response.append("\nSummary:");
ResultSummary summary = result.consume();
response.append("\nConstraints Added: ").append(summary.counters().constraintsAdded()).append("\nConstraints Removed: ").append(summary.counters().constraintsRemoved()).append("\nContains Updates: ").append(summary.counters().containsUpdates()).append("\nIndexes Added: ").append(summary.counters().indexesAdded()).append("\nIndexes Removed: ").append(summary.counters().indexesRemoved()).append("\nLabels Added: ").append(summary.counters().labelsAdded()).append("\nLabels Removed: ").append(summary.counters().labelsRemoved()).append("\nNodes Created: ").append(summary.counters().nodesCreated()).append("\nNodes Deleted: ").append(summary.counters().nodesDeleted()).append("\nRelationships Created: ").append(summary.counters().relationshipsCreated()).append("\nRelationships Deleted: ").append(summary.counters().relationshipsDeleted());
response.append("\n\nRecords: ");
if (isRecordQueryResults()) {
for (Record record : records) {
response.append("\n").append(record);
}
} else {
response.append("Skipped");
result.consume();
}
return response.toString();
}
use of org.neo4j.driver.Record in project spring-boot by spring-projects.
the class Neo4jReactiveHealthIndicatorTests method mockStatementResult.
private RxResult mockStatementResult(ResultSummary resultSummary, String version, String edition) {
Record record = mock(Record.class);
given(record.get("edition")).willReturn(Values.value(edition));
given(record.get("version")).willReturn(Values.value(version));
RxResult statementResult = mock(RxResult.class);
given(statementResult.records()).willReturn(Mono.just(record));
given(statementResult.consume()).willReturn(Mono.just(resultSummary));
return statementResult;
}
use of org.neo4j.driver.Record in project spring-boot by spring-projects.
the class Neo4jHealthIndicatorTests method mockStatementResult.
private Result mockStatementResult(ResultSummary resultSummary, String version, String edition) {
Record record = mock(Record.class);
given(record.get("edition")).willReturn(Values.value(edition));
given(record.get("version")).willReturn(Values.value(version));
Result statementResult = mock(Result.class);
given(statementResult.single()).willReturn(record);
given(statementResult.consume()).willReturn(resultSummary);
return statementResult;
}
Aggregations