@Test public void testGraphQueryIn() { String namePropertyName = "full.name"; graph.defineProperty("age").dataType(Integer.class).sortable(true).define(); graph.defineProperty(namePropertyName).dataType(String.class).sortable(true).textIndexHint(TextIndexHint.ALL).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty(namePropertyName, "joe ferner", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty(namePropertyName, "bob smith", VISIBILITY_B) .setProperty("age", 25, VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v3", VISIBILITY_A) .setProperty(namePropertyName, "tom thumb", VISIBILITY_A) .setProperty("age", 30, VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); List<String> strings = new ArrayList<>(); strings.add("joe ferner"); strings.add("tom thumb"); Iterable<Vertex> results = graph.query(AUTHORIZATIONS_A_AND_B).has(namePropertyName, Contains.IN, strings).vertices(); assertEquals(2, ((IterableWithTotalHits) results).getTotalHits()); assertVertexIdsAnyOrder(results, "v1", "v3"); }
@Test public void testGraphQueryIn() { String namePropertyName = "full.name"; graph.defineProperty("age").dataType(Integer.class).sortable(true).define(); graph.defineProperty(namePropertyName).dataType(String.class).sortable(true).textIndexHint(TextIndexHint.ALL).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty(namePropertyName, "joe ferner", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty(namePropertyName, "bob smith", VISIBILITY_B) .setProperty("age", 25, VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v3", VISIBILITY_A) .setProperty(namePropertyName, "tom thumb", VISIBILITY_A) .setProperty("age", 30, VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); List<String> strings = new ArrayList<>(); strings.add("joe ferner"); strings.add("tom thumb"); Iterable<Vertex> results = graph.query(AUTHORIZATIONS_A_AND_B).has(namePropertyName, Contains.IN, strings).vertices(); assertEquals(2, ((IterableWithTotalHits) results).getTotalHits()); assertVertexIdsAnyOrder(results, "v1", "v3"); }
) { if (!graph.isPropertyDefined(propertyName)) { DefinePropertyBuilder builder = graph.defineProperty(propertyName).dataType(dataType).sortable(sortable); if (textIndexHint != null) { builder.textIndexHint(textIndexHint);
@Test public void testGraphQuerySortOnPropertyThatHasNoValuesInTheIndex() { graph.defineProperty("age").dataType(Integer.class).sortable(true).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("name", "joe", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("name", "bob", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); QueryResultsIterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A).sort("age", SortDirection.ASCENDING).vertices(); Assert.assertEquals(2, count(vertices)); }
@Test public void testGraphQuerySortOnPropertyThatHasNoValuesInTheIndex() { graph.defineProperty("age").dataType(Integer.class).sortable(true).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("name", "joe", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("name", "bob", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); QueryResultsIterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A).sort("age", SortDirection.ASCENDING).vertices(); Assert.assertEquals(2, count(vertices)); }
graph.defineProperty("prop1") .dataType(String.class) .sortable(true) .textIndexHint(TextIndexHint.NONE) .define();
graph.defineProperty("prop1") .dataType(String.class) .sortable(true) .textIndexHint(TextIndexHint.NONE) .define();
@Test public void testExtendedDataQueryVerticesAfterVisibilityChange() { String nameColumnName = "name.column"; String tableName = "table.one"; String rowOneName = "row.one"; String rowTwoName = "row.two"; graph.defineProperty(nameColumnName).sortable(true).textIndexHint(TextIndexHint.values()).dataType(String.class).define(); graph.prepareVertex("v1", VISIBILITY_A) .addExtendedData(tableName, rowOneName, nameColumnName, "value 1", VISIBILITY_A) .addExtendedData(tableName, rowTwoName, nameColumnName, "value 2", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.prepareVertex("v2", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); QueryResultsIterable<? extends VertexiumObject> searchResults = graph.query("value", AUTHORIZATIONS_A) .search(); assertResultsCount(2, 2, searchResults); assertRowIdsAnyOrder(Lists.newArrayList(rowOneName, rowTwoName), searchResults); graph.createAuthorizations(AUTHORIZATIONS_A_AND_B); graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A) .prepareMutation() .alterElementVisibility(VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); searchResults = graph.query("value", AUTHORIZATIONS_A) .search(); assertResultsCount(0, 0, searchResults); }
@Test public void testExtendedDataQueryVerticesAfterVisibilityChange() { String nameColumnName = "name.column"; String tableName = "table.one"; String rowOneName = "row.one"; String rowTwoName = "row.two"; graph.defineProperty(nameColumnName).sortable(true).textIndexHint(TextIndexHint.values()).dataType(String.class).define(); graph.prepareVertex("v1", VISIBILITY_A) .addExtendedData(tableName, rowOneName, nameColumnName, "value 1", VISIBILITY_A) .addExtendedData(tableName, rowTwoName, nameColumnName, "value 2", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.prepareVertex("v2", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); QueryResultsIterable<? extends VertexiumObject> searchResults = graph.query("value", AUTHORIZATIONS_A) .search(); assertResultsCount(2, 2, searchResults); assertRowIdsAnyOrder(Lists.newArrayList(rowOneName, rowTwoName), searchResults); graph.createAuthorizations(AUTHORIZATIONS_A_AND_B); graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A) .prepareMutation() .alterElementVisibility(VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); searchResults = graph.query("value", AUTHORIZATIONS_A) .search(); assertResultsCount(0, 0, searchResults); }
@Test public void testGraphQuerySortOnPropertyWhichIsFullTextAndExactMatchIndexed() { graph.defineProperty("name") .dataType(String.class) .sortable(true) .textIndexHint(TextIndexHint.EXACT_MATCH, TextIndexHint.FULL_TEXT) .define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("name", "1-2", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("name", "1-1", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v3", VISIBILITY_A) .setProperty("name", "3-1", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); QueryResultsIterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A_AND_B).sort("name", SortDirection.ASCENDING).vertices(); assertVertexIds(vertices, "v2", "v1", "v3"); vertices = graph.query("3", AUTHORIZATIONS_A_AND_B).vertices(); assertVertexIds(vertices, "v3"); vertices = graph.query("*", AUTHORIZATIONS_A_AND_B) .has("name", Compare.EQUAL, "3-1") .vertices(); assertVertexIds(vertices, "v3"); }
@Test public void testGraphQuerySortOnPropertyWhichIsFullTextAndExactMatchIndexed() { graph.defineProperty("name") .dataType(String.class) .sortable(true) .textIndexHint(TextIndexHint.EXACT_MATCH, TextIndexHint.FULL_TEXT) .define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("name", "1-2", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("name", "1-1", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v3", VISIBILITY_A) .setProperty("name", "3-1", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); QueryResultsIterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A_AND_B).sort("name", SortDirection.ASCENDING).vertices(); assertVertexIds(vertices, "v2", "v1", "v3"); vertices = graph.query("3", AUTHORIZATIONS_A_AND_B).vertices(); assertVertexIds(vertices, "v3"); vertices = graph.query("*", AUTHORIZATIONS_A_AND_B) .has("name", Compare.EQUAL, "3-1") .vertices(); assertVertexIds(vertices, "v3"); }
@Test public void testGraphQueryPagingForUniqueIdsSortedOrder() { String namePropertyName = "first.name"; graph.defineProperty(namePropertyName).dataType(String.class).sortable(true).textIndexHint(TextIndexHint.ALL).define();
@Test public void testGraphQueryPagingForUniqueIdsSortedOrder() { String namePropertyName = "first.name"; graph.defineProperty(namePropertyName).dataType(String.class).sortable(true).textIndexHint(TextIndexHint.ALL).define();
Graph graph2 = AccumuloGraph.create(new AccumuloGraphConfiguration(getAccumuloResource().createConfig())); graph1.defineProperty("p1").dataType(String.class).sortable(true).textIndexHint(TextIndexHint.ALL).define(); assertTrue(graph2.getPropertyDefinition("p1").isSortable()); graph2.defineProperty("p1").dataType(String.class).sortable(false).textIndexHint(TextIndexHint.ALL).define(); assertFalse(graph2.getPropertyDefinition("p1").isSortable());
@Test public void testAddValuesToExistingProperties() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); graph.defineProperty("p1").dataType(String.class).sortable(true).textIndexHint(TextIndexHint.ALL).define(); v1.addPropertyValue("k1", "p1", "val1", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val1").vertexIds(), "v1"); v1.addPropertyValue("k2", "p1", "val2", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val1").vertexIds(), "v1"); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val2").vertexIds(), "v1"); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val3").vertexIds()); v1.addPropertyValue("k1", "p1", "val3", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val3").vertexIds(), "v1"); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val2").vertexIds(), "v1"); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val1").vertexIds()); }
@Test public void testAddValuesToExistingProperties() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); graph.defineProperty("p1").dataType(String.class).sortable(true).textIndexHint(TextIndexHint.ALL).define(); v1.addPropertyValue("k1", "p1", "val1", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val1").vertexIds(), "v1"); v1.addPropertyValue("k2", "p1", "val2", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val1").vertexIds(), "v1"); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val2").vertexIds(), "v1"); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val3").vertexIds()); v1.addPropertyValue("k1", "p1", "val3", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val3").vertexIds(), "v1"); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val2").vertexIds(), "v1"); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val1").vertexIds()); }
@Test public void testRemoveValuesFromMultivalueProperties() { graph.defineProperty("p1").dataType(String.class).sortable(true).textIndexHint(TextIndexHint.ALL).define(); Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("k1", "p1", "v1", VISIBILITY_A) .addPropertyValue("k2", "p1", "v2", VISIBILITY_A) .save(AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v1").vertexIds(), "v1"); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v2").vertexIds(), "v1"); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v3").vertexIds()); v1.prepareMutation() .addPropertyValue("k3", "p1", "v3", VISIBILITY_A) .deleteProperty("k1", "p1", VISIBILITY_A) .save(AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v2").vertexIds(), "v1"); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v3").vertexIds(), "v1"); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v1").vertexIds()); v1.deleteProperty("k2", "p1", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v3").vertexIds(), "v1"); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v1").vertexIds()); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v2").vertexIds()); }
@Test public void testRemoveValuesFromMultivalueProperties() { graph.defineProperty("p1").dataType(String.class).sortable(true).textIndexHint(TextIndexHint.ALL).define(); Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("k1", "p1", "v1", VISIBILITY_A) .addPropertyValue("k2", "p1", "v2", VISIBILITY_A) .save(AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v1").vertexIds(), "v1"); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v2").vertexIds(), "v1"); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v3").vertexIds()); v1.prepareMutation() .addPropertyValue("k3", "p1", "v3", VISIBILITY_A) .deleteProperty("k1", "p1", VISIBILITY_A) .save(AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v2").vertexIds(), "v1"); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v3").vertexIds(), "v1"); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v1").vertexIds()); v1.deleteProperty("k2", "p1", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v3").vertexIds(), "v1"); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v1").vertexIds()); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v2").vertexIds()); }