@Override public Number[] transform(final InputRow inputRow) { final long id; if (IdType.ROW_NUMBER == idType) { id = inputRow.getId(); } else { id = _counter.incrementAndGet(); } return new Number[] { id }; }
private long getNextVirtualRowId(final InputRow row, final int recordNo) { if (_idGenerator == null) { // this can more or less never happen, except in test cases or in // cases where the consumers are programmatically being used outside // of an AnalysisRunner. There's a risk then here that we get the // same row ID twice, but that's life :-P final long offset = Long.MAX_VALUE; final long hiLoIntervalOffset = row.getId() * 10000; return offset - hiLoIntervalOffset + recordNo; } return _idGenerator.nextVirtualRowId(); }
/** * Constructs a {@link TransformedInputRow} based on another row and a row * ID. * * @param delegate * @param rowId */ public TransformedInputRow(final InputRow delegate, final Number rowId) { if (delegate == null) { throw new IllegalArgumentException("Delegate cannot be null"); } _delegate = delegate; if (rowId == null) { _id = delegate.getId(); } else { _id = rowId.longValue(); } _values = new LinkedHashMap<>(); }
/** * Constructs a {@link TransformedInputRow} based on another row, or returns * the row if it is already a {@link TransformedInputRow}. * * @param row * @return */ public static TransformedInputRow of(final InputRow row) { if (row instanceof TransformedInputRow) { // re-use existing transformed input row. return (TransformedInputRow) row; } else { return new TransformedInputRow(row, row.getId()); } }
@Override public void run(final InputRow row, final int distinctCount) { if (list == null) { throw new IllegalStateException( "It seems that initialize() has not been invoked on component: " + identifier); } final long id = row.getId(); if (id % 3 == 0) { // one third of the times we will write to our result list list.add(id); } else { // other times we will write to the collectors that are available if (collector1 != null) { collector1.putValues("bar", new Date()); } if (collector2 != null) { final int count = counter.incrementAndGet(); final String uuid = UUID.randomUUID().toString(); collector2.putValues(count, uuid); } } }
@Override public void run(final InputRow row, final int distinctCount) { if (row.getId() % 2 == 0) { final List<Object> values = row.getValues(columns); collector.putValues(values); } }
@Override public Object[] transform(final InputRow inputRow) { final Object[] result = new Object[_initializedUnits.length]; for (int i = 0; i < _initializedUnits.length; i++) { final CoalesceUnit unit = _initializedUnits[i]; final InputColumn<?>[] inputColumns = unit.getInputColumns(); final List<Object> values = inputRow.getValues(inputColumns); final Object value = _coalesceFunction.coalesce(values); result[i] = value; } if (logger.isDebugEnabled()) { logger.debug("Coalesced values for row {}: {}", inputRow.getId(), Arrays.toString(result)); } return result; } }
@Override public Object[] transform(final InputRow parentInputRow) { final MockInputRow wrappedInputRow = new MockInputRow(parentInputRow.getId()); final Set<Entry<InputColumn<?>, InputColumn<?>>> conversionEntries = _inputColumnConversion.entrySet(); for (final Entry<InputColumn<?>, InputColumn<?>> conversionEntry : conversionEntries) { final InputColumn<?> parentColumn = conversionEntry.getKey(); final Object value = parentInputRow.getValue(parentColumn); final InputColumn<?> wrappedColumn = conversionEntry.getValue(); wrappedInputRow.put(wrappedColumn, value); } final List<InputRow> outputRows = _consumeRowHandler.consumeRow(wrappedInputRow).getRows(); for (final InputRow wrappedOutputRow : outputRows) { final Object[] outputValues = convertToOutputValues(wrappedOutputRow); _outputRowCollector.putValues(outputValues); } return null; }
final long rowId = row.getId();
/** * Thread-safe transformation method that runs transformer for an 'inputRow' * and puts a list of output rows to the 'results' map (key is the row ID). */ private void transform(InputRow inputRow, Map<Long, List<Object[]>> results) { ThreadLocalOutputListener outputListener = new ThreadLocalOutputListener(); final Set<ProvidedPropertyDescriptor> outputRowCollectorProperties = descriptor .getProvidedPropertiesByType(OutputRowCollector.class); try { // register output values listener in the transformer row collectors. registerOutputListener(outputRowCollectorProperties, outputListener); Object[] values = ((Transformer) component).transform(inputRow); if(values != null) { outputListener.onValues(values); } synchronized (results) { results.put(inputRow.getId(), outputListener.outputRows); } } finally { // unregister output values listener unregisterOutputListener(outputRowCollectorProperties); } }
final InputRow inputRow = inputRowIterator.next(); consumeRowHandler.consumeRow(inputRow); logger.debug("Consumed row no. {}", inputRow.getId());