Java Code Examples for com.google.common.collect.Iterators#emptyIterator()

The following examples show how to use com.google.common.collect.Iterators#emptyIterator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HiveDataset.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
/**
 * Finds all files read by the table and generates CopyableFiles.
 * For the specific semantics see {@link HiveCopyEntityHelper#getCopyEntities}.
 */
@Override
public Iterator<FileSet<CopyEntity>> getFileSetIterator(FileSystem targetFs, CopyConfiguration configuration,
    Comparator<FileSet<CopyEntity>> prioritizer, PushDownRequestor<FileSet<CopyEntity>> requestor)
    throws IOException {
  if (!canCopyTable()) {
    return Iterators.emptyIterator();
  }
  try {
    List<FileSet<CopyEntity>> fileSetList = Lists.newArrayList(new HiveCopyEntityHelper(this, configuration, targetFs)
        .getCopyEntities(configuration, prioritizer, requestor));
    Collections.sort(fileSetList, prioritizer);
    return fileSetList.iterator();
  } catch (IOException ioe) {
    log.error("Failed to copy table " + this.table, ioe);
    return Iterators.emptyIterator();
  }
}
 
Example 2
Source File: TripleStore.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
@Override
public Iterator<byte[][]> rangeDateTimeAsIDs(
		final Value[] query,
		final Literal lower,
		final boolean equalsLower,
		final Literal upper,
		final boolean equalsUpper,
		final boolean reverse,
		final int limit) throws DataAccessLayerException {

	if (query == null || query.length != 2 || isVariable(query[1])) {
		return Iterators.emptyIterator();
	}

	final long lowerBound = lower == null ? Long.MIN_VALUE : Util.parseXMLSchemaDateTimeAsMSecs(lower), upperBound = upper == null ? Long.MAX_VALUE
			: Util.parseXMLSchemaDateTimeAsMSecs(upper);

	return _rdfIndexDAO.dateRangeQuery(query, lowerBound, equalsLower, upperBound, equalsUpper, reverse, limit);
}
 
Example 3
Source File: LocalFsJobStatusRetriever.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
@Override
public Iterator<JobStatus> getJobStatusesForFlowExecution(String flowName, String flowGroup, long flowExecutionId,
    String jobName, String jobGroup) {
  Preconditions.checkArgument(flowName != null, "flowName cannot be null");
  Preconditions.checkArgument(flowGroup != null, "flowGroup cannot be null");
  Preconditions.checkArgument(jobName != null, "jobName cannot be null");
  Preconditions.checkArgument(jobGroup != null, "jobGroup cannot be null");
  List<JobStatus> jobStatuses = new ArrayList<>();
  JobStatus jobStatus;

  if (this.doesJobExist(flowName, flowGroup, flowExecutionId, JOB_DONE_SUFFIX)) {
    jobStatus = JobStatus.builder().flowName(flowName).flowGroup(flowGroup).flowExecutionId(flowExecutionId).
        jobName(jobName).jobGroup(jobGroup).jobExecutionId(flowExecutionId).eventName(ExecutionStatus.COMPLETE.name()).build();
  } else if (this.doesJobExist(flowName, flowGroup, flowExecutionId, "")) {
    jobStatus = JobStatus.builder().flowName(flowName).flowGroup(flowGroup).flowExecutionId(flowExecutionId).
        jobName(jobName).jobGroup(jobGroup).jobExecutionId(flowExecutionId).eventName(ExecutionStatus.PENDING.name()).build();
  } else {
    return Iterators.emptyIterator();
  }

  jobStatuses.add(jobStatus);
  return jobStatuses.iterator();
}
 
Example 4
Source File: RangeTombstoneList.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public Iterator<RangeTombstone> iterator(Composite from, Composite till)
{
    int startIdx = from.isEmpty() ? 0 : searchInternal(from, 0);
    final int start = startIdx < 0 ? -startIdx-1 : startIdx;

    if (start >= size)
        return Iterators.<RangeTombstone>emptyIterator();

    int finishIdx = till.isEmpty() ? size : searchInternal(till, start);
    // if stopIdx is the first range after 'till' we care only until the previous range
    final int finish = finishIdx < 0 ? -finishIdx-2 : finishIdx;

    // Note: the following is true because we know 'from' is before 'till' in sorted order.
    if (start > finish)
        return Iterators.<RangeTombstone>emptyIterator();
    else if (start == finish)
        return Iterators.<RangeTombstone>singletonIterator(rangeTombstone(start));

    return new AbstractIterator<RangeTombstone>()
    {
        private int idx = start;

        protected RangeTombstone computeNext()
        {
            if (idx >= size || idx > finish)
                return endOfData();

            return rangeTombstone(idx++);
        }
    };
}
 
Example 5
Source File: DFSInotifyEventInputStream.java    From big-c with Apache License 2.0 5 votes vote down vote up
DFSInotifyEventInputStream(Sampler traceSampler, ClientProtocol namenode,
      long lastReadTxid) throws IOException {
  this.traceSampler = traceSampler;
  this.namenode = namenode;
  this.it = Iterators.emptyIterator();
  this.lastReadTxid = lastReadTxid;
}
 
Example 6
Source File: DFSInotifyEventInputStream.java    From hadoop with Apache License 2.0 5 votes vote down vote up
DFSInotifyEventInputStream(Sampler traceSampler, ClientProtocol namenode,
      long lastReadTxid) throws IOException {
  this.traceSampler = traceSampler;
  this.namenode = namenode;
  this.it = Iterators.emptyIterator();
  this.lastReadTxid = lastReadTxid;
}
 
Example 7
Source File: MutationState.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public Iterator<Pair<byte[],List<Mutation>>> toMutations(final boolean includeMutableIndexes) {
    final Iterator<Map.Entry<TableRef, Map<ImmutableBytesPtr,Map<PColumn,byte[]>>>> iterator = this.mutations.entrySet().iterator();
    if (!iterator.hasNext()) {
        return Iterators.emptyIterator();
    }
    Long scn = connection.getSCN();
    final long timestamp = scn == null ? HConstants.LATEST_TIMESTAMP : scn;
    return new Iterator<Pair<byte[],List<Mutation>>>() {
        private Map.Entry<TableRef, Map<ImmutableBytesPtr,Map<PColumn,byte[]>>> current = iterator.next();
        private Iterator<Pair<byte[],List<Mutation>>> innerIterator = init();
                
        private Iterator<Pair<byte[],List<Mutation>>> init() {
            return addRowMutations(current.getKey(), current.getValue(), timestamp, includeMutableIndexes);
        }
        
        @Override
        public boolean hasNext() {
            return innerIterator.hasNext() || iterator.hasNext();
        }

        @Override
        public Pair<byte[], List<Mutation>> next() {
            if (!innerIterator.hasNext()) {
                current = iterator.next();
            }
            return innerIterator.next();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
        
    };
}
 
Example 8
Source File: AstyanaxEventReaderDAO.java    From emodb with Apache License 2.0 5 votes vote down vote up
/**
 * Reads the ordered manifest for a channel.  The read can either be weak or strong.  A weak read will use CL1
 * and may use the cached oldest slab from a previous strong call to improve performance.  A strong read will use
 * CL local_quorum and will always read the entire manifest row.  This makes a weak read significantly faster than a
 * strong read but also means the call is not guaranteed to return the entire manifest.  Because of this at least
 * every 10 seconds a weak read for a channel is automatically promoted to a strong read.
 *
 * The vast majority of calls to this method are performed during a "peek" or "poll" operation.  Since these are
 * typically called repeatedly a weak call provides improved performance while guaranteeing that at least every
 * 10 seconds the manifest is strongly read so no slabs are missed over time.  Calls which must guarantee
 * the full manifest should explicitly request strong consistency.
 */
private Iterator<Column<ByteBuffer>> readManifestForChannel(final String channel, final boolean weak) {
    final ByteBuffer oldestSlab = weak ? _oldestSlab.getIfPresent(channel) : null;
    final ConsistencyLevel consistency;

    RangeBuilder range = new RangeBuilder().setLimit(50);
    if (oldestSlab != null) {
        range.setStart(oldestSlab);
        consistency = ConsistencyLevel.CL_LOCAL_ONE;
    } else {
        consistency = ConsistencyLevel.CL_LOCAL_QUORUM;
    }

    final Iterator<Column<ByteBuffer>> manifestColumns = executePaginated(
            _keyspace.prepareQuery(ColumnFamilies.MANIFEST, consistency)
                    .getKey(channel)
                    .withColumnRange(range.build())
                    .autoPaginate(true));

    if (oldestSlab != null) {
        // Query was executed weakly using the cached oldest slab, so don't update the cache with an unreliable oldest value
        return manifestColumns;
    } else {
        PeekingIterator<Column<ByteBuffer>> peekingManifestColumns = Iterators.peekingIterator(manifestColumns);
        if (peekingManifestColumns.hasNext()) {
            // Cache the first slab returned from querying the full manifest column family since it is the oldest.
            cacheOldestSlabForChannel(channel, TimeUUIDSerializer.get().fromByteBuffer(peekingManifestColumns.peek().getName()));
            return peekingManifestColumns;
        } else {
            // Channel was completely empty.  Cache a TimeUUID for the current time.  This will cause future calls
            // to read at most 1 minute of tombstones until the cache expires 10 seconds later.
            cacheOldestSlabForChannel(channel, TimeUUIDs.newUUID());
            return Iterators.emptyIterator();
        }
    }
}
 
Example 9
Source File: SliceQueryFilter.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public Iterator<RangeTombstone> getRangeTombstoneIterator(final ColumnFamily source)
{
    final DeletionInfo delInfo = source.deletionInfo();
    if (!delInfo.hasRanges() || slices.length == 0)
        return Iterators.<RangeTombstone>emptyIterator();

    return new AbstractIterator<RangeTombstone>()
    {
        private int sliceIdx = 0;
        private Iterator<RangeTombstone> sliceIter = currentRangeIter();

        protected RangeTombstone computeNext()
        {
            while (true)
            {
                if (sliceIter.hasNext())
                    return sliceIter.next();

                if (!nextSlice())
                    return endOfData();

                sliceIter = currentRangeIter();
            }
        }

        private Iterator<RangeTombstone> currentRangeIter()
        {
            ColumnSlice slice = slices[reversed ? (slices.length - 1 - sliceIdx) : sliceIdx];
            return reversed ? delInfo.rangeIterator(slice.finish, slice.start)
                            : delInfo.rangeIterator(slice.start, slice.finish);
        }

        private boolean nextSlice()
        {
            return ++sliceIdx < slices.length;
        }
    };
}
 
Example 10
Source File: ExplainTable.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void appendScanRow(StringBuilder buf, Bound bound) {
    ScanRanges scanRanges = context.getScanRanges();
    // TODO: review this and potentially intersect the scan ranges
    // with the minMaxRange in ScanRanges to prevent having to do all this.
    KeyRange minMaxRange = scanRanges.getMinMaxRange();
    Iterator<byte[]> minMaxIterator = Iterators.emptyIterator();
    if (minMaxRange != KeyRange.EVERYTHING_RANGE) {
        RowKeySchema schema = tableRef.getTable().getRowKeySchema();
        if (!minMaxRange.isUnbound(bound)) {
            minMaxIterator = new RowKeyValueIterator(schema, minMaxRange.getRange(bound));
        }
    }
    int nRanges = scanRanges.getRanges().size();
    for (int i = 0, minPos = 0; minPos < nRanges || minMaxIterator.hasNext(); i++) {
        List<KeyRange> ranges = minPos >= nRanges ? EVERYTHING :  scanRanges.getRanges().get(minPos++);
        KeyRange range = bound == Bound.LOWER ? ranges.get(0) : ranges.get(ranges.size()-1);
        byte[] b = range.getRange(bound);
        Boolean isNull = KeyRange.IS_NULL_RANGE == range ? Boolean.TRUE : KeyRange.IS_NOT_NULL_RANGE == range ? Boolean.FALSE : null;
        if (minMaxIterator.hasNext()) {
            byte[] bMinMax = minMaxIterator.next();
            int cmp = Bytes.compareTo(bMinMax, b) * (bound == Bound.LOWER ? 1 : -1);
            if (cmp > 0) {
                minPos = nRanges;
                b = bMinMax;
                isNull = null;
            } else if (cmp < 0) {
                minMaxIterator = Iterators.emptyIterator();
            }
        }
        appendPKColumnValue(buf, b, isNull, i);
        buf.append(',');
    }
}
 
Example 11
Source File: TungstenAggregate.java    From indexr with Apache License 2.0 5 votes vote down vote up
@Override
protected Iterator<InternalRow> doExecute() {
    Iterator<InternalRow> chidlResIter = child.execute();

    //List<InternalRow> childResList = Helper.toList(chidlResIter);

    //Iterator<InternalRow> iter = childResList.iterator();
    boolean hasInput = chidlResIter.hasNext();
    if (!hasInput && !groupingExpressions.isEmpty()) {
        // This is a grouped aggregate and the input iterator is empty,
        // so return an empty iterator.
        return Iterators.emptyIterator();
    } else {
        TungstenAggregationIterator aggregationIterator =
                new TungstenAggregationIterator(
                        groupingExpressions,
                        aggregateExpressions,
                        aggregateAttributes,
                        initialInputBufferOffset,
                        resultExpressions,
                        this::newMutableProjection,
                        child.output(),
                        chidlResIter);
        if (!hasInput && groupingExpressions.isEmpty()) {
            UnsafeRow singleRowResult = aggregationIterator.outputForEmptyGroupingKeyWithoutInput();
            return Iterators.singletonIterator(singleRowResult);
        } else {

            List<InternalRow> aggResList = toList(aggregationIterator);

            return aggResList.iterator();
            //return StreamSupport.stream(Spliterators.spliteratorUnknownSize(aggregationIterator, 0), false);
        }
    }
}
 
Example 12
Source File: InMemoryHistoryStore.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<Change> getDeltaHistories(String table, String rowId) {
    String key = getKey(table, rowId);
    if (!_historyStore.containsKey(key)) {
        return Iterators.emptyIterator();
    }
    return Lists.transform(_historyStore.get(key), new Function<History, Change>() {
        @Override
        public Change apply(History input) {
            return new ChangeBuilder(input.getChangeId())
                    .with(input).with(input.getDelta()).build();
        }
    }).iterator();
}
 
Example 13
Source File: RowTraversal.java    From indexr with Apache License 2.0 5 votes vote down vote up
static RowTraversal empty() {
    return new RowTraversal() {
        @Override
        public Stream<Row> stream() {
            return Stream.empty();
        }

        @Override
        public Iterator<Row> iterator() {
            return Iterators.emptyIterator();
        }
    };
}
 
Example 14
Source File: GitMapSourceFactory.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Iterator<? extends MapSource> loadNewSources() throws MapMissingException {
  try {
    git.pull()
        .setCredentialsProvider(credentials)
        .setFastForward(MergeCommand.FastForwardMode.FF)
        .call();
  } catch (GitAPIException e) {
    throw new MapMissingException(
        git.getRepository().getDirectory().getPath(), e.getMessage(), e.getCause());
  }

  return Iterators.emptyIterator();
}
 
Example 15
Source File: InMemoryDataReaderDAO.java    From emodb with Apache License 2.0 4 votes vote down vote up
@Override
public Iterator<MultiTableScanResult> multiTableScan(MultiTableScanOptions query, TableSet tables, LimitCounter limit,
                                                     ReadConsistency consistency, @Nullable Instant cutoffTime) {
    // TODO:  Create a simulation for this method
    return Iterators.emptyIterator();
}
 
Example 16
Source File: DistinctAggregatingResultIterator.java    From phoenix with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void close()  {
    resultIterator = Iterators.emptyIterator();
}
 
Example 17
Source File: EmptyVertex.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public <V> Iterator<VertexProperty<V>> properties(String... propertyKeys) {
    return Iterators.emptyIterator();
}
 
Example 18
Source File: BasicInfoSchemaTablesServiceImpl.java    From sql-layer with GNU Affero General Public License v3.0 4 votes vote down vote up
public Scan(ListIterator<ScriptEngineFactory> factories, RowType rowType) {
    super(rowType);
    this.factories = factories;
    this.names = Iterators.emptyIterator();
}
 
Example 19
Source File: Pageables.java    From blueocean-plugin with MIT License 3 votes vote down vote up
/**
 * Poorman's {@link Pageable} implementation that does
 * skipping by simply fast-forwarding {@link Iterator}
 *
 * @param base base collection
 * @param start starting index requested from collection
 * @param limit max number of item requested in the page
 * @param <T> type of Pageable item
 * @return iterator with starting index==start and size &lt; limit
 */
public static <T> Iterator<T> slice(Iterator<T> base, int start, int limit) {
    // fast-forward
    int skipped = skip(base,start);
    if (skipped < start){ //already at the end, nothing to return
            Iterators.emptyIterator();
    }
    return Iterators.limit(base, limit);
}
 
Example 20
Source File: DebugInfo.java    From ZjDroid with Apache License 2.0 votes vote down vote up
@Nonnull @Override public Iterator<DebugItem> iterator() { return Iterators.emptyIterator(); }