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);
}
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);
}
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));
}
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));
}
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());
}
Aggregations