@Override public String toString() { if (isEmpty()) { return "[]"; } Iterator<GradoopId> it = iterator(); StringBuilder sb = new StringBuilder(); sb.append('['); for (;;) { GradoopId id = it.next(); sb.append(id); if (!it.hasNext()) { return sb.append(']').toString(); } sb.append(',').append(' '); } } }
@Override public boolean filter(EL value) throws Exception { return value.getGraphIds() == null || value.getGraphIds().isEmpty(); } }
@Override public boolean filter(EL value) throws Exception { return value.getGraphIds() == null || value.getGraphIds().isEmpty(); } }
@Override public void write(DataOutputView out) throws IOException { if (isEmpty()) { out.writeInt(0); } else { out.writeInt(size()); out.write(writeIds(ids)); } }
@Nonnull @Override public ClosableIterator<Vertex> getVertexSpace( @Nullable ElementQuery<AccumuloElementFilter<Vertex>> query, int cacheSize ) throws IOException { if (query != null && query.getQueryRanges() != null && query.getQueryRanges().isEmpty()) { return new EmptyClosableIterator<>(); } if (query != null) { LOG.info(query.toString()); } BatchScanner scanner = createBatchScanner( getVertexTableName(), GradoopVertexIterator.class, query); Iterator<Map.Entry<Key, Value>> iterator = scanner.iterator(); if (!iterator.hasNext()) { return new EmptyClosableIterator<>(); } else { return new ClientClosableIterator<>(scanner, new GradoopVertexIterator(), config.getVertexHandler(), cacheSize); } }
@Override public void flatMap( Tuple4<GradoopId, GradoopIdSet, GradoopIdSet, GradoopIdSet> edgeTuple, Collector<Tuple2<GradoopId, GradoopIdSet>> collector) throws Exception { GradoopIdSet set = new GradoopIdSet(); for (GradoopId edgeGraph : edgeTuple.f3) { for (GradoopId sourceGraph : edgeTuple.f1) { if (edgeGraph.equals(sourceGraph)) { for (GradoopId targetGraph : edgeTuple.f2) { if (edgeGraph.equals(targetGraph)) { set.add(edgeGraph); } } } } } if (!set.isEmpty()) { reuseTuple.f0 = edgeTuple.f0; reuseTuple.f1 = set; collector.collect(reuseTuple); } } }
@Override public void flatMap( Tuple4<GradoopId, GradoopIdSet, GradoopIdSet, GradoopIdSet> edgeTuple, Collector<Tuple2<GradoopId, GradoopIdSet>> collector) throws Exception { GradoopIdSet set = new GradoopIdSet(); for (GradoopId edgeGraph : edgeTuple.f3) { for (GradoopId sourceGraph : edgeTuple.f1) { if (edgeGraph.equals(sourceGraph)) { for (GradoopId targetGraph : edgeTuple.f2) { if (edgeGraph.equals(targetGraph)) { set.add(edgeGraph); } } } } } if (!set.isEmpty()) { reuseTuple.f0 = edgeTuple.f0; reuseTuple.f1 = set; collector.collect(reuseTuple); } } }
@Nonnull @Override public ClosableIterator<GraphHead> getGraphSpace( @Nullable ElementQuery<AccumuloElementFilter<GraphHead>> query, int cacheSize ) throws IOException { if (query != null && query.getQueryRanges() != null && query.getQueryRanges().isEmpty()) { return new EmptyClosableIterator<>(); } if (query != null) { LOG.info(query.toString()); } BatchScanner scanner = createBatchScanner( getGraphHeadName(), GradoopGraphHeadIterator.class, query); Iterator<Map.Entry<Key, Value>> iterator = scanner.iterator(); if (!iterator.hasNext()) { return new EmptyClosableIterator<>(); } else { return new ClientClosableIterator<>(scanner, new GradoopGraphHeadIterator(), config.getGraphHandler(), cacheSize); } }
@Nonnull @Override public ClosableIterator<Edge> getEdgeSpace( @Nullable ElementQuery<AccumuloElementFilter<Edge>> query, int cacheSize ) throws IOException { if (query != null && query.getQueryRanges() != null && query.getQueryRanges().isEmpty()) { return new EmptyClosableIterator<>(); } if (query != null) { LOG.info(query.toString()); } BatchScanner scanner = createBatchScanner( getEdgeTableName(), GradoopEdgeIterator.class, query); Iterator<Map.Entry<Key, Value>> iterator = scanner.iterator(); if (!iterator.hasNext()) { return new EmptyClosableIterator<>(); } else { return new ClientClosableIterator<>(scanner, new GradoopEdgeIterator(), config.getEdgeHandler(), cacheSize); } }
/** * Attach a HBase filter represented by the given query to the given scan instance. * * @param query the query that represents a filter * @param scan the HBase scan instance on which the filter will be applied * @param isSpreadingByteUsed indicates whether a spreading byte is used as row key prefix or not */ void attachFilter( @Nonnull ElementQuery<HBaseElementFilter<E>> query, @Nonnull Scan scan, boolean isSpreadingByteUsed) { FilterList conjunctFilters = new FilterList(FilterList.Operator.MUST_PASS_ALL); if (query.getQueryRanges() != null && !query.getQueryRanges().isEmpty()) { conjunctFilters.addFilter(HBaseFilterUtils.getIdFilter(query.getQueryRanges(), isSpreadingByteUsed)); } if (query.getFilterPredicate() != null) { conjunctFilters.addFilter(query.getFilterPredicate().toHBaseFilter(false)); } // if there are filters inside the root list, add it to the Scan object if (!conjunctFilters.getFilters().isEmpty()) { scan.setFilter(conjunctFilters); } } }
/** * Attach a HBase filter represented by the given query to the given scan instance. * * @param query the query that represents a filter * @param scan the HBase scan instance on which the filter will be applied * @param isSpreadingByteUsed indicates whether a spreading byte is used as row key prefix or not * @param <T> the type of the EPGM element */ private <T extends EPGMElement> void attachFilter( @Nonnull ElementQuery<HBaseElementFilter<T>> query, @Nonnull Scan scan, boolean isSpreadingByteUsed) { FilterList conjunctFilters = new FilterList(FilterList.Operator.MUST_PASS_ALL); if (query.getQueryRanges() != null && !query.getQueryRanges().isEmpty()) { conjunctFilters.addFilter(HBaseFilterUtils.getIdFilter(query.getQueryRanges(), isSpreadingByteUsed)); } if (query.getFilterPredicate() != null) { conjunctFilters.addFilter(query.getFilterPredicate().toHBaseFilter(false)); } // if there are filters inside the root list, add it to the Scan object if (!conjunctFilters.getFilters().isEmpty()) { scan.setFilter(conjunctFilters); } }
@Test public void testResetGraphIds() { Properties propertiesMock = mock(Properties.class); GradoopIdSet idSet = new GradoopIdSet(); idSet.add(GradoopId.get()); GraphElement graphElementMock = mock(GraphElement.class, withSettings() .useConstructor(GradoopId.get(), "someLabel", propertiesMock, idSet) .defaultAnswer(CALLS_REAL_METHODS)); graphElementMock.resetGraphIds(); assertTrue(graphElementMock.getGraphIds().isEmpty()); } }