Search in sources :

Example 46 with GetElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.

the class OperationControllerTest method shouldReturnOptionsAndSummariesForEnumFields.

@Test
public void shouldReturnOptionsAndSummariesForEnumFields() throws Exception {
    // Given
    when(store.getSupportedOperations()).thenReturn(Sets.newHashSet(GetElements.class));
    when(examplesFactory.generateExample(GetElements.class)).thenReturn(new GetElements());
    // When
    OperationDetail operationDetails = operationController.getOperationDetails(GetElements.class.getName());
    List<OperationField> operationFields = operationDetails.getFields();
    // Then
    final List<OperationField> fields = Arrays.asList(new OperationField("input", null, "java.lang.Object[]", null, false), new OperationField("view", null, "uk.gov.gchq.gaffer.data.elementdefinition.view.View", null, false), new OperationField("includeIncomingOutGoing", "Should the edges point towards, or away from your seeds", "java.lang.String", Sets.newHashSet("INCOMING", "EITHER", "OUTGOING"), false), new OperationField("seedMatching", "How should the seeds be matched?", "java.lang.String", Sets.newHashSet("RELATED", "EQUAL"), false), new OperationField("options", null, "java.util.Map<java.lang.String,java.lang.String>", null, false), new OperationField("directedType", "Is the Edge directed?", "java.lang.String", Sets.newHashSet("DIRECTED", "UNDIRECTED", "EITHER"), false), new OperationField("views", null, "java.util.List<uk.gov.gchq.gaffer.data.elementdefinition.view.View>", null, false));
    assertEquals(fields, operationFields);
}
Also used : OperationDetail(uk.gov.gchq.gaffer.rest.model.OperationDetail) OperationField(uk.gov.gchq.gaffer.rest.model.OperationField) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Test(org.junit.jupiter.api.Test)

Example 47 with GetElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.

the class GetAdjacentIdsHandler method doOperation.

private CloseableIterable<? extends EntityId> doOperation(final GetAdjacentIds op, final User user, final HBaseStore store) throws OperationException {
    if (null == op.getInput()) {
        // If null seeds no results are returned
        return new WrappedCloseableIterable<>();
    }
    final HBaseRetriever<?> edgeRetriever;
    final GetElements getEdges = new GetElements.Builder().options(op.getOptions()).view(new View.Builder().merge(op.getView()).entities(Collections.emptyMap()).build()).inputIds(op.getInput()).directedType(op.getDirectedType()).inOutType(op.getIncludeIncomingOutGoing()).build();
    try {
        edgeRetriever = store.createRetriever(getEdges, user, getEdges.getInput(), true);
    } catch (final StoreException e) {
        throw new OperationException(e.getMessage(), e);
    }
    return new ExtractDestinationEntityId(edgeRetriever);
}
Also used : WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) OperationException(uk.gov.gchq.gaffer.operation.OperationException) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 48 with GetElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.

the class FederatedStoreUtilTest method shouldUpdateNestedOperations.

@Test
public void shouldUpdateNestedOperations() {
    // Given
    final Graph graph = createGraph();
    final HashMap<String, String> options = new HashMap<>();
    options.put("key", "value");
    final HashMap<String, String> options2 = new HashMap<>();
    options2.put("key", "value");
    final GetElements operation = new GetElements.Builder().view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition()).edge(TestGroups.EDGE_2, new ViewElementDefinition()).entity(TestGroups.ENTITY, new ViewElementDefinition()).entity(TestGroups.ENTITY_2, new ViewElementDefinition()).build()).options(options2).build();
    final OperationChain opChain = new OperationChain.Builder().first(operation).options(options).build();
    // When
    final OperationChain<?> updatedOpChain = FederatedStoreUtil.updateOperationForGraph(opChain, graph);
    // Then
    assertNotSame(opChain, updatedOpChain);
    assertEquals(options, updatedOpChain.getOptions());
    assertEquals(1, updatedOpChain.getOperations().size());
    final GetElements updatedOperation = (GetElements) updatedOpChain.getOperations().get(0);
    assertNotSame(operation, updatedOperation);
    assertEquals(options2, updatedOperation.getOptions());
    assertNotSame(operation.getView(), updatedOperation.getView());
    assertEquals(Sets.newHashSet(TestGroups.ENTITY), updatedOperation.getView().getEntityGroups());
    assertEquals(Sets.newHashSet(TestGroups.EDGE), updatedOperation.getView().getEdgeGroups());
    assertSame(operation.getView().getEntity(TestGroups.ENTITY), updatedOperation.getView().getEntity(TestGroups.ENTITY));
    assertSame(operation.getView().getEdge(TestGroups.EDGE), updatedOperation.getView().getEdge(TestGroups.EDGE));
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) HashMap(java.util.HashMap) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) Test(org.junit.jupiter.api.Test)

Example 49 with GetElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.

the class FederatedStoreUtilTest method shouldUpdateOperationView.

@Test
public void shouldUpdateOperationView() {
    // Given
    final Graph graph = createGraph();
    final GetElements operation = new GetElements.Builder().view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition()).edge(TestGroups.EDGE_2, new ViewElementDefinition()).entity(TestGroups.ENTITY, new ViewElementDefinition()).entity(TestGroups.ENTITY_2, new ViewElementDefinition()).build()).build();
    // When
    final GetElements updatedOp = FederatedStoreUtil.updateOperationForGraph(operation, graph);
    // Then
    assertNotSame(operation, updatedOp);
    assertNotSame(operation.getView(), updatedOp.getView());
    assertEquals(Sets.newHashSet(TestGroups.ENTITY), updatedOp.getView().getEntityGroups());
    assertEquals(Sets.newHashSet(TestGroups.EDGE), updatedOp.getView().getEdgeGroups());
    assertSame(operation.getView().getEntity(TestGroups.ENTITY), updatedOp.getView().getEntity(TestGroups.ENTITY));
    assertSame(operation.getView().getEdge(TestGroups.EDGE), updatedOp.getView().getEdge(TestGroups.EDGE));
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.jupiter.api.Test)

Example 50 with GetElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.

the class QueryGeneratorTest method testQueryGeneratorForGetElementsWithEntitySeeds.

@Test
public void testQueryGeneratorForGetElementsWithEntitySeeds(@TempDir java.nio.file.Path tempDir) throws IOException, OperationException {
    // Given
    // - Create snapshot folder
    final String folder = String.format("file:///%s", tempDir.toString());
    final String snapshotFolder = folder + "/" + ParquetStore.getSnapshotPath(1000L);
    // - Write out Parquet files so know the partitioning
    CalculatePartitionerTest.writeData(snapshotFolder, new SchemaUtils(schema));
    // - Initialise store
    final ParquetStoreProperties storeProperties = new ParquetStoreProperties();
    storeProperties.setDataDir(folder);
    storeProperties.setTempFilesDir(folder + "/tmpdata");
    final ParquetStore store = (ParquetStore) ParquetStore.createStore("graphId", schema, storeProperties);
    // When 1 - no view, query for vertex 0
    GetElements getElements = new GetElements.Builder().input(new EntitySeed(0L)).seedMatching(SeedMatching.SeedMatchingType.RELATED).build();
    ParquetQuery query = new QueryGenerator(store).getParquetQuery(getElements);
    // Then 1
    final List expected = new ArrayList<>();
    final FilterPredicate vertex0 = eq(FilterApi.longColumn(ParquetStore.VERTEX), 0L);
    final FilterPredicate source0 = eq(FilterApi.longColumn(ParquetStore.SOURCE), 0L);
    final FilterPredicate destination0 = eq(FilterApi.longColumn(ParquetStore.DESTINATION), 0L);
    for (final String group : Arrays.asList(TestGroups.ENTITY, TestGroups.ENTITY_2)) {
        final Path groupFolderPath = new Path(snapshotFolder, ParquetStore.getGroupSubDir(group, false));
        final Path pathForPartitionFile = new Path(groupFolderPath, ParquetStore.getFile(0));
        expected.add(new ParquetFileQuery(pathForPartitionFile, vertex0, true));
    }
    for (final String group : Arrays.asList(TestGroups.EDGE, TestGroups.EDGE_2)) {
        final Path groupFolderPath = new Path(snapshotFolder, ParquetStore.getGroupSubDir(group, false));
        final Path pathForPartitionFile = new Path(groupFolderPath, ParquetStore.getFile(0));
        expected.add(new ParquetFileQuery(pathForPartitionFile, source0, true));
        final Path reversedGroupFolderPath = new Path(snapshotFolder, ParquetStore.getGroupSubDir(group, true));
        final Path pathForReversedPartitionFile = new Path(reversedGroupFolderPath, ParquetStore.getFile(0));
        expected.add(new ParquetFileQuery(pathForReversedPartitionFile, destination0, true));
    }
    assertThat(expected).containsOnly(query.getAllParquetFileQueries().toArray());
    // When 2 - no view, query for vertices 0 and 1000000
    getElements = new GetElements.Builder().input(new EntitySeed(0L), new EntitySeed(1000000L)).seedMatching(SeedMatching.SeedMatchingType.RELATED).build();
    query = new QueryGenerator(store).getParquetQuery(getElements);
    // Then 2
    expected.clear();
    final FilterPredicate vertex1000000 = eq(FilterApi.longColumn(ParquetStore.VERTEX), 1000000L);
    final FilterPredicate source1000000 = eq(FilterApi.longColumn(ParquetStore.SOURCE), 1000000L);
    final FilterPredicate destination1000000 = eq(FilterApi.longColumn(ParquetStore.DESTINATION), 1000000L);
    for (final String group : Arrays.asList(TestGroups.ENTITY, TestGroups.ENTITY_2)) {
        final Path groupFolderPath = new Path(snapshotFolder, ParquetStore.getGroupSubDir(group, false));
        final Path pathForPartitionFile1 = new Path(groupFolderPath, ParquetStore.getFile(0));
        expected.add(new ParquetFileQuery(pathForPartitionFile1, vertex0, true));
        final Path pathForPartitionFile2 = new Path(groupFolderPath, ParquetStore.getFile(9));
        expected.add(new ParquetFileQuery(pathForPartitionFile2, vertex1000000, true));
    }
    for (final String group : Arrays.asList(TestGroups.EDGE, TestGroups.EDGE_2)) {
        final Path groupFolderPath = new Path(snapshotFolder, ParquetStore.getGroupSubDir(group, false));
        final Path reversedGroupFolderPath = new Path(snapshotFolder, ParquetStore.getGroupSubDir(group, true));
        // Partition 0, vertex 0L
        final Path pathForPartitionFile1 = new Path(groupFolderPath, ParquetStore.getFile(0));
        expected.add(new ParquetFileQuery(pathForPartitionFile1, source0, true));
        // Partition 9, vertex 1000000L
        final Path pathForPartitionFile2 = new Path(groupFolderPath, ParquetStore.getFile(9));
        expected.add(new ParquetFileQuery(pathForPartitionFile2, source1000000, true));
        // Partition 0 of reversed, vertex 0L
        final Path pathForPartitionFile3 = new Path(reversedGroupFolderPath, ParquetStore.getFile(0));
        expected.add(new ParquetFileQuery(pathForPartitionFile3, destination0, true));
        // Partition 9 of reversed, vertex 1000000L
        final Path pathForPartitionFile4 = new Path(reversedGroupFolderPath, ParquetStore.getFile(9));
        expected.add(new ParquetFileQuery(pathForPartitionFile4, destination1000000, true));
    }
    assertThat(expected).containsOnly(query.getAllParquetFileQueries().toArray());
    // When 3 - view with filter that can be pushed down to Parquet, query for vertices 0 and 1000000
    getElements = new GetElements.Builder().input(new EntitySeed(0L), new EntitySeed(1000000L)).seedMatching(SeedMatching.SeedMatchingType.RELATED).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("count").execute(new IsMoreThan(10)).build()).build()).build()).build();
    query = new QueryGenerator(store).getParquetQuery(getElements);
    // Then 3
    expected.clear();
    final FilterPredicate source0AndCount = and(gt(FilterApi.intColumn("count"), 10), eq(FilterApi.longColumn(ParquetStore.SOURCE), 0L));
    final FilterPredicate source1000000AndCount = and(gt(FilterApi.intColumn("count"), 10), eq(FilterApi.longColumn(ParquetStore.SOURCE), 1000000L));
    final FilterPredicate destination0AndCount = and(gt(FilterApi.intColumn("count"), 10), eq(FilterApi.longColumn(ParquetStore.DESTINATION), 0L));
    final FilterPredicate destination1000000AndCount = and(gt(FilterApi.intColumn("count"), 10), eq(FilterApi.longColumn(ParquetStore.DESTINATION), 1000000L));
    final Path groupFolderPath = new Path(snapshotFolder, ParquetStore.getGroupSubDir(TestGroups.EDGE, false));
    final Path reversedGroupFolderPath = new Path(snapshotFolder, ParquetStore.getGroupSubDir(TestGroups.EDGE, true));
    // Partition 0, vertex 0L
    final Path pathForPartitionFile1 = new Path(groupFolderPath, ParquetStore.getFile(0));
    expected.add(new ParquetFileQuery(pathForPartitionFile1, source0AndCount, true));
    // Partition 9, vertex 1000000L
    final Path pathForPartitionFile2 = new Path(groupFolderPath, ParquetStore.getFile(9));
    expected.add(new ParquetFileQuery(pathForPartitionFile2, source1000000AndCount, true));
    // Partition 0 of reversed, vertex 0L
    final Path pathForPartitionFile3 = new Path(reversedGroupFolderPath, ParquetStore.getFile(0));
    expected.add(new ParquetFileQuery(pathForPartitionFile3, destination0AndCount, true));
    // Partition 9 of reversed, vertex 1000000L
    final Path pathForPartitionFile4 = new Path(reversedGroupFolderPath, ParquetStore.getFile(9));
    expected.add(new ParquetFileQuery(pathForPartitionFile4, destination1000000AndCount, true));
    assertThat(expected).containsOnly(query.getAllParquetFileQueries().toArray());
    // When 4 - view with filter that can't be pushed down to Parquet, query for vertices 0 and 1000000
    getElements = new GetElements.Builder().input(new EntitySeed(0L), new EntitySeed(1000000L)).seedMatching(SeedMatching.SeedMatchingType.RELATED).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("count").execute(new IsEvenFilter()).build()).build()).build()).build();
    query = new QueryGenerator(store).getParquetQuery(getElements);
    // Then 4
    expected.clear();
    // Partition 0, vertex 0L
    expected.add(new ParquetFileQuery(pathForPartitionFile1, source0, false));
    // Partition 9, vertex 1000000L
    expected.add(new ParquetFileQuery(pathForPartitionFile2, source1000000, false));
    // Partition 0 of reversed, vertex 0L
    expected.add(new ParquetFileQuery(pathForPartitionFile3, destination0, false));
    // Partition 9 of reversed, vertex 1000000L
    expected.add(new ParquetFileQuery(pathForPartitionFile4, destination1000000, false));
    assertThat(expected).containsOnly(query.getAllParquetFileQueries().toArray());
}
Also used : ParquetStore(uk.gov.gchq.gaffer.parquetstore.ParquetStore) Path(org.apache.hadoop.fs.Path) ArrayList(java.util.ArrayList) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) SchemaUtils(uk.gov.gchq.gaffer.parquetstore.utils.SchemaUtils) ParquetStoreProperties(uk.gov.gchq.gaffer.parquetstore.ParquetStoreProperties) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ArrayList(java.util.ArrayList) List(java.util.List) FilterPredicate(org.apache.parquet.filter2.predicate.FilterPredicate) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) CalculatePartitionerTest(uk.gov.gchq.gaffer.parquetstore.operation.handler.utilities.CalculatePartitionerTest) LongVertexOperationsTest(uk.gov.gchq.gaffer.parquetstore.operation.handler.LongVertexOperationsTest) Test(org.junit.jupiter.api.Test)

Aggregations

GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)256 Test (org.junit.jupiter.api.Test)153 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)112 User (uk.gov.gchq.gaffer.user.User)102 Element (uk.gov.gchq.gaffer.data.element.Element)91 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)84 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)83 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)67 Context (uk.gov.gchq.gaffer.store.Context)60 Test (org.junit.Test)56 HashSet (java.util.HashSet)52 Graph (uk.gov.gchq.gaffer.graph.Graph)49 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)46 Entity (uk.gov.gchq.gaffer.data.element.Entity)42 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)38 Operation (uk.gov.gchq.gaffer.operation.Operation)35 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)35 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)34 Edge (uk.gov.gchq.gaffer.data.element.Edge)32 ArrayList (java.util.ArrayList)31