use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.
the class AbstractGetIterableOperationTest method shouldCopyFieldsFromGivenOperationWhenConstructing.
@Test
public void shouldCopyFieldsFromGivenOperationWhenConstructing() {
// Given
final GetIterableOperation<ElementSeed, ?> operationToCopy = mock(GetIterableOperation.class);
final View view = mock(View.class);
final GetOperation.IncludeEdgeType includeEdges = GetOperation.IncludeEdgeType.ALL;
final boolean includeEntities = true;
final boolean populateProperties = true;
final CloseableIterable<ElementSeed> input = mock(CloseableIterable.class);
given(operationToCopy.getView()).willReturn(view);
given(operationToCopy.getInput()).willReturn(input);
// When
final GetIterableOperationImpl<ElementSeed, Element> operation = new GetIterableOperationImpl<>(operationToCopy);
// Then
assertSame(view, operation.getView());
assertSame(input, operation.getInput());
}
use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.
the class ExamplesServiceTest method shouldCreateViewForEdges.
@Test
public void shouldCreateViewForEdges() {
final View.Builder builder = service.generateViewBuilder();
final View view = builder.build();
assertNotNull(view);
final ViewValidator viewValidator = new ViewValidator();
final boolean validate = viewValidator.validate(view, schema, false);
assertTrue(validate);
}
use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.
the class GetDataFrameOfElementsExample method getDataFrameOfElementsWithEdgeGroup.
public void getDataFrameOfElementsWithEdgeGroup(final SQLContext sqlc, final Graph graph) throws OperationException {
ROOT_LOGGER.setLevel(Level.INFO);
log("#### " + getMethodNameAsSentence(0) + "\n");
printGraph();
ROOT_LOGGER.setLevel(Level.OFF);
final GetDataFrameOfElements operation = new GetDataFrameOfElements.Builder().view(new View.Builder().edge("edge").build()).sqlContext(sqlc).build();
final Dataset<Row> df = graph.execute(operation, new User("user01"));
// Show
String result = df.showString(100, 20);
ROOT_LOGGER.setLevel(Level.INFO);
printJava("GetDataFrameOfElements operation = new GetDataFrameOfElements.Builder()\n" + " .view(new View.Builder()\n" + " .entity(\"edge\")\n" + " .build()).\n" + " .sqlContext(sqlc)\n" + " .build();\n" + "Dataset<Row> df = getGraph().execute(operation, new User(\"user01\"));\n" + "df.show();");
log("The results are:");
log("```");
log(result.substring(0, result.length() - 2));
log("```");
ROOT_LOGGER.setLevel(Level.OFF);
// Restrict to edges involving given vertices
final Dataset<Row> seeded = df.filter("src = 1 OR src = 3");
result = seeded.showString(100, 20);
ROOT_LOGGER.setLevel(Level.INFO);
printJava("df.filter(\"src = 1 OR src = 3\").show();");
log("The results are:");
log("```");
log(result.substring(0, result.length() - 2));
log("```");
ROOT_LOGGER.setLevel(Level.OFF);
// Filter by property
final Dataset<Row> filtered = df.filter("count > 1");
result = filtered.showString(100, 20);
ROOT_LOGGER.setLevel(Level.INFO);
printJava("df.filter(\"count > 1\").show();");
log("The results are:");
log("```");
log(result.substring(0, result.length() - 2));
log("```");
ROOT_LOGGER.setLevel(Level.OFF);
}
use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.
the class AccumuloStoreRelationTest method testBuildScanFullView.
@Test
public void testBuildScanFullView() throws OperationException, StoreException {
final Schema schema = getSchema();
final View view = getViewFromSchema(schema);
testBuildScanWithView("testBuildScanFullView", view, e -> true);
}
use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.
the class AccumuloStoreRelationTest method testBuildScanRestrictViewByProperty.
@Test
public void testBuildScanRestrictViewByProperty() throws OperationException, StoreException {
final List<ConsumerFunctionContext<String, FilterFunction>> filters = new ArrayList<>();
filters.add(new ConsumerFunctionContext<>(new IsMoreThan(5, false), new ArrayList<>(Arrays.asList("property1"))));
final View view = new View.Builder().edge(GetDataFrameOfElementsHandlerTest.EDGE_GROUP, new ViewElementDefinition.Builder().postAggregationFilterFunctions(filters).build()).build();
final Predicate<Element> returnElement = (Element element) -> element.getGroup().equals(GetDataFrameOfElementsHandlerTest.EDGE_GROUP) && ((Integer) element.getProperty("property1")) > 5;
testBuildScanWithView("testBuildScanRestrictViewByProperty", view, returnElement);
}
Aggregations