List of usage examples for org.apache.commons.collections.iterators SingletonIterator SingletonIterator
public SingletonIterator(Object object)
SingletonIterator
where remove
is a permitted operation. From source file:com.splicemachine.derby.stream.output.direct.DirectDataSetWriter.java
@Override public DataSet<LocatedRow> write() throws StandardException { try {/*from w w w . j a v a 2 s . c om*/ pipelineWriter.open(); CountingIterator rows = new CountingIterator(dataSet.values().toLocalIterator()); pipelineWriter.write(rows); pipelineWriter.close(); //make sure everything gets written ValueRow valueRow = new ValueRow(1); valueRow.setColumn(1, new SQLLongint(rows.count)); return new ControlDataSet<>(new SingletonIterator(new LocatedRow(valueRow))); } catch (Exception e) { throw Exceptions.parseException(e); } }
From source file:com.splicemachine.derby.stream.iterator.GetNLJoinOneRowIterator.java
@Override public Pair<OperationContext, Iterator<LocatedRow>> call() throws Exception { JoinOperation op = (JoinOperation) this.operationContext.getOperation(); op.getLeftOperation().setCurrentLocatedRow(this.locatedRow); SpliceOperation rightOperation = op.getRightOperation(); rightOperation.openCore(EngineDriver.driver().processorFactory().localProcessor(op.getActivation(), op)); Iterator<LocatedRow> rightSideNLJIterator = rightOperation.getLocatedRowIterator(); // Lets make sure we perform a call... boolean hasNext = rightSideNLJIterator.hasNext(); if (hasNext) { // For left outer join, if there is no match, return an empty row from right side LocatedRow lr = rightSideNLJIterator.next(); StreamLogUtils.logOperationRecordWithMessage(lr, operationContext, "outer - right side no rows"); op.setCurrentLocatedRow(lr);//w w w . java2s . c o m rightSideNLJIterator = new SingletonIterator(lr); } return new Pair<>(operationContext, rightSideNLJIterator); }
From source file:com.splicemachine.derby.stream.function.InnerJoinRestrictionFlatMapFunction.java
@Override public Iterator<LocatedRow> call(Tuple2<LocatedRow, Iterable<LocatedRow>> tuple) throws Exception { checkInit();/*from w w w .j a v a 2 s . com*/ leftRow = tuple._1(); Iterator<LocatedRow> it = tuple._2.iterator(); while (it.hasNext()) { rightRow = it.next(); mergedRow = JoinUtils.getMergedRow(leftRow.getRow(), rightRow.getRow(), op.wasRightOuterJoin, executionFactory.getValueRow(numberOfColumns)); op.setCurrentRow(mergedRow); if (op.getRestriction().apply(mergedRow)) { // Has Row, abandon LocatedRow lr = new LocatedRow(rightRow.getRowLocation(), mergedRow); op.setCurrentLocatedRow(lr); return new SingletonIterator(lr); } operationContext.recordFilter(); } return Collections.EMPTY_LIST.iterator(); }
From source file:com.splicemachine.derby.stream.iterator.GetNLJoinLeftOuterIterator.java
@Override public Pair<OperationContext, Iterator<LocatedRow>> call() throws Exception { JoinOperation op = (JoinOperation) this.operationContext.getOperation(); op.getLeftOperation().setCurrentLocatedRow(this.locatedRow); SpliceOperation rightOperation = op.getRightOperation(); rightOperation.openCore(EngineDriver.driver().processorFactory().localProcessor(op.getActivation(), op)); Iterator<LocatedRow> rightSideNLJIterator = rightOperation.getLocatedRowIterator(); // Lets make sure we perform a call... boolean hasNext = rightSideNLJIterator.hasNext(); if (!hasNext) { // For left outer join, if there is no match, return an empty row from right side LocatedRow lr = new LocatedRow(locatedRow.getRowLocation(), op.getEmptyRow()); StreamLogUtils.logOperationRecordWithMessage(lr, operationContext, "outer - right side no rows"); op.setCurrentLocatedRow(lr);// w w w . j a va 2 s. c om rightSideNLJIterator = new SingletonIterator(lr); } return new Pair<>(operationContext, rightSideNLJIterator); }
From source file:com.splicemachine.derby.stream.iterator.GetNLJoinAntiIterator.java
@Override public Pair<OperationContext, Iterator<LocatedRow>> call() throws Exception { JoinOperation op = (JoinOperation) this.operationContext.getOperation(); op.getLeftOperation().setCurrentLocatedRow(this.locatedRow); SpliceOperation rightOperation = op.getRightOperation(); rightOperation.openCore(EngineDriver.driver().processorFactory().localProcessor(op.getActivation(), op)); Iterator<LocatedRow> rightSideNLJIterator = rightOperation.getLocatedRowIterator(); // Lets make sure we perform a call... boolean hasNext = rightSideNLJIterator.hasNext(); if (!hasNext) { // For anti join, if there is no match on the right side, return an empty row LocatedRow lr = new LocatedRow(locatedRow.getRowLocation(), op.getEmptyRow()); StreamLogUtils.logOperationRecordWithMessage(lr, operationContext, "outer - right side no rows"); op.setCurrentLocatedRow(lr);//www .j av a 2 s .c o m rightSideNLJIterator = new SingletonIterator(lr); } else { rightSideNLJIterator = Collections.<LocatedRow>emptyList().iterator(); } return new Pair<>(operationContext, rightSideNLJIterator); }
From source file:com.splicemachine.derby.stream.function.MergeAllAggregatesFlatMapFunction.java
@SuppressWarnings("unchecked") @Override//from w w w . ja va 2 s. c om public Iterator<LocatedRow> call(Iterator<LocatedRow> locatedRows) throws Exception { if (!locatedRows.hasNext()) { return returnDefault ? new SingletonIterator(new LocatedRow(getOperation().getExecRowDefinition())) : Collections.EMPTY_LIST.iterator(); } if (!initialized) { op = (GenericAggregateOperation) getOperation(); aggregates = op.aggregates; initialized = true; } ExecRow r1 = locatedRows.next().getRow(); for (SpliceGenericAggregator aggregator : aggregates) { if (!aggregator.isInitialized(r1)) { // if (RDDUtils.LOG.isTraceEnabled()) { // RDDUtils.LOG.trace(String.format("Initializing and accumulating %s", r1)); // } aggregator.initializeAndAccumulateIfNeeded(r1, r1); } } while (locatedRows.hasNext()) { ExecRow r2 = locatedRows.next().getRow(); for (SpliceGenericAggregator aggregator : aggregates) { if (!aggregator.isInitialized(r2)) { // if (RDDUtils.LOG.isTraceEnabled()) { // RDDUtils.LOG.trace(String.format("Accumulating %s to %s", r2, r1)); // } aggregator.accumulate(r2, r1); } else { // if (RDDUtils.LOG.isTraceEnabled()) { // RDDUtils.LOG.trace(String.format("Merging %s to %s", r2, r1)); // } aggregator.merge(r2, r1); } } } op.finishAggregation(r1); // calls setCurrentRow return new SingletonIterator(new LocatedRow(r1)); }
From source file:com.splicemachine.derby.stream.function.AntiJoinRestrictionFlatMapFunction.java
@Override public Iterator<LocatedRow> call(Tuple2<LocatedRow, Iterable<LocatedRow>> tuple) throws Exception { checkInit();/*from w ww .ja v a 2 s.c o m*/ leftRow = tuple._1(); Iterator<LocatedRow> it = tuple._2.iterator(); while (it.hasNext()) { rightRow = it.next(); mergedRow = JoinUtils.getMergedRow(leftRow.getRow(), rightRow.getRow(), op.wasRightOuterJoin, executionFactory.getValueRow(numberOfColumns)); op.setCurrentRow(mergedRow); if (op.getRestriction().apply(mergedRow)) { // Has Row, abandon operationContext.recordFilter(); return Collections.<LocatedRow>emptyList().iterator(); } } // No Rows Matched... LocatedRow returnRow = new LocatedRow(leftRow.getRowLocation(), JoinUtils.getMergedRow(leftRow.getRow(), op.getEmptyRow(), op.wasRightOuterJoin, executionFactory.getValueRow(numberOfColumns))); op.setCurrentLocatedRow(returnRow); return new SingletonIterator(returnRow); }
From source file:com.splicemachine.derby.stream.function.NormalizeFunction.java
@Override public Iterator<LocatedRow> call(LocatedRow sourceRow) throws Exception { NormalizeOperation normalize = operationContext.getOperation(); normalize.source.setCurrentLocatedRow(sourceRow); if (sourceRow != null) { ExecRow normalized = null;/*from w w w .j av a 2s . c o m*/ try { normalized = normalize.normalizeRow(sourceRow.getRow(), true); } catch (StandardException e) { if (operationContext != null && operationContext.isPermissive()) { operationContext.recordBadRecord(e.getLocalizedMessage() + sourceRow.toString(), e); return Collections.<LocatedRow>emptyList().iterator(); } throw e; } getActivation().setCurrentRow(normalized, normalize.getResultSetNumber()); return new SingletonIterator(new LocatedRow(sourceRow.getRowLocation(), normalized.getClone())); } else return Collections.<LocatedRow>emptyList().iterator(); }
From source file:com.jaspersoft.jasperserver.api.metadata.security.BasicMethodCollectionArgumentVoter.java
protected Iterator getObjectsIterator(Object secureObject) { Iterator<?> iterator;//from w w w .ja va2s . co m if (secureObject instanceof Collection) { iterator = ((Collection) secureObject).iterator(); } else if (secureObject != null && secureObject.getClass().isArray()) { iterator = new ArrayIterator(secureObject); } else { iterator = new SingletonIterator(secureObject); } return iterator; }
From source file:com.splicemachine.derby.stream.function.ProjectRestrictFlatMapFunction.java
@Override public Iterator<LocatedRow> call(LocatedRow from) throws Exception { if (!initialized) { initialized = true;/*w w w .jav a2 s .com*/ op = (ProjectRestrictOperation) getOperation(); executionFactory = op.getExecutionFactory(); } op.setCurrentRow(from.getRow()); op.source.setCurrentRow(from.getRow()); if (!op.getRestriction().apply(from.getRow())) { operationContext.recordFilter(); return Collections.<LocatedRow>emptyList().iterator(); } ExecRow preCopy = op.doProjection(from.getRow()); LocatedRow locatedRow = new LocatedRow(from.getRowLocation(), preCopy); op.setCurrentLocatedRow(locatedRow); return new SingletonIterator(locatedRow); }