use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.
the class FilterToOperationConverterTest method testSpecifySourceOrDestinationAndPropertyFilter.
@Test
public void testSpecifySourceOrDestinationAndPropertyFilter() {
final Schema schema = getSchema();
final SparkSession sparkSession = SparkSessionProvider.getSparkSession();
// Specify src and a filter on property1
Filter[] filters = new Filter[2];
filters[0] = new GreaterThan("property1", 5);
filters[1] = new EqualTo(SchemaToStructTypeConverter.SRC_COL_NAME, "0");
FiltersToOperationConverter converter = new FiltersToOperationConverter(getViewFromSchema(schema), schema, filters);
Operation operation = converter.getOperation();
assertTrue(operation instanceof GetRDDOfElements);
assertEquals(0, ((GraphFilters) operation).getView().getEntityGroups().size());
assertEquals(2, ((GraphFilters) operation).getView().getEdgeGroups().size());
final Set<EntityId> seeds = new HashSet<>();
for (final Object seed : ((GetRDDOfElements) operation).getInput()) {
seeds.add((EntitySeed) seed);
}
assertEquals(Collections.singleton(new EntitySeed("0")), seeds);
View opView = ((GraphFilters) operation).getView();
for (final String edgeGroup : EDGE_GROUPS) {
final List<TupleAdaptedPredicate<String, ?>> edgePostAggFilters = opView.getEdge(edgeGroup).getPostAggregationFilterFunctions();
assertThat(edgePostAggFilters).hasSize(1);
assertArrayEquals(new String[] { "property1" }, edgePostAggFilters.get(0).getSelection());
assertEquals(new IsMoreThan(5, false), edgePostAggFilters.get(0).getPredicate());
}
// Specify src and filters on property1 and property4
filters = new Filter[3];
filters[0] = new GreaterThan("property1", 5);
filters[1] = new EqualTo(SchemaToStructTypeConverter.SRC_COL_NAME, "0");
filters[2] = new LessThan("property4", 8);
converter = new FiltersToOperationConverter(getViewFromSchema(schema), schema, filters);
operation = converter.getOperation();
assertTrue(operation instanceof GetRDDOfElements);
assertEquals(0, ((GraphFilters) operation).getView().getEntityGroups().size());
assertEquals(1, ((GraphFilters) operation).getView().getEdgeGroups().size());
seeds.clear();
for (final Object seed : ((GetRDDOfElements) operation).getInput()) {
seeds.add((EntitySeed) seed);
}
assertEquals(Collections.singleton(new EntitySeed("0")), seeds);
opView = ((GraphFilters) operation).getView();
final List<TupleAdaptedPredicate<String, ?>> entityPostAggFilters = opView.getEdge(EDGE_GROUP).getPostAggregationFilterFunctions();
assertThat(entityPostAggFilters).hasSize(2);
final List<String> expectedProperties = new ArrayList<>();
expectedProperties.add("property1");
expectedProperties.add("property4");
assertThat(entityPostAggFilters.get(0).getSelection()).hasSize(1);
assertEquals(expectedProperties.get(0), entityPostAggFilters.get(0).getSelection()[0]);
assertEquals(new IsMoreThan(5, false), entityPostAggFilters.get(0).getPredicate());
assertThat(entityPostAggFilters.get(1).getSelection()).hasSize(1);
assertEquals(expectedProperties.get(1), entityPostAggFilters.get(1).getSelection()[0]);
assertEquals(new IsLessThan(8, false), entityPostAggFilters.get(1).getPredicate());
}
use of uk.gov.gchq.gaffer.operation.data.EntitySeed 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());
}
use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.
the class LongVertexOperationsTest method getSeeds.
@Override
public List<ElementSeed> getSeeds() {
final List<ElementSeed> seeds = new ArrayList<>();
seeds.add(new EntitySeed(5L));
seeds.add(new EntitySeed(10L));
seeds.add(new EntitySeed(15L));
seeds.add(new EdgeSeed(13L, 14L, true));
seeds.add(new EdgeSeed(2L, 3L, true));
return seeds;
}
use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.
the class LongVertexOperationsTest method getSeedsThatWontAppear.
@Override
protected List<ElementSeed> getSeedsThatWontAppear() {
final List<ElementSeed> seeds = new ArrayList<>();
seeds.add(new EntitySeed(-1L));
seeds.add(new EntitySeed(300L));
seeds.add(new EntitySeed(Long.MAX_VALUE));
return seeds;
}
use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.
the class FunctionAuthoriserTest method shouldMaintainOperationChainIfItFailsToSerialise.
@Test
public void shouldMaintainOperationChainIfItFailsToSerialise() {
// Given
FunctionAuthoriser authoriser = new FunctionAuthoriser(Lists.newArrayList(Identity.class));
List fakeInput = Lists.newArrayList(new EntitySeed(1), new EntitySeed(2), new EntitySeed(3));
GetElements getElements = new GetElements();
getElements.setInput(fakeInput);
// will fail serialisation
getElements = spy(getElements);
final OperationChain chain = new OperationChain.Builder().first(getElements).then(generateOperation(ToEntityId.class)).build();
// When
authoriser.preExecute(chain, new Context());
// Then
assertEquals(fakeInput, ((Input) chain.getOperations().get(0)).getInput());
}
Aggregations