use of org.apache.spark.sql.sources.EqualTo in project Gaffer by gchq.
the class FilterToOperationConverterTest method testSpecifyVertex.
@Test
public void testSpecifyVertex() throws OperationException {
final Schema schema = getSchema();
final SQLContext sqlContext = getSqlContext("testSpecifyVertex");
final Filter[] filters = new Filter[1];
filters[0] = new EqualTo(SchemaToStructTypeConverter.VERTEX_COL_NAME, "0");
final FiltersToOperationConverter converter = new FiltersToOperationConverter(sqlContext, getViewFromSchema(schema), schema, filters);
final AbstractGetRDD<?> operation = converter.getOperation();
assertTrue(operation instanceof GetRDDOfElements);
assertEquals(Collections.singleton(ENTITY_GROUP), operation.getView().getEntityGroups());
assertEquals(0, operation.getView().getEdgeGroups().size());
final Set<EntitySeed> seeds = new HashSet<>();
for (final Object seed : ((GetRDDOfElements) operation).getSeeds()) {
seeds.add((EntitySeed) seed);
}
assertEquals(Collections.singleton(new EntitySeed("0")), seeds);
sqlContext.sparkContext().stop();
}
use of org.apache.spark.sql.sources.EqualTo in project Gaffer by gchq.
the class FiltersToOperationConverter method applyVertexSourceDestinationFilters.
private AbstractGetRDD<?> applyVertexSourceDestinationFilters(final View view) {
View clonedView = view.clone();
AbstractGetRDD<?> operation = null;
for (final Filter filter : filters) {
if (filter instanceof EqualTo) {
final EqualTo equalTo = (EqualTo) filter;
final String attribute = equalTo.attribute();
if (attribute.equals(SchemaToStructTypeConverter.VERTEX_COL_NAME)) {
// Only entities are relevant, so remove any edge groups from the view
LOGGER.info("Found EqualTo filter with attribute {}, setting views to only contain entity groups", attribute);
View.Builder viewBuilder = new View.Builder();
for (final String entityGroup : view.getEntityGroups()) {
viewBuilder = viewBuilder.entity(entityGroup);
}
clonedView = viewBuilder.build();
LOGGER.info("Setting operation to GetRDDOfElements");
operation = new GetRDDOfElements<>(sqlContext.sparkContext(), new EntitySeed(equalTo.value()));
operation.setView(clonedView);
break;
} else if (attribute.equals(SchemaToStructTypeConverter.SRC_COL_NAME) || attribute.equals(SchemaToStructTypeConverter.DST_COL_NAME)) {
// Only edges are relevant, so remove any entity groups from the view
LOGGER.info("Found EqualTo filter with attribute {}, setting views to only contain edge groups", attribute);
View.Builder viewBuilder = new View.Builder();
for (final String edgeGroup : view.getEdgeGroups()) {
viewBuilder = viewBuilder.edge(edgeGroup);
}
clonedView = viewBuilder.build();
LOGGER.info("Setting operation to GetRDDOfElements");
operation = new GetRDDOfElements<>(sqlContext.sparkContext(), new EntitySeed(equalTo.value()));
operation.setView(clonedView);
break;
}
}
}
if (operation == null) {
LOGGER.debug("Setting operation to GetRDDOfAllElements");
operation = new GetRDDOfAllElements(sqlContext.sparkContext());
operation.setView(clonedView);
}
return operation;
}
use of org.apache.spark.sql.sources.EqualTo in project Gaffer by gchq.
the class FiltersToOperationConverter method checkForGroups.
/**
* Returns the set of all groups in the filter, if the filter specifies that the group must be equal to a certain
* value.
*
* @param filter The {@link Filter} that will be checked for groups.
* @return A set of strings containing the required groups, <code>null</code> if no groups are specified in the
* filter.
*/
private Set<String> checkForGroups(final Filter filter) {
if (filter instanceof EqualTo) {
final EqualTo equalTo = (EqualTo) filter;
if (equalTo.attribute().equals(SchemaToStructTypeConverter.GROUP)) {
LOGGER.info("Filter {} specifies that {} should be {}", filter, SchemaToStructTypeConverter.GROUP, equalTo.value());
return Collections.singleton((String) equalTo.value());
}
} else if (filter instanceof Or) {
final Or or = (Or) filter;
if (or.left() instanceof EqualTo && or.right() instanceof EqualTo && ((EqualTo) or.left()).attribute().equals(SchemaToStructTypeConverter.GROUP) && ((EqualTo) or.right()).attribute().equals(SchemaToStructTypeConverter.GROUP)) {
final Set<String> groups = new HashSet<>();
groups.add((String) ((EqualTo) or.left()).value());
groups.add((String) ((EqualTo) or.right()).value());
LOGGER.info("Filter {} specifies that {} should be {} or {}", filter, SchemaToStructTypeConverter.GROUP, ((EqualTo) or.left()).value(), ((EqualTo) or.right()).value());
return groups;
}
} else if (filter instanceof In) {
final In in = (In) filter;
if (in.attribute().equals(SchemaToStructTypeConverter.GROUP)) {
final Set<String> groups = new HashSet<>();
for (final Object o : in.values()) {
groups.add((String) o);
}
LOGGER.info("Filter {} specifies that {} should be in {}", filter, SchemaToStructTypeConverter.GROUP, StringUtils.join(in.values(), ','));
return groups;
}
}
return null;
}
use of org.apache.spark.sql.sources.EqualTo in project Gaffer by gchq.
the class FilterToOperationConverterTest method testSpecifySource.
@Test
public void testSpecifySource() throws OperationException {
final Schema schema = getSchema();
final SQLContext sqlContext = getSqlContext("testSpecifySource");
final Filter[] filters = new Filter[1];
filters[0] = new EqualTo(SchemaToStructTypeConverter.SRC_COL_NAME, "0");
FiltersToOperationConverter converter = new FiltersToOperationConverter(sqlContext, getViewFromSchema(schema), schema, filters);
AbstractGetRDD<?> operation = converter.getOperation();
assertTrue(operation instanceof GetRDDOfElements);
assertEquals(0, operation.getView().getEntityGroups().size());
assertEquals(EDGE_GROUPS, operation.getView().getEdgeGroups());
final Set<EntitySeed> seeds = new HashSet<>();
for (final Object seed : ((GetRDDOfElements) operation).getSeeds()) {
seeds.add((EntitySeed) seed);
}
assertEquals(Collections.singleton(new EntitySeed("0")), seeds);
sqlContext.sparkContext().stop();
}
use of org.apache.spark.sql.sources.EqualTo in project Gaffer by gchq.
the class FilterToOperationConverterTest method testIncompatibleGroups.
@Test
public void testIncompatibleGroups() throws OperationException {
final Schema schema = getSchema();
final SQLContext sqlContext = getSqlContext("testIncompatibleGroups");
final Filter[] filters = new Filter[2];
filters[0] = new EqualTo(SchemaToStructTypeConverter.GROUP, "A");
filters[1] = new EqualTo(SchemaToStructTypeConverter.GROUP, "B");
final FiltersToOperationConverter converter = new FiltersToOperationConverter(sqlContext, getViewFromSchema(schema), schema, filters);
final AbstractGetRDD<?> operation = converter.getOperation();
assertNull(operation);
sqlContext.sparkContext().stop();
}
Aggregations