private void benchmarkAddVertices(int vertexCount) { double startTime = System.currentTimeMillis(); for (int i = 0; i < vertexCount; i++) { String vertexId = "v" + i; graph.prepareVertex(vertexId, VISIBILITY_A) .addPropertyValue("k1", "prop1", "value1 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop2", "value2 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop3", "value3 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop4", "value4 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop5", "value5 " + i, VISIBILITY_A) .save(AUTHORIZATIONS_ALL); } graph.flush(); double endTime = System.currentTimeMillis(); LOGGER.info("add vertices in %.3fs", (endTime - startTime) / 1000); }
/** * Sets or updates a property value. The property key will be set to a constant. This is a convenience method * which allows treating the multi-valued nature of properties as only containing a single value. Care must be * taken when using this method because properties are not only uniquely identified by just key and name but also * visibility so adding properties with the same name and different visibility strings is still permitted. * <p> * The added property will also be indexed in the configured search provider. The type of the value * will determine how it gets indexed. * * @param name The name of the property. * @param value The value of the property. * @param visibility The visibility to give this property. */ public ElementBuilder<T> setProperty(String name, Object value, Visibility visibility) { return setProperty(name, value, Metadata.create(FetchHints.ALL), visibility); }
@Override public ElementBuilder<T> addExtendedData(String tableName, String row, String column, Object value, Visibility visibility) { return addExtendedData(tableName, row, column, null, value, visibility); }
@Test public void testConcurrentModificationOfProperties() { Vertex v = graph.prepareVertex("v1", VISIBILITY_EMPTY) .setProperty("prop1", "value1", VISIBILITY_A) .setProperty("prop2", "value2", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); int i = 0; for (Property p : v.getProperties()) { assertNotNull(p.toString()); if (i == 0) { v.setProperty("prop3", "value3", VISIBILITY_A, AUTHORIZATIONS_A_AND_B); } i++; } }
@Override public Iterable<Vertex> addVertices(Iterable<ElementBuilder<Vertex>> vertices, Authorizations authorizations) { List<Vertex> addedVertices = new ArrayList<>(); for (ElementBuilder<Vertex> vertexBuilder : vertices) { addedVertices.add(vertexBuilder.save(authorizations)); } return addedVertices; }
@Test public void testVertexQueryWithNestedTermsAggregationOnExtendedData() { graph.defineProperty("name").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH, TextIndexHint.FULL_TEXT).define(); graph.defineProperty("gender").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define(); graph.prepareVertex("v1", VISIBILITY_EMPTY) .addExtendedData("t1", "r1", "name", "Joe", VISIBILITY_EMPTY) .addExtendedData("t1", "r1", "gender", "male", VISIBILITY_EMPTY) .addExtendedData("t1", "r2", "name", "Sam", VISIBILITY_EMPTY) .addExtendedData("t1", "r2", "gender", "male", VISIBILITY_EMPTY) .addExtendedData("t1", "r3", "name", "Sam", VISIBILITY_EMPTY) .addExtendedData("t1", "r3", "gender", "female", VISIBILITY_EMPTY) .addExtendedData("t1", "r4", "name", "Sam", VISIBILITY_EMPTY) .addExtendedData("t1", "r4", "gender", "female", VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B); Query q = v1.getExtendedData("t1").query(AUTHORIZATIONS_A_AND_B).limit(0); TermsAggregation agg = new TermsAggregation("terms-count", "name"); agg.addNestedAggregation(new TermsAggregation("nested", "gender")); assumeTrue("terms aggregation not supported", q.isAggregationSupported(agg)); q.addAggregation(agg); TermsResult aggregationResult = q.extendedDataRows().getAggregationResult("terms-count", TermsResult.class); Map<Object, Map<Object, Long>> vertexPropertyCountByValue = nestedTermsBucketToMap(aggregationResult.getBuckets(), "nested"); assertEquals(2, vertexPropertyCountByValue.size()); assertEquals(1, vertexPropertyCountByValue.get("Joe").size()); assertEquals(1L, (long) vertexPropertyCountByValue.get("Joe").get("male")); assertEquals(2, vertexPropertyCountByValue.get("Sam").size()); assertEquals(1L, (long) vertexPropertyCountByValue.get("Sam").get("male")); assertEquals(2L, (long) vertexPropertyCountByValue.get("Sam").get("female")); }
@Test public void testGraphQueryHasTwoVisibilities() { String agePropertyName = "age.property"; graph.prepareVertex("v1", VISIBILITY_A) .setProperty("name", "v1", VISIBILITY_A) .setProperty(agePropertyName, 25, VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("name", "v2", VISIBILITY_A) .addPropertyValue("k1", agePropertyName, 30, VISIBILITY_A) .addPropertyValue("k2", agePropertyName, 35, VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v3", VISIBILITY_A) .setProperty("name", "v3", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Iterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A_AND_B) .has(agePropertyName) .vertices(); Assert.assertEquals(2, count(vertices)); vertices = graph.query(AUTHORIZATIONS_A_AND_B) .hasNot(agePropertyName) .vertices(); Assert.assertEquals(1, count(vertices)); }
/** * Adds or updates a property. * <p> * The added property will also be indexed in the configured search provider. The type of the value * will determine how it gets indexed. * * @param key The unique key given to the property allowing for multi-valued properties. * @param name The name of the property. * @param value The value of the property. * @param metadata The metadata to assign to this property. * @param visibility The visibility to give this property. */ public ElementBuilder<T> addPropertyValue(String key, String name, Object value, Metadata metadata, Visibility visibility) { return addPropertyValue(key, name, value, metadata, null, visibility); }
@Override public ElementBuilder<T> deleteExtendedData(String tableName, String row, String column, Visibility visibility) { return deleteExtendedData(tableName, row, column, null, visibility); }
@Test public void testConcurrentModificationOfProperties() { Vertex v = graph.prepareVertex("v1", VISIBILITY_EMPTY) .setProperty("prop1", "value1", VISIBILITY_A) .setProperty("prop2", "value2", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); int i = 0; for (Property p : v.getProperties()) { assertNotNull(p.toString()); if (i == 0) { v.setProperty("prop3", "value3", VISIBILITY_A, AUTHORIZATIONS_A_AND_B); } i++; } }
@Override public Iterable<Vertex> addVertices(Iterable<ElementBuilder<Vertex>> vertices, Authorizations authorizations) { List<Vertex> addedVertices = new ArrayList<>(); for (ElementBuilder<Vertex> vertexBuilder : vertices) { addedVertices.add(vertexBuilder.save(authorizations)); } return addedVertices; }
@Test public void testVertexQueryWithNestedTermsAggregationOnExtendedData() { graph.defineProperty("name").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH, TextIndexHint.FULL_TEXT).define(); graph.defineProperty("gender").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define(); graph.prepareVertex("v1", VISIBILITY_EMPTY) .addExtendedData("t1", "r1", "name", "Joe", VISIBILITY_EMPTY) .addExtendedData("t1", "r1", "gender", "male", VISIBILITY_EMPTY) .addExtendedData("t1", "r2", "name", "Sam", VISIBILITY_EMPTY) .addExtendedData("t1", "r2", "gender", "male", VISIBILITY_EMPTY) .addExtendedData("t1", "r3", "name", "Sam", VISIBILITY_EMPTY) .addExtendedData("t1", "r3", "gender", "female", VISIBILITY_EMPTY) .addExtendedData("t1", "r4", "name", "Sam", VISIBILITY_EMPTY) .addExtendedData("t1", "r4", "gender", "female", VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B); Query q = v1.getExtendedData("t1").query(AUTHORIZATIONS_A_AND_B).limit(0); TermsAggregation agg = new TermsAggregation("terms-count", "name"); agg.addNestedAggregation(new TermsAggregation("nested", "gender")); assumeTrue("terms aggregation not supported", q.isAggregationSupported(agg)); q.addAggregation(agg); TermsResult aggregationResult = q.extendedDataRows().getAggregationResult("terms-count", TermsResult.class); Map<Object, Map<Object, Long>> vertexPropertyCountByValue = nestedTermsBucketToMap(aggregationResult.getBuckets(), "nested"); assertEquals(2, vertexPropertyCountByValue.size()); assertEquals(1, vertexPropertyCountByValue.get("Joe").size()); assertEquals(1L, (long) vertexPropertyCountByValue.get("Joe").get("male")); assertEquals(2, vertexPropertyCountByValue.get("Sam").size()); assertEquals(1L, (long) vertexPropertyCountByValue.get("Sam").get("male")); assertEquals(2L, (long) vertexPropertyCountByValue.get("Sam").get("female")); }
@Test public void testGraphQueryHasTwoVisibilities() { String agePropertyName = "age.property"; graph.prepareVertex("v1", VISIBILITY_A) .setProperty("name", "v1", VISIBILITY_A) .setProperty(agePropertyName, 25, VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("name", "v2", VISIBILITY_A) .addPropertyValue("k1", agePropertyName, 30, VISIBILITY_A) .addPropertyValue("k2", agePropertyName, 35, VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v3", VISIBILITY_A) .setProperty("name", "v3", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Iterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A_AND_B) .has(agePropertyName) .vertices(); Assert.assertEquals(2, count(vertices)); vertices = graph.query(AUTHORIZATIONS_A_AND_B) .hasNot(agePropertyName) .vertices(); Assert.assertEquals(1, count(vertices)); }
/** * Adds or updates a property. * <p> * The added property will also be indexed in the configured search provider. The type of the value * will determine how it gets indexed. * * @param key The unique key given to the property allowing for multi-valued properties. * @param name The name of the property. * @param value The value of the property. * @param metadata The metadata to assign to this property. * @param visibility The visibility to give this property. */ public ElementBuilder<T> addPropertyValue(String key, String name, Object value, Metadata metadata, Visibility visibility) { return addPropertyValue(key, name, value, metadata, null, visibility); }
@Override public ElementBuilder<T> deleteExtendedData(String tableName, String row, String column, Visibility visibility) { return deleteExtendedData(tableName, row, column, null, visibility); }
@Test public void testPartialUpdateOfVertex() { graph.prepareVertex("v1", VISIBILITY_A) .setProperty("prop1", "value1", VISIBILITY_A) .setProperty("prop2", "value2", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("prop1", "value1New", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Iterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A_AND_B) .has("prop2", "value2") .vertices(); assertVertexIds(vertices, "v1"); }
private void benchmarkAddVertices(int vertexCount) { double startTime = System.currentTimeMillis(); for (int i = 0; i < vertexCount; i++) { String vertexId = "v" + i; graph.prepareVertex(vertexId, VISIBILITY_A) .addPropertyValue("k1", "prop1", "value1 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop2", "value2 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop3", "value3 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop4", "value4 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop5", "value5 " + i, VISIBILITY_A) .save(AUTHORIZATIONS_ALL); } graph.flush(); double endTime = System.currentTimeMillis(); LOGGER.info("add vertices in %.3fs", (endTime - startTime) / 1000); }
@Test public void testNullPropertyValue() { try { graph.prepareVertex("v1", VISIBILITY_EMPTY) .setProperty("prop1", null, VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); throw new VertexiumException("expected null check"); } catch (NullPointerException ex) { assertTrue(ex.getMessage().contains("prop1")); } }
@Test public void testExtendedDataQueryAfterDeleteForVertex() { graph.prepareVertex("v1", VISIBILITY_A) .addExtendedData("table1", "row1", "name", "value 1", VISIBILITY_A) .addExtendedData("table1", "row2", "name", "value 2", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); List<ExtendedDataRow> searchResultsList = toList(graph.query(AUTHORIZATIONS_A).extendedDataRows()); assertRowIdsAnyOrder(Lists.newArrayList("row1", "row2"), searchResultsList); graph.deleteVertex("v1", AUTHORIZATIONS_A); graph.flush(); searchResultsList = toList(graph.query(AUTHORIZATIONS_A).extendedDataRows()); assertRowIdsAnyOrder(Lists.newArrayList(), searchResultsList); }
/** * Sets or updates a property value. The property key will be set to a constant. This is a convenience method * which allows treating the multi-valued nature of properties as only containing a single value. Care must be * taken when using this method because properties are not only uniquely identified by just key and name but also * visibility so adding properties with the same name and different visibility strings is still permitted. * <p> * The added property will also be indexed in the configured search provider. The type of the value * will determine how it gets indexed. * * @param name The name of the property. * @param value The value of the property. * @param metadata The metadata to assign to this property. * @param visibility The visibility to give this property. */ public ElementBuilder<T> setProperty(String name, Object value, Metadata metadata, Visibility visibility) { return addPropertyValue(ElementMutation.DEFAULT_KEY, name, value, metadata, visibility); }