@Test public void testExtendedDataDifferentValue() { graph.prepareVertex("v1", VISIBILITY_A) .addExtendedData("table1", "row1", "name", "value1", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A); ArrayList<ExtendedDataRow> rows = Lists.newArrayList(v1.getExtendedData("table1")); assertEquals("value1", rows.get(0).getPropertyValue("name")); graph.prepareVertex("v1", VISIBILITY_A) .addExtendedData("table1", "row1", "name", "value2", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); v1 = graph.getVertex("v1", AUTHORIZATIONS_A); rows = Lists.newArrayList(v1.getExtendedData("table1")); assertEquals("value2", rows.get(0).getPropertyValue("name")); }
@Test public void testExtendedDataDifferentValue() { graph.prepareVertex("v1", VISIBILITY_A) .addExtendedData("table1", "row1", "name", "value1", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A); ArrayList<ExtendedDataRow> rows = Lists.newArrayList(v1.getExtendedData("table1")); assertEquals("value1", rows.get(0).getPropertyValue("name")); graph.prepareVertex("v1", VISIBILITY_A) .addExtendedData("table1", "row1", "name", "value2", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); v1 = graph.getVertex("v1", AUTHORIZATIONS_A); rows = Lists.newArrayList(v1.getExtendedData("table1")); assertEquals("value2", rows.get(0).getPropertyValue("name")); }
@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); }
@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); }
@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 testExtendedDataDelete() { graph.prepareVertex("v1", VISIBILITY_A) .addExtendedData("table1", "row1", "name", "value", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); graph.deleteVertex("v1", AUTHORIZATIONS_A); graph.flush(); QueryResultsIterable<? extends VertexiumObject> searchResults = graph.query("value", AUTHORIZATIONS_A) .search(); assertEquals(0, searchResults.getTotalHits()); }
@Test public void testExtendedDataDelete() { graph.prepareVertex("v1", VISIBILITY_A) .addExtendedData("table1", "row1", "name", "value", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); graph.deleteVertex("v1", AUTHORIZATIONS_A); graph.flush(); QueryResultsIterable<? extends VertexiumObject> searchResults = graph.query("value", AUTHORIZATIONS_A) .search(); assertEquals(0, searchResults.getTotalHits()); }
@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 testExtendedDataDeleteColumn() { graph.prepareVertex("v1", VISIBILITY_A) .addExtendedData("table1", "row1", "name", "value", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush();
@Test public void testExtendedDataDeleteColumn() { graph.prepareVertex("v1", VISIBILITY_A) .addExtendedData("table1", "row1", "name", "value", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush();
@Test public void testExtendedDataQueryWithMultiValue() { graph.prepareVertex("v1", VISIBILITY_A) .addExtendedData("table1", "row1", "col1", "key1", "joe", VISIBILITY_A) .addExtendedData("table1", "row1", "col1", "key2", "bob", VISIBILITY_A) .addExtendedData("table1", "row2", "col1", "key1", "joe", VISIBILITY_A)
@Test public void testExtendedDataQueryWithMultiValue() { graph.prepareVertex("v1", VISIBILITY_A) .addExtendedData("table1", "row1", "col1", "key1", "joe", VISIBILITY_A) .addExtendedData("table1", "row1", "col1", "key2", "bob", VISIBILITY_A) .addExtendedData("table1", "row2", "col1", "key1", "joe", VISIBILITY_A)
@Test public void testExtendedDataEdgeQuery() { 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.prepareVertex("v2", VISIBILITY_A) .addExtendedData("table1", "row3", "name", "value 1", VISIBILITY_A) .addExtendedData("table1", "row4", "name", "value 2", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.prepareEdge("e1", "v1", "v2", LABEL_LABEL1, VISIBILITY_A) .addExtendedData("table1", "row5", "name", "value 1", VISIBILITY_A) .addExtendedData("table1", "row6", "name", "value 2", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); Edge e1 = graph.getEdge("e1", AUTHORIZATIONS_A); List<ExtendedDataRow> searchResultsList = toList( getGraph().query("*", AUTHORIZATIONS_A) .hasExtendedData(ElementType.EDGE, e1.getId(), "table1") .extendedDataRows() ); assertRowIdsAnyOrder(Lists.newArrayList("row5", "row6"), searchResultsList); QueryResultsIterable<ExtendedDataRow> rows = graph.query(AUTHORIZATIONS_A).hasId("e1").extendedDataRows(); assertResultsCount(2, 2, rows); rows = graph.query(AUTHORIZATIONS_A).hasId("v1", "e1").extendedDataRows(); assertResultsCount(4, 4, rows); }
@Test public void testExtendedDataEdgeQuery() { 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.prepareVertex("v2", VISIBILITY_A) .addExtendedData("table1", "row3", "name", "value 1", VISIBILITY_A) .addExtendedData("table1", "row4", "name", "value 2", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.prepareEdge("e1", "v1", "v2", LABEL_LABEL1, VISIBILITY_A) .addExtendedData("table1", "row5", "name", "value 1", VISIBILITY_A) .addExtendedData("table1", "row6", "name", "value 2", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); Edge e1 = graph.getEdge("e1", AUTHORIZATIONS_A); List<ExtendedDataRow> searchResultsList = toList( getGraph().query("*", AUTHORIZATIONS_A) .hasExtendedData(ElementType.EDGE, e1.getId(), "table1") .extendedDataRows() ); assertRowIdsAnyOrder(Lists.newArrayList("row5", "row6"), searchResultsList); QueryResultsIterable<ExtendedDataRow> rows = graph.query(AUTHORIZATIONS_A).hasId("e1").extendedDataRows(); assertResultsCount(2, 2, rows); rows = graph.query(AUTHORIZATIONS_A).hasId("v1", "e1").extendedDataRows(); assertResultsCount(4, 4, rows); }
@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 testAddExtendedDataRows() { graph.prepareVertex("v1", VISIBILITY_A) .addExtendedData("table1", "row1", "name", "value1", VISIBILITY_A) .addExtendedData("table1", "row2", "name", "value2", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); if (graph instanceof GraphWithSearchIndex) { SearchIndex searchIndex = ((GraphWithSearchIndex) graph).getSearchIndex(); searchIndex.truncate(graph); searchIndex.flush(graph); Iterable<ExtendedDataRow> extendedData = graph.getExtendedData(ElementType.VERTEX, "v1", "table1", AUTHORIZATIONS_A); searchIndex.addExtendedData(graph, extendedData, AUTHORIZATIONS_A); graph.flush(); } QueryResultsIterable<ExtendedDataRow> rows = graph.query(AUTHORIZATIONS_A).extendedDataRows(); assertResultsCount(2, 2, rows); rows = graph.query(AUTHORIZATIONS_A) .has("name", "value1") .extendedDataRows(); assertResultsCount(1, 1, rows); ExtendedDataRow row = IterableUtils.single(rows); assertEquals("v1", row.getId().getElementId()); assertEquals("table1", row.getId().getTableName()); assertEquals("row1", row.getId().getRowId()); }
@Test public void testAddExtendedDataRows() { graph.prepareVertex("v1", VISIBILITY_A) .addExtendedData("table1", "row1", "name", "value1", VISIBILITY_A) .addExtendedData("table1", "row2", "name", "value2", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); if (graph instanceof GraphWithSearchIndex) { SearchIndex searchIndex = ((GraphWithSearchIndex) graph).getSearchIndex(); searchIndex.truncate(graph); searchIndex.flush(graph); Iterable<ExtendedDataRow> extendedData = graph.getExtendedData(ElementType.VERTEX, "v1", "table1", AUTHORIZATIONS_A); searchIndex.addExtendedData(graph, extendedData, AUTHORIZATIONS_A); graph.flush(); } QueryResultsIterable<ExtendedDataRow> rows = graph.query(AUTHORIZATIONS_A).extendedDataRows(); assertResultsCount(2, 2, rows); rows = graph.query(AUTHORIZATIONS_A) .has("name", "value1") .extendedDataRows(); assertResultsCount(1, 1, rows); ExtendedDataRow row = IterableUtils.single(rows); assertEquals("v1", row.getId().getElementId()); assertEquals("table1", row.getId().getTableName()); assertEquals("row1", row.getId().getRowId()); }
@Test public void testAddExtendedData() { graph.prepareVertex("v1", VISIBILITY_A) .addExtendedData("table1", "row1", "color", "red", VISIBILITY_A) .addExtendedData("table1", "row2", "color", "green", VISIBILITY_A) .save(AUTHORIZATIONS_A);
@Test public void testAddExtendedData() { graph.prepareVertex("v1", VISIBILITY_A) .addExtendedData("table1", "row1", "color", "red", VISIBILITY_A) .addExtendedData("table1", "row2", "color", "green", VISIBILITY_A) .save(AUTHORIZATIONS_A);